simplify as daniel suggests
authorChris Lattner <sabre@nondot.org>
Sun, 20 Sep 2009 22:56:43 +0000 (22:56 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 20 Sep 2009 22:56:43 +0000 (22:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82415 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/StringRef.cpp

index af64642a989d96b12e8761f3b01f651bf6749c73..a4c0e87c28eacd1574f4f1bc4da72b334d262bc4 100644 (file)
@@ -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.