WPILibC++  2019.1.1-beta-2-25-g73de336
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
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 size() == 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  size_t Idx = find(Separator);
687  if (Idx == npos)
688  return std::make_pair(*this, StringRef());
689  return std::make_pair(slice(0, Idx), slice(Idx+1, npos));
690  }
691 
702  LLVM_NODISCARD
703  std::pair<StringRef, StringRef> split(StringRef Separator) const {
704  size_t Idx = find(Separator);
705  if (Idx == npos)
706  return std::make_pair(*this, StringRef());
707  return std::make_pair(slice(0, Idx), slice(Idx + Separator.size(), npos));
708  }
709 
725  StringRef Separator, int MaxSplit = -1,
726  bool KeepEmpty = true) const;
727 
742  void split(SmallVectorImpl<StringRef> &A, char Separator, int MaxSplit = -1,
743  bool KeepEmpty = true) const;
744 
755  LLVM_NODISCARD
756  std::pair<StringRef, StringRef> rsplit(char Separator) const {
757  size_t Idx = rfind(Separator);
758  if (Idx == npos)
759  return std::make_pair(*this, StringRef());
760  return std::make_pair(slice(0, Idx), slice(Idx+1, npos));
761  }
762 
765  LLVM_NODISCARD
766  StringRef ltrim(char Char) const noexcept {
767  return drop_front(std::min(Length, find_first_not_of(Char)));
768  }
769 
772  LLVM_NODISCARD
773  StringRef ltrim(StringRef Chars = " \t\n\v\f\r") const noexcept {
774  return drop_front(std::min(Length, find_first_not_of(Chars)));
775  }
776 
779  LLVM_NODISCARD
780  StringRef rtrim(char Char) const noexcept {
781  return drop_back(size() - std::min(Length, find_last_not_of(Char) + 1));
782  }
783 
786  LLVM_NODISCARD
787  StringRef rtrim(StringRef Chars = " \t\n\v\f\r") const noexcept {
788  return drop_back(size() - std::min(Length, find_last_not_of(Chars) + 1));
789  }
790 
793  LLVM_NODISCARD
794  StringRef trim(char Char) const noexcept {
795  return ltrim(Char).rtrim(Char);
796  }
797 
800  LLVM_NODISCARD
801  StringRef trim(StringRef Chars = " \t\n\v\f\r") const noexcept {
802  return ltrim(Chars).rtrim(Chars);
803  }
804 
806  };
807 
815  class StringLiteral : public StringRef {
816  private:
817  constexpr StringLiteral(const char *Str, size_t N) : StringRef(Str, N) {
818  }
819 
820  public:
821  template <size_t N>
822  constexpr StringLiteral(const char (&Str)[N])
823 #if defined(__clang__) && __has_attribute(enable_if)
824 #pragma clang diagnostic push
825 #pragma clang diagnostic ignored "-Wgcc-compat"
826  __attribute((enable_if(__builtin_strlen(Str) == N - 1,
827  "invalid string literal")))
828 #pragma clang diagnostic pop
829 #endif
830  : StringRef(Str, N - 1) {
831  }
832 
833  // Explicit construction for strings like "foo\0bar".
834  template <size_t N>
835  static constexpr StringLiteral withInnerNUL(const char (&Str)[N]) {
836  return StringLiteral(Str, N - 1);
837  }
838  };
839 
842 
843  LLVM_ATTRIBUTE_ALWAYS_INLINE
844  bool operator==(StringRef LHS, StringRef RHS) noexcept {
845  return LHS.equals(RHS);
846  }
847 
848  LLVM_ATTRIBUTE_ALWAYS_INLINE
849  bool operator!=(StringRef LHS, StringRef RHS) noexcept {
850  return !(LHS == RHS);
851  }
852 
853  inline bool operator<(StringRef LHS, StringRef RHS) noexcept {
854  return LHS.compare(RHS) == -1;
855  }
856 
857  inline bool operator<=(StringRef LHS, StringRef RHS) noexcept {
858  return LHS.compare(RHS) != 1;
859  }
860 
861  inline bool operator>(StringRef LHS, StringRef RHS) noexcept {
862  return LHS.compare(RHS) == 1;
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, const char *RHS) noexcept {
870  return LHS.equals(StringRef(RHS));
871  }
872 
873  inline bool operator!=(StringRef LHS, const char *RHS) noexcept {
874  return !(LHS == StringRef(RHS));
875  }
876 
877  inline bool operator<(StringRef LHS, const char *RHS) noexcept {
878  return LHS.compare(StringRef(RHS)) == -1;
879  }
880 
881  inline bool operator<=(StringRef LHS, const char *RHS) noexcept {
882  return LHS.compare(StringRef(RHS)) != 1;
883  }
884 
885  inline bool operator>(StringRef LHS, const char *RHS) noexcept {
886  return LHS.compare(StringRef(RHS)) == 1;
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==(const char *LHS, StringRef RHS) noexcept {
894  return StringRef(LHS).equals(RHS);
895  }
896 
897  inline bool operator!=(const char *LHS, StringRef RHS) noexcept {
898  return !(StringRef(LHS) == RHS);
899  }
900 
901  inline bool operator<(const char *LHS, StringRef RHS) noexcept {
902  return StringRef(LHS).compare(RHS) == -1;
903  }
904 
905  inline bool operator<=(const char *LHS, StringRef RHS) noexcept {
906  return StringRef(LHS).compare(RHS) != 1;
907  }
908 
909  inline bool operator>(const char *LHS, StringRef RHS) noexcept {
910  return StringRef(LHS).compare(RHS) == 1;
911  }
912 
913  inline bool operator>=(const char *LHS, StringRef RHS) noexcept {
914  return StringRef(LHS).compare(RHS) != -1;
915  }
916 
917  inline std::string &operator+=(std::string &buffer, StringRef string) {
918  return buffer.append(string.data(), string.size());
919  }
920 
921  std::ostream &operator<<(std::ostream &os, StringRef string);
922 
924 
926  LLVM_NODISCARD
927  hash_code hash_value(StringRef S);
928 
929  // StringRefs can be treated like a POD type.
930  template <typename T> struct isPodLike;
931  template <> struct isPodLike<StringRef> { static const bool value = true; };
932 
933 } // end namespace wpi
934 
935 #endif // LLVM_ADT_STRINGREF_H
LLVM_NODISCARD bool startswith_lower(StringRef Prefix) const noexcept
Check if this string starts with the given Prefix, ignoring case.
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:773
LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef(const char *Str)
Construct a string ref from a cstring.
Definition: StringRef.h:85
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
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
LLVM_NODISCARD char front() const noexcept
front - Get the first character in the string.
Definition: StringRef.h:142
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
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
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
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: hostname.h:17
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
LLVM_NODISCARD bool equals_lower(StringRef RHS) const noexcept
equals_lower - Check for string equality, ignoring case.
Definition: StringRef.h:176
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
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
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
LLVM_NODISCARD int compare_lower(StringRef RHS) const noexcept
compare_lower - Compare two strings, ignoring case.
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
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
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
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
LLVM_ATTRIBUTE_ALWAYS_INLINE constexpr StringRef(const char *data, size_t length)
Construct a string ref from a pointer and length.
Definition: StringRef.h:90
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
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.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const noexcept
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:128
WPILib C++ utilities (wpiutil) namespace.
Definition: SmallString.h:21
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.
LLVM_NODISCARD std::string upper() const
Convert the given ASCII string to uppercase.
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:88
isPodLike - This is a type trait that is used to determine whether a given type can be copied around ...
Definition: ArrayRef.h:530
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
LLVM_NODISCARD StringRef trim(char Char) const noexcept
Return string with consecutive Char characters starting from the left and right removed.
Definition: StringRef.h:794
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.
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
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
bool getAsUnsignedInteger(StringRef Str, unsigned Radix, unsigned long long &Result) noexcept
Helper functions for 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
StringRef()=default
Construct an empty string ref.
LLVM_NODISCARD size_t count(char C) const noexcept
Return the number of occurrences of C in the string.
Definition: StringRef.h:454
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
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
LLVM_NODISCARD StringRef ltrim(char Char) const noexcept
Return string with consecutive Char characters starting from the the left removed.
Definition: StringRef.h:766
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
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:801
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
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
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Definition: iterator_range.h:54
LLVM_NODISCARD bool endswith_lower(StringRef Suffix) const noexcept
Check if this string ends with the given Suffix, ignoring case.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const noexcept
empty - Check if the string is empty.
Definition: StringRef.h:133
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition: StringRef.h:815
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
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
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:999
LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef(const std::string &Str)
Construct a string ref from an std::string.
Definition: StringRef.h:95
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:703
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
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
std::enable_if< std::is_same< T, std::string >::value, StringRef >::type & operator=(T &&Str)=delete
Disallow accidental assignment from a temporary std::string.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const noexcept
size - Get the string size.
Definition: StringRef.h:138
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
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.
LLVM_NODISCARD int compare_numeric(StringRef RHS) const noexcept
compare_numeric - Compare two strings, treating sequences of digits as numbers.
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
LLVM_NODISCARD char back() const noexcept
back - Get the last character in the string.
Definition: StringRef.h:149
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:756
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
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:206
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
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:787
LLVM_NODISCARD StringRef rtrim(char Char) const noexcept
Return string with consecutive Char characters starting from the right removed.
Definition: StringRef.h:780