WPILibC++  2020.3.2-60-g3011ebe
StringRef.h
1 //===- StringRef.h - Constant String Reference Wrapper ----------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef WPIUTIL_WPI_STRINGREF_H
11 #define WPIUTIL_WPI_STRINGREF_H
12 
13 #include "wpi/STLExtras.h"
14 #include "wpi/iterator_range.h"
15 #include "wpi/Compiler.h"
16 #include <algorithm>
17 #include <cassert>
18 #include <cstddef>
19 #include <cstring>
20 #include <iosfwd>
21 #include <limits>
22 #include <string>
23 #include <type_traits>
24 #include <utility>
25 
26 namespace wpi {
27 
28  class hash_code;
29  template <typename T> class SmallVectorImpl;
30  class StringRef;
31 
33  bool getAsUnsignedInteger(StringRef Str, unsigned Radix,
34  unsigned long long &Result) noexcept;
35 
36  bool getAsSignedInteger(StringRef Str, unsigned Radix, long long &Result) noexcept;
37 
38  bool consumeUnsignedInteger(StringRef &Str, unsigned Radix,
39  unsigned long long &Result) noexcept;
40  bool consumeSignedInteger(StringRef &Str, unsigned Radix, long long &Result) noexcept;
41 
49  class StringRef {
50  public:
51  static const size_t npos = ~size_t(0);
52 
53  using iterator = const char *;
54  using const_iterator = const char *;
55  using size_type = size_t;
56 
57  private:
59  const char *Data = nullptr;
60 
62  size_t Length = 0;
63 
64  // Workaround memcmp issue with null pointers (undefined behavior)
65  // by providing a specialized version
66  LLVM_ATTRIBUTE_ALWAYS_INLINE
67  static int compareMemory(const char *Lhs, const char *Rhs, size_t Length) noexcept {
68  if (Length == 0) { return 0; }
69  return ::memcmp(Lhs,Rhs,Length);
70  }
71 
72  public:
75 
77  /*implicit*/ StringRef() = default;
78 
81  StringRef(std::nullptr_t) = delete;
82 
84  LLVM_ATTRIBUTE_ALWAYS_INLINE
85  /*implicit*/ StringRef(const char *Str)
86  : Data(Str), Length(Str ? ::strlen(Str) : 0) {}
87 
89  LLVM_ATTRIBUTE_ALWAYS_INLINE
90  /*implicit*/ constexpr StringRef(const char *data, size_t length)
91  : Data(data), Length(length) {}
92 
94  LLVM_ATTRIBUTE_ALWAYS_INLINE
95  /*implicit*/ StringRef(const std::string &Str)
96  : Data(Str.data()), Length(Str.length()) {}
97 
98  static StringRef withNullAsEmpty(const char *data) {
99  return StringRef(data ? data : "");
100  }
101 
105 
106  iterator begin() const noexcept { return Data; }
107 
108  iterator end() const noexcept { return Data + Length; }
109 
110  const unsigned char *bytes_begin() const noexcept {
111  return reinterpret_cast<const unsigned char *>(begin());
112  }
113  const unsigned char *bytes_end() const noexcept {
114  return reinterpret_cast<const unsigned char *>(end());
115  }
116  iterator_range<const unsigned char *> bytes() const noexcept {
117  return make_range(bytes_begin(), bytes_end());
118  }
119 
123 
126  LLVM_NODISCARD
127  LLVM_ATTRIBUTE_ALWAYS_INLINE
128  const char *data() const noexcept { return Data; }
129 
131  LLVM_NODISCARD
132  LLVM_ATTRIBUTE_ALWAYS_INLINE
133  bool empty() const noexcept { return Length == 0; }
134 
136  LLVM_NODISCARD
137  LLVM_ATTRIBUTE_ALWAYS_INLINE
138  size_t size() const noexcept { return Length; }
139 
141  LLVM_NODISCARD
142  char front() const noexcept {
143  assert(!empty());
144  return Data[0];
145  }
146 
148  LLVM_NODISCARD
149  char back() const noexcept {
150  assert(!empty());
151  return Data[Length-1];
152  }
153 
154  // copy - Allocate copy in Allocator and return StringRef to it.
155  template <typename Allocator>
156  LLVM_NODISCARD StringRef copy(Allocator &A) const {
157  // Don't request a length 0 copy from the allocator.
158  if (empty())
159  return StringRef();
160  char *S = A.template Allocate<char>(Length);
161  std::copy(begin(), end(), S);
162  return StringRef(S, Length);
163  }
164 
167  LLVM_NODISCARD
168  LLVM_ATTRIBUTE_ALWAYS_INLINE
169  bool equals(StringRef RHS) const noexcept {
170  return (Length == RHS.Length &&
171  compareMemory(Data, RHS.Data, RHS.Length) == 0);
172  }
173 
175  LLVM_NODISCARD
176  bool equals_lower(StringRef RHS) const noexcept {
177  return Length == RHS.Length && compare_lower(RHS) == 0;
178  }
179 
182  LLVM_NODISCARD
183  LLVM_ATTRIBUTE_ALWAYS_INLINE
184  int compare(StringRef RHS) const noexcept {
185  // Check the prefix for a mismatch.
186  if (int Res = compareMemory(Data, RHS.Data, (std::min)(Length, RHS.Length)))
187  return Res < 0 ? -1 : 1;
188 
189  // Otherwise the prefixes match, so we only need to check the lengths.
190  if (Length == RHS.Length)
191  return 0;
192  return Length < RHS.Length ? -1 : 1;
193  }
194 
196  LLVM_NODISCARD
197  int compare_lower(StringRef RHS) const noexcept;
198 
201  LLVM_NODISCARD
202  int compare_numeric(StringRef RHS) const noexcept;
203 
205  LLVM_NODISCARD
206  std::string str() const {
207  if (!Data) return std::string();
208  return std::string(Data, Length);
209  }
210 
214 
215  LLVM_NODISCARD
216  char operator[](size_t Index) const noexcept {
217  assert(Index < Length && "Invalid index!");
218  return Data[Index];
219  }
220 
225  template <typename T>
226  typename std::enable_if<std::is_same<T, std::string>::value,
227  StringRef>::type &
228  operator=(T &&Str) = delete;
229 
233 
234  operator std::string() const {
235  return str();
236  }
237 
241 
243  LLVM_NODISCARD
244  LLVM_ATTRIBUTE_ALWAYS_INLINE
245  bool startswith(StringRef Prefix) const noexcept {
246  return Length >= Prefix.Length &&
247  compareMemory(Data, Prefix.Data, Prefix.Length) == 0;
248  }
249 
251  LLVM_NODISCARD
252  bool startswith_lower(StringRef Prefix) const noexcept;
253 
255  LLVM_NODISCARD
256  LLVM_ATTRIBUTE_ALWAYS_INLINE
257  bool endswith(StringRef Suffix) const noexcept {
258  return Length >= Suffix.Length &&
259  compareMemory(end() - Suffix.Length, Suffix.Data, Suffix.Length) == 0;
260  }
261 
263  LLVM_NODISCARD
264  bool endswith_lower(StringRef Suffix) const noexcept;
265 
269 
274  LLVM_NODISCARD
275  LLVM_ATTRIBUTE_ALWAYS_INLINE
276  size_t find(char C, size_t From = 0) const noexcept {
277  size_t FindBegin = (std::min)(From, Length);
278  if (FindBegin < Length) { // Avoid calling memchr with nullptr.
279  // Just forward to memchr, which is faster than a hand-rolled loop.
280  if (const void *P = ::memchr(Data + FindBegin, C, Length - FindBegin))
281  return static_cast<const char *>(P) - Data;
282  }
283  return npos;
284  }
285 
290  LLVM_NODISCARD
291  size_t find_lower(char C, size_t From = 0) const noexcept;
292 
297  LLVM_NODISCARD
298  LLVM_ATTRIBUTE_ALWAYS_INLINE
299  size_t find_if(function_ref<bool(char)> F, size_t From = 0) const noexcept {
300  StringRef S = drop_front(From);
301  while (!S.empty()) {
302  if (F(S.front()))
303  return size() - S.size();
304  S = S.drop_front();
305  }
306  return npos;
307  }
308 
313  LLVM_NODISCARD
314  LLVM_ATTRIBUTE_ALWAYS_INLINE
315  size_t find_if_not(function_ref<bool(char)> F, size_t From = 0) const noexcept {
316  return find_if([F](char c) { return !F(c); }, From);
317  }
318 
323  LLVM_NODISCARD
324  size_t find(StringRef Str, size_t From = 0) const noexcept;
325 
330  LLVM_NODISCARD
331  size_t find_lower(StringRef Str, size_t From = 0) const noexcept;
332 
337  LLVM_NODISCARD
338  size_t rfind(char C, size_t From = npos) const noexcept {
339  From = (std::min)(From, Length);
340  size_t i = From;
341  while (i != 0) {
342  --i;
343  if (Data[i] == C)
344  return i;
345  }
346  return npos;
347  }
348 
353  LLVM_NODISCARD
354  size_t rfind_lower(char C, size_t From = npos) const noexcept;
355 
360  LLVM_NODISCARD
361  size_t rfind(StringRef Str) const noexcept;
362 
367  LLVM_NODISCARD
368  size_t rfind_lower(StringRef Str) const noexcept;
369 
372  LLVM_NODISCARD
373  size_t find_first_of(char C, size_t From = 0) const noexcept {
374  return find(C, From);
375  }
376 
381  LLVM_NODISCARD
382  size_t find_first_of(StringRef Chars, size_t From = 0) const noexcept;
383 
386  LLVM_NODISCARD
387  size_t find_first_not_of(char C, size_t From = 0) const noexcept;
388 
393  LLVM_NODISCARD
394  size_t find_first_not_of(StringRef Chars, size_t From = 0) const noexcept;
395 
398  LLVM_NODISCARD
399  size_t find_last_of(char C, size_t From = npos) const noexcept {
400  return rfind(C, From);
401  }
402 
407  LLVM_NODISCARD
408  size_t find_last_of(StringRef Chars, size_t From = npos) const noexcept;
409 
412  LLVM_NODISCARD
413  size_t find_last_not_of(char C, size_t From = npos) const noexcept;
414 
419  LLVM_NODISCARD
420  size_t find_last_not_of(StringRef Chars, size_t From = npos) const noexcept;
421 
424  LLVM_NODISCARD
425  LLVM_ATTRIBUTE_ALWAYS_INLINE
426  bool contains(StringRef Other) const noexcept { return find(Other) != npos; }
427 
430  LLVM_NODISCARD
431  LLVM_ATTRIBUTE_ALWAYS_INLINE
432  bool contains(char C) const noexcept { return find_first_of(C) != npos; }
433 
436  LLVM_NODISCARD
437  LLVM_ATTRIBUTE_ALWAYS_INLINE
438  bool contains_lower(StringRef Other) const noexcept {
439  return find_lower(Other) != npos;
440  }
441 
444  LLVM_NODISCARD
445  LLVM_ATTRIBUTE_ALWAYS_INLINE
446  bool contains_lower(char C) const noexcept { return find_lower(C) != npos; }
447 
451 
453  LLVM_NODISCARD
454  size_t count(char C) const noexcept {
455  size_t Count = 0;
456  for (size_t i = 0, e = Length; i != e; ++i)
457  if (Data[i] == C)
458  ++Count;
459  return Count;
460  }
461 
464  size_t count(StringRef Str) const noexcept;
465 
473  template <typename T>
474  typename std::enable_if<std::numeric_limits<T>::is_signed, bool>::type
475  getAsInteger(unsigned Radix, T &Result) const noexcept {
476  long long LLVal;
477  if (getAsSignedInteger(*this, Radix, LLVal) ||
478  static_cast<T>(LLVal) != LLVal)
479  return true;
480  Result = LLVal;
481  return false;
482  }
483 
484  template <typename T>
485  typename std::enable_if<!std::numeric_limits<T>::is_signed, bool>::type
486  getAsInteger(unsigned Radix, T &Result) const noexcept {
487  unsigned long long ULLVal;
488  // The additional cast to unsigned long long is required to avoid the
489  // Visual C++ warning C4805: '!=' : unsafe mix of type 'bool' and type
490  // 'unsigned __int64' when instantiating getAsInteger with T = bool.
491  if (getAsUnsignedInteger(*this, Radix, ULLVal) ||
492  static_cast<unsigned long long>(static_cast<T>(ULLVal)) != ULLVal)
493  return true;
494  Result = ULLVal;
495  return false;
496  }
497 
507  template <typename T>
508  typename std::enable_if<std::numeric_limits<T>::is_signed, bool>::type
509  consumeInteger(unsigned Radix, T &Result) noexcept {
510  long long LLVal;
511  if (consumeSignedInteger(*this, Radix, LLVal) ||
512  static_cast<long long>(static_cast<T>(LLVal)) != LLVal)
513  return true;
514  Result = LLVal;
515  return false;
516  }
517 
518  template <typename T>
519  typename std::enable_if<!std::numeric_limits<T>::is_signed, bool>::type
520  consumeInteger(unsigned Radix, T &Result) noexcept {
521  unsigned long long ULLVal;
522  if (consumeUnsignedInteger(*this, Radix, ULLVal) ||
523  static_cast<unsigned long long>(static_cast<T>(ULLVal)) != ULLVal)
524  return true;
525  Result = ULLVal;
526  return false;
527  }
528 
532 
533  // Convert the given ASCII string to lowercase.
534  LLVM_NODISCARD
535  std::string lower() const;
536 
538  LLVM_NODISCARD
539  std::string upper() const;
540 
544 
554  LLVM_NODISCARD
555  LLVM_ATTRIBUTE_ALWAYS_INLINE
556  StringRef substr(size_t Start, size_t N = npos) const noexcept {
557  Start = (std::min)(Start, Length);
558  return StringRef(Data + Start, (std::min)(N, Length - Start));
559  }
560 
564  LLVM_NODISCARD
565  LLVM_ATTRIBUTE_ALWAYS_INLINE
566  StringRef take_front(size_t N = 1) const noexcept {
567  if (N >= size())
568  return *this;
569  return drop_back(size() - N);
570  }
571 
575  LLVM_NODISCARD
576  LLVM_ATTRIBUTE_ALWAYS_INLINE
577  StringRef take_back(size_t N = 1) const noexcept {
578  if (N >= size())
579  return *this;
580  return drop_front(size() - N);
581  }
582 
585  LLVM_NODISCARD
586  LLVM_ATTRIBUTE_ALWAYS_INLINE
587  StringRef take_while(function_ref<bool(char)> F) const noexcept {
588  return substr(0, find_if_not(F));
589  }
590 
593  LLVM_NODISCARD
594  LLVM_ATTRIBUTE_ALWAYS_INLINE
595  StringRef take_until(function_ref<bool(char)> F) const noexcept {
596  return substr(0, find_if(F));
597  }
598 
601  LLVM_NODISCARD
602  LLVM_ATTRIBUTE_ALWAYS_INLINE
603  StringRef drop_front(size_t N = 1) const noexcept {
604  assert(size() >= N && "Dropping more elements than exist");
605  return substr(N);
606  }
607 
610  LLVM_NODISCARD
611  LLVM_ATTRIBUTE_ALWAYS_INLINE
612  StringRef drop_back(size_t N = 1) const noexcept {
613  assert(size() >= N && "Dropping more elements than exist");
614  return substr(0, size()-N);
615  }
616 
619  LLVM_NODISCARD
620  LLVM_ATTRIBUTE_ALWAYS_INLINE
621  StringRef drop_while(function_ref<bool(char)> F) const noexcept {
622  return substr(find_if_not(F));
623  }
624 
627  LLVM_NODISCARD
628  LLVM_ATTRIBUTE_ALWAYS_INLINE
629  StringRef drop_until(function_ref<bool(char)> F) const noexcept {
630  return substr(find_if(F));
631  }
632 
635  LLVM_ATTRIBUTE_ALWAYS_INLINE
636  bool consume_front(StringRef Prefix) noexcept {
637  if (!startswith(Prefix))
638  return false;
639 
640  *this = drop_front(Prefix.size());
641  return true;
642  }
643 
646  LLVM_ATTRIBUTE_ALWAYS_INLINE
647  bool consume_back(StringRef Suffix) noexcept {
648  if (!endswith(Suffix))
649  return false;
650 
651  *this = drop_back(Suffix.size());
652  return true;
653  }
654 
666  LLVM_NODISCARD
667  LLVM_ATTRIBUTE_ALWAYS_INLINE
668  StringRef slice(size_t Start, size_t End) const noexcept {
669  Start = (std::min)(Start, Length);
670  End = (std::min)((std::max)(Start, End), Length);
671  return StringRef(Data + Start, End - Start);
672  }
673 
684  LLVM_NODISCARD
685  std::pair<StringRef, StringRef> split(char Separator) const {
686  return split(StringRef(&Separator, 1));
687  }
688 
699  LLVM_NODISCARD
700  std::pair<StringRef, StringRef> split(StringRef Separator) const {
701  size_t Idx = find(Separator);
702  if (Idx == npos)
703  return std::make_pair(*this, StringRef());
704  return std::make_pair(slice(0, Idx), slice(Idx + Separator.size(), npos));
705  }
706 
717  LLVM_NODISCARD
718  std::pair<StringRef, StringRef> rsplit(StringRef Separator) const {
719  size_t Idx = rfind(Separator);
720  if (Idx == npos)
721  return std::make_pair(*this, StringRef());
722  return std::make_pair(slice(0, Idx), slice(Idx + Separator.size(), npos));
723  }
724 
740  StringRef Separator, int MaxSplit = -1,
741  bool KeepEmpty = true) const;
742 
757  void split(SmallVectorImpl<StringRef> &A, char Separator, int MaxSplit = -1,
758  bool KeepEmpty = true) const;
759 
770  LLVM_NODISCARD
771  std::pair<StringRef, StringRef> rsplit(char Separator) const {
772  return rsplit(StringRef(&Separator, 1));
773  }
774 
777  LLVM_NODISCARD
778  StringRef ltrim(char Char) const noexcept {
779  return drop_front((std::min)(Length, find_first_not_of(Char)));
780  }
781 
784  LLVM_NODISCARD
785  StringRef ltrim(StringRef Chars = " \t\n\v\f\r") const noexcept {
786  return drop_front((std::min)(Length, find_first_not_of(Chars)));
787  }
788 
791  LLVM_NODISCARD
792  StringRef rtrim(char Char) const noexcept {
793  return drop_back(size() - (std::min)(Length, find_last_not_of(Char) + 1));
794  }
795 
798  LLVM_NODISCARD
799  StringRef rtrim(StringRef Chars = " \t\n\v\f\r") const noexcept {
800  return drop_back(size() - (std::min)(Length, find_last_not_of(Chars) + 1));
801  }
802 
805  LLVM_NODISCARD
806  StringRef trim(char Char) const noexcept {
807  return ltrim(Char).rtrim(Char);
808  }
809 
812  LLVM_NODISCARD
813  StringRef trim(StringRef Chars = " \t\n\v\f\r") const noexcept {
814  return ltrim(Chars).rtrim(Chars);
815  }
816 
818  };
819 
827  class StringLiteral : public StringRef {
828  private:
829  constexpr StringLiteral(const char *Str, size_t N) : StringRef(Str, N) {
830  }
831 
832  public:
833  template <size_t N>
834  constexpr StringLiteral(const char (&Str)[N])
835 #if defined(__clang__) && __has_attribute(enable_if)
836 #pragma clang diagnostic push
837 #pragma clang diagnostic ignored "-Wgcc-compat"
838  __attribute((enable_if(__builtin_strlen(Str) == N - 1,
839  "invalid string literal")))
840 #pragma clang diagnostic pop
841 #endif
842  : StringRef(Str, N - 1) {
843  }
844 
845  // Explicit construction for strings like "foo\0bar".
846  template <size_t N>
847  static constexpr StringLiteral withInnerNUL(const char (&Str)[N]) {
848  return StringLiteral(Str, N - 1);
849  }
850  };
851 
854 
855  LLVM_ATTRIBUTE_ALWAYS_INLINE
856  bool operator==(StringRef LHS, StringRef RHS) noexcept {
857  return LHS.equals(RHS);
858  }
859 
860  LLVM_ATTRIBUTE_ALWAYS_INLINE
861  bool operator!=(StringRef LHS, StringRef RHS) noexcept {
862  return !(LHS == RHS);
863  }
864 
865  inline bool operator<(StringRef LHS, StringRef RHS) noexcept {
866  return LHS.compare(RHS) == -1;
867  }
868 
869  inline bool operator<=(StringRef LHS, StringRef RHS) noexcept {
870  return LHS.compare(RHS) != 1;
871  }
872 
873  inline bool operator>(StringRef LHS, StringRef RHS) noexcept {
874  return LHS.compare(RHS) == 1;
875  }
876 
877  inline bool operator>=(StringRef LHS, StringRef RHS) noexcept {
878  return LHS.compare(RHS) != -1;
879  }
880 
881  inline bool operator==(StringRef LHS, const char *RHS) noexcept {
882  return LHS.equals(StringRef(RHS));
883  }
884 
885  inline bool operator!=(StringRef LHS, const char *RHS) noexcept {
886  return !(LHS == StringRef(RHS));
887  }
888 
889  inline bool operator<(StringRef LHS, const char *RHS) noexcept {
890  return LHS.compare(StringRef(RHS)) == -1;
891  }
892 
893  inline bool operator<=(StringRef LHS, const char *RHS) noexcept {
894  return LHS.compare(StringRef(RHS)) != 1;
895  }
896 
897  inline bool operator>(StringRef LHS, const char *RHS) noexcept {
898  return LHS.compare(StringRef(RHS)) == 1;
899  }
900 
901  inline bool operator>=(StringRef LHS, const char *RHS) noexcept {
902  return LHS.compare(StringRef(RHS)) != -1;
903  }
904 
905  inline bool operator==(const char *LHS, StringRef RHS) noexcept {
906  return StringRef(LHS).equals(RHS);
907  }
908 
909  inline bool operator!=(const char *LHS, StringRef RHS) noexcept {
910  return !(StringRef(LHS) == RHS);
911  }
912 
913  inline bool operator<(const char *LHS, StringRef RHS) noexcept {
914  return StringRef(LHS).compare(RHS) == -1;
915  }
916 
917  inline bool operator<=(const char *LHS, StringRef RHS) noexcept {
918  return StringRef(LHS).compare(RHS) != 1;
919  }
920 
921  inline bool operator>(const char *LHS, StringRef RHS) noexcept {
922  return StringRef(LHS).compare(RHS) == 1;
923  }
924 
925  inline bool operator>=(const char *LHS, StringRef RHS) noexcept {
926  return StringRef(LHS).compare(RHS) != -1;
927  }
928 
929  inline std::string &operator+=(std::string &buffer, StringRef string) {
930  return buffer.append(string.data(), string.size());
931  }
932 
933  std::ostream &operator<<(std::ostream &os, StringRef string);
934 
936 
938  LLVM_NODISCARD
939  hash_code hash_value(StringRef S);
940 
941  // StringRefs can be treated like a POD type.
942  template <typename T> struct isPodLike;
943  template <> struct isPodLike<StringRef> { static const bool value = true; };
944 
945 } // end namespace wpi
946 
947 #endif // LLVM_ADT_STRINGREF_H
wpi::StringRef::count
LLVM_NODISCARD size_t count(char C) const noexcept
Return the number of occurrences of C in the string.
Definition: StringRef.h:454
wpi::StringRef::empty
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const noexcept
empty - Check if the string is empty.
Definition: StringRef.h:133
wpi::StringRef::trim
LLVM_NODISCARD StringRef trim(char Char) const noexcept
Return string with consecutive Char characters starting from the left and right removed.
Definition: StringRef.h:806
wpi::isPodLike
isPodLike - This is a type trait that is used to determine whether a given type can be copied around ...
Definition: StringRef.h:942
wpi::StringRef::take_front
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef take_front(size_t N=1) const noexcept
Return a StringRef equal to 'this' but with only the first N elements remaining.
Definition: StringRef.h:566
wpi::StringRef::split
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition: StringRef.h:685
wpi::operator!=
bool operator!=(const DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT > &LHS, const DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT > &RHS)
Inequality comparison for DenseMap.
Definition: DenseMap.h:659
wpi::StringRef::operator=
std::enable_if< std::is_same< T, std::string >::value, StringRef >::type & operator=(T &&Str)=delete
Disallow accidental assignment from a temporary std::string.
wpi::StringRef::endswith_lower
LLVM_NODISCARD bool endswith_lower(StringRef Suffix) const noexcept
Check if this string ends with the given Suffix, ignoring case.
wpi::StringRef::slice
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef slice(size_t Start, size_t End) const noexcept
Return a reference to the substring from [Start, End).
Definition: StringRef.h:668
wpi::StringRef::take_until
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef take_until(function_ref< bool(char)> F) const noexcept
Return the longest prefix of 'this' such that no character in the prefix satisfies the given predicat...
Definition: StringRef.h:595
wpi::StringRef::drop_back
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef drop_back(size_t N=1) const noexcept
Return a StringRef equal to 'this' but with the last N elements dropped.
Definition: StringRef.h:612
wpi::StringRef::rfind
LLVM_NODISCARD size_t rfind(char C, size_t From=npos) const noexcept
Search for the last character C in the string.
Definition: StringRef.h:338
wpi::StringRef::compare_numeric
LLVM_NODISCARD int compare_numeric(StringRef RHS) const noexcept
compare_numeric - Compare two strings, treating sequences of digits as numbers.
wpi::StringRef::equals
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool equals(StringRef RHS) const noexcept
equals - Check for string equality, this is more efficient than compare() when the relative ordering ...
Definition: StringRef.h:169
wpi::StringRef::ltrim
LLVM_NODISCARD StringRef ltrim(char Char) const noexcept
Return string with consecutive Char characters starting from the the left removed.
Definition: StringRef.h:778
wpi::StringRef::size
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const noexcept
size - Get the string size.
Definition: StringRef.h:138
wpi::StringRef::trim
LLVM_NODISCARD StringRef trim(StringRef Chars=" \t\n\v\f\r") const noexcept
Return string with consecutive characters in Chars starting from the left and right removed.
Definition: StringRef.h:813
wpi::StringLiteral
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition: StringRef.h:827
wpi::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: StringExtras.h:32
wpi::StringRef::drop_while
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef drop_while(function_ref< bool(char)> F) const noexcept
Return a StringRef equal to 'this', but with all characters satisfying the given predicate dropped fr...
Definition: StringRef.h:621
wpi::getAsUnsignedInteger
bool getAsUnsignedInteger(StringRef Str, unsigned Radix, unsigned long long &Result) noexcept
Helper functions for StringRef::getAsInteger.
wpi::StringRef::StringRef
LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef(const std::string &Str)
Construct a string ref from an std::string.
Definition: StringRef.h:95
wpi::StringRef::startswith_lower
LLVM_NODISCARD bool startswith_lower(StringRef Prefix) const noexcept
Check if this string starts with the given Prefix, ignoring case.
wpi::StringRef::StringRef
LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef(const char *Str)
Construct a string ref from a cstring.
Definition: StringRef.h:85
wpi::StringRef::take_back
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef take_back(size_t N=1) const noexcept
Return a StringRef equal to 'this' but with only the last N elements remaining.
Definition: StringRef.h:577
wpi::StringRef::back
LLVM_NODISCARD char back() const noexcept
back - Get the last character in the string.
Definition: StringRef.h:149
wpi::StringRef::find_first_not_of
LLVM_NODISCARD size_t find_first_not_of(char C, size_t From=0) const noexcept
Find the first character in the string that is not C or npos if not found.
wpi
WPILib C++ utilities (wpiutil) namespace.
Definition: Endian.h:31
wpi::StringRef::rtrim
LLVM_NODISCARD StringRef rtrim(StringRef Chars=" \t\n\v\f\r") const noexcept
Return string with consecutive characters in Chars starting from the right removed.
Definition: StringRef.h:799
wpi::StringRef::ltrim
LLVM_NODISCARD StringRef ltrim(StringRef Chars=" \t\n\v\f\r") const noexcept
Return string with consecutive characters in Chars starting from the left removed.
Definition: StringRef.h:785
wpi::StringRef::upper
LLVM_NODISCARD std::string upper() const
Convert the given ASCII string to uppercase.
wpi::StringRef::rsplit
LLVM_NODISCARD std::pair< StringRef, StringRef > rsplit(char Separator) const
Split into two substrings around the last occurrence of a separator character.
Definition: StringRef.h:771
wpi::StringRef::find_first_of
LLVM_NODISCARD size_t find_first_of(char C, size_t From=0) const noexcept
Find the first character in the string that is C, or npos if not found.
Definition: StringRef.h:373
wpi::make_range
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Definition: iterator_range.h:54
wpi::StringRef::find_last_of
LLVM_NODISCARD size_t find_last_of(char C, size_t From=npos) const noexcept
Find the last character in the string that is C, or npos if not found.
Definition: StringRef.h:399
wpi::StringRef::take_while
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef take_while(function_ref< bool(char)> F) const noexcept
Return the longest prefix of 'this' such that every character in the prefix satisfies the given predi...
Definition: StringRef.h:587
wpi::StringRef::drop_until
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef drop_until(function_ref< bool(char)> F) const noexcept
Return a StringRef equal to 'this', but with all characters not satisfying the given predicate droppe...
Definition: StringRef.h:629
wpi::StringRef::contains
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool contains(StringRef Other) const noexcept
Return true if the given string is a substring of *this, and false otherwise.
Definition: StringRef.h:426
wpi::StringRef::equals_lower
LLVM_NODISCARD bool equals_lower(StringRef RHS) const noexcept
equals_lower - Check for string equality, ignoring case.
Definition: StringRef.h:176
wpi::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
wpi::StringRef::find_if_not
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t find_if_not(function_ref< bool(char)> F, size_t From=0) const noexcept
Search for the first character not satisfying the predicate F.
Definition: StringRef.h:315
wpi::StringRef::find_if
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t find_if(function_ref< bool(char)> F, size_t From=0) const noexcept
Search for the first character satisfying the predicate F.
Definition: StringRef.h:299
iterator_range.h
wpi::StringRef::consumeInteger
std::enable_if< std::numeric_limits< T >::is_signed, bool >::type consumeInteger(unsigned Radix, T &Result) noexcept
Parse the current string as an integer of the specified radix.
Definition: StringRef.h:509
wpi::StringRef::substr
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const noexcept
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:556
wpi::StringRef::startswith
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const noexcept
Check if this string starts with the given Prefix.
Definition: StringRef.h:245
wpi::StringRef::consume_back
LLVM_ATTRIBUTE_ALWAYS_INLINE bool consume_back(StringRef Suffix) noexcept
Returns true if this StringRef has the given suffix and removes that suffix.
Definition: StringRef.h:647
wpi::StringRef::rtrim
LLVM_NODISCARD StringRef rtrim(char Char) const noexcept
Return string with consecutive Char characters starting from the right removed.
Definition: StringRef.h:792
wpi::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:103
wpi::StringRef::endswith
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool endswith(StringRef Suffix) const noexcept
Check if this string ends with the given Suffix.
Definition: StringRef.h:257
wpi::StringRef::front
LLVM_NODISCARD char front() const noexcept
front - Get the first character in the string.
Definition: StringRef.h:142
wpi::StringRef::StringRef
constexpr LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef(const char *data, size_t length)
Construct a string ref from a pointer and length.
Definition: StringRef.h:90
wpi::StringRef::consume_front
LLVM_ATTRIBUTE_ALWAYS_INLINE bool consume_front(StringRef Prefix) noexcept
Returns true if this StringRef has the given prefix and removes that prefix.
Definition: StringRef.h:636
wpi::StringRef::rfind_lower
LLVM_NODISCARD size_t rfind_lower(char C, size_t From=npos) const noexcept
Search for the last character C in the string, ignoring case.
wpi::StringRef::find
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t find(char C, size_t From=0) const noexcept
Search for the first character C in the string.
Definition: StringRef.h:276
wpi::StringRef::data
LLVM_NODISCARD const LLVM_ATTRIBUTE_ALWAYS_INLINE char * data() const noexcept
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:128
wpi::size
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
Definition: STLExtras.h:1007
wpi::hash_value
LLVM_NODISCARD hash_code hash_value(StringRef S)
Compute a hash_code for a StringRef.
wpi::StringRef::str
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:206
wpi::StringRef::find_lower
LLVM_NODISCARD size_t find_lower(char C, size_t From=0) const noexcept
Search for the first character C in the string, ignoring case.
wpi::StringRef::contains_lower
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool contains_lower(StringRef Other) const noexcept
Return true if the given string is a substring of *this, and false otherwise.
Definition: StringRef.h:438
wpi::StringRef::rsplit
LLVM_NODISCARD std::pair< StringRef, StringRef > rsplit(StringRef Separator) const
Split into two substrings around the last occurrence of a separator string.
Definition: StringRef.h:718
wpi::StringRef::compare_lower
LLVM_NODISCARD int compare_lower(StringRef RHS) const noexcept
compare_lower - Compare two strings, ignoring case.
wpi::StringRef::compare
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE int compare(StringRef RHS) const noexcept
compare - Compare two strings; the result is -1, 0, or 1 if this string is lexicographically less tha...
Definition: StringRef.h:184
wpi::StringRef::contains
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool contains(char C) const noexcept
Return true if the given character is contained in *this, and false otherwise.
Definition: StringRef.h:432
wpi::StringRef::find_last_not_of
LLVM_NODISCARD size_t find_last_not_of(char C, size_t From=npos) const noexcept
Find the last character in the string that is not C, or npos if not found.
wpi::StringRef::getAsInteger
std::enable_if< std::numeric_limits< T >::is_signed, bool >::type getAsInteger(unsigned Radix, T &Result) const noexcept
Parse the current string as an integer of the specified radix.
Definition: StringRef.h:475
wpi::StringRef::contains_lower
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool contains_lower(char C) const noexcept
Return true if the given character is contained in *this, and false otherwise.
Definition: StringRef.h:446
wpi::StringRef::drop_front
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef drop_front(size_t N=1) const noexcept
Return a StringRef equal to 'this' but with the first N elements dropped.
Definition: StringRef.h:603
wpi::StringRef::split
LLVM_NODISCARD std::pair< StringRef, StringRef > split(StringRef Separator) const
Split into two substrings around the first occurrence of a separator string.
Definition: StringRef.h:700
wpi::StringRef::StringRef
StringRef()=default
Construct an empty string ref.