diff options
author | Chris Lattner <sabre@nondot.org> | 2009-09-20 22:56:43 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-09-20 22:56:43 +0000 |
commit | 6441e547ccf563ccebd8a81e57def810172c93bf (patch) | |
tree | 3f00a7a4e229237829fb3aa297f6f762fd152875 /lib/Support/StringRef.cpp | |
parent | c936fe8cb356931f23e6f17ce1bd5789eeae1ecb (diff) |
simplify as daniel suggests
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82415 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/StringRef.cpp')
-rw-r--r-- | lib/Support/StringRef.cpp | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/lib/Support/StringRef.cpp b/lib/Support/StringRef.cpp index af64642a98..a4c0e87c28 100644 --- a/lib/Support/StringRef.cpp +++ b/lib/Support/StringRef.cpp @@ -89,23 +89,16 @@ static bool GetAsUnsignedInteger(StringRef Str, unsigned Radix, unsigned long long &Result) { // Autosense radix if not specified. if (Radix == 0) { - if (Str[0] != '0') { + if (Str.startswith("0x")) { + Str = Str.substr(2); + Radix = 16; + } else if (Str.startswith("0b")) { + Str = Str.substr(2); + Radix = 2; + } else if (Str.startswith("0")) + Radix = 8; + else Radix = 10; - } else { - if (Str.size() < 2) { - Radix = 8; - } else { - if (Str[1] == 'x') { - Str = Str.substr(2); - Radix = 16; - } else if (Str[1] == 'b') { - Str = Str.substr(2); - Radix = 2; - } else { - Radix = 8; - } - } - } } // Empty strings (after the radix autosense) are invalid. |