(CharSequence sequence, final int p, int lim)
| 2886 | } |
| 2887 | |
| 2888 | private static int parseInt0(CharSequence sequence, final int p, int lim) throws NumericException { |
| 2889 | if (lim == p) { |
| 2890 | throw NumericException.instance().put("empty integer string"); |
| 2891 | } |
| 2892 | |
| 2893 | final char sign = sequence.charAt(p); |
| 2894 | final boolean negative = sign == '-'; |
| 2895 | int i = p; |
| 2896 | if (negative || sign == '+') { |
| 2897 | i++; |
| 2898 | } |
| 2899 | |
| 2900 | if (i >= lim) { |
| 2901 | throw NumericException.instance().put("empty integer string"); |
| 2902 | } |
| 2903 | |
| 2904 | int digitCounter = 0; |
| 2905 | int val = 0; |
| 2906 | for (; i < lim; i++) { |
| 2907 | char c = sequence.charAt(i); |
| 2908 | if (c == '_') { |
| 2909 | if (digitCounter == 0) { |
| 2910 | throw NumericException.instance().put("invalid integer format: ").put(sequence, p, lim); |
| 2911 | } |
| 2912 | digitCounter = 0; |
| 2913 | } else if (c < '0' || c > '9') { |
| 2914 | throw NumericException.instance().put("invalid character in integer: ").put(sequence, p, lim); |
| 2915 | } else { |
| 2916 | // val * 10 + (c - '0') |
| 2917 | if (val < (Integer.MIN_VALUE / 10)) { |
| 2918 | throw NumericException.instance().put("integer overflow: ").put(sequence, p, lim); |
| 2919 | } |
| 2920 | int r = (val << 3) + (val << 1) - (c - '0'); |
| 2921 | if (r > val) { |
| 2922 | throw NumericException.instance().put("integer overflow: ").put(sequence, p, lim); |
| 2923 | } |
| 2924 | val = r; |
| 2925 | digitCounter++; |
| 2926 | } |
| 2927 | } |
| 2928 | |
| 2929 | if ((val == Integer.MIN_VALUE && !negative) || digitCounter == 0) { |
| 2930 | throw NumericException.instance().put("invalid integer format: ").put(sequence, p, lim); |
| 2931 | } |
| 2932 | return negative ? val : -val; |
| 2933 | } |
| 2934 | |
| 2935 | private static long parseLong0(CharSequence sequence, final int p, int lim) throws NumericException { |
| 2936 | if (lim == p) { |
no test coverage detected