(CharSequence in, int start, int length,
int terminator, String field)
| 1140 | } |
| 1141 | |
| 1142 | private static int read_digits(CharSequence in, int start, int length, |
| 1143 | int terminator, String field) |
| 1144 | { |
| 1145 | int ii, value = 0; |
| 1146 | int end = start + length; |
| 1147 | |
| 1148 | if (in.length() < end) { |
| 1149 | throw fail(in, |
| 1150 | field + " requires " + length + " digits"); |
| 1151 | } |
| 1152 | |
| 1153 | for (ii=start; ii<end; ii++) { |
| 1154 | char c = in.charAt(ii); |
| 1155 | if (!Character.isDigit(c)) { |
| 1156 | // FIXME this will give incorrect message if c is a surrogate |
| 1157 | throw fail(in, |
| 1158 | field + " has non-digit character " |
| 1159 | + printCodePointAsString(c)); |
| 1160 | } |
| 1161 | value *= 10; |
| 1162 | value += c - '0'; |
| 1163 | } |
| 1164 | |
| 1165 | // Check the terminator if requested. |
| 1166 | if (terminator != -1) { |
| 1167 | if (ii >= in.length() || in.charAt(ii) != terminator) { |
| 1168 | throw fail(in, |
| 1169 | field + " should end with " |
| 1170 | + printCodePointAsString(terminator)); |
| 1171 | } |
| 1172 | } |
| 1173 | // Otherwise make sure we don't have too many digits. |
| 1174 | else if (ii < in.length() && Character.isDigit(in.charAt(ii))) { |
| 1175 | throw fail(in, |
| 1176 | field + " requires " + length + " digits but has more"); |
| 1177 | } |
| 1178 | |
| 1179 | return value; |
| 1180 | } |
| 1181 | |
| 1182 | private static boolean isValidFollowChar(char c) { |
| 1183 | switch (c) { |
no test coverage detected