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.lang.UCharacter; |
| 6 import com.ibm.icu.text.DecimalFormatSymbols; |
| 7 import com.ibm.icu.text.UnicodeSet; |
| 8 |
| 9 /** |
| 10 * @author sffc |
| 11 * |
| 12 */ |
| 13 public class NanMatcher extends SymbolMatcher { |
| 14 |
| 15 private static final NanMatcher DEFAULT = new NanMatcher("NaN"); |
| 16 private static final NanMatcher DEFAULT_FOLDED = new NanMatcher(UCharacter.f
oldCase("NaN", true)); |
| 17 |
| 18 public static NanMatcher getInstance(DecimalFormatSymbols symbols, int parse
Flags) { |
| 19 String symbolString = ParsingUtils.maybeFold(symbols.getNaN(), parseFlag
s); |
| 20 if (DEFAULT.string.equals(symbolString)) { |
| 21 return DEFAULT; |
| 22 } else if (DEFAULT_FOLDED.string.equals(symbolString)) { |
| 23 return DEFAULT_FOLDED; |
| 24 } else { |
| 25 return new NanMatcher(symbolString); |
| 26 } |
| 27 } |
| 28 |
| 29 private NanMatcher(String symbolString) { |
| 30 super(symbolString, UnicodeSet.EMPTY); |
| 31 } |
| 32 |
| 33 @Override |
| 34 public UnicodeSet getLeadCodePoints() { |
| 35 // Overriding this here to allow use of statically allocated sets |
| 36 if (this == DEFAULT) { |
| 37 return UnicodeSetStaticCache.get(UnicodeSetStaticCache.Key.CAPITAL_N
); |
| 38 } else if (this == DEFAULT_FOLDED) { |
| 39 return UnicodeSetStaticCache.get(UnicodeSetStaticCache.Key.FOLDED_N)
; |
| 40 } else { |
| 41 return super.getLeadCodePoints(); |
| 42 } |
| 43 } |
| 44 |
| 45 @Override |
| 46 protected boolean isDisabled(ParsedNumber result) { |
| 47 return result.seenNumber(); |
| 48 } |
| 49 |
| 50 @Override |
| 51 protected void accept(StringSegment segment, ParsedNumber result) { |
| 52 result.flags |= ParsedNumber.FLAG_NAN; |
| 53 result.setCharsConsumed(segment); |
| 54 } |
| 55 |
| 56 @Override |
| 57 public String toString() { |
| 58 return "<NanMatcher>"; |
| 59 } |
| 60 |
| 61 } |
LEFT | RIGHT |