| 1374 | } |
| 1375 | |
| 1376 | public static long parseIntSafely(CharSequence sequence, final int p, int lim) throws NumericException { |
| 1377 | if (lim == p) { |
| 1378 | throw NumericException.instance().put("empty number string"); |
| 1379 | } |
| 1380 | |
| 1381 | boolean negative = sequence.charAt(p) == '-'; |
| 1382 | int i = p; |
| 1383 | if (negative) { |
| 1384 | i++; |
| 1385 | } |
| 1386 | |
| 1387 | if (i >= lim || notDigit(sequence.charAt(i))) { |
| 1388 | throw NumericException.instance().put("not a number: ").put(sequence); |
| 1389 | } |
| 1390 | |
| 1391 | int val = 0; |
| 1392 | for (; i < lim; i++) { |
| 1393 | char c = sequence.charAt(i); |
| 1394 | |
| 1395 | if (notDigit(c)) { |
| 1396 | break; |
| 1397 | } |
| 1398 | |
| 1399 | // val * 10 + (c - '0') |
| 1400 | int r = (val << 3) + (val << 1) - (c - '0'); |
| 1401 | if (r > val) { |
| 1402 | throw NumericException.instance().put("number overflow"); |
| 1403 | } |
| 1404 | val = r; |
| 1405 | } |
| 1406 | |
| 1407 | if (val == Integer.MIN_VALUE && !negative) { |
| 1408 | throw NumericException.instance().put("number overflow"); |
| 1409 | } |
| 1410 | |
| 1411 | return encodeLowHighInts(negative ? val : -val, i - p); |
| 1412 | } |
| 1413 | |
| 1414 | public static int parseIntSize(CharSequence sequence) throws NumericException { |
| 1415 | int lim = sequence.length(); |