/**
* Creates a new, empty parser.
*
- * @param ignoreCase
- * If true, perform case-folding. This parameter needs to go into the constructor because
- * its value is used during the construction of the matcher chain.
- * @param optimize
- * If true, compute "lead chars" UnicodeSets for the matchers. This reduces parsing
- * runtime but increases construction runtime. If the parser is going to be used only once
- * or twice, set this to false; if it is going to be used hundreds of times, set it to
- * true.
+ * @param parseFlags
+ * The parser settings defined in the PARSE_FLAG_* fields.
*/
public NumberParserImpl(int parseFlags) {
matchers = new ArrayList<NumberParseMatcher>();
public int getCodePoint() {
assert start < end;
char lead = str.charAt(start);
- if (Character.isHighSurrogate(lead) && start + 1 < end) {
- return Character.toCodePoint(lead, str.charAt(start + 1));
- } else if (Character.isSurrogate(lead)) {
- return -1;
- } else {
- return lead;
+ char trail;
+ if (Character.isHighSurrogate(lead)
+ && start + 1 < end
+ && Character.isLowSurrogate(trail = str.charAt(start + 1))) {
+ return Character.toCodePoint(lead, trail);
}
+ return lead;
}
/**
StringSegment segment = new StringSegment(SAMPLE_STRING, 0);
assertEquals(0x1F4FB, segment.getCodePoint());
segment.setLength(1);
- assertEquals(-1, segment.getCodePoint());
+ assertEquals(0xD83D, segment.getCodePoint());
segment.resetLength();
segment.adjustOffset(1);
- assertEquals(-1, segment.getCodePoint());
+ assertEquals(0xDCFB, segment.getCodePoint());
segment.adjustOffset(1);
assertEquals(0x20, segment.getCodePoint());
}