38constexpr char hexdigit(
unsigned X,
bool LowerCase =
false) noexcept {
39 const char HexChar = LowerCase ?
'a' :
'A';
40 return X < 10 ?
'0' + X : HexChar + X - 10;
48 if (C >=
'0' && C <=
'9') {
51 if (C >=
'a' && C <=
'f') {
54 if (C >=
'A' && C <=
'F') {
57 return (std::numeric_limits<unsigned>::max)();
62 return C >=
'0' && C <=
'9';
67 return hexDigitValue(C) != (std::numeric_limits<unsigned>::max)();
72 return (
'a' <= C && C <=
'z') || (
'A' <= C && C <=
'Z');
83 return static_cast<unsigned char>(C) <= 127;
91 unsigned char UC =
static_cast<unsigned char>(C);
92 return (0x20 <= UC) && (UC <= 0x7E);
97 if (x >=
'A' && x <=
'Z') {
105 if (x >=
'a' && x <=
'z') {
106 return x -
'a' +
'A';
112 bool lowerCase =
false) {
114 char* bufptr = std::end(buf);
121 unsigned char mod =
static_cast<unsigned char>(val) & 15;
126 return std::string(bufptr, std::end(buf));
133constexpr bool equals(std::string_view lhs, std::string_view rhs)
noexcept {
134 auto length = lhs.size();
136 lhs.data(), rhs.data(), length) == 0;
148 std::string_view rhs)
noexcept {
149 return lhs.size() == rhs.size() &&
compare_lower(lhs, rhs) == 0;
159 std::string_view str,
char ch,
160 std::string_view::size_type
from = 0) noexcept;
191 std::string_view str,
char ch,
192 std::string_view::size_type
from = std::string_view::npos)
noexcept;
201 std::string_view other)
noexcept;
209inline std::string_view::size_type
rfind_lower(std::string_view str,
210 const char* other)
noexcept {
226 std::string_view str, std::string_view::size_type start,
227 std::string_view::size_type n = std::string_view::npos)
noexcept {
228 auto length = str.size();
229 start = (std::min)(start, length);
230 return {str.data() + start, (std::min)(n, length - start)};
237 std::string_view prefix)
noexcept {
238 return substr(str, 0, prefix.size()) == prefix;
244constexpr bool starts_with(std::string_view str,
char prefix)
noexcept {
245 return !str.empty() && std::string_view::traits_type::eq(str.front(), prefix);
251constexpr bool starts_with(std::string_view str,
const char* prefix)
noexcept {
271 const char* prefix)
noexcept {
279 std::string_view suffix)
noexcept {
280 return str.size() >= suffix.size() &&
281 str.compare(str.size() - suffix.size(), std::string_view::npos,
288constexpr bool ends_with(std::string_view str,
char suffix)
noexcept {
289 return !str.empty() && std::string_view::traits_type::eq(str.back(), suffix);
295constexpr bool ends_with(std::string_view str,
const char* suffix)
noexcept {
296 return ends_with(str, std::string_view(suffix));
321constexpr bool contains(std::string_view str, std::string_view other)
noexcept {
322 return str.find(other) != std::string_view::npos;
328constexpr bool contains(std::string_view str,
char ch)
noexcept {
329 return str.find(ch) != std::string_view::npos;
335constexpr bool contains(std::string_view str,
const char* other)
noexcept {
336 return str.find(other) != std::string_view::npos;
343 std::string_view other)
noexcept {
344 return find_lower(str, other) != std::string_view::npos;
351 return find_lower(str, ch) != std::string_view::npos;
358 return find_lower(str, other) != std::string_view::npos;
366constexpr std::optional<std::string_view>
remove_prefix(std::string_view str, std::string_view prefix)
noexcept {
367 if (str.starts_with(prefix)) {
368 str.remove_prefix(prefix.size());
379constexpr std::optional<std::string_view>
remove_suffix(std::string_view str, std::string_view suffix)
noexcept {
380 if (str.ends_with(suffix)) {
381 str.remove_suffix(suffix.size());
392 std::string_view str, std::string_view::size_type n = 1) noexcept {
401 std::string_view str, std::string_view::size_type n = 1) noexcept {
402 str.remove_suffix(n);
412 std::string_view str, std::string_view::size_type n = 1) noexcept {
413 auto length = str.size();
426 std::string_view str, std::string_view::size_type n = 1) noexcept {
427 auto length = str.size();
447constexpr std::string_view
slice(std::string_view str,
448 std::string_view::size_type start,
449 std::string_view::size_type end)
noexcept {
450 auto length = str.size();
451 start = (std::min)(start, length);
452 end = (std::min)((std::max)(start, end), length);
453 return {str.data() + start, end - start};
468constexpr std::pair<std::string_view, std::string_view>
split(
469 std::string_view str,
char separator)
noexcept {
470 auto idx = str.find(separator);
471 if (idx == std::string_view::npos) {
474 return {
slice(str, 0, idx),
slice(str, idx + 1, std::string_view::npos)};
489constexpr std::pair<std::string_view, std::string_view>
split(
490 std::string_view str, std::string_view separator)
noexcept {
491 auto idx = str.find(separator);
492 if (idx == std::string_view::npos) {
495 return {
slice(str, 0, idx),
496 slice(str, idx + separator.size(), std::string_view::npos)};
511constexpr std::pair<std::string_view, std::string_view>
rsplit(
512 std::string_view str,
char separator)
noexcept {
513 auto idx = str.rfind(separator);
514 if (idx == std::string_view::npos) {
517 return {
slice(str, 0, idx),
slice(str, idx + 1, std::string_view::npos)};
532constexpr std::pair<std::string_view, std::string_view>
rsplit(
533 std::string_view str, std::string_view separator)
noexcept {
534 auto idx = str.rfind(separator);
535 if (idx == std::string_view::npos) {
538 return {
slice(str, 0, idx),
539 slice(str, idx + separator.size(), std::string_view::npos)};
558template <std::invocable<std::
string_view> F>
559void split(std::string_view str, std::string_view separator,
int maxSplit,
560 bool keepEmpty, F&& func) {
561 std::string_view s = str;
567 while (maxSplit-- != 0) {
568 auto idx = s.find(separator);
569 if (idx == std::string_view::npos) {
574 if (keepEmpty || idx > 0) {
575 func(
slice(s, 0, idx));
579 s =
slice(s, idx + separator.size(), std::string_view::npos);
583 if (keepEmpty || !s.empty()) {
605template <std::invocable<std::
string_view> F>
606void split(std::string_view str,
char separator,
int maxSplit,
bool keepEmpty,
608 std::string_view s = str;
614 while (maxSplit-- != 0) {
615 size_t idx = s.find(separator);
616 if (idx == std::string_view::npos) {
621 if (keepEmpty || idx > 0) {
622 func(
slice(s, 0, idx));
626 s =
slice(s, idx + 1, std::string_view::npos);
630 if (keepEmpty || !s.empty()) {
639constexpr std::string_view
ltrim(std::string_view str,
char ch)
noexcept {
640 return drop_front(str, (std::min)(str.size(), str.find_first_not_of(ch)));
648 std::string_view str, std::string_view chars =
" \t\n\v\f\r") noexcept {
649 return drop_front(str, (std::min)(str.size(), str.find_first_not_of(chars)));
656constexpr std::string_view
rtrim(std::string_view str,
char ch)
noexcept {
658 str, str.size() - (std::min)(str.size(), str.find_last_not_of(ch) + 1));
666 std::string_view str, std::string_view chars =
" \t\n\v\f\r") noexcept {
669 str.size() - (std::min)(str.size(), str.find_last_not_of(chars) + 1));
676constexpr std::string_view
trim(std::string_view str,
char ch)
noexcept {
684constexpr std::string_view
trim(
685 std::string_view str, std::string_view chars =
" \t\n\v\f\r") noexcept {
691 std::string_view str,
unsigned radix,
692 unsigned long long& result)
noexcept;
694 long long& result)
noexcept;
697 std::string_view& str,
unsigned radix,
698 unsigned long long& result)
noexcept;
700 long long& result)
noexcept;
713 std::enable_if_t<std::numeric_limits<T>::is_signed,
bool> =
true>
715 unsigned radix)
noexcept {
718 static_cast<T
>(val) != val) {
725 std::enable_if_t<!std::numeric_limits<T>::is_signed,
bool> =
true>
727 unsigned radix)
noexcept {
728 using Int =
unsigned long long;
734 static_cast<Int
>(
static_cast<T
>(val)) != val) {
737 return static_cast<T
>(val);
752 std::enable_if_t<std::numeric_limits<T>::is_signed,
bool> =
true>
754 unsigned radix)
noexcept {
755 using Int =
long long;
758 static_cast<Int
>(
static_cast<T
>(val)) != val) {
765 std::enable_if_t<!std::numeric_limits<T>::is_signed,
bool> =
true>
767 unsigned radix)
noexcept {
768 using Int =
unsigned long long;
771 static_cast<Int
>(
static_cast<T
>(val)) != val) {
793 std::string_view str)
noexcept;
818template <
class OutputIt,
class... Args>
820 fmt::format_string<Args...> fmt, Args&&... args) {
822 fmt::format_to_n(out, n - 1, fmt, std::forward<Args>(args)...);
and restrictions which apply to each piece of software is included later in this file and or inside of the individual applicable source files The disclaimer of warranty in the WPILib license above applies to all code in and nothing in any of the other licenses gives permission to use the names of FIRST nor the names of the WPILib contributors to endorse or promote products derived from this software The following pieces of software have additional or alternate and or glfw and nanopb were modified for use in Google Inc All rights reserved Redistribution and use in source and binary with or without are permitted provided that the following conditions are this list of conditions and the following disclaimer *Redistributions in binary form must reproduce the above copyright this list of conditions and the following disclaimer in the documentation and or other materials provided with the distribution *Neither the name of Google Inc nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY EXPRESS OR IMPLIED BUT NOT LIMITED THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY OR CONSEQUENTIAL WHETHER IN STRICT OR EVEN IF ADVISED OF THE POSSIBILITY OF SUCH January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation and configuration files Object form shall mean any form resulting from mechanical transformation or translation of a Source including but not limited to compiled object generated and conversions to other media types Work shall mean the work of whether in Source or Object made available under the as indicated by a copyright notice that is included in or attached to the whether in Source or Object that is based or other modifications as a an original work of authorship For the purposes of this Derivative Works shall not include works that remain separable from
Definition ThirdPartyNotices.txt:140
FMT_CONSTEXPR void remove_prefix(size_t n) noexcept
Definition base.h:572
FMT_CONSTEXPR auto compare(basic_string_view other) const -> int
Definition base.h:588
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition sha1.h:30
detail namespace with internal helper functions
Definition input_adapters.h:32
Definition PointerIntPair.h:280
bool GetAsSignedInteger(std::string_view str, unsigned radix, long long &result) noexcept
bool ConsumeUnsignedInteger(std::string_view &str, unsigned radix, unsigned long long &result) noexcept
bool GetAsUnsignedInteger(std::string_view str, unsigned radix, unsigned long long &result) noexcept
bool ConsumeSignedInteger(std::string_view &str, unsigned radix, long long &result) noexcept
Definition ntcore_cpp.h:26
constexpr char hexdigit(unsigned X, bool LowerCase=false) noexcept
hexdigit - Return the hexadecimal character for the given number X (which should be less than 16).
Definition StringExtras.h:38
constexpr std::string_view slice(std::string_view str, std::string_view::size_type start, std::string_view::size_type end) noexcept
Returns a reference to the substring of str from [start, end).
Definition StringExtras.h:447
constexpr std::pair< std::string_view, std::string_view > split(std::string_view str, char separator) noexcept
Splits str into two substrings around the first occurrence of a separator character.
Definition StringExtras.h:468
int compare_lower(std::string_view lhs, std::string_view rhs) noexcept
compare_lower - Compare two strings, ignoring case.
constexpr std::optional< std::string_view > remove_prefix(std::string_view str, std::string_view prefix) noexcept
Return an optional containing str but with prefix removed if the string starts with the prefix.
Definition StringExtras.h:366
constexpr std::string_view ltrim(std::string_view str, char ch) noexcept
Returns str with consecutive ch characters starting from the the left removed.
Definition StringExtras.h:639
constexpr std::span< T > drop_back(std::span< T, N > in, typename std::span< T >::size_type n=1)
Drop the last N elements of the array.
Definition SpanExtras.h:22
constexpr std::span< T > drop_front(std::span< T, N > in, typename std::span< T >::size_type n=1)
Drop the first N elements of the array.
Definition SpanExtras.h:14
std::optional< double > parse_float< double >(std::string_view str) noexcept
constexpr bool isAlnum(char C) noexcept
Checks whether character C is either a decimal digit or an uppercase or lowercase letter as classifie...
Definition StringExtras.h:77
std::optional< T > consume_integer(std::string_view *str, unsigned radix) noexcept
Parses the string str as an integer of the specified radix.
Definition StringExtras.h:753
std::string_view::size_type find_lower(std::string_view str, char ch, std::string_view::size_type from=0) noexcept
Search for the first character ch in str, ignoring case.
constexpr bool isHexDigit(char C) noexcept
Checks if character C is a hexadecimal numeric character.
Definition StringExtras.h:66
constexpr bool isDigit(char C) noexcept
Checks if character C is one of the 10 decimal digits.
Definition StringExtras.h:61
std::optional< T > parse_integer(std::string_view str, unsigned radix) noexcept
Parses the string str as an integer of the specified radix.
Definition StringExtras.h:714
constexpr unsigned hexDigitValue(char C) noexcept
Interpret the given character C as a hexadecimal digit and return its value.
Definition StringExtras.h:47
constexpr char toLower(char x) noexcept
Returns the corresponding lowercase character if x is uppercase.
Definition StringExtras.h:96
constexpr std::optional< std::string_view > remove_suffix(std::string_view str, std::string_view suffix) noexcept
Return an optional containing str but with suffix removed if the string ends with the suffix.
Definition StringExtras.h:379
constexpr std::string_view trim(std::string_view str, char ch) noexcept
Returns str with consecutive ch characters starting from the left and right removed.
Definition StringExtras.h:676
constexpr char toUpper(char x) noexcept
Returns the corresponding uppercase character if x is lowercase.
Definition StringExtras.h:104
constexpr std::span< T > take_front(std::span< T, N > in, typename std::span< T >::size_type n=1)
Returns a span equal to in but with only the first n elements remaining.
Definition SpanExtras.h:34
constexpr bool contains(std::string_view str, std::string_view other) noexcept
Checks if str contains the substring other.
Definition StringExtras.h:321
bool ends_with_lower(std::string_view str, std::string_view suffix) noexcept
Checks if str ends with the given suffix, ignoring case.
std::string_view::size_type rfind_lower(std::string_view str, char ch, std::string_view::size_type from=std::string_view::npos) noexcept
Search for the last character ch in str, ignoring case.
bool starts_with_lower(std::string_view str, std::string_view prefix) noexcept
Checks if str starts with the given prefix, ignoring case.
constexpr bool equals_lower(std::string_view lhs, std::string_view rhs) noexcept
equals_lower - Check for string equality, ignoring case.
Definition StringExtras.h:147
std::optional< long double > parse_float< long double >(std::string_view str) noexcept
constexpr std::pair< std::string_view, std::string_view > rsplit(std::string_view str, char separator) noexcept
Splits str into two substrings around the last occurrence of a separator character.
Definition StringExtras.h:511
constexpr std::string_view substr(std::string_view str, std::string_view::size_type start, std::string_view::size_type n=std::string_view::npos) noexcept
Returns the substring of str from [start, start + n).
Definition StringExtras.h:225
constexpr bool equals(std::string_view lhs, std::string_view rhs) noexcept
equals - Check for string equality, this is more efficient than compare() when the relative ordering ...
Definition StringExtras.h:133
constexpr T mod(U Numerator, V Denominator)
Returns the remainder of the Euclidean division of LHS by RHS.
Definition MathExtras.h:432
constexpr bool isPrint(char C) noexcept
Checks whether character C is printable.
Definition StringExtras.h:90
constexpr std::span< T > take_back(std::span< T, N > in, typename std::span< T >::size_type n=1)
Returns a span equal to in but with only the last n elements remaining.
Definition SpanExtras.h:49
std::pair< std::string_view, std::string_view > UnescapeCString(std::string_view str, SmallVectorImpl< char > &buf)
Unescapes a C-style string (reverse operation to raw_ostream::write_escaped).
void format_to_n_c_str(OutputIt out, std::iter_difference_t< OutputIt > n, fmt::format_string< Args... > fmt, Args &&... args)
Like std::format_to_n() in that it writes at most n bytes to the output buffer, but also includes a t...
Definition StringExtras.h:819
constexpr bool isASCII(char C) noexcept
Checks whether character C is valid ASCII (high bit is zero).
Definition StringExtras.h:82
constexpr bool isAlpha(char C) noexcept
Checks if character C is a valid letter as classified by "C" locale.
Definition StringExtras.h:71
constexpr std::string_view rtrim(std::string_view str, char ch) noexcept
Returns str with consecutive Char characters starting from the right removed.
Definition StringExtras.h:656
std::optional< T > parse_float(std::string_view str) noexcept
Parses the string str as a floating point value.
constexpr bool ends_with(std::string_view str, std::string_view suffix) noexcept
Checks if str ends with the given suffix.
Definition StringExtras.h:278
std::string utohexstr(unsigned long long val, bool lowerCase=false)
Definition StringExtras.h:111
std::optional< float > parse_float< float >(std::string_view str) noexcept
constexpr bool starts_with(std::string_view str, std::string_view prefix) noexcept
Checks if str starts with the given prefix.
Definition StringExtras.h:236
bool contains_lower(std::string_view str, std::string_view other) noexcept
Checks if str contains the substring other, ignoring case.
Definition StringExtras.h:342