(String string, int offset, int radix, boolean negative)
| 150 | } |
| 151 | |
| 152 | private static int parse(String string, int offset, int radix, boolean negative) throws NumberFormatException { |
| 153 | int max = Integer.MIN_VALUE / radix; |
| 154 | int result = 0, length = string.length(); |
| 155 | while (offset < length) { |
| 156 | int digit = Character.digit(string.charAt(offset++), radix); |
| 157 | if (digit == -1) { |
| 158 | throw invalidInt(string); |
| 159 | } |
| 160 | if (max > result) { |
| 161 | throw invalidInt(string); |
| 162 | } |
| 163 | int next = result * radix - digit; |
| 164 | if (next > result) { |
| 165 | throw invalidInt(string); |
| 166 | } |
| 167 | result = next; |
| 168 | } |
| 169 | if (!negative) { |
| 170 | result = -result; |
| 171 | if (result < 0) { |
| 172 | throw invalidInt(string); |
| 173 | } |
| 174 | } |
| 175 | return result; |
| 176 | } |
| 177 | |
| 178 | private static NumberFormatException invalidInt(String s) { |
| 179 | throw new NumberFormatException("Invalid int"); |
no test coverage detected