summaryrefslogtreecommitdiff
path: root/lib/Support/StringRef.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Support/StringRef.cpp')
-rw-r--r--lib/Support/StringRef.cpp36
1 files changed, 7 insertions, 29 deletions
diff --git a/lib/Support/StringRef.cpp b/lib/Support/StringRef.cpp
index 1c28bf879e..abe570f6df 100644
--- a/lib/Support/StringRef.cpp
+++ b/lib/Support/StringRef.cpp
@@ -285,8 +285,8 @@ static unsigned GetAutoSenseRadix(StringRef &Str) {
/// GetAsUnsignedInteger - Workhorse method that converts a integer character
/// sequence of radix up to 36 to an unsigned long long value.
-static bool GetAsUnsignedInteger(StringRef Str, unsigned Radix,
- unsigned long long &Result) {
+bool llvm::getAsUnsignedInteger(StringRef Str, unsigned Radix,
+ unsigned long long &Result) {
// Autosense radix if not specified.
if (Radix == 0)
Radix = GetAutoSenseRadix(Str);
@@ -326,17 +326,13 @@ static bool GetAsUnsignedInteger(StringRef Str, unsigned Radix,
return false;
}
-bool StringRef::getAsInteger(unsigned Radix, unsigned long long &Result) const {
- return GetAsUnsignedInteger(*this, Radix, Result);
-}
-
-
-bool StringRef::getAsInteger(unsigned Radix, long long &Result) const {
+bool llvm::getAsSignedInteger(StringRef Str, unsigned Radix,
+ long long &Result) {
unsigned long long ULLVal;
// Handle positive strings first.
- if (empty() || front() != '-') {
- if (GetAsUnsignedInteger(*this, Radix, ULLVal) ||
+ if (Str.empty() || Str.front() != '-') {
+ if (getAsUnsignedInteger(Str, Radix, ULLVal) ||
// Check for value so large it overflows a signed value.
(long long)ULLVal < 0)
return true;
@@ -345,7 +341,7 @@ bool StringRef::getAsInteger(unsigned Radix, long long &Result) const {
}
// Get the positive part of the value.
- if (GetAsUnsignedInteger(substr(1), Radix, ULLVal) ||
+ if (getAsUnsignedInteger(Str.substr(1), Radix, ULLVal) ||
// Reject values so large they'd overflow as negative signed, but allow
// "-0". This negates the unsigned so that the negative isn't undefined
// on signed overflow.
@@ -356,24 +352,6 @@ bool StringRef::getAsInteger(unsigned Radix, long long &Result) const {
return false;
}
-bool StringRef::getAsInteger(unsigned Radix, int &Result) const {
- long long Val;
- if (getAsInteger(Radix, Val) ||
- (int)Val != Val)
- return true;
- Result = Val;
- return false;
-}
-
-bool StringRef::getAsInteger(unsigned Radix, unsigned &Result) const {
- unsigned long long Val;
- if (getAsInteger(Radix, Val) ||
- (unsigned)Val != Val)
- return true;
- Result = Val;
- return false;
-}
-
bool StringRef::getAsInteger(unsigned Radix, APInt &Result) const {
StringRef Str = *this;