OLD | NEW |
1 // © 2016 and later: Unicode, Inc. and others. | 1 // © 2016 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 /* | 3 /* |
4 * Copyright (C) 1996-2011, International Business Machines Corporation and | 4 * Copyright (C) 1996-2011, International Business Machines Corporation and |
5 * others. All Rights Reserved. | 5 * others. All Rights Reserved. |
6 * | 6 * |
7 */ | 7 */ |
8 package com.ibm.icu.text; | 8 package com.ibm.icu.text; |
9 | 9 |
10 import com.ibm.icu.impl.UCaseProps; | 10 import com.ibm.icu.impl.UCaseProps; |
(...skipping 24 matching lines...) Expand all Loading... |
35 }); | 35 }); |
36 | 36 |
37 registerSpecialInverse("Title", "Lower", false); | 37 registerSpecialInverse("Title", "Lower", false); |
38 } | 38 } |
39 | 39 |
40 private final ULocale locale; | 40 private final ULocale locale; |
41 | 41 |
42 private final UCaseProps csp; | 42 private final UCaseProps csp; |
43 private ReplaceableContextIterator iter; | 43 private ReplaceableContextIterator iter; |
44 private StringBuilder result; | 44 private StringBuilder result; |
45 private int[] locCache; | 45 private int caseLocale; |
46 | 46 |
47 /** | 47 /** |
48 * Constructs a transliterator. | 48 * Constructs a transliterator. |
49 */ | 49 */ |
50 public TitlecaseTransliterator(ULocale loc) { | 50 public TitlecaseTransliterator(ULocale loc) { |
51 super(_ID, null); | 51 super(_ID, null); |
52 locale = loc; | 52 locale = loc; |
53 // Need to look back 2 characters in the case of "can't" | 53 // Need to look back 2 characters in the case of "can't" |
54 setMaximumContextLength(2); | 54 setMaximumContextLength(2); |
55 csp=UCaseProps.INSTANCE; | 55 csp=UCaseProps.INSTANCE; |
56 iter=new ReplaceableContextIterator(); | 56 iter=new ReplaceableContextIterator(); |
57 result = new StringBuilder(); | 57 result = new StringBuilder(); |
58 locCache = new int[1]; | 58 caseLocale = UCaseProps.getCaseLocale(locale); |
59 locCache[0]=0; | |
60 } | 59 } |
61 | 60 |
62 /** | 61 /** |
63 * Implements {@link Transliterator#handleTransliterate}. | 62 * Implements {@link Transliterator#handleTransliterate}. |
64 */ | 63 */ |
65 @Override | 64 @Override |
66 protected synchronized void handleTransliterate(Replaceable text, | 65 protected synchronized void handleTransliterate(Replaceable text, |
67 Position offsets, boolean isIncremental)
{ | 66 Position offsets, boolean isIncremental)
{ |
68 // TODO reimplement, see ustrcase.c | 67 // TODO reimplement, see ustrcase.c |
69 // using a real word break iterator | 68 // using a real word break iterator |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 result.setLength(0); | 111 result.setLength(0); |
113 | 112 |
114 // Walk through original string | 113 // Walk through original string |
115 // If there is a case change, modify corresponding position in replaceab
le | 114 // If there is a case change, modify corresponding position in replaceab
le |
116 int delta; | 115 int delta; |
117 | 116 |
118 while((c=iter.nextCaseMapCP())>=0) { | 117 while((c=iter.nextCaseMapCP())>=0) { |
119 type=csp.getTypeOrIgnorable(c); | 118 type=csp.getTypeOrIgnorable(c); |
120 if(type>=0) { // not case-ignorable | 119 if(type>=0) { // not case-ignorable |
121 if(doTitle) { | 120 if(doTitle) { |
122 c=csp.toFullTitle(c, iter, result, locale, locCache); | 121 c=csp.toFullTitle(c, iter, result, caseLocale); |
123 } else { | 122 } else { |
124 c=csp.toFullLower(c, iter, result, locale, locCache); | 123 c=csp.toFullLower(c, iter, result, caseLocale); |
125 } | 124 } |
126 doTitle = type==0; // doTitle=isUncased | 125 doTitle = type==0; // doTitle=isUncased |
127 | 126 |
128 if(iter.didReachLimit() && isIncremental) { | 127 if(iter.didReachLimit() && isIncremental) { |
129 // the case mapping function tried to look beyond the contex
t limit | 128 // the case mapping function tried to look beyond the contex
t limit |
130 // wait for more input | 129 // wait for more input |
131 offsets.start=iter.getCaseMapCPStart(); | 130 offsets.start=iter.getCaseMapCPStart(); |
132 return; | 131 return; |
133 } | 132 } |
134 | 133 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 @Override | 167 @Override |
169 public String transform(String source) { | 168 public String transform(String source) { |
170 return UCharacter.toTitleCase(locale, source, null); | 169 return UCharacter.toTitleCase(locale, source, null); |
171 } | 170 } |
172 }); | 171 }); |
173 } | 172 } |
174 } | 173 } |
175 sourceTargetUtility.addSourceTargetSet(this, inputFilter, sourceSet, tar
getSet); | 174 sourceTargetUtility.addSourceTargetSet(this, inputFilter, sourceSet, tar
getSet); |
176 } | 175 } |
177 } | 176 } |
OLD | NEW |