xref: /llvm-project/llvm/include/llvm/ADT/StringExtras.h (revision b03b170dd39799b4fb25ffe70b81d0cf0c7d7346)
1 //===- llvm/ADT/StringExtras.h - Useful string functions --------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// This file contains some functions that are useful when dealing with strings.
11 ///
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_ADT_STRINGEXTRAS_H
15 #define LLVM_ADT_STRINGEXTRAS_H
16 
17 #include "llvm/ADT/APSInt.h"
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/ADT/SmallString.h"
20 #include "llvm/ADT/StringRef.h"
21 #include "llvm/ADT/Twine.h"
22 #include <cassert>
23 #include <cstddef>
24 #include <cstdint>
25 #include <cstdlib>
26 #include <cstring>
27 #include <iterator>
28 #include <string>
29 #include <utility>
30 
31 namespace llvm {
32 
33 class raw_ostream;
34 
35 /// hexdigit - Return the hexadecimal character for the
36 /// given number \p X (which should be less than 16).
37 inline char hexdigit(unsigned X, bool LowerCase = false) {
38   assert(X < 16);
39   static const char LUT[] = "0123456789ABCDEF";
40   const uint8_t Offset = LowerCase ? 32 : 0;
41   return LUT[X] | Offset;
42 }
43 
44 /// Given an array of c-style strings terminated by a null pointer, construct
45 /// a vector of StringRefs representing the same strings without the terminating
46 /// null string.
47 inline std::vector<StringRef> toStringRefArray(const char *const *Strings) {
48   std::vector<StringRef> Result;
49   while (*Strings)
50     Result.push_back(*Strings++);
51   return Result;
52 }
53 
54 /// Construct a string ref from a boolean.
55 inline StringRef toStringRef(bool B) { return StringRef(B ? "true" : "false"); }
56 
57 /// Construct a string ref from an array ref of unsigned chars.
58 inline StringRef toStringRef(ArrayRef<uint8_t> Input) {
59   return StringRef(reinterpret_cast<const char *>(Input.begin()), Input.size());
60 }
61 inline StringRef toStringRef(ArrayRef<char> Input) {
62   return StringRef(Input.begin(), Input.size());
63 }
64 
65 /// Construct a string ref from an array ref of unsigned chars.
66 template <class CharT = uint8_t>
67 inline ArrayRef<CharT> arrayRefFromStringRef(StringRef Input) {
68   static_assert(std::is_same<CharT, char>::value ||
69                     std::is_same<CharT, unsigned char>::value ||
70                     std::is_same<CharT, signed char>::value,
71                 "Expected byte type");
72   return ArrayRef<CharT>(reinterpret_cast<const CharT *>(Input.data()),
73                          Input.size());
74 }
75 
76 /// Interpret the given character \p C as a hexadecimal digit and return its
77 /// value.
78 ///
79 /// If \p C is not a valid hex digit, -1U is returned.
80 inline unsigned hexDigitValue(char C) {
81   /* clang-format off */
82   static const int16_t LUT[256] = {
83     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
84     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
85     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
86      0,  1,  2,  3,  4,  5,  6,  7,  8,  9, -1, -1, -1, -1, -1, -1,  // '0'..'9'
87     -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,  // 'A'..'F'
88     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
89     -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,  // 'a'..'f'
90     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
91     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
92     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
93     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
94     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
95     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
96     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
97     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
98     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
99   };
100   /* clang-format on */
101   return LUT[static_cast<unsigned char>(C)];
102 }
103 
104 /// Checks if character \p C is one of the 10 decimal digits.
105 inline bool isDigit(char C) { return C >= '0' && C <= '9'; }
106 
107 /// Checks if character \p C is a hexadecimal numeric character.
108 inline bool isHexDigit(char C) { return hexDigitValue(C) != ~0U; }
109 
110 /// Checks if character \p C is a lowercase letter as classified by "C" locale.
111 inline bool isLower(char C) { return 'a' <= C && C <= 'z'; }
112 
113 /// Checks if character \p C is a uppercase letter as classified by "C" locale.
114 inline bool isUpper(char C) { return 'A' <= C && C <= 'Z'; }
115 
116 /// Checks if character \p C is a valid letter as classified by "C" locale.
117 inline bool isAlpha(char C) { return isLower(C) || isUpper(C); }
118 
119 /// Checks whether character \p C is either a decimal digit or an uppercase or
120 /// lowercase letter as classified by "C" locale.
121 inline bool isAlnum(char C) { return isAlpha(C) || isDigit(C); }
122 
123 /// Checks whether character \p C is valid ASCII (high bit is zero).
124 inline bool isASCII(char C) { return static_cast<unsigned char>(C) <= 127; }
125 
126 /// Checks whether all characters in S are ASCII.
127 inline bool isASCII(llvm::StringRef S) {
128   for (char C : S)
129     if (LLVM_UNLIKELY(!isASCII(C)))
130       return false;
131   return true;
132 }
133 
134 /// Checks whether character \p C is printable.
135 ///
136 /// Locale-independent version of the C standard library isprint whose results
137 /// may differ on different platforms.
138 inline bool isPrint(char C) {
139   unsigned char UC = static_cast<unsigned char>(C);
140   return (0x20 <= UC) && (UC <= 0x7E);
141 }
142 
143 /// Checks whether character \p C is a punctuation character.
144 ///
145 /// Locale-independent version of the C standard library ispunct. The list of
146 /// punctuation characters can be found in the documentation of std::ispunct:
147 /// https://en.cppreference.com/w/cpp/string/byte/ispunct.
148 inline bool isPunct(char C) {
149   static constexpr StringLiteral Punctuations =
150       R"(!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~)";
151   return Punctuations.contains(C);
152 }
153 
154 /// Checks whether character \p C is whitespace in the "C" locale.
155 ///
156 /// Locale-independent version of the C standard library isspace.
157 inline bool isSpace(char C) {
158   return C == ' ' || C == '\f' || C == '\n' || C == '\r' || C == '\t' ||
159          C == '\v';
160 }
161 
162 /// Returns the corresponding lowercase character if \p x is uppercase.
163 inline char toLower(char x) {
164   if (isUpper(x))
165     return x - 'A' + 'a';
166   return x;
167 }
168 
169 /// Returns the corresponding uppercase character if \p x is lowercase.
170 inline char toUpper(char x) {
171   if (isLower(x))
172     return x - 'a' + 'A';
173   return x;
174 }
175 
176 inline std::string utohexstr(uint64_t X, bool LowerCase = false,
177                              unsigned Width = 0) {
178   char Buffer[17];
179   char *BufPtr = std::end(Buffer);
180 
181   if (X == 0) *--BufPtr = '0';
182 
183   for (unsigned i = 0; Width ? (i < Width) : X; ++i) {
184     unsigned char Mod = static_cast<unsigned char>(X) & 15;
185     *--BufPtr = hexdigit(Mod, LowerCase);
186     X >>= 4;
187   }
188 
189   return std::string(BufPtr, std::end(Buffer));
190 }
191 
192 /// Convert buffer \p Input to its hexadecimal representation.
193 /// The returned string is double the size of \p Input.
194 inline void toHex(ArrayRef<uint8_t> Input, bool LowerCase,
195                   SmallVectorImpl<char> &Output) {
196   const size_t Length = Input.size();
197   Output.resize_for_overwrite(Length * 2);
198 
199   for (size_t i = 0; i < Length; i++) {
200     const uint8_t c = Input[i];
201     Output[i * 2    ] = hexdigit(c >> 4, LowerCase);
202     Output[i * 2 + 1] = hexdigit(c & 15, LowerCase);
203   }
204 }
205 
206 inline std::string toHex(ArrayRef<uint8_t> Input, bool LowerCase = false) {
207   SmallString<16> Output;
208   toHex(Input, LowerCase, Output);
209   return std::string(Output);
210 }
211 
212 inline std::string toHex(StringRef Input, bool LowerCase = false) {
213   return toHex(arrayRefFromStringRef(Input), LowerCase);
214 }
215 
216 /// Store the binary representation of the two provided values, \p MSB and
217 /// \p LSB, that make up the nibbles of a hexadecimal digit. If \p MSB or \p LSB
218 /// do not correspond to proper nibbles of a hexadecimal digit, this method
219 /// returns false. Otherwise, returns true.
220 inline bool tryGetHexFromNibbles(char MSB, char LSB, uint8_t &Hex) {
221   unsigned U1 = hexDigitValue(MSB);
222   unsigned U2 = hexDigitValue(LSB);
223   if (U1 == ~0U || U2 == ~0U)
224     return false;
225 
226   Hex = static_cast<uint8_t>((U1 << 4) | U2);
227   return true;
228 }
229 
230 /// Return the binary representation of the two provided values, \p MSB and
231 /// \p LSB, that make up the nibbles of a hexadecimal digit.
232 inline uint8_t hexFromNibbles(char MSB, char LSB) {
233   uint8_t Hex = 0;
234   bool GotHex = tryGetHexFromNibbles(MSB, LSB, Hex);
235   (void)GotHex;
236   assert(GotHex && "MSB and/or LSB do not correspond to hex digits");
237   return Hex;
238 }
239 
240 /// Convert hexadecimal string \p Input to its binary representation and store
241 /// the result in \p Output. Returns true if the binary representation could be
242 /// converted from the hexadecimal string. Returns false if \p Input contains
243 /// non-hexadecimal digits. The output string is half the size of \p Input.
244 inline bool tryGetFromHex(StringRef Input, std::string &Output) {
245   if (Input.empty())
246     return true;
247 
248   // If the input string is not properly aligned on 2 nibbles we pad out the
249   // front with a 0 prefix; e.g. `ABC` -> `0ABC`.
250   Output.resize((Input.size() + 1) / 2);
251   char *OutputPtr = const_cast<char *>(Output.data());
252   if (Input.size() % 2 == 1) {
253     uint8_t Hex = 0;
254     if (!tryGetHexFromNibbles('0', Input.front(), Hex))
255       return false;
256     *OutputPtr++ = Hex;
257     Input = Input.drop_front();
258   }
259 
260   // Convert the nibble pairs (e.g. `9C`) into bytes (0x9C).
261   // With the padding above we know the input is aligned and the output expects
262   // exactly half as many bytes as nibbles in the input.
263   size_t InputSize = Input.size();
264   assert(InputSize % 2 == 0);
265   const char *InputPtr = Input.data();
266   for (size_t OutputIndex = 0; OutputIndex < InputSize / 2; ++OutputIndex) {
267     uint8_t Hex = 0;
268     if (!tryGetHexFromNibbles(InputPtr[OutputIndex * 2 + 0], // MSB
269                               InputPtr[OutputIndex * 2 + 1], // LSB
270                               Hex))
271       return false;
272     OutputPtr[OutputIndex] = Hex;
273   }
274   return true;
275 }
276 
277 /// Convert hexadecimal string \p Input to its binary representation.
278 /// The return string is half the size of \p Input.
279 inline std::string fromHex(StringRef Input) {
280   std::string Hex;
281   bool GotHex = tryGetFromHex(Input, Hex);
282   (void)GotHex;
283   assert(GotHex && "Input contains non hex digits");
284   return Hex;
285 }
286 
287 /// Convert the string \p S to an integer of the specified type using
288 /// the radix \p Base.  If \p Base is 0, auto-detects the radix.
289 /// Returns true if the number was successfully converted, false otherwise.
290 template <typename N> bool to_integer(StringRef S, N &Num, unsigned Base = 0) {
291   return !S.getAsInteger(Base, Num);
292 }
293 
294 namespace detail {
295 template <typename N>
296 inline bool to_float(const Twine &T, N &Num, N (*StrTo)(const char *, char **)) {
297   SmallString<32> Storage;
298   StringRef S = T.toNullTerminatedStringRef(Storage);
299   char *End;
300   N Temp = StrTo(S.data(), &End);
301   if (*End != '\0')
302     return false;
303   Num = Temp;
304   return true;
305 }
306 }
307 
308 inline bool to_float(const Twine &T, float &Num) {
309   return detail::to_float(T, Num, strtof);
310 }
311 
312 inline bool to_float(const Twine &T, double &Num) {
313   return detail::to_float(T, Num, strtod);
314 }
315 
316 inline bool to_float(const Twine &T, long double &Num) {
317   return detail::to_float(T, Num, strtold);
318 }
319 
320 inline std::string utostr(uint64_t X, bool isNeg = false) {
321   char Buffer[21];
322   char *BufPtr = std::end(Buffer);
323 
324   if (X == 0) *--BufPtr = '0';  // Handle special case...
325 
326   while (X) {
327     *--BufPtr = '0' + char(X % 10);
328     X /= 10;
329   }
330 
331   if (isNeg) *--BufPtr = '-';   // Add negative sign...
332   return std::string(BufPtr, std::end(Buffer));
333 }
334 
335 inline std::string itostr(int64_t X) {
336   if (X < 0)
337     return utostr(static_cast<uint64_t>(1) + ~static_cast<uint64_t>(X), true);
338   else
339     return utostr(static_cast<uint64_t>(X));
340 }
341 
342 inline std::string toString(const APInt &I, unsigned Radix, bool Signed,
343                             bool formatAsCLiteral = false,
344                             bool UpperCase = true,
345                             bool InsertSeparators = false) {
346   SmallString<40> S;
347   I.toString(S, Radix, Signed, formatAsCLiteral, UpperCase, InsertSeparators);
348   return std::string(S);
349 }
350 
351 inline std::string toString(const APSInt &I, unsigned Radix) {
352   return toString(I, Radix, I.isSigned());
353 }
354 
355 /// StrInStrNoCase - Portable version of strcasestr.  Locates the first
356 /// occurrence of string 's1' in string 's2', ignoring case.  Returns
357 /// the offset of s2 in s1 or npos if s2 cannot be found.
358 StringRef::size_type StrInStrNoCase(StringRef s1, StringRef s2);
359 
360 /// getToken - This function extracts one token from source, ignoring any
361 /// leading characters that appear in the Delimiters string, and ending the
362 /// token at any of the characters that appear in the Delimiters string.  If
363 /// there are no tokens in the source string, an empty string is returned.
364 /// The function returns a pair containing the extracted token and the
365 /// remaining tail string.
366 std::pair<StringRef, StringRef> getToken(StringRef Source,
367                                          StringRef Delimiters = " \t\n\v\f\r");
368 
369 /// SplitString - Split up the specified string according to the specified
370 /// delimiters, appending the result fragments to the output list.
371 void SplitString(StringRef Source,
372                  SmallVectorImpl<StringRef> &OutFragments,
373                  StringRef Delimiters = " \t\n\v\f\r");
374 
375 /// Returns the English suffix for an ordinal integer (-st, -nd, -rd, -th).
376 inline StringRef getOrdinalSuffix(unsigned Val) {
377   // It is critically important that we do this perfectly for
378   // user-written sequences with over 100 elements.
379   switch (Val % 100) {
380   case 11:
381   case 12:
382   case 13:
383     return "th";
384   default:
385     switch (Val % 10) {
386       case 1: return "st";
387       case 2: return "nd";
388       case 3: return "rd";
389       default: return "th";
390     }
391   }
392 }
393 
394 /// Print each character of the specified string, escaping it if it is not
395 /// printable or if it is an escape char.
396 void printEscapedString(StringRef Name, raw_ostream &Out);
397 
398 /// Print each character of the specified string, escaping HTML special
399 /// characters.
400 void printHTMLEscaped(StringRef String, raw_ostream &Out);
401 
402 /// printLowerCase - Print each character as lowercase if it is uppercase.
403 void printLowerCase(StringRef String, raw_ostream &Out);
404 
405 /// Converts a string from camel-case to snake-case by replacing all uppercase
406 /// letters with '_' followed by the letter in lowercase, except if the
407 /// uppercase letter is the first character of the string.
408 std::string convertToSnakeFromCamelCase(StringRef input);
409 
410 /// Converts a string from snake-case to camel-case by replacing all occurrences
411 /// of '_' followed by a lowercase letter with the letter in uppercase.
412 /// Optionally allow capitalization of the first letter (if it is a lowercase
413 /// letter)
414 std::string convertToCamelFromSnakeCase(StringRef input,
415                                         bool capitalizeFirst = false);
416 
417 namespace detail {
418 
419 template <typename IteratorT>
420 inline std::string join_impl(IteratorT Begin, IteratorT End,
421                              StringRef Separator, std::input_iterator_tag) {
422   std::string S;
423   if (Begin == End)
424     return S;
425 
426   S += (*Begin);
427   while (++Begin != End) {
428     S += Separator;
429     S += (*Begin);
430   }
431   return S;
432 }
433 
434 template <typename IteratorT>
435 inline std::string join_impl(IteratorT Begin, IteratorT End,
436                              StringRef Separator, std::forward_iterator_tag) {
437   std::string S;
438   if (Begin == End)
439     return S;
440 
441   size_t Len = (std::distance(Begin, End) - 1) * Separator.size();
442   for (IteratorT I = Begin; I != End; ++I)
443     Len += StringRef(*I).size();
444   S.reserve(Len);
445   size_t PrevCapacity = S.capacity();
446   (void)PrevCapacity;
447   S += (*Begin);
448   while (++Begin != End) {
449     S += Separator;
450     S += (*Begin);
451   }
452   assert(PrevCapacity == S.capacity() && "String grew during building");
453   return S;
454 }
455 
456 template <typename Sep>
457 inline void join_items_impl(std::string &Result, Sep Separator) {}
458 
459 template <typename Sep, typename Arg>
460 inline void join_items_impl(std::string &Result, Sep Separator,
461                             const Arg &Item) {
462   Result += Item;
463 }
464 
465 template <typename Sep, typename Arg1, typename... Args>
466 inline void join_items_impl(std::string &Result, Sep Separator, const Arg1 &A1,
467                             Args &&... Items) {
468   Result += A1;
469   Result += Separator;
470   join_items_impl(Result, Separator, std::forward<Args>(Items)...);
471 }
472 
473 inline size_t join_one_item_size(char) { return 1; }
474 inline size_t join_one_item_size(const char *S) { return S ? ::strlen(S) : 0; }
475 
476 template <typename T> inline size_t join_one_item_size(const T &Str) {
477   return Str.size();
478 }
479 
480 template <typename... Args> inline size_t join_items_size(Args &&...Items) {
481   return (0 + ... + join_one_item_size(std::forward<Args>(Items)));
482 }
483 
484 } // end namespace detail
485 
486 /// Joins the strings in the range [Begin, End), adding Separator between
487 /// the elements.
488 template <typename IteratorT>
489 inline std::string join(IteratorT Begin, IteratorT End, StringRef Separator) {
490   using tag = typename std::iterator_traits<IteratorT>::iterator_category;
491   return detail::join_impl(Begin, End, Separator, tag());
492 }
493 
494 /// Joins the strings in the range [R.begin(), R.end()), adding Separator
495 /// between the elements.
496 template <typename Range>
497 inline std::string join(Range &&R, StringRef Separator) {
498   return join(R.begin(), R.end(), Separator);
499 }
500 
501 /// Joins the strings in the parameter pack \p Items, adding \p Separator
502 /// between the elements.  All arguments must be implicitly convertible to
503 /// std::string, or there should be an overload of std::string::operator+=()
504 /// that accepts the argument explicitly.
505 template <typename Sep, typename... Args>
506 inline std::string join_items(Sep Separator, Args &&... Items) {
507   std::string Result;
508   if (sizeof...(Items) == 0)
509     return Result;
510 
511   size_t NS = detail::join_one_item_size(Separator);
512   size_t NI = detail::join_items_size(std::forward<Args>(Items)...);
513   Result.reserve(NI + (sizeof...(Items) - 1) * NS + 1);
514   detail::join_items_impl(Result, Separator, std::forward<Args>(Items)...);
515   return Result;
516 }
517 
518 /// A helper class to return the specified delimiter string after the first
519 /// invocation of operator StringRef().  Used to generate a comma-separated
520 /// list from a loop like so:
521 ///
522 /// \code
523 ///   ListSeparator LS;
524 ///   for (auto &I : C)
525 ///     OS << LS << I.getName();
526 /// \end
527 class ListSeparator {
528   bool First = true;
529   StringRef Separator;
530 
531 public:
532   ListSeparator(StringRef Separator = ", ") : Separator(Separator) {}
533   operator StringRef() {
534     if (First) {
535       First = false;
536       return {};
537     }
538     return Separator;
539   }
540 };
541 
542 /// A forward iterator over partitions of string over a separator.
543 class SplittingIterator
544     : public iterator_facade_base<SplittingIterator, std::forward_iterator_tag,
545                                   StringRef> {
546   char SeparatorStorage;
547   StringRef Current;
548   StringRef Next;
549   StringRef Separator;
550 
551 public:
552   SplittingIterator(StringRef Str, StringRef Separator)
553       : Next(Str), Separator(Separator) {
554     ++*this;
555   }
556 
557   SplittingIterator(StringRef Str, char Separator)
558       : SeparatorStorage(Separator), Next(Str),
559         Separator(&SeparatorStorage, 1) {
560     ++*this;
561   }
562 
563   SplittingIterator(const SplittingIterator &R)
564       : SeparatorStorage(R.SeparatorStorage), Current(R.Current), Next(R.Next),
565         Separator(R.Separator) {
566     if (R.Separator.data() == &R.SeparatorStorage)
567       Separator = StringRef(&SeparatorStorage, 1);
568   }
569 
570   SplittingIterator &operator=(const SplittingIterator &R) {
571     if (this == &R)
572       return *this;
573 
574     SeparatorStorage = R.SeparatorStorage;
575     Current = R.Current;
576     Next = R.Next;
577     Separator = R.Separator;
578     if (R.Separator.data() == &R.SeparatorStorage)
579       Separator = StringRef(&SeparatorStorage, 1);
580     return *this;
581   }
582 
583   bool operator==(const SplittingIterator &R) const {
584     assert(Separator == R.Separator);
585     return Current.data() == R.Current.data();
586   }
587 
588   const StringRef &operator*() const { return Current; }
589 
590   StringRef &operator*() { return Current; }
591 
592   SplittingIterator &operator++() {
593     std::tie(Current, Next) = Next.split(Separator);
594     return *this;
595   }
596 };
597 
598 /// Split the specified string over a separator and return a range-compatible
599 /// iterable over its partitions.  Used to permit conveniently iterating
600 /// over separated strings like so:
601 ///
602 /// \code
603 ///   for (StringRef x : llvm::split("foo,bar,baz", ","))
604 ///     ...;
605 /// \end
606 ///
607 /// Note that the passed string must remain valid throuhgout lifetime
608 /// of the iterators.
609 inline iterator_range<SplittingIterator> split(StringRef Str, StringRef Separator) {
610   return {SplittingIterator(Str, Separator),
611           SplittingIterator(StringRef(), Separator)};
612 }
613 
614 inline iterator_range<SplittingIterator> split(StringRef Str, char Separator) {
615   return {SplittingIterator(Str, Separator),
616           SplittingIterator(StringRef(), Separator)};
617 }
618 
619 } // end namespace llvm
620 
621 #endif // LLVM_ADT_STRINGEXTRAS_H
622