(CharSequence s, int start, int end, int radix)
| 7 | public class StringUtils |
| 8 | { |
| 9 | public static int parseInt(CharSequence s, int start, int end, int radix) |
| 10 | { |
| 11 | boolean negative = false; |
| 12 | int val = 0; |
| 13 | |
| 14 | for(int i = start; i < end; i++) |
| 15 | { |
| 16 | char c = s.charAt(i); |
| 17 | if (c == '-') |
| 18 | if (i == start) |
| 19 | negative = true; |
| 20 | else |
| 21 | throw new NumberFormatException("Negative sign did not occur at begining of sequence"); |
| 22 | else if (c == '+') |
| 23 | if (i == start) |
| 24 | negative = false;//do nothing really |
| 25 | else |
| 26 | throw new NumberFormatException("Positive sign did not occur at begining of sequence"); |
| 27 | else |
| 28 | { |
| 29 | int digit = Character.digit(c, radix); |
| 30 | if(digit < 0) |
| 31 | throw new NumberFormatException("Non digit character '" + c + "' encountered"); |
| 32 | val *= radix; |
| 33 | val += digit; |
| 34 | } |
| 35 | } |
| 36 | if(negative) |
| 37 | return -val; |
| 38 | else |
| 39 | return val; |
| 40 | } |
| 41 | |
| 42 | public static int parseInt(CharSequence s, int start, int end) |
| 43 | { |
no outgoing calls