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 SymbolMatcher implements NumberParseMatcher { |
| 12 private final String string; |
| 13 private final UnicodeSet uniSet; |
| 14 |
| 15 protected SymbolMatcher(String symbolString, UnicodeSet symbolUniSet) { |
| 16 string = symbolString; |
| 17 uniSet = symbolUniSet; |
| 18 } |
| 19 |
| 20 @Override |
| 21 public boolean match(StringSegment segment, ParsedNumber result) { |
| 22 // Smoke test first; this matcher might be disabled. |
| 23 if (isDisabled(result)) { |
| 24 return false; |
| 25 } |
| 26 |
| 27 int cp = segment.getCodePoint(); |
| 28 if (cp != -1 && uniSet.contains(cp)) { |
| 29 accept(result); |
| 30 segment.adjustOffset(Character.charCount(cp)); |
| 31 return false; |
| 32 } |
| 33 int overlap = segment.getCommonPrefixLength(string); |
| 34 if (overlap == string.length()) { |
| 35 accept(result); |
| 36 segment.adjustOffset(string.length()); |
| 37 return false; |
| 38 } |
| 39 return overlap == segment.length(); |
| 40 } |
| 41 |
| 42 @Override |
| 43 public void postProcess(ParsedNumber result) { |
| 44 // No-op |
| 45 } |
| 46 |
| 47 protected abstract boolean isDisabled(ParsedNumber result); |
| 48 |
| 49 protected abstract void accept(ParsedNumber result); |
| 50 } |
LEFT | RIGHT |