size_t, not unsigned here to silence a warning.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84900 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Christopher 2009-10-22 22:06:50 +00:00
parent a0b0562a35
commit abc5ac7289

View File

@ -29,7 +29,7 @@ namespace llvm {
typedef const char *iterator; typedef const char *iterator;
static const size_t npos = ~size_t(0); static const size_t npos = ~size_t(0);
typedef size_t size_type; typedef size_t size_type;
private: private:
/// The start of the string, in an external buffer. /// The start of the string, in an external buffer.
const char *Data; const char *Data;
@ -45,15 +45,15 @@ namespace llvm {
/*implicit*/ StringRef() : Data(0), Length(0) {} /*implicit*/ StringRef() : Data(0), Length(0) {}
/// Construct a string ref from a cstring. /// Construct a string ref from a cstring.
/*implicit*/ StringRef(const char *Str) /*implicit*/ StringRef(const char *Str)
: Data(Str) { if (Str) Length = ::strlen(Str); else Length = 0; } : Data(Str) { if (Str) Length = ::strlen(Str); else Length = 0; }
/// Construct a string ref from a pointer and length. /// Construct a string ref from a pointer and length.
/*implicit*/ StringRef(const char *data, unsigned length) /*implicit*/ StringRef(const char *data, size_t length)
: Data(data), Length(length) {} : Data(data), Length(length) {}
/// Construct a string ref from an std::string. /// Construct a string ref from an std::string.
/*implicit*/ StringRef(const std::string &Str) /*implicit*/ StringRef(const std::string &Str)
: Data(Str.c_str()), Length(Str.length()) {} : Data(Str.c_str()), Length(Str.length()) {}
/// @} /// @}
@ -83,7 +83,7 @@ namespace llvm {
assert(!empty()); assert(!empty());
return Data[0]; return Data[0];
} }
/// back - Get the last character in the string. /// back - Get the last character in the string.
char back() const { char back() const {
assert(!empty()); assert(!empty());
@ -93,7 +93,7 @@ namespace llvm {
/// equals - Check for string equality, this is more efficient than /// equals - Check for string equality, this is more efficient than
/// compare() when the relative ordering of inequal strings isn't needed. /// compare() when the relative ordering of inequal strings isn't needed.
bool equals(const StringRef &RHS) const { bool equals(const StringRef &RHS) const {
return (Length == RHS.Length && return (Length == RHS.Length &&
memcmp(Data, RHS.Data, RHS.Length) == 0); memcmp(Data, RHS.Data, RHS.Length) == 0);
} }
@ -117,9 +117,9 @@ namespace llvm {
/// @name Operator Overloads /// @name Operator Overloads
/// @{ /// @{
char operator[](size_t Index) const { char operator[](size_t Index) const {
assert(Index < Length && "Invalid index!"); assert(Index < Length && "Invalid index!");
return Data[Index]; return Data[Index];
} }
/// @} /// @}
@ -135,7 +135,7 @@ namespace llvm {
/// @{ /// @{
/// startswith - Check if this string starts with the given \arg Prefix. /// startswith - Check if this string starts with the given \arg Prefix.
bool startswith(const StringRef &Prefix) const { bool startswith(const StringRef &Prefix) const {
return substr(0, Prefix.Length).equals(Prefix); return substr(0, Prefix.Length).equals(Prefix);
} }
@ -164,7 +164,7 @@ namespace llvm {
/// \return - The index of the first occurence of \arg Str, or npos if not /// \return - The index of the first occurence of \arg Str, or npos if not
/// found. /// found.
size_t find(const StringRef &Str) const; size_t find(const StringRef &Str) const;
/// rfind - Search for the last character \arg C in the string. /// rfind - Search for the last character \arg C in the string.
/// ///
/// \return - The index of the last occurence of \arg C, or npos if not /// \return - The index of the last occurence of \arg C, or npos if not
@ -179,29 +179,29 @@ namespace llvm {
} }
return npos; return npos;
} }
/// rfind - Search for the last string \arg Str in the string. /// rfind - Search for the last string \arg Str in the string.
/// ///
/// \return - The index of the last occurence of \arg Str, or npos if not /// \return - The index of the last occurence of \arg Str, or npos if not
/// found. /// found.
size_t rfind(const StringRef &Str) const; size_t rfind(const StringRef &Str) const;
/// find_first_of - Find the first instance of the specified character or /// find_first_of - Find the first instance of the specified character or
/// return npos if not in string. Same as find. /// return npos if not in string. Same as find.
size_type find_first_of(char C) const { return find(C); } size_type find_first_of(char C) const { return find(C); }
/// find_first_of - Find the first character from the string 'Chars' in the /// find_first_of - Find the first character from the string 'Chars' in the
/// current string or return npos if not in string. /// current string or return npos if not in string.
size_type find_first_of(StringRef Chars) const; size_type find_first_of(StringRef Chars) const;
/// find_first_not_of - Find the first character in the string that is not /// find_first_not_of - Find the first character in the string that is not
/// in the string 'Chars' or return npos if all are in string. Same as find. /// in the string 'Chars' or return npos if all are in string. Same as find.
size_type find_first_not_of(StringRef Chars) const; size_type find_first_not_of(StringRef Chars) const;
/// @} /// @}
/// @name Helpful Algorithms /// @name Helpful Algorithms
/// @{ /// @{
/// count - Return the number of occurrences of \arg C in the string. /// count - Return the number of occurrences of \arg C in the string.
size_t count(char C) const { size_t count(char C) const {
size_t Count = 0; size_t Count = 0;
@ -210,11 +210,11 @@ namespace llvm {
++Count; ++Count;
return Count; return Count;
} }
/// count - Return the number of non-overlapped occurrences of \arg Str in /// count - Return the number of non-overlapped occurrences of \arg Str in
/// the string. /// the string.
size_t count(const StringRef &Str) const; size_t count(const StringRef &Str) const;
/// getAsInteger - Parse the current string as an integer of the specified /// getAsInteger - Parse the current string as an integer of the specified
/// radix. If Radix is specified as zero, this does radix autosensing using /// radix. If Radix is specified as zero, this does radix autosensing using
/// extended C rules: 0 is octal, 0x is hex, 0b is binary. /// extended C rules: 0 is octal, 0x is hex, 0b is binary.
@ -229,7 +229,7 @@ namespace llvm {
bool getAsInteger(unsigned Radix, unsigned &Result) const; bool getAsInteger(unsigned Radix, unsigned &Result) const;
// TODO: Provide overloads for int/unsigned that check for overflow. // TODO: Provide overloads for int/unsigned that check for overflow.
/// @} /// @}
/// @name Substring Operations /// @name Substring Operations
/// @{ /// @{
@ -308,24 +308,24 @@ namespace llvm {
return LHS.equals(RHS); return LHS.equals(RHS);
} }
inline bool operator!=(const StringRef &LHS, const StringRef &RHS) { inline bool operator!=(const StringRef &LHS, const StringRef &RHS) {
return !(LHS == RHS); return !(LHS == RHS);
} }
inline bool operator<(const StringRef &LHS, const StringRef &RHS) { inline bool operator<(const StringRef &LHS, const StringRef &RHS) {
return LHS.compare(RHS) == -1; return LHS.compare(RHS) == -1;
} }
inline bool operator<=(const StringRef &LHS, const StringRef &RHS) { inline bool operator<=(const StringRef &LHS, const StringRef &RHS) {
return LHS.compare(RHS) != 1; return LHS.compare(RHS) != 1;
} }
inline bool operator>(const StringRef &LHS, const StringRef &RHS) { inline bool operator>(const StringRef &LHS, const StringRef &RHS) {
return LHS.compare(RHS) == 1; return LHS.compare(RHS) == 1;
} }
inline bool operator>=(const StringRef &LHS, const StringRef &RHS) { inline bool operator>=(const StringRef &LHS, const StringRef &RHS) {
return LHS.compare(RHS) != -1; return LHS.compare(RHS) != -1;
} }
/// @} /// @}