StringRef.h revision 847d2f93ca692fa627a97ba9743bc1e9b8c5cbae
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 135326990f1eb7ff005adabe46a1f982eff8835813eMichael J. Spencer /// \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 /// 1455ee568ac2704d7302017d42ad162d4b53d076cbcDouglas Gregor /// \param MaxEditDistance If non-zero, the maximum edit distance that 1465ee568ac2704d7302017d42ad162d4b53d076cbcDouglas Gregor /// this routine is allowed to compute. If the edit distance will exceed 1475ee568ac2704d7302017d42ad162d4b53d076cbcDouglas Gregor /// that maximum, returns \c MaxEditDistance+1. 1485ee568ac2704d7302017d42ad162d4b53d076cbcDouglas Gregor /// 149441c8b4ad17c0d029b2247c367111395e7ad068cDouglas Gregor /// \returns the minimum number of character insertions, removals, 150441c8b4ad17c0d029b2247c367111395e7ad068cDouglas Gregor /// or (if \p AllowReplacements is \c true) replacements needed to 151441c8b4ad17c0d029b2247c367111395e7ad068cDouglas Gregor /// transform one of the given strings into the other. If zero, 152441c8b4ad17c0d029b2247c367111395e7ad068cDouglas Gregor /// the strings are identical. 1535ee568ac2704d7302017d42ad162d4b53d076cbcDouglas Gregor unsigned edit_distance(StringRef Other, bool AllowReplacements = true, 1545ee568ac2704d7302017d42ad162d4b53d076cbcDouglas Gregor unsigned MaxEditDistance = 0); 155441c8b4ad17c0d029b2247c367111395e7ad068cDouglas Gregor 1564cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar /// str - Get the contents as an std::string. 1577f7274ce7f3243bd71588c7a75a142c39e5c7e34Chris Lattner std::string str() const { 15879ed2c597a134cb4dd5da90199053f322b7d8a2dBenjamin Kramer if (Data == 0) return std::string(); 1597f7274ce7f3243bd71588c7a75a142c39e5c7e34Chris Lattner return std::string(Data, Length); 1607f7274ce7f3243bd71588c7a75a142c39e5c7e34Chris Lattner } 1614cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar 1624cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar /// @} 1634cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar /// @name Operator Overloads 1644cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar /// @{ 1654cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar 166abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher char operator[](size_t Index) const { 1674cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar assert(Index < Length && "Invalid index!"); 168abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher return Data[Index]; 1694cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar } 1704cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar 1714cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar /// @} 1724cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar /// @name Type Conversions 1734cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar /// @{ 1744cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar 1754cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar operator std::string() const { 1764cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar return str(); 1774cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar } 1784cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar 1794cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar /// @} 1800ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar /// @name String Predicates 1810ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar /// @{ 1820ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar 1830ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar /// startswith - Check if this string starts with the given \arg Prefix. 1842928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar bool startswith(StringRef Prefix) const { 185d5b1f8a8426e82990dafc6e3336fefc6635c8fa4Eli Friedman return Length >= Prefix.Length && 186d5b1f8a8426e82990dafc6e3336fefc6635c8fa4Eli Friedman memcmp(Data, Prefix.Data, Prefix.Length) == 0; 1870ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar } 1880ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar 1890ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar /// endswith - Check if this string ends with the given \arg Suffix. 1902928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar bool endswith(StringRef Suffix) const { 191d5b1f8a8426e82990dafc6e3336fefc6635c8fa4Eli Friedman return Length >= Suffix.Length && 192d5b1f8a8426e82990dafc6e3336fefc6635c8fa4Eli Friedman memcmp(end() - Suffix.Length, Suffix.Data, Suffix.Length) == 0; 1930ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar } 1940ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar 1950ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar /// @} 1960ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar /// @name String Searching 1970ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar /// @{ 1980ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar 199e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar /// find - Search for the first character \arg C in the string. 2000ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar /// 2013c37bb8dbe886993dcd8f37dec0d94762393f3d4Kovarththanan Rajaratnam /// \return - The index of the first occurrence of \arg C, or npos if not 2020ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar /// found. 20364066bd8b593082f622bbc25716938a453363d2fDaniel Dunbar size_t find(char C, size_t From = 0) const { 2042fe05d80d396b6ca0bdc66ec17732b8c514d575eTorok Edwin for (size_t i = min(From, Length), e = Length; i != e; ++i) 2050ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar if (Data[i] == C) 2060ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar return i; 2070ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar return npos; 2080ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar } 2090ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar 210e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar /// find - Search for the first string \arg Str in the string. 2110ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar /// 2123c37bb8dbe886993dcd8f37dec0d94762393f3d4Kovarththanan Rajaratnam /// \return - The index of the first occurrence of \arg Str, or npos if not 2130ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar /// found. 21464066bd8b593082f622bbc25716938a453363d2fDaniel Dunbar size_t find(StringRef Str, size_t From = 0) const; 215abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher 216e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar /// rfind - Search for the last character \arg C in the string. 217e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar /// 2183c37bb8dbe886993dcd8f37dec0d94762393f3d4Kovarththanan Rajaratnam /// \return - The index of the last occurrence of \arg C, or npos if not 219e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar /// found. 220c936fe8cb356931f23e6f17ce1bd5789eeae1ecbChris Lattner size_t rfind(char C, size_t From = npos) const { 2212fe05d80d396b6ca0bdc66ec17732b8c514d575eTorok Edwin From = min(From, Length); 222c936fe8cb356931f23e6f17ce1bd5789eeae1ecbChris Lattner size_t i = From; 223c936fe8cb356931f23e6f17ce1bd5789eeae1ecbChris Lattner while (i != 0) { 224e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar --i; 225e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar if (Data[i] == C) 226e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar return i; 227e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar } 228e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar return npos; 229e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar } 230abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher 231e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar /// rfind - Search for the last string \arg Str in the string. 232e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar /// 2333c37bb8dbe886993dcd8f37dec0d94762393f3d4Kovarththanan Rajaratnam /// \return - The index of the last occurrence of \arg Str, or npos if not 234e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar /// found. 2352928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar size_t rfind(StringRef Str) const; 236abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher 23764066bd8b593082f622bbc25716938a453363d2fDaniel Dunbar /// find_first_of - Find the first character in the string that is \arg C, 23864066bd8b593082f622bbc25716938a453363d2fDaniel Dunbar /// or npos if not found. Same as find. 23979ed2c597a134cb4dd5da90199053f322b7d8a2dBenjamin Kramer size_type find_first_of(char C, size_t From = 0) const { 24079ed2c597a134cb4dd5da90199053f322b7d8a2dBenjamin Kramer return find(C, From); 24179ed2c597a134cb4dd5da90199053f322b7d8a2dBenjamin Kramer } 242abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher 24364066bd8b593082f622bbc25716938a453363d2fDaniel Dunbar /// find_first_of - Find the first character in the string that is in \arg 24464066bd8b593082f622bbc25716938a453363d2fDaniel Dunbar /// Chars, or npos if not found. 24564066bd8b593082f622bbc25716938a453363d2fDaniel Dunbar /// 246250eb005d91e80b05a61345394bae9e9528151acBenjamin Kramer /// Note: O(size() + Chars.size()) 24764066bd8b593082f622bbc25716938a453363d2fDaniel Dunbar size_type find_first_of(StringRef Chars, size_t From = 0) const; 248abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher 24905a32c8ab118d9c92dc9b4ecaa7a6fed67241215Chris Lattner /// find_first_not_of - Find the first character in the string that is not 25064066bd8b593082f622bbc25716938a453363d2fDaniel Dunbar /// \arg C or npos if not found. 25164066bd8b593082f622bbc25716938a453363d2fDaniel Dunbar size_type find_first_not_of(char C, size_t From = 0) const; 25264066bd8b593082f622bbc25716938a453363d2fDaniel Dunbar 25364066bd8b593082f622bbc25716938a453363d2fDaniel Dunbar /// find_first_not_of - Find the first character in the string that is not 25464066bd8b593082f622bbc25716938a453363d2fDaniel Dunbar /// in the string \arg Chars, or npos if not found. 25564066bd8b593082f622bbc25716938a453363d2fDaniel Dunbar /// 256250eb005d91e80b05a61345394bae9e9528151acBenjamin Kramer /// Note: O(size() + Chars.size()) 25764066bd8b593082f622bbc25716938a453363d2fDaniel Dunbar size_type find_first_not_of(StringRef Chars, size_t From = 0) const; 258abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher 25905a32c8ab118d9c92dc9b4ecaa7a6fed67241215Chris Lattner /// @} 26005a32c8ab118d9c92dc9b4ecaa7a6fed67241215Chris Lattner /// @name Helpful Algorithms 26105a32c8ab118d9c92dc9b4ecaa7a6fed67241215Chris Lattner /// @{ 262abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher 2635caba3bcb14fae4b36924463ed2bcf3846f029a9Daniel Dunbar /// count - Return the number of occurrences of \arg C in the string. 2645caba3bcb14fae4b36924463ed2bcf3846f029a9Daniel Dunbar size_t count(char C) const { 2655caba3bcb14fae4b36924463ed2bcf3846f029a9Daniel Dunbar size_t Count = 0; 2665caba3bcb14fae4b36924463ed2bcf3846f029a9Daniel Dunbar for (size_t i = 0, e = Length; i != e; ++i) 2675caba3bcb14fae4b36924463ed2bcf3846f029a9Daniel Dunbar if (Data[i] == C) 268323a3e653340781bad4c4c3245d9b25d5ab02685Daniel Dunbar ++Count; 2695caba3bcb14fae4b36924463ed2bcf3846f029a9Daniel Dunbar return Count; 2705caba3bcb14fae4b36924463ed2bcf3846f029a9Daniel Dunbar } 271abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher 2725caba3bcb14fae4b36924463ed2bcf3846f029a9Daniel Dunbar /// count - Return the number of non-overlapped occurrences of \arg Str in 2735caba3bcb14fae4b36924463ed2bcf3846f029a9Daniel Dunbar /// the string. 2742928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar size_t count(StringRef Str) const; 275abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher 276cea1438cf59c7cd3a632d61d78e68589315510d3Chris Lattner /// getAsInteger - Parse the current string as an integer of the specified 277cea1438cf59c7cd3a632d61d78e68589315510d3Chris Lattner /// radix. If Radix is specified as zero, this does radix autosensing using 278cea1438cf59c7cd3a632d61d78e68589315510d3Chris Lattner /// extended C rules: 0 is octal, 0x is hex, 0b is binary. 279cea1438cf59c7cd3a632d61d78e68589315510d3Chris Lattner /// 280cea1438cf59c7cd3a632d61d78e68589315510d3Chris Lattner /// If the string is invalid or if only a subset of the string is valid, 281cea1438cf59c7cd3a632d61d78e68589315510d3Chris Lattner /// this returns true to signify the error. The string is considered 282cea1438cf59c7cd3a632d61d78e68589315510d3Chris Lattner /// erroneous if empty. 283cea1438cf59c7cd3a632d61d78e68589315510d3Chris Lattner /// 28463c6b7dc67f0061340c0701f3d5b1de142f58cecChris Lattner bool getAsInteger(unsigned Radix, long long &Result) const; 285cea1438cf59c7cd3a632d61d78e68589315510d3Chris Lattner bool getAsInteger(unsigned Radix, unsigned long long &Result) const; 28663c6b7dc67f0061340c0701f3d5b1de142f58cecChris Lattner bool getAsInteger(unsigned Radix, int &Result) const; 28763c6b7dc67f0061340c0701f3d5b1de142f58cecChris Lattner bool getAsInteger(unsigned Radix, unsigned &Result) const; 288cea1438cf59c7cd3a632d61d78e68589315510d3Chris Lattner 289cea1438cf59c7cd3a632d61d78e68589315510d3Chris Lattner // TODO: Provide overloads for int/unsigned that check for overflow. 290abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher 2911e7ad3993d8700488895fa372ecad55443f53485John McCall /// getAsInteger - Parse the current string as an integer of the 2921e7ad3993d8700488895fa372ecad55443f53485John McCall /// specified radix, or of an autosensed radix if the radix given 2931e7ad3993d8700488895fa372ecad55443f53485John McCall /// is 0. The current value in Result is discarded, and the 2941e7ad3993d8700488895fa372ecad55443f53485John McCall /// storage is changed to be wide enough to store the parsed 2951e7ad3993d8700488895fa372ecad55443f53485John McCall /// integer. 2961e7ad3993d8700488895fa372ecad55443f53485John McCall /// 2971e7ad3993d8700488895fa372ecad55443f53485John McCall /// Returns true if the string does not solely consist of a valid 2981e7ad3993d8700488895fa372ecad55443f53485John McCall /// non-empty number in the appropriate base. 2991e7ad3993d8700488895fa372ecad55443f53485John McCall /// 3001e7ad3993d8700488895fa372ecad55443f53485John McCall /// APInt::fromString is superficially similar but assumes the 3011e7ad3993d8700488895fa372ecad55443f53485John McCall /// string is well-formed in the given radix. 3021e7ad3993d8700488895fa372ecad55443f53485John McCall bool getAsInteger(unsigned Radix, APInt &Result) const; 3031e7ad3993d8700488895fa372ecad55443f53485John McCall 304cea1438cf59c7cd3a632d61d78e68589315510d3Chris Lattner /// @} 3050ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar /// @name Substring Operations 306f5fdf73238dfd923f33bcbbd397cff6752d9c41eDaniel Dunbar /// @{ 307f5fdf73238dfd923f33bcbbd397cff6752d9c41eDaniel Dunbar 308d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar /// substr - Return a reference to the substring from [Start, Start + N). 309f5fdf73238dfd923f33bcbbd397cff6752d9c41eDaniel Dunbar /// 310f5fdf73238dfd923f33bcbbd397cff6752d9c41eDaniel Dunbar /// \param Start - The index of the starting character in the substring; if 311d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar /// the index is npos or greater than the length of the string then the 312d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar /// empty substring will be returned. 313f5fdf73238dfd923f33bcbbd397cff6752d9c41eDaniel Dunbar /// 314f5fdf73238dfd923f33bcbbd397cff6752d9c41eDaniel Dunbar /// \param N - The number of characters to included in the substring. If N 315f5fdf73238dfd923f33bcbbd397cff6752d9c41eDaniel Dunbar /// exceeds the number of characters remaining in the string, the string 316f5fdf73238dfd923f33bcbbd397cff6752d9c41eDaniel Dunbar /// suffix (starting with \arg Start) will be returned. 317f5fdf73238dfd923f33bcbbd397cff6752d9c41eDaniel Dunbar StringRef substr(size_t Start, size_t N = npos) const { 3182fe05d80d396b6ca0bdc66ec17732b8c514d575eTorok Edwin Start = min(Start, Length); 3192fe05d80d396b6ca0bdc66ec17732b8c514d575eTorok Edwin return StringRef(Data + Start, min(N, Length - Start)); 320f5fdf73238dfd923f33bcbbd397cff6752d9c41eDaniel Dunbar } 321f5fdf73238dfd923f33bcbbd397cff6752d9c41eDaniel Dunbar 322d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar /// slice - Return a reference to the substring from [Start, End). 323d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar /// 324d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar /// \param Start - The index of the starting character in the substring; if 325d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar /// the index is npos or greater than the length of the string then the 326d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar /// empty substring will be returned. 327d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar /// 328d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar /// \param End - The index following the last character to include in the 329d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar /// substring. If this is npos, or less than \arg Start, or exceeds the 330d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar /// number of characters remaining in the string, the string suffix 331d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar /// (starting with \arg Start) will be returned. 332d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar StringRef slice(size_t Start, size_t End) const { 3332fe05d80d396b6ca0bdc66ec17732b8c514d575eTorok Edwin Start = min(Start, Length); 3342fe05d80d396b6ca0bdc66ec17732b8c514d575eTorok Edwin End = min(max(Start, End), Length); 335d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar return StringRef(Data + Start, End - Start); 336d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar } 337d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar 3383c37bb8dbe886993dcd8f37dec0d94762393f3d4Kovarththanan Rajaratnam /// split - Split into two substrings around the first occurrence of a 339d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar /// separator character. 340d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar /// 341d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar /// If \arg Separator is in the string, then the result is a pair (LHS, RHS) 342d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar /// such that (*this == LHS + Separator + RHS) is true and RHS is 343d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar /// maximal. If \arg Separator is not in the string, then the result is a 344d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar /// pair (LHS, RHS) where (*this == LHS) and (RHS == ""). 345d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar /// 346d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar /// \param Separator - The character to split on. 347d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar /// \return - The split substrings. 348d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar std::pair<StringRef, StringRef> split(char Separator) const { 3490ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar size_t Idx = find(Separator); 3500ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar if (Idx == npos) 351d61918fc6898a89df8b0a03e068f234ded010cdfDaniel Dunbar return std::make_pair(*this, StringRef()); 3520ad7f9bb2f806387e53ffeaf6a564b9a80b962afDaniel Dunbar return std::make_pair(slice(0, Idx), slice(Idx+1, npos)); 353c9af366fc39d657b7d416d16988265d86a641184Daniel Dunbar } 354c9af366fc39d657b7d416d16988265d86a641184Daniel Dunbar 3553c37bb8dbe886993dcd8f37dec0d94762393f3d4Kovarththanan Rajaratnam /// split - Split into two substrings around the first occurrence of a 356a8333d3d107df1e0b6bde986ed0532915e154b65Daniel Dunbar /// separator string. 357a8333d3d107df1e0b6bde986ed0532915e154b65Daniel Dunbar /// 358a8333d3d107df1e0b6bde986ed0532915e154b65Daniel Dunbar /// If \arg Separator is in the string, then the result is a pair (LHS, RHS) 359a8333d3d107df1e0b6bde986ed0532915e154b65Daniel Dunbar /// such that (*this == LHS + Separator + RHS) is true and RHS is 360a8333d3d107df1e0b6bde986ed0532915e154b65Daniel Dunbar /// maximal. If \arg Separator is not in the string, then the result is a 361a8333d3d107df1e0b6bde986ed0532915e154b65Daniel Dunbar /// pair (LHS, RHS) where (*this == LHS) and (RHS == ""). 362a8333d3d107df1e0b6bde986ed0532915e154b65Daniel Dunbar /// 363a8333d3d107df1e0b6bde986ed0532915e154b65Daniel Dunbar /// \param Separator - The string to split on. 364a8333d3d107df1e0b6bde986ed0532915e154b65Daniel Dunbar /// \return - The split substrings. 365a8333d3d107df1e0b6bde986ed0532915e154b65Daniel Dunbar std::pair<StringRef, StringRef> split(StringRef Separator) const { 366a8333d3d107df1e0b6bde986ed0532915e154b65Daniel Dunbar size_t Idx = find(Separator); 367a8333d3d107df1e0b6bde986ed0532915e154b65Daniel Dunbar if (Idx == npos) 368a8333d3d107df1e0b6bde986ed0532915e154b65Daniel Dunbar return std::make_pair(*this, StringRef()); 369a8333d3d107df1e0b6bde986ed0532915e154b65Daniel Dunbar return std::make_pair(slice(0, Idx), slice(Idx + Separator.size(), npos)); 370a8333d3d107df1e0b6bde986ed0532915e154b65Daniel Dunbar } 371a8333d3d107df1e0b6bde986ed0532915e154b65Daniel Dunbar 3723c37bb8dbe886993dcd8f37dec0d94762393f3d4Kovarththanan Rajaratnam /// split - Split into substrings around the occurrences of a separator 3735ccac247263ab62975f3b72421fc783f10ccf5f6Rafael Espindola /// string. 3745ccac247263ab62975f3b72421fc783f10ccf5f6Rafael Espindola /// 3755ccac247263ab62975f3b72421fc783f10ccf5f6Rafael Espindola /// Each substring is stored in \arg A. If \arg MaxSplit is >= 0, at most 3765ccac247263ab62975f3b72421fc783f10ccf5f6Rafael Espindola /// \arg MaxSplit splits are done and consequently <= \arg MaxSplit 3775ccac247263ab62975f3b72421fc783f10ccf5f6Rafael Espindola /// elements are added to A. 3785ccac247263ab62975f3b72421fc783f10ccf5f6Rafael Espindola /// If \arg KeepEmpty is false, empty strings are not added to \arg A. They 3795ccac247263ab62975f3b72421fc783f10ccf5f6Rafael Espindola /// still count when considering \arg MaxSplit 3805ccac247263ab62975f3b72421fc783f10ccf5f6Rafael Espindola /// An useful invariant is that 3815ccac247263ab62975f3b72421fc783f10ccf5f6Rafael Espindola /// Separator.join(A) == *this if MaxSplit == -1 and KeepEmpty == true 3825ccac247263ab62975f3b72421fc783f10ccf5f6Rafael Espindola /// 3835ccac247263ab62975f3b72421fc783f10ccf5f6Rafael Espindola /// \param A - Where to put the substrings. 3845ccac247263ab62975f3b72421fc783f10ccf5f6Rafael Espindola /// \param Separator - The string to split on. 3855ccac247263ab62975f3b72421fc783f10ccf5f6Rafael Espindola /// \param MaxSplit - The maximum number of times the string is split. 386fb76fe09297ee292129e44d723127f2408602a3dDan Gohman /// \param KeepEmpty - True if empty substring should be added. 387c78c0c99a0fe1703ae72fc51e440aaa8e4e19e91Rafael Espindola void split(SmallVectorImpl<StringRef> &A, 388c78c0c99a0fe1703ae72fc51e440aaa8e4e19e91Rafael Espindola StringRef Separator, int MaxSplit = -1, 3895ccac247263ab62975f3b72421fc783f10ccf5f6Rafael Espindola bool KeepEmpty = true) const; 3905ccac247263ab62975f3b72421fc783f10ccf5f6Rafael Espindola 3913c37bb8dbe886993dcd8f37dec0d94762393f3d4Kovarththanan Rajaratnam /// rsplit - Split into two substrings around the last occurrence of a 392e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar /// separator character. 393e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar /// 394e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar /// If \arg Separator is in the string, then the result is a pair (LHS, RHS) 395e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar /// such that (*this == LHS + Separator + RHS) is true and RHS is 396e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar /// minimal. If \arg Separator is not in the string, then the result is a 397e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar /// pair (LHS, RHS) where (*this == LHS) and (RHS == ""). 398e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar /// 399e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar /// \param Separator - The character to split on. 400e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar /// \return - The split substrings. 401e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar std::pair<StringRef, StringRef> rsplit(char Separator) const { 402e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar size_t Idx = rfind(Separator); 403e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar if (Idx == npos) 404e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar return std::make_pair(*this, StringRef()); 405e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar return std::make_pair(slice(0, Idx), slice(Idx+1, npos)); 406e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar } 407e65512809a4144c17538aac4cc59fac6d325a7e4Daniel Dunbar 408f5fdf73238dfd923f33bcbbd397cff6752d9c41eDaniel Dunbar /// @} 4094cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar }; 410f5fdf73238dfd923f33bcbbd397cff6752d9c41eDaniel Dunbar 4117cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar /// @name StringRef Comparison Operators 4127cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar /// @{ 4137cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar 4142928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar inline bool operator==(StringRef LHS, StringRef RHS) { 4157cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar return LHS.equals(RHS); 4167cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar } 4177cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar 4182928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar inline bool operator!=(StringRef LHS, StringRef RHS) { 4197cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar return !(LHS == RHS); 4207cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar } 421abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher 4222928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar inline bool operator<(StringRef LHS, StringRef RHS) { 423abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher return LHS.compare(RHS) == -1; 4247cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar } 4257cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar 4262928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar inline bool operator<=(StringRef LHS, StringRef RHS) { 427abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher return LHS.compare(RHS) != 1; 4287cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar } 4297cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar 4302928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar inline bool operator>(StringRef LHS, StringRef RHS) { 431abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher return LHS.compare(RHS) == 1; 4327cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar } 4337cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar 4342928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar inline bool operator>=(StringRef LHS, StringRef RHS) { 435abc5ac728961cb23b1041a3466fe2eb4521603c3Eric Christopher return LHS.compare(RHS) != -1; 4367cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar } 4377cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar 4387cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar /// @} 4397cb6860185187c74a1205deebff9e0f09a0ddae4Daniel Dunbar 440847d2f93ca692fa627a97ba9743bc1e9b8c5cbaeBenjamin Kramer // StringRefs can be treated like a POD type. 441847d2f93ca692fa627a97ba9743bc1e9b8c5cbaeBenjamin Kramer template <typename T> struct isPodLike; 442847d2f93ca692fa627a97ba9743bc1e9b8c5cbaeBenjamin Kramer template <> struct isPodLike<StringRef> { static const bool value = true; }; 443847d2f93ca692fa627a97ba9743bc1e9b8c5cbaeBenjamin Kramer 4444cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar} 4454cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar 4464cf95d75c65f37677d306952b0d2306bc6d20b1fDaniel Dunbar#endif 447