]>
Commit | Line | Data |
---|---|---|
f3c0d7a5 A |
1 | // © 2016 and later: Unicode, Inc. and others. |
2 | // License & terms of use: http://www.unicode.org/copyright.html | |
4388f060 A |
3 | /* |
4 | ******************************************************************************* | |
5 | * Copyright (C) 2011, International Business Machines | |
6 | * Corporation and others. All Rights Reserved. | |
7 | ******************************************************************************* | |
8 | * file name: ustr_titlecase_brkiter.cpp | |
f3c0d7a5 | 9 | * encoding: UTF-8 |
4388f060 A |
10 | * tab size: 8 (not used) |
11 | * indentation:4 | |
12 | * | |
13 | * created on: 2011may30 | |
14 | * created by: Markus W. Scherer | |
15 | * | |
16 | * Titlecasing functions that are based on BreakIterator | |
17 | * were moved here to break dependency cycles among parts of the common library. | |
18 | */ | |
19 | ||
20 | #include "unicode/utypes.h" | |
21 | ||
22 | #if !UCONFIG_NO_BREAK_ITERATION | |
23 | ||
24 | #include "unicode/brkiter.h" | |
f3c0d7a5 A |
25 | #include "unicode/casemap.h" |
26 | #include "unicode/localpointer.h" | |
4388f060 A |
27 | #include "unicode/ubrk.h" |
28 | #include "unicode/ucasemap.h" | |
29 | #include "cmemory.h" | |
30 | #include "ucase.h" | |
f3c0d7a5 | 31 | #include "ucasemap_imp.h" |
4388f060 | 32 | |
f3c0d7a5 | 33 | U_NAMESPACE_USE |
4388f060 | 34 | |
f3c0d7a5 | 35 | /* functions available in the common library (for unistr_case.cpp) */ |
4388f060 A |
36 | |
37 | /* public API functions */ | |
38 | ||
39 | U_CAPI int32_t U_EXPORT2 | |
40 | u_strToTitle(UChar *dest, int32_t destCapacity, | |
41 | const UChar *src, int32_t srcLength, | |
42 | UBreakIterator *titleIter, | |
43 | const char *locale, | |
44 | UErrorCode *pErrorCode) { | |
f3c0d7a5 A |
45 | LocalPointer<BreakIterator> ownedIter; |
46 | BreakIterator *iter; | |
4388f060 | 47 | if(titleIter!=NULL) { |
f3c0d7a5 | 48 | iter=reinterpret_cast<BreakIterator *>(titleIter); |
4388f060 | 49 | } else { |
f3c0d7a5 A |
50 | iter=BreakIterator::createWordInstance(Locale(locale), *pErrorCode); |
51 | ownedIter.adoptInstead(iter); | |
52 | } | |
53 | if(U_FAILURE(*pErrorCode)) { | |
54 | return 0; | |
4388f060 | 55 | } |
f3c0d7a5 A |
56 | UnicodeString s(srcLength<0, src, srcLength); |
57 | iter->setText(s); | |
58 | return ustrcase_mapWithOverlap( | |
59 | ustrcase_getCaseLocale(locale), 0, iter, | |
4388f060 A |
60 | dest, destCapacity, |
61 | src, srcLength, | |
f3c0d7a5 A |
62 | ustrcase_internalToTitle, *pErrorCode); |
63 | } | |
64 | ||
65 | U_NAMESPACE_BEGIN | |
66 | ||
67 | int32_t CaseMap::toTitle( | |
68 | const char *locale, uint32_t options, BreakIterator *iter, | |
69 | const UChar *src, int32_t srcLength, | |
70 | UChar *dest, int32_t destCapacity, Edits *edits, | |
71 | UErrorCode &errorCode) { | |
72 | LocalPointer<BreakIterator> ownedIter; | |
73 | if(iter==NULL) { | |
74 | iter=BreakIterator::createWordInstance(Locale(locale), errorCode); | |
75 | ownedIter.adoptInstead(iter); | |
76 | } | |
77 | if(U_FAILURE(errorCode)) { | |
78 | return 0; | |
4388f060 | 79 | } |
f3c0d7a5 A |
80 | UnicodeString s(srcLength<0, src, srcLength); |
81 | iter->setText(s); | |
82 | return ustrcase_map( | |
83 | ustrcase_getCaseLocale(locale), options, iter, | |
84 | dest, destCapacity, | |
85 | src, srcLength, | |
86 | ustrcase_internalToTitle, edits, errorCode); | |
4388f060 A |
87 | } |
88 | ||
f3c0d7a5 A |
89 | U_NAMESPACE_END |
90 | ||
4388f060 A |
91 | U_CAPI int32_t U_EXPORT2 |
92 | ucasemap_toTitle(UCaseMap *csm, | |
93 | UChar *dest, int32_t destCapacity, | |
94 | const UChar *src, int32_t srcLength, | |
95 | UErrorCode *pErrorCode) { | |
f3c0d7a5 A |
96 | if (U_FAILURE(*pErrorCode)) { |
97 | return 0; | |
98 | } | |
99 | if (csm->iter == NULL) { | |
100 | csm->iter = BreakIterator::createWordInstance(Locale(csm->locale), *pErrorCode); | |
101 | } | |
102 | if (U_FAILURE(*pErrorCode)) { | |
103 | return 0; | |
4388f060 | 104 | } |
f3c0d7a5 A |
105 | UnicodeString s(srcLength<0, src, srcLength); |
106 | csm->iter->setText(s); | |
4388f060 | 107 | return ustrcase_map( |
f3c0d7a5 | 108 | csm->caseLocale, csm->options, csm->iter, |
4388f060 A |
109 | dest, destCapacity, |
110 | src, srcLength, | |
f3c0d7a5 | 111 | ustrcase_internalToTitle, NULL, *pErrorCode); |
4388f060 A |
112 | } |
113 | ||
114 | #endif // !UCONFIG_NO_BREAK_ITERATION |