WPILibC++ 2023.4.3-108-ge5452e3
StringExtras.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5//===- llvm/ADT/StringExtras.h - Useful string functions --------*- C++ -*-===//
6//
7// The LLVM Compiler Infrastructure
8//
9// This file is distributed under the University of Illinois Open Source
10// License. See LICENSE.TXT for details.
11//
12//===----------------------------------------------------------------------===//
13//
14// This file contains some functions that are useful when dealing with strings.
15//
16//===----------------------------------------------------------------------===//
17
18#pragma once
19
20#include <limits>
21#include <optional>
22#include <string>
23#include <string_view>
24#include <type_traits>
25#include <utility>
26
27namespace wpi {
28
29template <typename T>
30class SmallVectorImpl;
31
32/// hexdigit - Return the hexadecimal character for the
33/// given number \p X (which should be less than 16).
34constexpr char hexdigit(unsigned X, bool LowerCase = false) noexcept {
35 const char HexChar = LowerCase ? 'a' : 'A';
36 return X < 10 ? '0' + X : HexChar + X - 10;
37}
38
39/// Interpret the given character \p C as a hexadecimal digit and return its
40/// value.
41///
42/// If \p C is not a valid hex digit, -1U is returned.
43constexpr unsigned hexDigitValue(char C) noexcept {
44 if (C >= '0' && C <= '9') {
45 return C - '0';
46 }
47 if (C >= 'a' && C <= 'f') {
48 return C - 'a' + 10U;
49 }
50 if (C >= 'A' && C <= 'F') {
51 return C - 'A' + 10U;
52 }
54}
55
56/// Checks if character \p C is one of the 10 decimal digits.
57constexpr bool isDigit(char C) noexcept {
58 return C >= '0' && C <= '9';
59}
60
61/// Checks if character \p C is a hexadecimal numeric character.
62constexpr bool isHexDigit(char C) noexcept {
64}
65
66/// Checks if character \p C is a valid letter as classified by "C" locale.
67constexpr bool isAlpha(char C) noexcept {
68 return ('a' <= C && C <= 'z') || ('A' <= C && C <= 'Z');
69}
70
71/// Checks whether character \p C is either a decimal digit or an uppercase or
72/// lowercase letter as classified by "C" locale.
73constexpr bool isAlnum(char C) noexcept {
74 return isAlpha(C) || isDigit(C);
75}
76
77/// Checks whether character \p C is valid ASCII (high bit is zero).
78constexpr bool isASCII(char C) noexcept {
79 return static_cast<unsigned char>(C) <= 127;
80}
81
82/// Checks whether character \p C is printable.
83///
84/// Locale-independent version of the C standard library isprint whose results
85/// may differ on different platforms.
86constexpr bool isPrint(char C) noexcept {
87 unsigned char UC = static_cast<unsigned char>(C);
88 return (0x20 <= UC) && (UC <= 0x7E);
89}
90
91/// Returns the corresponding lowercase character if \p x is uppercase.
92constexpr char toLower(char x) noexcept {
93 if (x >= 'A' && x <= 'Z') {
94 return x - 'A' + 'a';
95 }
96 return x;
97}
98
99/// Returns the corresponding uppercase character if \p x is lowercase.
100constexpr char toUpper(char x) noexcept {
101 if (x >= 'a' && x <= 'z') {
102 return x - 'a' + 'A';
103 }
104 return x;
105}
106
107inline std::string utohexstr(unsigned long long val, // NOLINT(runtime/int)
108 bool lowerCase = false) {
109 char buf[17];
110 char* bufptr = std::end(buf);
111
112 if (val == 0) {
113 *--bufptr = '0';
114 }
115
116 while (val) {
117 unsigned char mod = static_cast<unsigned char>(val) & 15;
118 *--bufptr = hexdigit(mod, lowerCase);
119 val >>= 4;
120 }
121
122 return std::string(bufptr, std::end(buf));
123}
124
125/**
126 * equals - Check for string equality, this is more efficient than
127 * compare() when the relative ordering of inequal strings isn't needed.
128 */
129constexpr bool equals(std::string_view lhs, std::string_view rhs) noexcept {
130 auto length = lhs.size();
131 return length == rhs.size() && std::string_view::traits_type::compare(
132 lhs.data(), rhs.data(), length) == 0;
133}
134
135/**
136 * compare_lower - Compare two strings, ignoring case.
137 */
139
140/**
141 * equals_lower - Check for string equality, ignoring case.
142 */
144 std::string_view rhs) noexcept {
145 return lhs.size() == rhs.size() && compare_lower(lhs, rhs) == 0;
146}
147
148/**
149 * Search for the first character @p ch in @p str, ignoring case.
150 *
151 * @returns The index of the first occurrence of @p ch, or npos if not
152 * found.
153 */
154std::string_view::size_type find_lower(
155 std::string_view str, char ch,
156 std::string_view::size_type from = 0) noexcept;
157
158/**
159 * Search for the first string @p other in @p str, ignoring case.
160 *
161 * @returns The index of the first occurrence of @p other, or npos if not
162 * found.
163 */
165 std::string_view str, std::string_view other,
166 std::string_view::size_type from = 0) noexcept;
167
168/**
169 * Search for the first string @p other in @p str, ignoring case.
170 *
171 * @returns The index of the first occurrence of @p other, or npos if not
172 * found.
173 */
174inline std::string_view::size_type find_lower(
175 std::string_view str, const char* other,
176 std::string_view::size_type from = 0) noexcept {
177 return find_lower(str, std::string_view{other}, from);
178}
179
180/**
181 * Search for the last character @p ch in @p str, ignoring case.
182 *
183 * @returns The index of the last occurrence of @p ch, or npos if not
184 * found.
185 */
186std::string_view::size_type rfind_lower(
187 std::string_view str, char ch,
188 std::string_view::size_type from = std::string_view::npos) noexcept;
189
190/**
191 * Search for the last string @p other in @p str, ignoring case.
192 *
193 * @returns The index of the last occurrence of @p other, or npos if not
194 * found.
195 */
196std::string_view::size_type rfind_lower(std::string_view str,
197 std::string_view other) noexcept;
198
199/**
200 * Search for the last string @p other in @p str, ignoring case.
201 *
202 * @returns The index of the last occurrence of @p other, or npos if not
203 * found.
204 */
205inline std::string_view::size_type rfind_lower(std::string_view str,
206 const char* other) noexcept {
207 return rfind_lower(str, std::string_view{other});
208}
209
210/**
211 * Returns the substring of @p str from [start, start + n).
212 *
213 * @param start The index of the starting character in the substring; if
214 * the index is npos or greater than the length of the string then the
215 * empty substring will be returned.
216 *
217 * @param n The number of characters to included in the substring. If n
218 * exceeds the number of characters remaining in the string, the string
219 * suffix (starting with @p start) will be returned.
220 */
222 std::string_view str, std::string_view::size_type start,
223 std::string_view::size_type n = std::string_view::npos) noexcept {
224 auto length = str.size();
225 start = (std::min)(start, length);
226 return {str.data() + start, (std::min)(n, length - start)};
227}
228
229/**
230 * Checks if @p str starts with the given @p prefix.
231 */
232constexpr bool starts_with(std::string_view str,
233 std::string_view prefix) noexcept {
234 return substr(str, 0, prefix.size()) == prefix;
235}
236
237/**
238 * Checks if @p str starts with the given @p prefix.
239 */
240constexpr bool starts_with(std::string_view str, char prefix) noexcept {
241 return !str.empty() && std::string_view::traits_type::eq(str.front(), prefix);
242}
243
244/**
245 * Checks if @p str starts with the given @p prefix.
246 */
247constexpr bool starts_with(std::string_view str, const char* prefix) noexcept {
248 return starts_with(str, std::string_view(prefix));
249}
250
251/**
252 * Checks if @p str starts with the given @p prefix, ignoring case.
253 */
255
256/**
257 * Checks if @p str starts with the given @p prefix, ignoring case.
258 */
259constexpr bool starts_with_lower(std::string_view str, char prefix) noexcept {
260 return !str.empty() && toLower(str.front()) == toLower(prefix);
261}
262
263/**
264 * Checks if @p str starts with the given @p prefix, ignoring case.
265 */
267 const char* prefix) noexcept {
268 return starts_with_lower(str, std::string_view(prefix));
269}
270
271/**
272 * Checks if @p str ends with the given @p suffix.
273 */
274constexpr bool ends_with(std::string_view str,
275 std::string_view suffix) noexcept {
276 return str.size() >= suffix.size() &&
277 str.compare(str.size() - suffix.size(), std::string_view::npos,
278 suffix) == 0;
279}
280
281/**
282 * Checks if @p str ends with the given @p suffix.
283 */
284constexpr bool ends_with(std::string_view str, char suffix) noexcept {
285 return !str.empty() && std::string_view::traits_type::eq(str.back(), suffix);
286}
287
288/**
289 * Checks if @p str ends with the given @p suffix.
290 */
291constexpr bool ends_with(std::string_view str, const char* suffix) noexcept {
292 return ends_with(str, std::string_view(suffix));
293}
294
295/**
296 * Checks if @p str ends with the given @p suffix, ignoring case.
297 */
299
300/**
301 * Checks if @p str ends with the given @p suffix, ignoring case.
302 */
303constexpr bool ends_with_lower(std::string_view str, char suffix) noexcept {
304 return !str.empty() && toLower(str.back()) == toLower(suffix);
305}
306
307/**
308 * Checks if @p str ends with the given @p suffix, ignoring case.
309 */
310inline bool ends_with_lower(std::string_view str, const char* suffix) noexcept {
311 return ends_with_lower(str, std::string_view(suffix));
312}
313
314/**
315 * Checks if @p str contains the substring @p other.
316 */
317constexpr bool contains(std::string_view str, std::string_view other) noexcept {
318 return str.find(other) != std::string_view::npos;
319}
320
321/**
322 * Checks if @p str contains the substring @p other.
323 */
324constexpr bool contains(std::string_view str, char ch) noexcept {
325 return str.find(ch) != std::string_view::npos;
326}
327
328/**
329 * Checks if @p str contains the substring @p other.
330 */
331constexpr bool contains(std::string_view str, const char* other) noexcept {
332 return str.find(other) != std::string_view::npos;
333}
334
335/**
336 * Checks if @p str contains the substring @p other, ignoring case.
337 */
339 std::string_view other) noexcept {
340 return find_lower(str, other) != std::string_view::npos;
341}
342
343/**
344 * Checks if @p str contains the substring @p other, ignoring case.
345 */
346inline bool contains_lower(std::string_view str, char ch) noexcept {
347 return find_lower(str, ch) != std::string_view::npos;
348}
349
350/**
351 * Checks if @p str contains the substring @p other, ignoring case.
352 */
353inline bool contains_lower(std::string_view str, const char* other) noexcept {
354 return find_lower(str, other) != std::string_view::npos;
355}
356
357/**
358 * Return a string_view equal to @p str but with the first @p n elements
359 * dropped.
360 */
362 std::string_view str, std::string_view::size_type n = 1) noexcept {
363 str.remove_prefix(n);
364 return str;
365}
366
367/**
368 * Return a string_view equal to @p str but with the last @p n elements dropped.
369 */
371 std::string_view str, std::string_view::size_type n = 1) noexcept {
372 str.remove_suffix(n);
373 return str;
374}
375
376/**
377 * Returns a view equal to @p str but with only the first @p n
378 * elements remaining. If @p n is greater than the length of the
379 * string, the entire string is returned.
380 */
382 std::string_view str, std::string_view::size_type n = 1) noexcept {
383 auto length = str.size();
384 if (n >= length) {
385 return str;
386 }
387 return drop_back(str, length - n);
388}
389
390/**
391 * Returns a view equal to @p str but with only the last @p n
392 * elements remaining. If @p n is greater than the length of the
393 * string, the entire string is returned.
394 */
396 std::string_view str, std::string_view::size_type n = 1) noexcept {
397 auto length = str.size();
398 if (n >= length) {
399 return str;
400 }
401 return drop_front(str, length - n);
402}
403
404/**
405 * Returns a reference to the substring of @p str from [start, end).
406 *
407 * @param start The index of the starting character in the substring; if
408 * the index is npos or greater than the length of the string then the
409 * empty substring will be returned.
410 *
411 * @param end The index following the last character to include in the
412 * substring. If this is npos or exceeds the number of characters
413 * remaining in the string, the string suffix (starting with @p start)
414 * will be returned. If this is less than @p start, an empty string will
415 * be returned.
416 */
418 std::string_view::size_type start,
419 std::string_view::size_type end) noexcept {
420 auto length = str.size();
421 start = (std::min)(start, length);
422 end = (std::min)((std::max)(start, end), length);
423 return {str.data() + start, end - start};
424}
425
426/**
427 * Splits @p str into two substrings around the first occurrence of a separator
428 * character.
429 *
430 * If @p separator is in the string, then the result is a pair (LHS, RHS)
431 * such that (str == LHS + separator + RHS) is true and RHS is
432 * maximal. If @p separator is not in the string, then the result is a
433 * pair (LHS, RHS) where (str == LHS) and (RHS == "").
434 *
435 * @param separator The character to split on.
436 * @returns The split substrings.
437 */
438constexpr std::pair<std::string_view, std::string_view> split(
439 std::string_view str, char separator) noexcept {
440 auto idx = str.find(separator);
441 if (idx == std::string_view::npos) {
442 return {str, {}};
443 }
444 return {slice(str, 0, idx), slice(str, idx + 1, std::string_view::npos)};
445}
446
447/**
448 * Splits @p str into two substrings around the first occurrence of a separator
449 * string.
450 *
451 * If @p separator is in the string, then the result is a pair (LHS, RHS)
452 * such that (str == LHS + separator + RHS) is true and RHS is
453 * maximal. If @p separator is not in the string, then the result is a
454 * pair (LHS, RHS) where (str == LHS) and (RHS == "").
455 *
456 * @param separator The string to split on.
457 * @return The split substrings.
458 */
459constexpr std::pair<std::string_view, std::string_view> split(
460 std::string_view str, std::string_view separator) noexcept {
461 auto idx = str.find(separator);
462 if (idx == std::string_view::npos) {
463 return {str, {}};
464 }
465 return {slice(str, 0, idx),
466 slice(str, idx + separator.size(), std::string_view::npos)};
467}
468
469/**
470 * Splits @p str into two substrings around the last occurrence of a separator
471 * character.
472 *
473 * If @p separator is in the string, then the result is a pair (LHS, RHS)
474 * such that (str == LHS + separator + RHS) is true and RHS is
475 * minimal. If @p separator is not in the string, then the result is a
476 * pair (LHS, RHS) where (str == LHS) and (RHS == "").
477 *
478 * @param separator The string to split on.
479 * @return The split substrings.
480 */
481constexpr std::pair<std::string_view, std::string_view> rsplit(
482 std::string_view str, char separator) noexcept {
483 auto idx = str.rfind(separator);
484 if (idx == std::string_view::npos) {
485 return {str, {}};
486 }
487 return {slice(str, 0, idx), slice(str, idx + 1, std::string_view::npos)};
488}
489
490/**
491 * Splits @p str into two substrings around the last occurrence of a separator
492 * string.
493 *
494 * If @p separator is in the string, then the result is a pair (LHS, RHS)
495 * such that (str == LHS + separator + RHS) is true and RHS is
496 * minimal. If @p separator is not in the string, then the result is a
497 * pair (LHS, RHS) where (str == LHS) and (RHS == "").
498 *
499 * @param separator The string to split on.
500 * @return The split substrings.
501 */
502constexpr std::pair<std::string_view, std::string_view> rsplit(
503 std::string_view str, std::string_view separator) noexcept {
504 auto idx = str.rfind(separator);
505 if (idx == std::string_view::npos) {
506 return {str, {}};
507 }
508 return {slice(str, 0, idx),
509 slice(str, idx + separator.size(), std::string_view::npos)};
510}
511
512/**
513 * Splits @p str into substrings around the occurrences of a separator string.
514 *
515 * Each substring is stored in @p arr. If @p maxSplit is >= 0, at most
516 * @p maxSplit splits are done and consequently <= @p maxSplit + 1
517 * elements are added to arr.
518 * If @p keepEmpty is false, empty strings are not added to @p arr. They
519 * still count when considering @p maxSplit
520 * An useful invariant is that
521 * separator.join(arr) == str if maxSplit == -1 and keepEmpty == true
522 *
523 * @param arr Where to put the substrings.
524 * @param separator The string to split on.
525 * @param maxSplit The maximum number of times the string is split.
526 * @param keepEmpty True if empty substring should be added.
527 */
529 std::string_view separator, int maxSplit = -1,
530 bool keepEmpty = true) noexcept;
531
532/**
533 * Splits @p str into substrings around the occurrences of a separator
534 * character.
535 *
536 * Each substring is stored in @p arr. If @p maxSplit is >= 0, at most
537 * @p maxSplit splits are done and consequently <= @p maxSplit + 1
538 * elements are added to arr.
539 * If @p keepEmpty is false, empty strings are not added to @p arr. They
540 * still count when considering @p maxSplit
541 * An useful invariant is that
542 * separator.join(arr) == str if maxSplit == -1 and keepEmpty == true
543 *
544 * @param arr Where to put the substrings.
545 * @param separator The character to split on.
546 * @param maxSplit The maximum number of times the string is split.
547 * @param keepEmpty True if empty substring should be added.
548 */
550 char separator, int maxSplit = -1, bool keepEmpty = true) noexcept;
551
552/**
553 * Returns @p str with consecutive @p ch characters starting from the
554 * the left removed.
555 */
556constexpr std::string_view ltrim(std::string_view str, char ch) noexcept {
557 return drop_front(str, (std::min)(str.size(), str.find_first_not_of(ch)));
558}
559
560/**
561 * Returns @p str with consecutive characters in @p chars starting from
562 * the left removed.
563 */
565 std::string_view str, std::string_view chars = " \t\n\v\f\r") noexcept {
566 return drop_front(str, (std::min)(str.size(), str.find_first_not_of(chars)));
567}
568
569/**
570 * Returns @p str with consecutive @p Char characters starting from the
571 * right removed.
572 */
573constexpr std::string_view rtrim(std::string_view str, char ch) noexcept {
574 return drop_back(
575 str, str.size() - (std::min)(str.size(), str.find_last_not_of(ch) + 1));
576}
577
578/**
579 * Returns @p str with consecutive characters in @p chars starting from
580 * the right removed.
581 */
583 std::string_view str, std::string_view chars = " \t\n\v\f\r") noexcept {
584 return drop_back(
585 str,
586 str.size() - (std::min)(str.size(), str.find_last_not_of(chars) + 1));
587}
588
589/**
590 * Returns @p str with consecutive @p ch characters starting from the
591 * left and right removed.
592 */
593constexpr std::string_view trim(std::string_view str, char ch) noexcept {
594 return rtrim(ltrim(str, ch), ch);
595}
596
597/**
598 * Returns @p str with consecutive characters in @p chars starting from
599 * the left and right removed.
600 */
602 std::string_view str, std::string_view chars = " \t\n\v\f\r") noexcept {
603 return rtrim(ltrim(str, chars), chars);
604}
605
606namespace detail {
608 std::string_view str, unsigned radix,
609 unsigned long long& result) noexcept; // NOLINT(runtime/int)
610bool GetAsSignedInteger(std::string_view str, unsigned radix,
611 long long& result) noexcept; // NOLINT(runtime/int)
612
614 std::string_view& str, unsigned radix,
615 unsigned long long& result) noexcept; // NOLINT(runtime/int)
616bool ConsumeSignedInteger(std::string_view& str, unsigned radix,
617 long long& result) noexcept; // NOLINT(runtime/int)
618} // namespace detail
619
620/**
621 * Parses the string @p str as an integer of the specified radix. If
622 * @p radix is specified as zero, this does radix autosensing using
623 * extended C rules: 0 is octal, 0x is hex, 0b is binary.
624 *
625 * If the string is invalid or if only a subset of the string is valid,
626 * this returns nullopt to signify the error. The string is considered
627 * erroneous if empty or if it overflows T.
628 */
629template <typename T,
631inline std::optional<T> parse_integer(std::string_view str,
632 unsigned radix) noexcept {
633 long long val; // NOLINT(runtime/int)
634 if (detail::GetAsSignedInteger(str, radix, val) ||
635 static_cast<T>(val) != val) {
636 return std::nullopt;
637 }
638 return val;
639}
640
641template <typename T,
643inline std::optional<T> parse_integer(std::string_view str,
644 unsigned radix) noexcept {
645 using Int = unsigned long long; // NOLINT(runtime/int)
646 Int val;
647 // The additional cast to unsigned long long is required to avoid the
648 // Visual C++ warning C4805: '!=' : unsafe mix of type 'bool' and type
649 // 'unsigned __int64' when instantiating getAsInteger with T = bool.
650 if (detail::GetAsUnsignedInteger(str, radix, val) ||
651 static_cast<Int>(static_cast<T>(val)) != val) {
652 return std::nullopt;
653 }
654 return val;
655}
656
657/**
658 * Parses the string @p str as an integer of the specified radix. If
659 * @p radix is specified as zero, this does radix autosensing using
660 * extended C rules: 0 is octal, 0x is hex, 0b is binary.
661 *
662 * If the string does not begin with a number of the specified radix,
663 * this returns nullopt to signify the error. The string is considered
664 * erroneous if empty or if it overflows T.
665 * The portion of the string representing the discovered numeric value
666 * is removed from the beginning of the string.
667 */
668template <typename T,
670inline std::optional<T> consume_integer(std::string_view* str,
671 unsigned radix) noexcept {
672 using Int = long long; // NOLINT(runtime/int)
673 Int val;
674 if (detail::ConsumeSignedInteger(*str, radix, val) ||
675 static_cast<Int>(static_cast<T>(val)) != val) {
676 return std::nullopt;
677 }
678 return val;
679}
680
681template <typename T,
683inline std::optional<T> consume_integer(std::string_view* str,
684 unsigned radix) noexcept {
685 using Int = unsigned long long; // NOLINT(runtime/int)
686 Int val;
687 if (detail::ConsumeUnsignedInteger(*str, radix, val) ||
688 static_cast<Int>(static_cast<T>(val)) != val) {
689 return std::nullopt;
690 }
691 return val;
692}
693
694/**
695 * Parses the string @p str as a floating point value.
696 *
697 * If the string is invalid or if only a subset of the string is valid,
698 * this returns nullopt to signify the error. The string is considered
699 * erroneous if empty or if it overflows T.
700 */
701template <typename T>
702std::optional<T> parse_float(std::string_view str) noexcept;
703
704template <>
705std::optional<float> parse_float<float>(std::string_view str) noexcept;
706template <>
707std::optional<double> parse_float<double>(std::string_view str) noexcept;
708template <>
709std::optional<long double> parse_float<long double>(
710 std::string_view str) noexcept;
711
712/**
713 * Unescapes a C-style string (reverse operation to raw_ostream::write_escaped).
714 * Scans through @p str until either the end is reached or an unescaped double
715 * quote character is found.
716 *
717 * @param str input string
718 * @param buf buffer for unescaped characters
719 * @return pair of the unescaped string and any remaining input
720 */
721std::pair<std::string_view, std::string_view> UnescapeCString(
723
724} // namespace wpi
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 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:128
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:557
basic_string_view< char > string_view
Definition: core.h:520
T mod(T x, int y)
Definition: chrono.h:1413
std::integral_constant< bool, std::numeric_limits< T >::is_signed||std::is_same< T, int128_opt >::value > is_signed
Definition: format.h:1004
constexpr common_t< T1, T2 > max(const T1 x, const T2 y) noexcept
Compile-time pairwise maximum function.
Definition: max.hpp:35
constexpr common_t< T1, T2 > min(const T1 x, const T2 y) noexcept
Compile-time pairwise minimum function.
Definition: min.hpp:35
static EIGEN_DEPRECATED const end_t end
Definition: IndexedViewHelper.h:181
Definition: format-inl.h:32
result
Definition: format.h:2564
Definition: BFloat16.h:88
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: AprilTagFieldLayout.h:18
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:34
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:417
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:438
int compare_lower(std::string_view lhs, std::string_view rhs) noexcept
compare_lower - Compare two strings, ignoring case.
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:556
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:73
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:670
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:62
constexpr bool isDigit(char C) noexcept
Checks if character C is one of the 10 decimal digits.
Definition: StringExtras.h:57
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:631
constexpr unsigned hexDigitValue(char C) noexcept
Interpret the given character C as a hexadecimal digit and return its value.
Definition: StringExtras.h:43
constexpr char toLower(char x) noexcept
Returns the corresponding lowercase character if x is uppercase.
Definition: StringExtras.h:92
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:593
constexpr char toUpper(char x) noexcept
Returns the corresponding uppercase character if x is lowercase.
Definition: StringExtras.h:100
constexpr bool contains(std::string_view str, std::string_view other) noexcept
Checks if str contains the substring other.
Definition: StringExtras.h:317
constexpr std::span< T > drop_back(std::span< T > in, typename std::span< T >::size_type n=1)
Drop the last N elements of the array.
Definition: SpanExtras.h:22
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:143
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:481
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:221
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:129
constexpr bool isPrint(char C) noexcept
Checks whether character C is printable.
Definition: StringExtras.h:86
constexpr std::string_view take_back(std::string_view str, std::string_view::size_type n=1) noexcept
Returns a view equal to str but with only the last n elements remaining.
Definition: StringExtras.h:395
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).
constexpr std::span< T > drop_front(std::span< T > in, typename std::span< T >::size_type n=1)
Drop the first N elements of the array.
Definition: SpanExtras.h:14
constexpr bool isASCII(char C) noexcept
Checks whether character C is valid ASCII (high bit is zero).
Definition: StringExtras.h:78
constexpr bool isAlpha(char C) noexcept
Checks if character C is a valid letter as classified by "C" locale.
Definition: StringExtras.h:67
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:573
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:274
std::string utohexstr(unsigned long long val, bool lowerCase=false)
Definition: StringExtras.h:107
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:232
bool contains_lower(std::string_view str, std::string_view other) noexcept
Checks if str contains the substring other, ignoring case.
Definition: StringExtras.h:338
constexpr std::string_view take_front(std::string_view str, std::string_view::size_type n=1) noexcept
Returns a view equal to str but with only the first n elements remaining.
Definition: StringExtras.h:381