(String string, int offset, int radix, boolean negative)
| 140 | } |
| 141 | |
| 142 | private static long parse(String string, int offset, int radix, boolean negative) { |
| 143 | long max = Long.MIN_VALUE / radix; |
| 144 | long result = 0, length = string.length(); |
| 145 | while (offset < length) { |
| 146 | int digit = Character.digit(string.charAt(offset++), radix); |
| 147 | if (digit == -1) { |
| 148 | throw invalidLong(string); |
| 149 | } |
| 150 | if (max > result) { |
| 151 | throw invalidLong(string); |
| 152 | } |
| 153 | long next = result * radix - digit; |
| 154 | if (next > result) { |
| 155 | throw invalidLong(string); |
| 156 | } |
| 157 | result = next; |
| 158 | } |
| 159 | if (!negative) { |
| 160 | result = -result; |
| 161 | if (result < 0) { |
| 162 | throw invalidLong(string); |
| 163 | } |
| 164 | } |
| 165 | return result; |
| 166 | } |
| 167 | |
| 168 | private static NumberFormatException invalidLong(String s) { |
| 169 | throw new NumberFormatException("Invalid long: \"" + s + "\""); |
no test coverage detected