StringRef.h revision 160a3bf74d1a2b048f65e2162d038ed96eddde01
14cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar//===--- StringRef.h - Constant String Reference Wrapper --------*- C++ -*-===//
24cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar//
34cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar//                     The LLVM Compiler Infrastructure
44cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar//
54cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar// This file is distributed under the University of Illinois Open Source
64cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar// License. See LICENSE.TXT for details.
74cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar//
84cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar//===----------------------------------------------------------------------===//
94cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar
104cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar#ifndef LLVM_ADT_STRINGREF_H
114cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar#define LLVM_ADT_STRINGREF_H
124cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar
1385f49835c288b0107cb4020d4e59e491c146973dDaniel Dunbar#include <cassert>
144cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar#include <cstring>
151acdcd5b0d0893e6c9a3b7618a7facf9e2d5dec6Benjamin Kramer#include <utility>
164cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar#include <string>
174cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar
184cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbarnamespace llvm {
19c78c0c99a0fe1703ae72fc51e440aaa8e4e19e91Rafael Espindola  template<typename T>
20c78c0c99a0fe1703ae72fc51e440aaa8e4e19e91Rafael Espindola  class SmallVectorImpl;
211e7ad3993d8700488895fa372ecad55443f53485John McCall  class APInt;
22f5fdf73238dfd923f33bcbbd397cff6752d9c41eDaniel Dunbar
234cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar  /// StringRef - Represent a constant reference to a string, i.e. a character
244cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar  /// array and a length, which need not be null terminated.
254cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar  ///
264cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar  /// This class does not own the string data, it is expected to be used in
274cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar  /// situations where the character data resides in some other buffer, whose
284cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar  /// lifetime extends past that of the StringRef. For this reason, it is not in
294cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar  /// general safe to store a StringRef.
304cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar  class StringRef {
314cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar  public:
324cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    typedef const char *iterator;
33af2a8361e4e5b45441b6e73c332fb60c36892468Chris Lattner    typedef const char *const_iterator;
34b834a7b73ce0dcf8fbf8d8b0d62f69e4b78059adDaniel Dunbar    static const size_t npos = ~size_t(0);
35db513bc0963fbf372f898f8b94fc13994663c0c6Chris Lattner    typedef size_t size_type;
36abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher
374cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar  private:
384cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    /// The start of the string, in an external buffer.
394cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    const char *Data;
404cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar
414cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    /// The length of the string.
42f5fdf73238dfd923f33bcbbd397cff6752d9c41eDaniel Dunbar    size_t Length;
434cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar
442fe05d80d396b6ca0bdc66ec17732b8c514d575eTorok Edwin    // Workaround PR5482: nearly all gcc 4.x miscompile StringRef and std::min()
452fe05d80d396b6ca0bdc66ec17732b8c514d575eTorok Edwin    // Changing the arg of min to be an integer, instead of a reference to an
462fe05d80d396b6ca0bdc66ec17732b8c514d575eTorok Edwin    // integer works around this bug.
47fd813bc85027b8e4f8dc42b485b254cff210012dDan Gohman    static size_t min(size_t a, size_t b) { return a < b ? a : b; }
48fd813bc85027b8e4f8dc42b485b254cff210012dDan Gohman    static size_t max(size_t a, size_t b) { return a > b ? a : b; }
492fe05d80d396b6ca0bdc66ec17732b8c514d575eTorok Edwin
504cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar  public:
514cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    /// @name Constructors
524cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    /// @{
534cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar
544cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    /// Construct an empty string ref.
554cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    /*implicit*/ StringRef() : Data(0), Length(0) {}
564cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar
574cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    /// Construct a string ref from a cstring.
58abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher    /*implicit*/ StringRef(const char *Str)
5989fccca4b01f148a7244f47e5a484cd793a1c30bDaniel Dunbar      : Data(Str), Length(::strlen(Str)) {}
60abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher
614cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    /// Construct a string ref from a pointer and length.
62abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher    /*implicit*/ StringRef(const char *data, size_t length)
63835b142edd2a3da6d0b7a4e47d50408953a49db4Dan Gohman      : Data(data), Length(length) {}
644cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar
654cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    /// Construct a string ref from an std::string.
66abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher    /*implicit*/ StringRef(const std::string &Str)
6724f8e29b4efe70496474c6d43aa6abfa27c21511Dan Gohman      : Data(Str.data()), Length(Str.length()) {}
684cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar
694cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    /// @}
704cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    /// @name Iterators
714cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    /// @{
724cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar
734cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    iterator begin() const { return Data; }
744cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar
754cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    iterator end() const { return Data + Length; }
764cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar
774cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    /// @}
784cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    /// @name String Operations
794cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    /// @{
804cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar
814cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    /// data - Get a pointer to the start of the string (which may not be null
824cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    /// terminated).
834cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    const char *data() const { return Data; }
844cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar
854cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    /// empty - Check if the string is empty.
864cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    bool empty() const { return Length == 0; }
874cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar
884cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    /// size - Get the string size.
897cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar    size_t size() const { return Length; }
90ac55b85438da378bab227fd34167bb0c4a9249aaDaniel Dunbar
91ac55b85438da378bab227fd34167bb0c4a9249aaDaniel Dunbar    /// front - Get the first character in the string.
92ac55b85438da378bab227fd34167bb0c4a9249aaDaniel Dunbar    char front() const {
93ac55b85438da378bab227fd34167bb0c4a9249aaDaniel Dunbar      assert(!empty());
94ac55b85438da378bab227fd34167bb0c4a9249aaDaniel Dunbar      return Data[0];
95ac55b85438da378bab227fd34167bb0c4a9249aaDaniel Dunbar    }
96abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher
97ac55b85438da378bab227fd34167bb0c4a9249aaDaniel Dunbar    /// back - Get the last character in the string.
98e36df3fd31a08a41d9ad04fcba182b616b030c9cChris Lattner    char back() const {
99e36df3fd31a08a41d9ad04fcba182b616b030c9cChris Lattner      assert(!empty());
100e36df3fd31a08a41d9ad04fcba182b616b030c9cChris Lattner      return Data[Length-1];
101e36df3fd31a08a41d9ad04fcba182b616b030c9cChris Lattner    }
1027cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar
1037cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar    /// equals - Check for string equality, this is more efficient than
104ac55b85438da378bab227fd34167bb0c4a9249aaDaniel Dunbar    /// compare() when the relative ordering of inequal strings isn't needed.
1052928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar    bool equals(StringRef RHS) const {
106abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher      return (Length == RHS.Length &&
1077e763ebd982e199224a2d2e0cc802d09d2822b34Chris Lattner              memcmp(Data, RHS.Data, RHS.Length) == 0);
1087cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar    }
1094cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar
11005872ea804cdc9534960b30d28a391928c61481aBenjamin Kramer    /// equals_lower - Check for string equality, ignoring case.
11105872ea804cdc9534960b30d28a391928c61481aBenjamin Kramer    bool equals_lower(StringRef RHS) const {
11205872ea804cdc9534960b30d28a391928c61481aBenjamin Kramer      return Length == RHS.Length && compare_lower(RHS) == 0;
11305872ea804cdc9534960b30d28a391928c61481aBenjamin Kramer    }
11405872ea804cdc9534960b30d28a391928c61481aBenjamin Kramer
1154cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    /// compare - Compare two strings; the result is -1, 0, or 1 if this string
1164cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    /// is lexicographically less than, equal to, or greater than the \arg RHS.
1172928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar    int compare(StringRef RHS) const {
1184cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar      // Check the prefix for a mismatch.
1192fe05d80d396b6ca0bdc66ec17732b8c514d575eTorok Edwin      if (int Res = memcmp(Data, RHS.Data, min(Length, RHS.Length)))
1204cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar        return Res < 0 ? -1 : 1;
1214cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar
1224cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar      // Otherwise the prefixes match, so we only need to check the lengths.
1234cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar      if (Length == RHS.Length)
1244cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar        return 0;
1254cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar      return Length < RHS.Length ? -1 : 1;
1264cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    }
1274cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar
12805872ea804cdc9534960b30d28a391928c61481aBenjamin Kramer    /// compare_lower - Compare two strings, ignoring case.
12905872ea804cdc9534960b30d28a391928c61481aBenjamin Kramer    int compare_lower(StringRef RHS) const;
13005872ea804cdc9534960b30d28a391928c61481aBenjamin Kramer
131160a3bf74d1a2b048f65e2162d038ed96eddde01Jakob Stoklund Olesen    /// compare_numeric - Compare two strings, treating sequences of digits as
132160a3bf74d1a2b048f65e2162d038ed96eddde01Jakob Stoklund Olesen    /// numbers.
133160a3bf74d1a2b048f65e2162d038ed96eddde01Jakob Stoklund Olesen    int compare_numeric(StringRef RHS) const;
134160a3bf74d1a2b048f65e2162d038ed96eddde01Jakob Stoklund Olesen
135441c8b4ad17c0d029b2247c367111395e7ad068cDouglas Gregor    /// \brief Determine the edit distance between this string and another
136441c8b4ad17c0d029b2247c367111395e7ad068cDouglas Gregor    /// string.
137441c8b4ad17c0d029b2247c367111395e7ad068cDouglas Gregor    ///
138441c8b4ad17c0d029b2247c367111395e7ad068cDouglas Gregor    /// \param Other the string to compare this string against.
139441c8b4ad17c0d029b2247c367111395e7ad068cDouglas Gregor    ///
140441c8b4ad17c0d029b2247c367111395e7ad068cDouglas Gregor    /// \param AllowReplacements whether to allow character
141441c8b4ad17c0d029b2247c367111395e7ad068cDouglas Gregor    /// replacements (change one character into another) as a single
142441c8b4ad17c0d029b2247c367111395e7ad068cDouglas Gregor    /// operation, rather than as two operations (an insertion and a
143441c8b4ad17c0d029b2247c367111395e7ad068cDouglas Gregor    /// removal).
144441c8b4ad17c0d029b2247c367111395e7ad068cDouglas Gregor    ///
145441c8b4ad17c0d029b2247c367111395e7ad068cDouglas Gregor    /// \returns the minimum number of character insertions, removals,
146441c8b4ad17c0d029b2247c367111395e7ad068cDouglas Gregor    /// or (if \p AllowReplacements is \c true) replacements needed to
147441c8b4ad17c0d029b2247c367111395e7ad068cDouglas Gregor    /// transform one of the given strings into the other. If zero,
148441c8b4ad17c0d029b2247c367111395e7ad068cDouglas Gregor    /// the strings are identical.
149441c8b4ad17c0d029b2247c367111395e7ad068cDouglas Gregor    unsigned edit_distance(StringRef Other, bool AllowReplacements = true);
150441c8b4ad17c0d029b2247c367111395e7ad068cDouglas Gregor
1514cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    /// str - Get the contents as an std::string.
1524cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    std::string str() const { return std::string(Data, Length); }
1534cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar
1544cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    /// @}
1554cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    /// @name Operator Overloads
1564cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    /// @{
1574cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar
158abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher    char operator[](size_t Index) const {
1594cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar      assert(Index < Length && "Invalid index!");
160abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher      return Data[Index];
1614cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    }
1624cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar
1634cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    /// @}
1644cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    /// @name Type Conversions
1654cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    /// @{
1664cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar
1674cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    operator std::string() const {
1684cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar      return str();
1694cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    }
1704cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar
1714cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar    /// @}
1720ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar    /// @name String Predicates
1730ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar    /// @{
1740ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar
1750ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar    /// startswith - Check if this string starts with the given \arg Prefix.
1762928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar    bool startswith(StringRef Prefix) const {
177d5b1f8a8426e82990dafc6e3336fefc6635c8fa4Eli Friedman      return Length >= Prefix.Length &&
178d5b1f8a8426e82990dafc6e3336fefc6635c8fa4Eli Friedman             memcmp(Data, Prefix.Data, Prefix.Length) == 0;
1790ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar    }
1800ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar
1810ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar    /// endswith - Check if this string ends with the given \arg Suffix.
1822928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar    bool endswith(StringRef Suffix) const {
183d5b1f8a8426e82990dafc6e3336fefc6635c8fa4Eli Friedman      return Length >= Suffix.Length &&
184d5b1f8a8426e82990dafc6e3336fefc6635c8fa4Eli Friedman             memcmp(end() - Suffix.Length, Suffix.Data, Suffix.Length) == 0;
1850ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar    }
1860ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar
1870ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar    /// @}
1880ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar    /// @name String Searching
1890ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar    /// @{
1900ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar
191e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar    /// find - Search for the first character \arg C in the string.
1920ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar    ///
1933c37bb8dbe886993dcd8f37dec0d94762393f3d4Kovarththanan Rajaratnam    /// \return - The index of the first occurrence of \arg C, or npos if not
1940ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar    /// found.
19564066bd8b593082f622bbc25716938a453363d2fDaniel Dunbar    size_t find(char C, size_t From = 0) const {
1962fe05d80d396b6ca0bdc66ec17732b8c514d575eTorok Edwin      for (size_t i = min(From, Length), e = Length; i != e; ++i)
1970ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar        if (Data[i] == C)
1980ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar          return i;
1990ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar      return npos;
2000ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar    }
2010ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar
202e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar    /// find - Search for the first string \arg Str in the string.
2030ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar    ///
2043c37bb8dbe886993dcd8f37dec0d94762393f3d4Kovarththanan Rajaratnam    /// \return - The index of the first occurrence of \arg Str, or npos if not
2050ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar    /// found.
20664066bd8b593082f622bbc25716938a453363d2fDaniel Dunbar    size_t find(StringRef Str, size_t From = 0) const;
207abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher
208e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar    /// rfind - Search for the last character \arg C in the string.
209e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar    ///
2103c37bb8dbe886993dcd8f37dec0d94762393f3d4Kovarththanan Rajaratnam    /// \return - The index of the last occurrence of \arg C, or npos if not
211e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar    /// found.
212c936fe8cb356931f23e6f17ce1bd5789eeae1ecbChris Lattner    size_t rfind(char C, size_t From = npos) const {
2132fe05d80d396b6ca0bdc66ec17732b8c514d575eTorok Edwin      From = min(From, Length);
214c936fe8cb356931f23e6f17ce1bd5789eeae1ecbChris Lattner      size_t i = From;
215c936fe8cb356931f23e6f17ce1bd5789eeae1ecbChris Lattner      while (i != 0) {
216e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar        --i;
217e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar        if (Data[i] == C)
218e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar          return i;
219e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar      }
220e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar      return npos;
221e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar    }
222abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher
223e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar    /// rfind - Search for the last string \arg Str in the string.
224e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar    ///
2253c37bb8dbe886993dcd8f37dec0d94762393f3d4Kovarththanan Rajaratnam    /// \return - The index of the last occurrence of \arg Str, or npos if not
226e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar    /// found.
2272928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar    size_t rfind(StringRef Str) const;
228abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher
22964066bd8b593082f622bbc25716938a453363d2fDaniel Dunbar    /// find_first_of - Find the first character in the string that is \arg C,
23064066bd8b593082f622bbc25716938a453363d2fDaniel Dunbar    /// or npos if not found. Same as find.
2314c269e2feb230d4380c0b3cd72da517bd2222023Eric Christopher    size_type find_first_of(char C, size_t = 0) const { return find(C); }
232abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher
23364066bd8b593082f622bbc25716938a453363d2fDaniel Dunbar    /// find_first_of - Find the first character in the string that is in \arg
23464066bd8b593082f622bbc25716938a453363d2fDaniel Dunbar    /// Chars, or npos if not found.
23564066bd8b593082f622bbc25716938a453363d2fDaniel Dunbar    ///
23664066bd8b593082f622bbc25716938a453363d2fDaniel Dunbar    /// Note: O(size() * Chars.size())
23764066bd8b593082f622bbc25716938a453363d2fDaniel Dunbar    size_type find_first_of(StringRef Chars, size_t From = 0) const;
238abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher
23905a32c8ab118d9c92dc9b4ecaa7a6fed67241215Chris Lattner    /// find_first_not_of - Find the first character in the string that is not
24064066bd8b593082f622bbc25716938a453363d2fDaniel Dunbar    /// \arg C or npos if not found.
24164066bd8b593082f622bbc25716938a453363d2fDaniel Dunbar    size_type find_first_not_of(char C, size_t From = 0) const;
24264066bd8b593082f622bbc25716938a453363d2fDaniel Dunbar
24364066bd8b593082f622bbc25716938a453363d2fDaniel Dunbar    /// find_first_not_of - Find the first character in the string that is not
24464066bd8b593082f622bbc25716938a453363d2fDaniel Dunbar    /// in the string \arg Chars, or npos if not found.
24564066bd8b593082f622bbc25716938a453363d2fDaniel Dunbar    ///
24664066bd8b593082f622bbc25716938a453363d2fDaniel Dunbar    /// Note: O(size() * Chars.size())
24764066bd8b593082f622bbc25716938a453363d2fDaniel Dunbar    size_type find_first_not_of(StringRef Chars, size_t From = 0) const;
248abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher
24905a32c8ab118d9c92dc9b4ecaa7a6fed67241215Chris Lattner    /// @}
25005a32c8ab118d9c92dc9b4ecaa7a6fed67241215Chris Lattner    /// @name Helpful Algorithms
25105a32c8ab118d9c92dc9b4ecaa7a6fed67241215Chris Lattner    /// @{
252abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher
2535caba3bcb14fae4b36924463ed2bcf3846f029a9Daniel Dunbar    /// count - Return the number of occurrences of \arg C in the string.
2545caba3bcb14fae4b36924463ed2bcf3846f029a9Daniel Dunbar    size_t count(char C) const {
2555caba3bcb14fae4b36924463ed2bcf3846f029a9Daniel Dunbar      size_t Count = 0;
2565caba3bcb14fae4b36924463ed2bcf3846f029a9Daniel Dunbar      for (size_t i = 0, e = Length; i != e; ++i)
2575caba3bcb14fae4b36924463ed2bcf3846f029a9Daniel Dunbar        if (Data[i] == C)
258323a3e653340781bad4c4c3245d9b25d5ab02685Daniel Dunbar          ++Count;
2595caba3bcb14fae4b36924463ed2bcf3846f029a9Daniel Dunbar      return Count;
2605caba3bcb14fae4b36924463ed2bcf3846f029a9Daniel Dunbar    }
261abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher
2625caba3bcb14fae4b36924463ed2bcf3846f029a9Daniel Dunbar    /// count - Return the number of non-overlapped occurrences of \arg Str in
2635caba3bcb14fae4b36924463ed2bcf3846f029a9Daniel Dunbar    /// the string.
2642928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar    size_t count(StringRef Str) const;
265abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher
266cea1438cf59c7cd3a632d61d78e68589315510d3Chris Lattner    /// getAsInteger - Parse the current string as an integer of the specified
267cea1438cf59c7cd3a632d61d78e68589315510d3Chris Lattner    /// radix.  If Radix is specified as zero, this does radix autosensing using
268cea1438cf59c7cd3a632d61d78e68589315510d3Chris Lattner    /// extended C rules: 0 is octal, 0x is hex, 0b is binary.
269cea1438cf59c7cd3a632d61d78e68589315510d3Chris Lattner    ///
270cea1438cf59c7cd3a632d61d78e68589315510d3Chris Lattner    /// If the string is invalid or if only a subset of the string is valid,
271cea1438cf59c7cd3a632d61d78e68589315510d3Chris Lattner    /// this returns true to signify the error.  The string is considered
272cea1438cf59c7cd3a632d61d78e68589315510d3Chris Lattner    /// erroneous if empty.
273cea1438cf59c7cd3a632d61d78e68589315510d3Chris Lattner    ///
27463c6b7dc67f0061340c0701f3d5b1de142f58cecChris Lattner    bool getAsInteger(unsigned Radix, long long &Result) const;
275cea1438cf59c7cd3a632d61d78e68589315510d3Chris Lattner    bool getAsInteger(unsigned Radix, unsigned long long &Result) const;
27663c6b7dc67f0061340c0701f3d5b1de142f58cecChris Lattner    bool getAsInteger(unsigned Radix, int &Result) const;
27763c6b7dc67f0061340c0701f3d5b1de142f58cecChris Lattner    bool getAsInteger(unsigned Radix, unsigned &Result) const;
278cea1438cf59c7cd3a632d61d78e68589315510d3Chris Lattner
279cea1438cf59c7cd3a632d61d78e68589315510d3Chris Lattner    // TODO: Provide overloads for int/unsigned that check for overflow.
280abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher
2811e7ad3993d8700488895fa372ecad55443f53485John McCall    /// getAsInteger - Parse the current string as an integer of the
2821e7ad3993d8700488895fa372ecad55443f53485John McCall    /// specified radix, or of an autosensed radix if the radix given
2831e7ad3993d8700488895fa372ecad55443f53485John McCall    /// is 0.  The current value in Result is discarded, and the
2841e7ad3993d8700488895fa372ecad55443f53485John McCall    /// storage is changed to be wide enough to store the parsed
2851e7ad3993d8700488895fa372ecad55443f53485John McCall    /// integer.
2861e7ad3993d8700488895fa372ecad55443f53485John McCall    ///
2871e7ad3993d8700488895fa372ecad55443f53485John McCall    /// Returns true if the string does not solely consist of a valid
2881e7ad3993d8700488895fa372ecad55443f53485John McCall    /// non-empty number in the appropriate base.
2891e7ad3993d8700488895fa372ecad55443f53485John McCall    ///
2901e7ad3993d8700488895fa372ecad55443f53485John McCall    /// APInt::fromString is superficially similar but assumes the
2911e7ad3993d8700488895fa372ecad55443f53485John McCall    /// string is well-formed in the given radix.
2921e7ad3993d8700488895fa372ecad55443f53485John McCall    bool getAsInteger(unsigned Radix, APInt &Result) const;
2931e7ad3993d8700488895fa372ecad55443f53485John McCall
294cea1438cf59c7cd3a632d61d78e68589315510d3Chris Lattner    /// @}
2950ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar    /// @name Substring Operations
296f5fdf73238dfd923f33bcbbd397cff6752d9c41eDaniel Dunbar    /// @{
297f5fdf73238dfd923f33bcbbd397cff6752d9c41eDaniel Dunbar
298d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar    /// substr - Return a reference to the substring from [Start, Start + N).
299f5fdf73238dfd923f33bcbbd397cff6752d9c41eDaniel Dunbar    ///
300f5fdf73238dfd923f33bcbbd397cff6752d9c41eDaniel Dunbar    /// \param Start - The index of the starting character in the substring; if
301d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar    /// the index is npos or greater than the length of the string then the
302d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar    /// empty substring will be returned.
303f5fdf73238dfd923f33bcbbd397cff6752d9c41eDaniel Dunbar    ///
304f5fdf73238dfd923f33bcbbd397cff6752d9c41eDaniel Dunbar    /// \param N - The number of characters to included in the substring. If N
305f5fdf73238dfd923f33bcbbd397cff6752d9c41eDaniel Dunbar    /// exceeds the number of characters remaining in the string, the string
306f5fdf73238dfd923f33bcbbd397cff6752d9c41eDaniel Dunbar    /// suffix (starting with \arg Start) will be returned.
307f5fdf73238dfd923f33bcbbd397cff6752d9c41eDaniel Dunbar    StringRef substr(size_t Start, size_t N = npos) const {
3082fe05d80d396b6ca0bdc66ec17732b8c514d575eTorok Edwin      Start = min(Start, Length);
3092fe05d80d396b6ca0bdc66ec17732b8c514d575eTorok Edwin      return StringRef(Data + Start, min(N, Length - Start));
310f5fdf73238dfd923f33bcbbd397cff6752d9c41eDaniel Dunbar    }
311f5fdf73238dfd923f33bcbbd397cff6752d9c41eDaniel Dunbar
312d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar    /// slice - Return a reference to the substring from [Start, End).
313d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar    ///
314d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar    /// \param Start - The index of the starting character in the substring; if
315d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar    /// the index is npos or greater than the length of the string then the
316d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar    /// empty substring will be returned.
317d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar    ///
318d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar    /// \param End - The index following the last character to include in the
319d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar    /// substring. If this is npos, or less than \arg Start, or exceeds the
320d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar    /// number of characters remaining in the string, the string suffix
321d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar    /// (starting with \arg Start) will be returned.
322d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar    StringRef slice(size_t Start, size_t End) const {
3232fe05d80d396b6ca0bdc66ec17732b8c514d575eTorok Edwin      Start = min(Start, Length);
3242fe05d80d396b6ca0bdc66ec17732b8c514d575eTorok Edwin      End = min(max(Start, End), Length);
325d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar      return StringRef(Data + Start, End - Start);
326d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar    }
327d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar
3283c37bb8dbe886993dcd8f37dec0d94762393f3d4Kovarththanan Rajaratnam    /// split - Split into two substrings around the first occurrence of a
329d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar    /// separator character.
330d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar    ///
331d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar    /// If \arg Separator is in the string, then the result is a pair (LHS, RHS)
332d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar    /// such that (*this == LHS + Separator + RHS) is true and RHS is
333d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar    /// maximal. If \arg Separator is not in the string, then the result is a
334d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar    /// pair (LHS, RHS) where (*this == LHS) and (RHS == "").
335d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar    ///
336d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar    /// \param Separator - The character to split on.
337d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar    /// \return - The split substrings.
338d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar    std::pair<StringRef, StringRef> split(char Separator) const {
3390ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar      size_t Idx = find(Separator);
3400ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar      if (Idx == npos)
341d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar        return std::make_pair(*this, StringRef());
3420ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar      return std::make_pair(slice(0, Idx), slice(Idx+1, npos));
343c9af366fc39d657b7d416d16988265d86a641184Daniel Dunbar    }
344c9af366fc39d657b7d416d16988265d86a641184Daniel Dunbar
3453c37bb8dbe886993dcd8f37dec0d94762393f3d4Kovarththanan Rajaratnam    /// split - Split into two substrings around the first occurrence of a
346a8333d3d107df1e0b6bde986ed0532915e154b65Daniel Dunbar    /// separator string.
347a8333d3d107df1e0b6bde986ed0532915e154b65Daniel Dunbar    ///
348a8333d3d107df1e0b6bde986ed0532915e154b65Daniel Dunbar    /// If \arg Separator is in the string, then the result is a pair (LHS, RHS)
349a8333d3d107df1e0b6bde986ed0532915e154b65Daniel Dunbar    /// such that (*this == LHS + Separator + RHS) is true and RHS is
350a8333d3d107df1e0b6bde986ed0532915e154b65Daniel Dunbar    /// maximal. If \arg Separator is not in the string, then the result is a
351a8333d3d107df1e0b6bde986ed0532915e154b65Daniel Dunbar    /// pair (LHS, RHS) where (*this == LHS) and (RHS == "").
352a8333d3d107df1e0b6bde986ed0532915e154b65Daniel Dunbar    ///
353a8333d3d107df1e0b6bde986ed0532915e154b65Daniel Dunbar    /// \param Separator - The string to split on.
354a8333d3d107df1e0b6bde986ed0532915e154b65Daniel Dunbar    /// \return - The split substrings.
355a8333d3d107df1e0b6bde986ed0532915e154b65Daniel Dunbar    std::pair<StringRef, StringRef> split(StringRef Separator) const {
356a8333d3d107df1e0b6bde986ed0532915e154b65Daniel Dunbar      size_t Idx = find(Separator);
357a8333d3d107df1e0b6bde986ed0532915e154b65Daniel Dunbar      if (Idx == npos)
358a8333d3d107df1e0b6bde986ed0532915e154b65Daniel Dunbar        return std::make_pair(*this, StringRef());
359a8333d3d107df1e0b6bde986ed0532915e154b65Daniel Dunbar      return std::make_pair(slice(0, Idx), slice(Idx + Separator.size(), npos));
360a8333d3d107df1e0b6bde986ed0532915e154b65Daniel Dunbar    }
361a8333d3d107df1e0b6bde986ed0532915e154b65Daniel Dunbar
3623c37bb8dbe886993dcd8f37dec0d94762393f3d4Kovarththanan Rajaratnam    /// split - Split into substrings around the occurrences of a separator
3635ccac247263ab62975f3b72421fc783f10ccf5f6Rafael Espindola    /// string.
3645ccac247263ab62975f3b72421fc783f10ccf5f6Rafael Espindola    ///
3655ccac247263ab62975f3b72421fc783f10ccf5f6Rafael Espindola    /// Each substring is stored in \arg A. If \arg MaxSplit is >= 0, at most
3665ccac247263ab62975f3b72421fc783f10ccf5f6Rafael Espindola    /// \arg MaxSplit splits are done and consequently <= \arg MaxSplit
3675ccac247263ab62975f3b72421fc783f10ccf5f6Rafael Espindola    /// elements are added to A.
3685ccac247263ab62975f3b72421fc783f10ccf5f6Rafael Espindola    /// If \arg KeepEmpty is false, empty strings are not added to \arg A. They
3695ccac247263ab62975f3b72421fc783f10ccf5f6Rafael Espindola    /// still count when considering \arg MaxSplit
3705ccac247263ab62975f3b72421fc783f10ccf5f6Rafael Espindola    /// An useful invariant is that
3715ccac247263ab62975f3b72421fc783f10ccf5f6Rafael Espindola    /// Separator.join(A) == *this if MaxSplit == -1 and KeepEmpty == true
3725ccac247263ab62975f3b72421fc783f10ccf5f6Rafael Espindola    ///
3735ccac247263ab62975f3b72421fc783f10ccf5f6Rafael Espindola    /// \param A - Where to put the substrings.
3745ccac247263ab62975f3b72421fc783f10ccf5f6Rafael Espindola    /// \param Separator - The string to split on.
3755ccac247263ab62975f3b72421fc783f10ccf5f6Rafael Espindola    /// \param MaxSplit - The maximum number of times the string is split.
376fb76fe09297ee292129e44d723127f2408602a3dDan Gohman    /// \param KeepEmpty - True if empty substring should be added.
377c78c0c99a0fe1703ae72fc51e440aaa8e4e19e91Rafael Espindola    void split(SmallVectorImpl<StringRef> &A,
378c78c0c99a0fe1703ae72fc51e440aaa8e4e19e91Rafael Espindola               StringRef Separator, int MaxSplit = -1,
3795ccac247263ab62975f3b72421fc783f10ccf5f6Rafael Espindola               bool KeepEmpty = true) const;
3805ccac247263ab62975f3b72421fc783f10ccf5f6Rafael Espindola
3813c37bb8dbe886993dcd8f37dec0d94762393f3d4Kovarththanan Rajaratnam    /// rsplit - Split into two substrings around the last occurrence of a
382e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar    /// separator character.
383e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar    ///
384e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar    /// If \arg Separator is in the string, then the result is a pair (LHS, RHS)
385e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar    /// such that (*this == LHS + Separator + RHS) is true and RHS is
386e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar    /// minimal. If \arg Separator is not in the string, then the result is a
387e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar    /// pair (LHS, RHS) where (*this == LHS) and (RHS == "").
388e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar    ///
389e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar    /// \param Separator - The character to split on.
390e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar    /// \return - The split substrings.
391e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar    std::pair<StringRef, StringRef> rsplit(char Separator) const {
392e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar      size_t Idx = rfind(Separator);
393e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar      if (Idx == npos)
394e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar        return std::make_pair(*this, StringRef());
395e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar      return std::make_pair(slice(0, Idx), slice(Idx+1, npos));
396e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar    }
397e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar
398f5fdf73238dfd923f33bcbbd397cff6752d9c41eDaniel Dunbar    /// @}
3994cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar  };
400f5fdf73238dfd923f33bcbbd397cff6752d9c41eDaniel Dunbar
4017cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar  /// @name StringRef Comparison Operators
4027cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar  /// @{
4037cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar
4042928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar  inline bool operator==(StringRef LHS, StringRef RHS) {
4057cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar    return LHS.equals(RHS);
4067cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar  }
4077cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar
4082928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar  inline bool operator!=(StringRef LHS, StringRef RHS) {
4097cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar    return !(LHS == RHS);
4107cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar  }
411abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher
4122928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar  inline bool operator<(StringRef LHS, StringRef RHS) {
413abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher    return LHS.compare(RHS) == -1;
4147cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar  }
4157cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar
4162928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar  inline bool operator<=(StringRef LHS, StringRef RHS) {
417abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher    return LHS.compare(RHS) != 1;
4187cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar  }
4197cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar
4202928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar  inline bool operator>(StringRef LHS, StringRef RHS) {
421abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher    return LHS.compare(RHS) == 1;
4227cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar  }
4237cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar
4242928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar  inline bool operator>=(StringRef LHS, StringRef RHS) {
425abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher    return LHS.compare(RHS) != -1;
4267cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar  }
4277cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar
4287cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar  /// @}
4297cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar
4304cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar}
4314cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar
4324cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar#endif
433