195 return false; |
195 return false; |
196 } |
196 } |
197 } |
197 } |
198 |
198 |
199 /** Scan surrogate pairs. If 'ch' is a high surrogate and |
199 /** Scan surrogate pairs. If 'ch' is a high surrogate and |
200 * the next character is a low surrogate, then put the low |
200 * the next character is a low surrogate, returns the code point |
201 * surrogate in 'ch', and return the high surrogate. |
201 * constructed from these surrogates. Otherwise, returns -1. |
202 * otherwise, just return 0. |
202 * This method will not consume any of the characters. |
203 */ |
203 */ |
204 protected char scanSurrogates() { |
204 protected int peekSurrogates() { |
205 if (surrogatesSupported && Character.isHighSurrogate(ch)) { |
205 if (surrogatesSupported && Character.isHighSurrogate(ch)) { |
206 char high = ch; |
206 char high = ch; |
|
207 int prevBP = bp; |
207 |
208 |
208 scanChar(); |
209 scanChar(); |
209 |
210 |
210 if (Character.isLowSurrogate(ch)) { |
211 char low = ch; |
211 return high; |
|
212 } |
|
213 |
212 |
214 ch = high; |
213 ch = high; |
215 } |
214 bp = prevBP; |
216 |
215 |
217 return 0; |
216 if (Character.isLowSurrogate(low)) { |
|
217 return Character.toCodePoint(high, low); |
|
218 } |
|
219 } |
|
220 |
|
221 return -1; |
218 } |
222 } |
219 |
223 |
220 /** Convert an ASCII digit from its base (8, 10, or 16) |
224 /** Convert an ASCII digit from its base (8, 10, or 16) |
221 * to its value. |
225 * to its value. |
222 */ |
226 */ |
223 protected int digit(int pos, int base) { |
227 protected int digit(int pos, int base) { |
224 char c = ch; |
228 char c = ch; |
225 int result = Character.digit(c, base); |
229 if ('0' <= c && c <= '9') |
|
230 return Character.digit(c, base); //a fast common case |
|
231 int codePoint = peekSurrogates(); |
|
232 int result = codePoint >= 0 ? Character.digit(codePoint, base) : Character.digit(c, base); |
226 if (result >= 0 && c > 0x7f) { |
233 if (result >= 0 && c > 0x7f) { |
227 log.error(pos + 1, "illegal.nonascii.digit"); |
234 log.error(pos + 1, "illegal.nonascii.digit"); |
|
235 if (codePoint >= 0) |
|
236 scanChar(); |
228 ch = "0123456789abcdef".charAt(result); |
237 ch = "0123456789abcdef".charAt(result); |
229 } |
238 } |
230 return result; |
239 return result; |
231 } |
240 } |
232 |
241 |