| 1164 | // parseInt parses a nonnegative decimal integer. |
| 1165 | // -1 => bad format. -2 => format ok, but integer overflow. |
| 1166 | private static int parseInt(StringIterator t) { |
| 1167 | int start = t.pos(); |
| 1168 | int c; |
| 1169 | while (t.more() && (c = t.peek()) >= '0' && c <= '9') { |
| 1170 | t.skip(1); // digit |
| 1171 | } |
| 1172 | String n = t.from(start); |
| 1173 | if (n.isEmpty() || (n.length() > 1 && n.charAt(0) == '0')) { // disallow leading zeros |
| 1174 | return -1; // bad format |
| 1175 | } |
| 1176 | if (n.length() > 8) { |
| 1177 | return -2; // overflow |
| 1178 | } |
| 1179 | return Integer.valueOf(n, 10); // can't fail |
| 1180 | } |
| 1181 | |
| 1182 | // can this be represented as a character class? |
| 1183 | // single-rune literal string, char class, ., and .|\n. |