diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2023-09-02 21:17:18 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2023-12-08 17:34:50 +0000 |
commit | 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e (patch) | |
tree | 62f873df87c7c675557a179e0c4c83fe9f3087bc /contrib/llvm-project/llvm/lib/Support/StringRef.cpp | |
parent | cf037972ea8863e2bab7461d77345367d2c1e054 (diff) | |
parent | 7fa27ce4a07f19b07799a767fc29416f3b625afb (diff) |
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Support/StringRef.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/Support/StringRef.cpp | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/contrib/llvm-project/llvm/lib/Support/StringRef.cpp b/contrib/llvm-project/llvm/lib/Support/StringRef.cpp index fb93940592c7..3cce83a982c4 100644 --- a/contrib/llvm-project/llvm/lib/Support/StringRef.cpp +++ b/contrib/llvm-project/llvm/lib/Support/StringRef.cpp @@ -191,7 +191,7 @@ size_t StringRef::find(StringRef Str, size_t From) const { size_t StringRef::find_insensitive(StringRef Str, size_t From) const { StringRef This = substr(From); while (This.size() >= Str.size()) { - if (This.startswith_insensitive(Str)) + if (This.starts_with_insensitive(Str)) return From; This = This.drop_front(); ++From; @@ -509,7 +509,7 @@ bool llvm::getAsSignedInteger(StringRef Str, unsigned Radix, return !Str.empty(); } -bool StringRef::getAsInteger(unsigned Radix, APInt &Result) const { +bool StringRef::consumeInteger(unsigned Radix, APInt &Result) { StringRef Str = *this; // Autosense radix if not specified. @@ -529,6 +529,7 @@ bool StringRef::getAsInteger(unsigned Radix, APInt &Result) const { // If it was nothing but zeroes.... if (Str.empty()) { Result = APInt(64, 0); + *this = Str; return false; } @@ -561,12 +562,12 @@ bool StringRef::getAsInteger(unsigned Radix, APInt &Result) const { else if (Str[0] >= 'A' && Str[0] <= 'Z') CharVal = Str[0]-'A'+10; else - return true; + break; // If the parsed value is larger than the integer radix, the string is // invalid. if (CharVal >= Radix) - return true; + break; // Add in this character. if (IsPowerOf2Radix) { @@ -581,9 +582,25 @@ bool StringRef::getAsInteger(unsigned Radix, APInt &Result) const { Str = Str.substr(1); } + // We consider the operation a failure if no characters were consumed + // successfully. + if (size() == Str.size()) + return true; + + *this = Str; return false; } +bool StringRef::getAsInteger(unsigned Radix, APInt &Result) const { + StringRef Str = *this; + if (Str.consumeInteger(Radix, Result)) + return true; + + // For getAsInteger, we require the whole string to be consumed or else we + // consider it a failure. + return !Str.empty(); +} + bool StringRef::getAsDouble(double &Result, bool AllowInexact) const { APFloat F(0.0); auto StatusOrErr = F.convertFromString(*this, APFloat::rmNearestTiesToEven); |