LEFT | RIGHT |
(no file at all) | |
| 1 // © 2017 and later: Unicode, Inc. and others. |
| 2 // License & terms of use: http://www.unicode.org/copyright.html#License |
| 3 package com.ibm.icu.impl.number.parse; |
| 4 |
| 5 import com.ibm.icu.text.UnicodeSet; |
| 6 |
| 7 /** |
| 8 * @author sffc |
| 9 * |
| 10 */ |
| 11 public abstract class RangeMatcher implements NumberParseMatcher { |
| 12 protected final UnicodeSet uniSet; |
| 13 |
| 14 protected RangeMatcher(UnicodeSet uniSet) { |
| 15 this.uniSet = uniSet; |
| 16 } |
| 17 |
| 18 public UnicodeSet getSet() { |
| 19 return uniSet; |
| 20 } |
| 21 |
| 22 @Override |
| 23 public boolean match(StringSegment segment, ParsedNumber result) { |
| 24 // Smoke test first; this matcher might be disabled. |
| 25 if (isDisabled(result)) { |
| 26 return false; |
| 27 } |
| 28 |
| 29 while (segment.length() > 0) { |
| 30 int cp = segment.getCodePoint(); |
| 31 if (cp != -1 && uniSet.contains(cp)) { |
| 32 segment.adjustOffset(Character.charCount(cp)); |
| 33 accept(segment, result); |
| 34 continue; |
| 35 } |
| 36 |
| 37 // If we get here, the code point didn't match the uniSet. |
| 38 return false; |
| 39 } |
| 40 |
| 41 // If we get here, we consumed the entire string segment. |
| 42 return true; |
| 43 } |
| 44 |
| 45 @Override |
| 46 public UnicodeSet getLeadCodePoints() { |
| 47 UnicodeSet leadCodePoints = new UnicodeSet(); |
| 48 ParsingUtils.putLeadCodePoints(uniSet, leadCodePoints); |
| 49 return leadCodePoints.freeze(); |
| 50 } |
| 51 |
| 52 @Override |
| 53 public void postProcess(ParsedNumber result) { |
| 54 // No-op |
| 55 } |
| 56 |
| 57 protected abstract boolean isDisabled(ParsedNumber result); |
| 58 |
| 59 protected abstract void accept(StringSegment segment, ParsedNumber result); |
| 60 |
| 61 } |
LEFT | RIGHT |