LEFT | RIGHT |
(no file at all) | |
1 // © 2017 and later: Unicode, Inc. and others. | 1 // © 2017 and later: Unicode, Inc. and others. |
2 // License & terms of use: http://www.unicode.org/copyright.html#License | 2 // License & terms of use: http://www.unicode.org/copyright.html#License |
3 package com.ibm.icu.impl.number; | 3 package com.ibm.icu.impl.number; |
4 | 4 |
5 import com.ibm.icu.impl.SimpleFormatterImpl; | 5 import com.ibm.icu.impl.SimpleFormatterImpl; |
6 import com.ibm.icu.text.NumberFormat.Field; | 6 import com.ibm.icu.text.NumberFormat.Field; |
7 | 7 |
8 /** | 8 /** |
9 * The second primary implementation of {@link Modifier}, this one consuming a {
@link com.ibm.icu.text.SimpleFormatter} | 9 * The second primary implementation of {@link Modifier}, this one consuming a |
10 * pattern. | 10 * {@link com.ibm.icu.text.SimpleFormatter} pattern. |
11 */ | 11 */ |
12 public class SimpleModifier implements Modifier { | 12 public class SimpleModifier implements Modifier { |
13 private final String compiledPattern; | 13 private final String compiledPattern; |
14 private final Field field; | 14 private final Field field; |
15 private final boolean strong; | 15 private final boolean strong; |
16 private final int prefixLength; | 16 private final int prefixLength; |
17 private final int suffixOffset; | 17 private final int suffixOffset; |
18 private final int suffixLength; | 18 private final int suffixLength; |
19 | 19 |
20 /** TODO: This is copied from SimpleFormatterImpl. */ | 20 /** TODO: This is copied from SimpleFormatterImpl. */ |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 return prefixLength; | 52 return prefixLength; |
53 } | 53 } |
54 | 54 |
55 @Override | 55 @Override |
56 public int getCodePointCount() { | 56 public int getCodePointCount() { |
57 int count = 0; | 57 int count = 0; |
58 if (prefixLength > 0) { | 58 if (prefixLength > 0) { |
59 count += Character.codePointCount(compiledPattern, 2, 2 + prefixLeng
th); | 59 count += Character.codePointCount(compiledPattern, 2, 2 + prefixLeng
th); |
60 } | 60 } |
61 if (suffixLength > 0) { | 61 if (suffixLength > 0) { |
62 count += Character.codePointCount(compiledPattern, 1 + suffixOffset,
1 + suffixOffset + suffixLength); | 62 count += Character |
| 63 .codePointCount(compiledPattern, 1 + suffixOffset, 1 + suffi
xOffset + suffixLength); |
63 } | 64 } |
64 return count; | 65 return count; |
65 } | 66 } |
66 | 67 |
67 @Override | 68 @Override |
68 public boolean isStrong() { | 69 public boolean isStrong() { |
69 return strong; | 70 return strong; |
70 } | 71 } |
71 | 72 |
72 /** | 73 /** |
73 * TODO: This belongs in SimpleFormatterImpl. The only reason I haven't move
d it there yet is because | 74 * TODO: This belongs in SimpleFormatterImpl. The only reason I haven't move
d it there yet is because |
74 * DoubleSidedStringBuilder is an internal class and SimpleFormatterImpl fee
ls like it should not depend on it. | 75 * DoubleSidedStringBuilder is an internal class and SimpleFormatterImpl fee
ls like it should not |
| 76 * depend on it. |
75 * | 77 * |
76 * <p> | 78 * <p> |
77 * Formats a value that is already stored inside the StringBuilder <code>res
ult</code> between the indices | 79 * Formats a value that is already stored inside the StringBuilder <code>res
ult</code> between the |
78 * <code>startIndex</code> and <code>endIndex</code> by inserting characters
before the start index and after the | 80 * indices <code>startIndex</code> and <code>endIndex</code> by inserting ch
aracters before the start |
79 * end index. | 81 * index and after the end index. |
80 * | 82 * |
81 * <p> | 83 * <p> |
82 * This is well-defined only for patterns with exactly one argument. | 84 * This is well-defined only for patterns with exactly one argument. |
83 * | 85 * |
84 * @param result | 86 * @param result |
85 * The StringBuilder containing the value argument. | 87 * The StringBuilder containing the value argument. |
86 * @param startIndex | 88 * @param startIndex |
87 * The left index of the value within the string builder. | 89 * The left index of the value within the string builder. |
88 * @param endIndex | 90 * @param endIndex |
89 * The right index of the value within the string builder. | 91 * The right index of the value within the string builder. |
90 * @return The number of characters (UTF-16 code points) that were added to
the StringBuilder. | 92 * @return The number of characters (UTF-16 code points) that were added to
the StringBuilder. |
91 */ | 93 */ |
92 public int formatAsPrefixSuffix(NumberStringBuilder result, int startIndex,
int endIndex, Field field) { | 94 public int formatAsPrefixSuffix( |
| 95 NumberStringBuilder result, |
| 96 int startIndex, |
| 97 int endIndex, |
| 98 Field field) { |
93 if (prefixLength > 0) { | 99 if (prefixLength > 0) { |
94 result.insert(startIndex, compiledPattern, 2, 2 + prefixLength, fiel
d); | 100 result.insert(startIndex, compiledPattern, 2, 2 + prefixLength, fiel
d); |
95 } | 101 } |
96 if (suffixLength > 0) { | 102 if (suffixLength > 0) { |
97 result.insert(endIndex + prefixLength, compiledPattern, 1 + suffixOf
fset, 1 + suffixOffset + suffixLength, | 103 result.insert(endIndex + prefixLength, |
| 104 compiledPattern, |
| 105 1 + suffixOffset, |
| 106 1 + suffixOffset + suffixLength, |
98 field); | 107 field); |
99 } | 108 } |
100 return prefixLength + suffixLength; | 109 return prefixLength + suffixLength; |
101 } | 110 } |
102 } | 111 } |
LEFT | RIGHT |