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.UnicodeSet; |
| 7 import com.ibm.icu.text.UnicodeSet.EntryRange; |
| 8 |
| 9 /** |
| 10 * A collection of utility functions used by the number parsing package. |
| 11 */ |
| 12 public class ParsingUtils { |
| 13 |
| 14 public static final int PARSE_FLAG_IGNORE_CASE = 0x0001; |
| 15 public static final int PARSE_FLAG_MONETARY_SEPARATORS = 0x0002; |
| 16 public static final int PARSE_FLAG_STRICT_SEPARATORS = 0x0004; |
| 17 public static final int PARSE_FLAG_STRICT_GROUPING_SIZE = 0x0008; |
| 18 public static final int PARSE_FLAG_INTEGER_ONLY = 0x0010; |
| 19 public static final int PARSE_FLAG_GROUPING_DISABLED = 0x0020; |
| 20 public static final int PARSE_FLAG_DECIMAL_SCIENTIFIC = 0x0040; |
| 21 public static final int PARSE_FLAG_INCLUDE_UNPAIRED_AFFIXES = 0x0080; |
| 22 |
| 23 public static void putLeadCodePoints(UnicodeSet input, UnicodeSet output) { |
| 24 for (EntryRange range : input.ranges()) { |
| 25 output.add(range.codepoint, range.codepointEnd); |
| 26 } |
| 27 for (String str : input.strings()) { |
| 28 output.add(str.codePointAt(0)); |
| 29 } |
| 30 } |
| 31 |
| 32 public static void putLeadCodePoint(String input, UnicodeSet output) { |
| 33 if (!input.isEmpty()) { |
| 34 output.add(input.codePointAt(0)); |
| 35 } |
| 36 } |
| 37 |
| 38 private static final UnicodeSet LETTERS = new UnicodeSet("[:letter:]").freez
e(); |
| 39 |
| 40 /** |
| 41 * Case-folds the string if IGNORE_CASE flag is set; otherwise, returns the
same string. |
| 42 */ |
| 43 public static String maybeFold(String input, int parseFlags) { |
| 44 if (0 != (parseFlags & PARSE_FLAG_IGNORE_CASE) && LETTERS.containsSome(i
nput)) { |
| 45 return UCharacter.foldCase(input, true); |
| 46 } else { |
| 47 return input; |
| 48 } |
| 49 } |
| 50 |
| 51 } |
LEFT | RIGHT |