OLD | NEW |
(Empty) | |
| 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.DecimalFormatSymbols; |
| 6 |
| 7 /** |
| 8 * @author sffc |
| 9 * |
| 10 */ |
| 11 public class PermilleMatcher extends SymbolMatcher { |
| 12 |
| 13 private static final PermilleMatcher DEFAULT = new PermilleMatcher(); |
| 14 |
| 15 public static PermilleMatcher getInstance(DecimalFormatSymbols symbols) { |
| 16 String symbolString = symbols.getPerMillString(); |
| 17 if (DEFAULT.uniSet.contains(symbolString)) { |
| 18 return DEFAULT; |
| 19 } else { |
| 20 return new PermilleMatcher(symbolString); |
| 21 } |
| 22 } |
| 23 |
| 24 private PermilleMatcher(String symbolString) { |
| 25 super(symbolString, DEFAULT.uniSet); |
| 26 } |
| 27 |
| 28 private PermilleMatcher() { |
| 29 super(UnicodeSetStaticCache.Key.PERMILLE_SIGN); |
| 30 } |
| 31 |
| 32 @Override |
| 33 protected boolean isDisabled(ParsedNumber result) { |
| 34 return 0 != (result.flags & ParsedNumber.FLAG_PERMILLE); |
| 35 } |
| 36 |
| 37 @Override |
| 38 protected void accept(StringSegment segment, ParsedNumber result) { |
| 39 result.flags |= ParsedNumber.FLAG_PERMILLE; |
| 40 result.setCharsConsumed(segment); |
| 41 } |
| 42 |
| 43 @Override |
| 44 public void postProcess(ParsedNumber result) { |
| 45 super.postProcess(result); |
| 46 if (0 != (result.flags & ParsedNumber.FLAG_PERMILLE) && result.quantity
!= null) { |
| 47 result.quantity.adjustMagnitude(-3); |
| 48 } |
| 49 } |
| 50 |
| 51 @Override |
| 52 public String toString() { |
| 53 return "<PermilleMatcher>"; |
| 54 } |
| 55 } |
OLD | NEW |