xref: /aosp_15_r20/external/icu/icu4c/source/common/unicode/casemap.h (revision 0e209d3975ff4a8c132096b14b0e9364a753506e)
1*0e209d39SAndroid Build Coastguard Worker // © 2017 and later: Unicode, Inc. and others.
2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html
3*0e209d39SAndroid Build Coastguard Worker 
4*0e209d39SAndroid Build Coastguard Worker // casemap.h
5*0e209d39SAndroid Build Coastguard Worker // created: 2017jan12 Markus W. Scherer
6*0e209d39SAndroid Build Coastguard Worker 
7*0e209d39SAndroid Build Coastguard Worker #ifndef __CASEMAP_H__
8*0e209d39SAndroid Build Coastguard Worker #define __CASEMAP_H__
9*0e209d39SAndroid Build Coastguard Worker 
10*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h"
11*0e209d39SAndroid Build Coastguard Worker 
12*0e209d39SAndroid Build Coastguard Worker #if U_SHOW_CPLUSPLUS_API
13*0e209d39SAndroid Build Coastguard Worker 
14*0e209d39SAndroid Build Coastguard Worker #include "unicode/stringpiece.h"
15*0e209d39SAndroid Build Coastguard Worker #include "unicode/uobject.h"
16*0e209d39SAndroid Build Coastguard Worker 
17*0e209d39SAndroid Build Coastguard Worker /**
18*0e209d39SAndroid Build Coastguard Worker  * \file
19*0e209d39SAndroid Build Coastguard Worker  * \brief C++ API: Low-level C++ case mapping functions.
20*0e209d39SAndroid Build Coastguard Worker  */
21*0e209d39SAndroid Build Coastguard Worker 
22*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN
23*0e209d39SAndroid Build Coastguard Worker 
24*0e209d39SAndroid Build Coastguard Worker class BreakIterator;
25*0e209d39SAndroid Build Coastguard Worker class ByteSink;
26*0e209d39SAndroid Build Coastguard Worker class Edits;
27*0e209d39SAndroid Build Coastguard Worker 
28*0e209d39SAndroid Build Coastguard Worker /**
29*0e209d39SAndroid Build Coastguard Worker  * Low-level C++ case mapping functions.
30*0e209d39SAndroid Build Coastguard Worker  *
31*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 59
32*0e209d39SAndroid Build Coastguard Worker  */
33*0e209d39SAndroid Build Coastguard Worker class U_COMMON_API CaseMap final : public UMemory {
34*0e209d39SAndroid Build Coastguard Worker public:
35*0e209d39SAndroid Build Coastguard Worker     /**
36*0e209d39SAndroid Build Coastguard Worker      * Lowercases a UTF-16 string and optionally records edits.
37*0e209d39SAndroid Build Coastguard Worker      * Casing is locale-dependent and context-sensitive.
38*0e209d39SAndroid Build Coastguard Worker      * The result may be longer or shorter than the original.
39*0e209d39SAndroid Build Coastguard Worker      * The source string and the destination buffer must not overlap.
40*0e209d39SAndroid Build Coastguard Worker      *
41*0e209d39SAndroid Build Coastguard Worker      * @param locale    The locale ID. ("" = root locale, nullptr = default locale.)
42*0e209d39SAndroid Build Coastguard Worker      * @param options   Options bit set, usually 0. See U_OMIT_UNCHANGED_TEXT and U_EDITS_NO_RESET.
43*0e209d39SAndroid Build Coastguard Worker      * @param src       The original string.
44*0e209d39SAndroid Build Coastguard Worker      * @param srcLength The length of the original string. If -1, then src must be NUL-terminated.
45*0e209d39SAndroid Build Coastguard Worker      * @param dest      A buffer for the result string. The result will be NUL-terminated if
46*0e209d39SAndroid Build Coastguard Worker      *                  the buffer is large enough.
47*0e209d39SAndroid Build Coastguard Worker      *                  The contents is undefined in case of failure.
48*0e209d39SAndroid Build Coastguard Worker      * @param destCapacity The size of the buffer (number of char16_ts). If it is 0, then
49*0e209d39SAndroid Build Coastguard Worker      *                  dest may be nullptr and the function will only return the length of the result
50*0e209d39SAndroid Build Coastguard Worker      *                  without writing any of the result string.
51*0e209d39SAndroid Build Coastguard Worker      * @param edits     Records edits for index mapping, working with styled text,
52*0e209d39SAndroid Build Coastguard Worker      *                  and getting only changes (if any).
53*0e209d39SAndroid Build Coastguard Worker      *                  The Edits contents is undefined if any error occurs.
54*0e209d39SAndroid Build Coastguard Worker      *                  This function calls edits->reset() first unless
55*0e209d39SAndroid Build Coastguard Worker      *                  options includes U_EDITS_NO_RESET. edits can be nullptr.
56*0e209d39SAndroid Build Coastguard Worker      * @param errorCode Reference to an in/out error code value
57*0e209d39SAndroid Build Coastguard Worker      *                  which must not indicate a failure before the function call.
58*0e209d39SAndroid Build Coastguard Worker      * @return The length of the result string, if successful.
59*0e209d39SAndroid Build Coastguard Worker      *         When the result would be longer than destCapacity,
60*0e209d39SAndroid Build Coastguard Worker      *         the full length is returned and a U_BUFFER_OVERFLOW_ERROR is set.
61*0e209d39SAndroid Build Coastguard Worker      *
62*0e209d39SAndroid Build Coastguard Worker      * @see u_strToLower
63*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 59
64*0e209d39SAndroid Build Coastguard Worker      */
65*0e209d39SAndroid Build Coastguard Worker      static int32_t toLower(
66*0e209d39SAndroid Build Coastguard Worker             const char *locale, uint32_t options,
67*0e209d39SAndroid Build Coastguard Worker             const char16_t *src, int32_t srcLength,
68*0e209d39SAndroid Build Coastguard Worker             char16_t *dest, int32_t destCapacity, Edits *edits,
69*0e209d39SAndroid Build Coastguard Worker             UErrorCode &errorCode);
70*0e209d39SAndroid Build Coastguard Worker 
71*0e209d39SAndroid Build Coastguard Worker     /**
72*0e209d39SAndroid Build Coastguard Worker      * Uppercases a UTF-16 string and optionally records edits.
73*0e209d39SAndroid Build Coastguard Worker      * Casing is locale-dependent and context-sensitive.
74*0e209d39SAndroid Build Coastguard Worker      * The result may be longer or shorter than the original.
75*0e209d39SAndroid Build Coastguard Worker      * The source string and the destination buffer must not overlap.
76*0e209d39SAndroid Build Coastguard Worker      *
77*0e209d39SAndroid Build Coastguard Worker      * @param locale    The locale ID. ("" = root locale, nullptr = default locale.)
78*0e209d39SAndroid Build Coastguard Worker      * @param options   Options bit set, usually 0. See U_OMIT_UNCHANGED_TEXT and U_EDITS_NO_RESET.
79*0e209d39SAndroid Build Coastguard Worker      * @param src       The original string.
80*0e209d39SAndroid Build Coastguard Worker      * @param srcLength The length of the original string. If -1, then src must be NUL-terminated.
81*0e209d39SAndroid Build Coastguard Worker      * @param dest      A buffer for the result string. The result will be NUL-terminated if
82*0e209d39SAndroid Build Coastguard Worker      *                  the buffer is large enough.
83*0e209d39SAndroid Build Coastguard Worker      *                  The contents is undefined in case of failure.
84*0e209d39SAndroid Build Coastguard Worker      * @param destCapacity The size of the buffer (number of char16_ts). If it is 0, then
85*0e209d39SAndroid Build Coastguard Worker      *                  dest may be nullptr and the function will only return the length of the result
86*0e209d39SAndroid Build Coastguard Worker      *                  without writing any of the result string.
87*0e209d39SAndroid Build Coastguard Worker      * @param edits     Records edits for index mapping, working with styled text,
88*0e209d39SAndroid Build Coastguard Worker      *                  and getting only changes (if any).
89*0e209d39SAndroid Build Coastguard Worker      *                  The Edits contents is undefined if any error occurs.
90*0e209d39SAndroid Build Coastguard Worker      *                  This function calls edits->reset() first unless
91*0e209d39SAndroid Build Coastguard Worker      *                  options includes U_EDITS_NO_RESET. edits can be nullptr.
92*0e209d39SAndroid Build Coastguard Worker      * @param errorCode Reference to an in/out error code value
93*0e209d39SAndroid Build Coastguard Worker      *                  which must not indicate a failure before the function call.
94*0e209d39SAndroid Build Coastguard Worker      * @return The length of the result string, if successful.
95*0e209d39SAndroid Build Coastguard Worker      *         When the result would be longer than destCapacity,
96*0e209d39SAndroid Build Coastguard Worker      *         the full length is returned and a U_BUFFER_OVERFLOW_ERROR is set.
97*0e209d39SAndroid Build Coastguard Worker      *
98*0e209d39SAndroid Build Coastguard Worker      * @see u_strToUpper
99*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 59
100*0e209d39SAndroid Build Coastguard Worker      */
101*0e209d39SAndroid Build Coastguard Worker     static int32_t toUpper(
102*0e209d39SAndroid Build Coastguard Worker             const char *locale, uint32_t options,
103*0e209d39SAndroid Build Coastguard Worker             const char16_t *src, int32_t srcLength,
104*0e209d39SAndroid Build Coastguard Worker             char16_t *dest, int32_t destCapacity, Edits *edits,
105*0e209d39SAndroid Build Coastguard Worker             UErrorCode &errorCode);
106*0e209d39SAndroid Build Coastguard Worker 
107*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_BREAK_ITERATION
108*0e209d39SAndroid Build Coastguard Worker 
109*0e209d39SAndroid Build Coastguard Worker     /**
110*0e209d39SAndroid Build Coastguard Worker      * Titlecases a UTF-16 string and optionally records edits.
111*0e209d39SAndroid Build Coastguard Worker      * Casing is locale-dependent and context-sensitive.
112*0e209d39SAndroid Build Coastguard Worker      * The result may be longer or shorter than the original.
113*0e209d39SAndroid Build Coastguard Worker      * The source string and the destination buffer must not overlap.
114*0e209d39SAndroid Build Coastguard Worker      *
115*0e209d39SAndroid Build Coastguard Worker      * Titlecasing uses a break iterator to find the first characters of words
116*0e209d39SAndroid Build Coastguard Worker      * that are to be titlecased. It titlecases those characters and lowercases
117*0e209d39SAndroid Build Coastguard Worker      * all others. (This can be modified with options bits.)
118*0e209d39SAndroid Build Coastguard Worker      *
119*0e209d39SAndroid Build Coastguard Worker      * @param locale    The locale ID. ("" = root locale, nullptr = default locale.)
120*0e209d39SAndroid Build Coastguard Worker      * @param options   Options bit set, usually 0. See U_OMIT_UNCHANGED_TEXT, U_EDITS_NO_RESET,
121*0e209d39SAndroid Build Coastguard Worker      *                  U_TITLECASE_NO_LOWERCASE,
122*0e209d39SAndroid Build Coastguard Worker      *                  U_TITLECASE_NO_BREAK_ADJUSTMENT, U_TITLECASE_ADJUST_TO_CASED,
123*0e209d39SAndroid Build Coastguard Worker      *                  U_TITLECASE_WHOLE_STRING, U_TITLECASE_SENTENCES.
124*0e209d39SAndroid Build Coastguard Worker      * @param iter      A break iterator to find the first characters of words that are to be titlecased.
125*0e209d39SAndroid Build Coastguard Worker      *                  It is set to the source string (setText())
126*0e209d39SAndroid Build Coastguard Worker      *                  and used one or more times for iteration (first() and next()).
127*0e209d39SAndroid Build Coastguard Worker      *                  If nullptr, then a word break iterator for the locale is used
128*0e209d39SAndroid Build Coastguard Worker      *                  (or something equivalent).
129*0e209d39SAndroid Build Coastguard Worker      * @param src       The original string.
130*0e209d39SAndroid Build Coastguard Worker      * @param srcLength The length of the original string. If -1, then src must be NUL-terminated.
131*0e209d39SAndroid Build Coastguard Worker      * @param dest      A buffer for the result string. The result will be NUL-terminated if
132*0e209d39SAndroid Build Coastguard Worker      *                  the buffer is large enough.
133*0e209d39SAndroid Build Coastguard Worker      *                  The contents is undefined in case of failure.
134*0e209d39SAndroid Build Coastguard Worker      * @param destCapacity The size of the buffer (number of char16_ts). If it is 0, then
135*0e209d39SAndroid Build Coastguard Worker      *                  dest may be nullptr and the function will only return the length of the result
136*0e209d39SAndroid Build Coastguard Worker      *                  without writing any of the result string.
137*0e209d39SAndroid Build Coastguard Worker      * @param edits     Records edits for index mapping, working with styled text,
138*0e209d39SAndroid Build Coastguard Worker      *                  and getting only changes (if any).
139*0e209d39SAndroid Build Coastguard Worker      *                  The Edits contents is undefined if any error occurs.
140*0e209d39SAndroid Build Coastguard Worker      *                  This function calls edits->reset() first unless
141*0e209d39SAndroid Build Coastguard Worker      *                  options includes U_EDITS_NO_RESET. edits can be nullptr.
142*0e209d39SAndroid Build Coastguard Worker      * @param errorCode Reference to an in/out error code value
143*0e209d39SAndroid Build Coastguard Worker      *                  which must not indicate a failure before the function call.
144*0e209d39SAndroid Build Coastguard Worker      * @return The length of the result string, if successful.
145*0e209d39SAndroid Build Coastguard Worker      *         When the result would be longer than destCapacity,
146*0e209d39SAndroid Build Coastguard Worker      *         the full length is returned and a U_BUFFER_OVERFLOW_ERROR is set.
147*0e209d39SAndroid Build Coastguard Worker      *
148*0e209d39SAndroid Build Coastguard Worker      * @see u_strToTitle
149*0e209d39SAndroid Build Coastguard Worker      * @see ucasemap_toTitle
150*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 59
151*0e209d39SAndroid Build Coastguard Worker      */
152*0e209d39SAndroid Build Coastguard Worker     static int32_t toTitle(
153*0e209d39SAndroid Build Coastguard Worker             const char *locale, uint32_t options, BreakIterator *iter,
154*0e209d39SAndroid Build Coastguard Worker             const char16_t *src, int32_t srcLength,
155*0e209d39SAndroid Build Coastguard Worker             char16_t *dest, int32_t destCapacity, Edits *edits,
156*0e209d39SAndroid Build Coastguard Worker             UErrorCode &errorCode);
157*0e209d39SAndroid Build Coastguard Worker 
158*0e209d39SAndroid Build Coastguard Worker #endif  // UCONFIG_NO_BREAK_ITERATION
159*0e209d39SAndroid Build Coastguard Worker 
160*0e209d39SAndroid Build Coastguard Worker     /**
161*0e209d39SAndroid Build Coastguard Worker      * Case-folds a UTF-16 string and optionally records edits.
162*0e209d39SAndroid Build Coastguard Worker      *
163*0e209d39SAndroid Build Coastguard Worker      * Case folding is locale-independent and not context-sensitive,
164*0e209d39SAndroid Build Coastguard Worker      * but there is an option for whether to include or exclude mappings for dotted I
165*0e209d39SAndroid Build Coastguard Worker      * and dotless i that are marked with 'T' in CaseFolding.txt.
166*0e209d39SAndroid Build Coastguard Worker      *
167*0e209d39SAndroid Build Coastguard Worker      * The result may be longer or shorter than the original.
168*0e209d39SAndroid Build Coastguard Worker      * The source string and the destination buffer must not overlap.
169*0e209d39SAndroid Build Coastguard Worker      *
170*0e209d39SAndroid Build Coastguard Worker      * @param options   Options bit set, usually 0. See U_OMIT_UNCHANGED_TEXT, U_EDITS_NO_RESET,
171*0e209d39SAndroid Build Coastguard Worker      *                  U_FOLD_CASE_DEFAULT, U_FOLD_CASE_EXCLUDE_SPECIAL_I.
172*0e209d39SAndroid Build Coastguard Worker      * @param src       The original string.
173*0e209d39SAndroid Build Coastguard Worker      * @param srcLength The length of the original string. If -1, then src must be NUL-terminated.
174*0e209d39SAndroid Build Coastguard Worker      * @param dest      A buffer for the result string. The result will be NUL-terminated if
175*0e209d39SAndroid Build Coastguard Worker      *                  the buffer is large enough.
176*0e209d39SAndroid Build Coastguard Worker      *                  The contents is undefined in case of failure.
177*0e209d39SAndroid Build Coastguard Worker      * @param destCapacity The size of the buffer (number of char16_ts). If it is 0, then
178*0e209d39SAndroid Build Coastguard Worker      *                  dest may be nullptr and the function will only return the length of the result
179*0e209d39SAndroid Build Coastguard Worker      *                  without writing any of the result string.
180*0e209d39SAndroid Build Coastguard Worker      * @param edits     Records edits for index mapping, working with styled text,
181*0e209d39SAndroid Build Coastguard Worker      *                  and getting only changes (if any).
182*0e209d39SAndroid Build Coastguard Worker      *                  The Edits contents is undefined if any error occurs.
183*0e209d39SAndroid Build Coastguard Worker      *                  This function calls edits->reset() first unless
184*0e209d39SAndroid Build Coastguard Worker      *                  options includes U_EDITS_NO_RESET. edits can be nullptr.
185*0e209d39SAndroid Build Coastguard Worker      * @param errorCode Reference to an in/out error code value
186*0e209d39SAndroid Build Coastguard Worker      *                  which must not indicate a failure before the function call.
187*0e209d39SAndroid Build Coastguard Worker      * @return The length of the result string, if successful.
188*0e209d39SAndroid Build Coastguard Worker      *         When the result would be longer than destCapacity,
189*0e209d39SAndroid Build Coastguard Worker      *         the full length is returned and a U_BUFFER_OVERFLOW_ERROR is set.
190*0e209d39SAndroid Build Coastguard Worker      *
191*0e209d39SAndroid Build Coastguard Worker      * @see u_strFoldCase
192*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 59
193*0e209d39SAndroid Build Coastguard Worker      */
194*0e209d39SAndroid Build Coastguard Worker     static int32_t fold(
195*0e209d39SAndroid Build Coastguard Worker             uint32_t options,
196*0e209d39SAndroid Build Coastguard Worker             const char16_t *src, int32_t srcLength,
197*0e209d39SAndroid Build Coastguard Worker             char16_t *dest, int32_t destCapacity, Edits *edits,
198*0e209d39SAndroid Build Coastguard Worker             UErrorCode &errorCode);
199*0e209d39SAndroid Build Coastguard Worker 
200*0e209d39SAndroid Build Coastguard Worker     /**
201*0e209d39SAndroid Build Coastguard Worker      * Lowercases a UTF-8 string and optionally records edits.
202*0e209d39SAndroid Build Coastguard Worker      * Casing is locale-dependent and context-sensitive.
203*0e209d39SAndroid Build Coastguard Worker      * The result may be longer or shorter than the original.
204*0e209d39SAndroid Build Coastguard Worker      *
205*0e209d39SAndroid Build Coastguard Worker      * @param locale    The locale ID. ("" = root locale, nullptr = default locale.)
206*0e209d39SAndroid Build Coastguard Worker      * @param options   Options bit set, usually 0. See U_OMIT_UNCHANGED_TEXT and U_EDITS_NO_RESET.
207*0e209d39SAndroid Build Coastguard Worker      * @param src       The original string.
208*0e209d39SAndroid Build Coastguard Worker      * @param sink      A ByteSink to which the result string is written.
209*0e209d39SAndroid Build Coastguard Worker      *                  sink.Flush() is called at the end.
210*0e209d39SAndroid Build Coastguard Worker      * @param edits     Records edits for index mapping, working with styled text,
211*0e209d39SAndroid Build Coastguard Worker      *                  and getting only changes (if any).
212*0e209d39SAndroid Build Coastguard Worker      *                  The Edits contents is undefined if any error occurs.
213*0e209d39SAndroid Build Coastguard Worker      *                  This function calls edits->reset() first unless
214*0e209d39SAndroid Build Coastguard Worker      *                  options includes U_EDITS_NO_RESET. edits can be nullptr.
215*0e209d39SAndroid Build Coastguard Worker      * @param errorCode Reference to an in/out error code value
216*0e209d39SAndroid Build Coastguard Worker      *                  which must not indicate a failure before the function call.
217*0e209d39SAndroid Build Coastguard Worker      *
218*0e209d39SAndroid Build Coastguard Worker      * @see ucasemap_utf8ToLower
219*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 60
220*0e209d39SAndroid Build Coastguard Worker      */
221*0e209d39SAndroid Build Coastguard Worker     static void utf8ToLower(
222*0e209d39SAndroid Build Coastguard Worker             const char *locale, uint32_t options,
223*0e209d39SAndroid Build Coastguard Worker             StringPiece src, ByteSink &sink, Edits *edits,
224*0e209d39SAndroid Build Coastguard Worker             UErrorCode &errorCode);
225*0e209d39SAndroid Build Coastguard Worker 
226*0e209d39SAndroid Build Coastguard Worker     /**
227*0e209d39SAndroid Build Coastguard Worker      * Uppercases a UTF-8 string and optionally records edits.
228*0e209d39SAndroid Build Coastguard Worker      * Casing is locale-dependent and context-sensitive.
229*0e209d39SAndroid Build Coastguard Worker      * The result may be longer or shorter than the original.
230*0e209d39SAndroid Build Coastguard Worker      *
231*0e209d39SAndroid Build Coastguard Worker      * @param locale    The locale ID. ("" = root locale, nullptr = default locale.)
232*0e209d39SAndroid Build Coastguard Worker      * @param options   Options bit set, usually 0. See U_OMIT_UNCHANGED_TEXT and U_EDITS_NO_RESET.
233*0e209d39SAndroid Build Coastguard Worker      * @param src       The original string.
234*0e209d39SAndroid Build Coastguard Worker      * @param sink      A ByteSink to which the result string is written.
235*0e209d39SAndroid Build Coastguard Worker      *                  sink.Flush() is called at the end.
236*0e209d39SAndroid Build Coastguard Worker      * @param edits     Records edits for index mapping, working with styled text,
237*0e209d39SAndroid Build Coastguard Worker      *                  and getting only changes (if any).
238*0e209d39SAndroid Build Coastguard Worker      *                  The Edits contents is undefined if any error occurs.
239*0e209d39SAndroid Build Coastguard Worker      *                  This function calls edits->reset() first unless
240*0e209d39SAndroid Build Coastguard Worker      *                  options includes U_EDITS_NO_RESET. edits can be nullptr.
241*0e209d39SAndroid Build Coastguard Worker      * @param errorCode Reference to an in/out error code value
242*0e209d39SAndroid Build Coastguard Worker      *                  which must not indicate a failure before the function call.
243*0e209d39SAndroid Build Coastguard Worker      *
244*0e209d39SAndroid Build Coastguard Worker      * @see ucasemap_utf8ToUpper
245*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 60
246*0e209d39SAndroid Build Coastguard Worker      */
247*0e209d39SAndroid Build Coastguard Worker     static void utf8ToUpper(
248*0e209d39SAndroid Build Coastguard Worker             const char *locale, uint32_t options,
249*0e209d39SAndroid Build Coastguard Worker             StringPiece src, ByteSink &sink, Edits *edits,
250*0e209d39SAndroid Build Coastguard Worker             UErrorCode &errorCode);
251*0e209d39SAndroid Build Coastguard Worker 
252*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_BREAK_ITERATION
253*0e209d39SAndroid Build Coastguard Worker 
254*0e209d39SAndroid Build Coastguard Worker     /**
255*0e209d39SAndroid Build Coastguard Worker      * Titlecases a UTF-8 string and optionally records edits.
256*0e209d39SAndroid Build Coastguard Worker      * Casing is locale-dependent and context-sensitive.
257*0e209d39SAndroid Build Coastguard Worker      * The result may be longer or shorter than the original.
258*0e209d39SAndroid Build Coastguard Worker      *
259*0e209d39SAndroid Build Coastguard Worker      * Titlecasing uses a break iterator to find the first characters of words
260*0e209d39SAndroid Build Coastguard Worker      * that are to be titlecased. It titlecases those characters and lowercases
261*0e209d39SAndroid Build Coastguard Worker      * all others. (This can be modified with options bits.)
262*0e209d39SAndroid Build Coastguard Worker      *
263*0e209d39SAndroid Build Coastguard Worker      * @param locale    The locale ID. ("" = root locale, nullptr = default locale.)
264*0e209d39SAndroid Build Coastguard Worker      * @param options   Options bit set, usually 0. See U_OMIT_UNCHANGED_TEXT, U_EDITS_NO_RESET,
265*0e209d39SAndroid Build Coastguard Worker      *                  U_TITLECASE_NO_LOWERCASE,
266*0e209d39SAndroid Build Coastguard Worker      *                  U_TITLECASE_NO_BREAK_ADJUSTMENT, U_TITLECASE_ADJUST_TO_CASED,
267*0e209d39SAndroid Build Coastguard Worker      *                  U_TITLECASE_WHOLE_STRING, U_TITLECASE_SENTENCES.
268*0e209d39SAndroid Build Coastguard Worker      * @param iter      A break iterator to find the first characters of words that are to be titlecased.
269*0e209d39SAndroid Build Coastguard Worker      *                  It is set to the source string (setUText())
270*0e209d39SAndroid Build Coastguard Worker      *                  and used one or more times for iteration (first() and next()).
271*0e209d39SAndroid Build Coastguard Worker      *                  If nullptr, then a word break iterator for the locale is used
272*0e209d39SAndroid Build Coastguard Worker      *                  (or something equivalent).
273*0e209d39SAndroid Build Coastguard Worker      * @param src       The original string.
274*0e209d39SAndroid Build Coastguard Worker      * @param sink      A ByteSink to which the result string is written.
275*0e209d39SAndroid Build Coastguard Worker      *                  sink.Flush() is called at the end.
276*0e209d39SAndroid Build Coastguard Worker      * @param edits     Records edits for index mapping, working with styled text,
277*0e209d39SAndroid Build Coastguard Worker      *                  and getting only changes (if any).
278*0e209d39SAndroid Build Coastguard Worker      *                  The Edits contents is undefined if any error occurs.
279*0e209d39SAndroid Build Coastguard Worker      *                  This function calls edits->reset() first unless
280*0e209d39SAndroid Build Coastguard Worker      *                  options includes U_EDITS_NO_RESET. edits can be nullptr.
281*0e209d39SAndroid Build Coastguard Worker      * @param errorCode Reference to an in/out error code value
282*0e209d39SAndroid Build Coastguard Worker      *                  which must not indicate a failure before the function call.
283*0e209d39SAndroid Build Coastguard Worker      *
284*0e209d39SAndroid Build Coastguard Worker      * @see ucasemap_utf8ToTitle
285*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 60
286*0e209d39SAndroid Build Coastguard Worker      */
287*0e209d39SAndroid Build Coastguard Worker     static void utf8ToTitle(
288*0e209d39SAndroid Build Coastguard Worker             const char *locale, uint32_t options, BreakIterator *iter,
289*0e209d39SAndroid Build Coastguard Worker             StringPiece src, ByteSink &sink, Edits *edits,
290*0e209d39SAndroid Build Coastguard Worker             UErrorCode &errorCode);
291*0e209d39SAndroid Build Coastguard Worker 
292*0e209d39SAndroid Build Coastguard Worker #endif  // UCONFIG_NO_BREAK_ITERATION
293*0e209d39SAndroid Build Coastguard Worker 
294*0e209d39SAndroid Build Coastguard Worker     /**
295*0e209d39SAndroid Build Coastguard Worker      * Case-folds a UTF-8 string and optionally records edits.
296*0e209d39SAndroid Build Coastguard Worker      *
297*0e209d39SAndroid Build Coastguard Worker      * Case folding is locale-independent and not context-sensitive,
298*0e209d39SAndroid Build Coastguard Worker      * but there is an option for whether to include or exclude mappings for dotted I
299*0e209d39SAndroid Build Coastguard Worker      * and dotless i that are marked with 'T' in CaseFolding.txt.
300*0e209d39SAndroid Build Coastguard Worker      *
301*0e209d39SAndroid Build Coastguard Worker      * The result may be longer or shorter than the original.
302*0e209d39SAndroid Build Coastguard Worker      *
303*0e209d39SAndroid Build Coastguard Worker      * @param options   Options bit set, usually 0. See U_OMIT_UNCHANGED_TEXT and U_EDITS_NO_RESET.
304*0e209d39SAndroid Build Coastguard Worker      * @param src       The original string.
305*0e209d39SAndroid Build Coastguard Worker      * @param sink      A ByteSink to which the result string is written.
306*0e209d39SAndroid Build Coastguard Worker      *                  sink.Flush() is called at the end.
307*0e209d39SAndroid Build Coastguard Worker      * @param edits     Records edits for index mapping, working with styled text,
308*0e209d39SAndroid Build Coastguard Worker      *                  and getting only changes (if any).
309*0e209d39SAndroid Build Coastguard Worker      *                  The Edits contents is undefined if any error occurs.
310*0e209d39SAndroid Build Coastguard Worker      *                  This function calls edits->reset() first unless
311*0e209d39SAndroid Build Coastguard Worker      *                  options includes U_EDITS_NO_RESET. edits can be nullptr.
312*0e209d39SAndroid Build Coastguard Worker      * @param errorCode Reference to an in/out error code value
313*0e209d39SAndroid Build Coastguard Worker      *                  which must not indicate a failure before the function call.
314*0e209d39SAndroid Build Coastguard Worker      *
315*0e209d39SAndroid Build Coastguard Worker      * @see ucasemap_utf8FoldCase
316*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 60
317*0e209d39SAndroid Build Coastguard Worker      */
318*0e209d39SAndroid Build Coastguard Worker     static void utf8Fold(
319*0e209d39SAndroid Build Coastguard Worker             uint32_t options,
320*0e209d39SAndroid Build Coastguard Worker             StringPiece src, ByteSink &sink, Edits *edits,
321*0e209d39SAndroid Build Coastguard Worker             UErrorCode &errorCode);
322*0e209d39SAndroid Build Coastguard Worker 
323*0e209d39SAndroid Build Coastguard Worker     /**
324*0e209d39SAndroid Build Coastguard Worker      * Lowercases a UTF-8 string and optionally records edits.
325*0e209d39SAndroid Build Coastguard Worker      * Casing is locale-dependent and context-sensitive.
326*0e209d39SAndroid Build Coastguard Worker      * The result may be longer or shorter than the original.
327*0e209d39SAndroid Build Coastguard Worker      * The source string and the destination buffer must not overlap.
328*0e209d39SAndroid Build Coastguard Worker      *
329*0e209d39SAndroid Build Coastguard Worker      * @param locale    The locale ID. ("" = root locale, nullptr = default locale.)
330*0e209d39SAndroid Build Coastguard Worker      * @param options   Options bit set, usually 0. See U_OMIT_UNCHANGED_TEXT and U_EDITS_NO_RESET.
331*0e209d39SAndroid Build Coastguard Worker      * @param src       The original string.
332*0e209d39SAndroid Build Coastguard Worker      * @param srcLength The length of the original string. If -1, then src must be NUL-terminated.
333*0e209d39SAndroid Build Coastguard Worker      * @param dest      A buffer for the result string. The result will be NUL-terminated if
334*0e209d39SAndroid Build Coastguard Worker      *                  the buffer is large enough.
335*0e209d39SAndroid Build Coastguard Worker      *                  The contents is undefined in case of failure.
336*0e209d39SAndroid Build Coastguard Worker      * @param destCapacity The size of the buffer (number of bytes). If it is 0, then
337*0e209d39SAndroid Build Coastguard Worker      *                  dest may be nullptr and the function will only return the length of the result
338*0e209d39SAndroid Build Coastguard Worker      *                  without writing any of the result string.
339*0e209d39SAndroid Build Coastguard Worker      * @param edits     Records edits for index mapping, working with styled text,
340*0e209d39SAndroid Build Coastguard Worker      *                  and getting only changes (if any).
341*0e209d39SAndroid Build Coastguard Worker      *                  The Edits contents is undefined if any error occurs.
342*0e209d39SAndroid Build Coastguard Worker      *                  This function calls edits->reset() first unless
343*0e209d39SAndroid Build Coastguard Worker      *                  options includes U_EDITS_NO_RESET. edits can be nullptr.
344*0e209d39SAndroid Build Coastguard Worker      * @param errorCode Reference to an in/out error code value
345*0e209d39SAndroid Build Coastguard Worker      *                  which must not indicate a failure before the function call.
346*0e209d39SAndroid Build Coastguard Worker      * @return The length of the result string, if successful.
347*0e209d39SAndroid Build Coastguard Worker      *         When the result would be longer than destCapacity,
348*0e209d39SAndroid Build Coastguard Worker      *         the full length is returned and a U_BUFFER_OVERFLOW_ERROR is set.
349*0e209d39SAndroid Build Coastguard Worker      *
350*0e209d39SAndroid Build Coastguard Worker      * @see ucasemap_utf8ToLower
351*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 59
352*0e209d39SAndroid Build Coastguard Worker      */
353*0e209d39SAndroid Build Coastguard Worker     static int32_t utf8ToLower(
354*0e209d39SAndroid Build Coastguard Worker             const char *locale, uint32_t options,
355*0e209d39SAndroid Build Coastguard Worker             const char *src, int32_t srcLength,
356*0e209d39SAndroid Build Coastguard Worker             char *dest, int32_t destCapacity, Edits *edits,
357*0e209d39SAndroid Build Coastguard Worker             UErrorCode &errorCode);
358*0e209d39SAndroid Build Coastguard Worker 
359*0e209d39SAndroid Build Coastguard Worker     /**
360*0e209d39SAndroid Build Coastguard Worker      * Uppercases a UTF-8 string and optionally records edits.
361*0e209d39SAndroid Build Coastguard Worker      * Casing is locale-dependent and context-sensitive.
362*0e209d39SAndroid Build Coastguard Worker      * The result may be longer or shorter than the original.
363*0e209d39SAndroid Build Coastguard Worker      * The source string and the destination buffer must not overlap.
364*0e209d39SAndroid Build Coastguard Worker      *
365*0e209d39SAndroid Build Coastguard Worker      * @param locale    The locale ID. ("" = root locale, nullptr = default locale.)
366*0e209d39SAndroid Build Coastguard Worker      * @param options   Options bit set, usually 0. See U_OMIT_UNCHANGED_TEXT and U_EDITS_NO_RESET.
367*0e209d39SAndroid Build Coastguard Worker      * @param src       The original string.
368*0e209d39SAndroid Build Coastguard Worker      * @param srcLength The length of the original string. If -1, then src must be NUL-terminated.
369*0e209d39SAndroid Build Coastguard Worker      * @param dest      A buffer for the result string. The result will be NUL-terminated if
370*0e209d39SAndroid Build Coastguard Worker      *                  the buffer is large enough.
371*0e209d39SAndroid Build Coastguard Worker      *                  The contents is undefined in case of failure.
372*0e209d39SAndroid Build Coastguard Worker      * @param destCapacity The size of the buffer (number of bytes). If it is 0, then
373*0e209d39SAndroid Build Coastguard Worker      *                  dest may be nullptr and the function will only return the length of the result
374*0e209d39SAndroid Build Coastguard Worker      *                  without writing any of the result string.
375*0e209d39SAndroid Build Coastguard Worker      * @param edits     Records edits for index mapping, working with styled text,
376*0e209d39SAndroid Build Coastguard Worker      *                  and getting only changes (if any).
377*0e209d39SAndroid Build Coastguard Worker      *                  The Edits contents is undefined if any error occurs.
378*0e209d39SAndroid Build Coastguard Worker      *                  This function calls edits->reset() first unless
379*0e209d39SAndroid Build Coastguard Worker      *                  options includes U_EDITS_NO_RESET. edits can be nullptr.
380*0e209d39SAndroid Build Coastguard Worker      * @param errorCode Reference to an in/out error code value
381*0e209d39SAndroid Build Coastguard Worker      *                  which must not indicate a failure before the function call.
382*0e209d39SAndroid Build Coastguard Worker      * @return The length of the result string, if successful.
383*0e209d39SAndroid Build Coastguard Worker      *         When the result would be longer than destCapacity,
384*0e209d39SAndroid Build Coastguard Worker      *         the full length is returned and a U_BUFFER_OVERFLOW_ERROR is set.
385*0e209d39SAndroid Build Coastguard Worker      *
386*0e209d39SAndroid Build Coastguard Worker      * @see ucasemap_utf8ToUpper
387*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 59
388*0e209d39SAndroid Build Coastguard Worker      */
389*0e209d39SAndroid Build Coastguard Worker     static int32_t utf8ToUpper(
390*0e209d39SAndroid Build Coastguard Worker             const char *locale, uint32_t options,
391*0e209d39SAndroid Build Coastguard Worker             const char *src, int32_t srcLength,
392*0e209d39SAndroid Build Coastguard Worker             char *dest, int32_t destCapacity, Edits *edits,
393*0e209d39SAndroid Build Coastguard Worker             UErrorCode &errorCode);
394*0e209d39SAndroid Build Coastguard Worker 
395*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_BREAK_ITERATION
396*0e209d39SAndroid Build Coastguard Worker 
397*0e209d39SAndroid Build Coastguard Worker     /**
398*0e209d39SAndroid Build Coastguard Worker      * Titlecases a UTF-8 string and optionally records edits.
399*0e209d39SAndroid Build Coastguard Worker      * Casing is locale-dependent and context-sensitive.
400*0e209d39SAndroid Build Coastguard Worker      * The result may be longer or shorter than the original.
401*0e209d39SAndroid Build Coastguard Worker      * The source string and the destination buffer must not overlap.
402*0e209d39SAndroid Build Coastguard Worker      *
403*0e209d39SAndroid Build Coastguard Worker      * Titlecasing uses a break iterator to find the first characters of words
404*0e209d39SAndroid Build Coastguard Worker      * that are to be titlecased. It titlecases those characters and lowercases
405*0e209d39SAndroid Build Coastguard Worker      * all others. (This can be modified with options bits.)
406*0e209d39SAndroid Build Coastguard Worker      *
407*0e209d39SAndroid Build Coastguard Worker      * @param locale    The locale ID. ("" = root locale, nullptr = default locale.)
408*0e209d39SAndroid Build Coastguard Worker      * @param options   Options bit set, usually 0. See U_OMIT_UNCHANGED_TEXT, U_EDITS_NO_RESET,
409*0e209d39SAndroid Build Coastguard Worker      *                  U_TITLECASE_NO_LOWERCASE,
410*0e209d39SAndroid Build Coastguard Worker      *                  U_TITLECASE_NO_BREAK_ADJUSTMENT, U_TITLECASE_ADJUST_TO_CASED,
411*0e209d39SAndroid Build Coastguard Worker      *                  U_TITLECASE_WHOLE_STRING, U_TITLECASE_SENTENCES.
412*0e209d39SAndroid Build Coastguard Worker      * @param iter      A break iterator to find the first characters of words that are to be titlecased.
413*0e209d39SAndroid Build Coastguard Worker      *                  It is set to the source string (setUText())
414*0e209d39SAndroid Build Coastguard Worker      *                  and used one or more times for iteration (first() and next()).
415*0e209d39SAndroid Build Coastguard Worker      *                  If nullptr, then a word break iterator for the locale is used
416*0e209d39SAndroid Build Coastguard Worker      *                  (or something equivalent).
417*0e209d39SAndroid Build Coastguard Worker      * @param src       The original string.
418*0e209d39SAndroid Build Coastguard Worker      * @param srcLength The length of the original string. If -1, then src must be NUL-terminated.
419*0e209d39SAndroid Build Coastguard Worker      * @param dest      A buffer for the result string. The result will be NUL-terminated if
420*0e209d39SAndroid Build Coastguard Worker      *                  the buffer is large enough.
421*0e209d39SAndroid Build Coastguard Worker      *                  The contents is undefined in case of failure.
422*0e209d39SAndroid Build Coastguard Worker      * @param destCapacity The size of the buffer (number of bytes). If it is 0, then
423*0e209d39SAndroid Build Coastguard Worker      *                  dest may be nullptr and the function will only return the length of the result
424*0e209d39SAndroid Build Coastguard Worker      *                  without writing any of the result string.
425*0e209d39SAndroid Build Coastguard Worker      * @param edits     Records edits for index mapping, working with styled text,
426*0e209d39SAndroid Build Coastguard Worker      *                  and getting only changes (if any).
427*0e209d39SAndroid Build Coastguard Worker      *                  The Edits contents is undefined if any error occurs.
428*0e209d39SAndroid Build Coastguard Worker      *                  This function calls edits->reset() first unless
429*0e209d39SAndroid Build Coastguard Worker      *                  options includes U_EDITS_NO_RESET. edits can be nullptr.
430*0e209d39SAndroid Build Coastguard Worker      * @param errorCode Reference to an in/out error code value
431*0e209d39SAndroid Build Coastguard Worker      *                  which must not indicate a failure before the function call.
432*0e209d39SAndroid Build Coastguard Worker      * @return The length of the result string, if successful.
433*0e209d39SAndroid Build Coastguard Worker      *         When the result would be longer than destCapacity,
434*0e209d39SAndroid Build Coastguard Worker      *         the full length is returned and a U_BUFFER_OVERFLOW_ERROR is set.
435*0e209d39SAndroid Build Coastguard Worker      *
436*0e209d39SAndroid Build Coastguard Worker      * @see ucasemap_utf8ToTitle
437*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 59
438*0e209d39SAndroid Build Coastguard Worker      */
439*0e209d39SAndroid Build Coastguard Worker     static int32_t utf8ToTitle(
440*0e209d39SAndroid Build Coastguard Worker             const char *locale, uint32_t options, BreakIterator *iter,
441*0e209d39SAndroid Build Coastguard Worker             const char *src, int32_t srcLength,
442*0e209d39SAndroid Build Coastguard Worker             char *dest, int32_t destCapacity, Edits *edits,
443*0e209d39SAndroid Build Coastguard Worker             UErrorCode &errorCode);
444*0e209d39SAndroid Build Coastguard Worker 
445*0e209d39SAndroid Build Coastguard Worker #endif  // UCONFIG_NO_BREAK_ITERATION
446*0e209d39SAndroid Build Coastguard Worker 
447*0e209d39SAndroid Build Coastguard Worker     /**
448*0e209d39SAndroid Build Coastguard Worker      * Case-folds a UTF-8 string and optionally records edits.
449*0e209d39SAndroid Build Coastguard Worker      *
450*0e209d39SAndroid Build Coastguard Worker      * Case folding is locale-independent and not context-sensitive,
451*0e209d39SAndroid Build Coastguard Worker      * but there is an option for whether to include or exclude mappings for dotted I
452*0e209d39SAndroid Build Coastguard Worker      * and dotless i that are marked with 'T' in CaseFolding.txt.
453*0e209d39SAndroid Build Coastguard Worker      *
454*0e209d39SAndroid Build Coastguard Worker      * The result may be longer or shorter than the original.
455*0e209d39SAndroid Build Coastguard Worker      * The source string and the destination buffer must not overlap.
456*0e209d39SAndroid Build Coastguard Worker      *
457*0e209d39SAndroid Build Coastguard Worker      * @param options   Options bit set, usually 0. See U_OMIT_UNCHANGED_TEXT, U_EDITS_NO_RESET,
458*0e209d39SAndroid Build Coastguard Worker      *                  U_FOLD_CASE_DEFAULT, U_FOLD_CASE_EXCLUDE_SPECIAL_I.
459*0e209d39SAndroid Build Coastguard Worker      * @param src       The original string.
460*0e209d39SAndroid Build Coastguard Worker      * @param srcLength The length of the original string. If -1, then src must be NUL-terminated.
461*0e209d39SAndroid Build Coastguard Worker      * @param dest      A buffer for the result string. The result will be NUL-terminated if
462*0e209d39SAndroid Build Coastguard Worker      *                  the buffer is large enough.
463*0e209d39SAndroid Build Coastguard Worker      *                  The contents is undefined in case of failure.
464*0e209d39SAndroid Build Coastguard Worker      * @param destCapacity The size of the buffer (number of bytes). If it is 0, then
465*0e209d39SAndroid Build Coastguard Worker      *                  dest may be nullptr and the function will only return the length of the result
466*0e209d39SAndroid Build Coastguard Worker      *                  without writing any of the result string.
467*0e209d39SAndroid Build Coastguard Worker      * @param edits     Records edits for index mapping, working with styled text,
468*0e209d39SAndroid Build Coastguard Worker      *                  and getting only changes (if any).
469*0e209d39SAndroid Build Coastguard Worker      *                  The Edits contents is undefined if any error occurs.
470*0e209d39SAndroid Build Coastguard Worker      *                  This function calls edits->reset() first unless
471*0e209d39SAndroid Build Coastguard Worker      *                  options includes U_EDITS_NO_RESET. edits can be nullptr.
472*0e209d39SAndroid Build Coastguard Worker      * @param errorCode Reference to an in/out error code value
473*0e209d39SAndroid Build Coastguard Worker      *                  which must not indicate a failure before the function call.
474*0e209d39SAndroid Build Coastguard Worker      * @return The length of the result string, if successful.
475*0e209d39SAndroid Build Coastguard Worker      *         When the result would be longer than destCapacity,
476*0e209d39SAndroid Build Coastguard Worker      *         the full length is returned and a U_BUFFER_OVERFLOW_ERROR is set.
477*0e209d39SAndroid Build Coastguard Worker      *
478*0e209d39SAndroid Build Coastguard Worker      * @see ucasemap_utf8FoldCase
479*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 59
480*0e209d39SAndroid Build Coastguard Worker      */
481*0e209d39SAndroid Build Coastguard Worker     static int32_t utf8Fold(
482*0e209d39SAndroid Build Coastguard Worker             uint32_t options,
483*0e209d39SAndroid Build Coastguard Worker             const char *src, int32_t srcLength,
484*0e209d39SAndroid Build Coastguard Worker             char *dest, int32_t destCapacity, Edits *edits,
485*0e209d39SAndroid Build Coastguard Worker             UErrorCode &errorCode);
486*0e209d39SAndroid Build Coastguard Worker 
487*0e209d39SAndroid Build Coastguard Worker private:
488*0e209d39SAndroid Build Coastguard Worker     CaseMap() = delete;
489*0e209d39SAndroid Build Coastguard Worker     CaseMap(const CaseMap &other) = delete;
490*0e209d39SAndroid Build Coastguard Worker     CaseMap &operator=(const CaseMap &other) = delete;
491*0e209d39SAndroid Build Coastguard Worker };
492*0e209d39SAndroid Build Coastguard Worker 
493*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END
494*0e209d39SAndroid Build Coastguard Worker 
495*0e209d39SAndroid Build Coastguard Worker #endif /* U_SHOW_CPLUSPLUS_API */
496*0e209d39SAndroid Build Coastguard Worker 
497*0e209d39SAndroid Build Coastguard Worker #endif  // __CASEMAP_H__
498