From 6441e547ccf563ccebd8a81e57def810172c93bf Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 20 Sep 2009 22:56:43 +0000 Subject: simplify as daniel suggests git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82415 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/StringRef.cpp | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) (limited to 'lib/Support/StringRef.cpp') 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. -- cgit v1.2.3