]>
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: ucasemap_titlecase_brkiter.cpp | |
f3c0d7a5 | 9 | * encoding: UTF-8 |
4388f060 A |
10 | * tab size: 8 (not used) |
11 | * indentation:4 | |
12 | * | |
13 | * created on: 2011jun02 | |
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" | |
25 | #include "unicode/ubrk.h" | |
f3c0d7a5 | 26 | #include "unicode/casemap.h" |
4388f060 A |
27 | #include "unicode/ucasemap.h" |
28 | #include "cmemory.h" | |
29 | #include "ucase.h" | |
f3c0d7a5 A |
30 | #include "ucasemap_imp.h" |
31 | ||
32 | U_NAMESPACE_BEGIN | |
33 | ||
34 | int32_t CaseMap::utf8ToTitle( | |
35 | const char *locale, uint32_t options, BreakIterator *iter, | |
36 | const char *src, int32_t srcLength, | |
37 | char *dest, int32_t destCapacity, Edits *edits, | |
38 | UErrorCode &errorCode) { | |
39 | if (U_FAILURE(errorCode)) { | |
40 | return 0; | |
41 | } | |
42 | UText utext=UTEXT_INITIALIZER; | |
43 | utext_openUTF8(&utext, src, srcLength, &errorCode); | |
44 | LocalPointer<BreakIterator> ownedIter; | |
45 | if(iter==NULL) { | |
46 | iter=BreakIterator::createWordInstance(Locale(locale), errorCode); | |
47 | ownedIter.adoptInstead(iter); | |
48 | } | |
49 | if(U_FAILURE(errorCode)) { | |
50 | utext_close(&utext); | |
51 | return 0; | |
52 | } | |
53 | iter->setText(&utext, errorCode); | |
54 | int32_t length=ucasemap_mapUTF8( | |
55 | ustrcase_getCaseLocale(locale), options, iter, | |
56 | (uint8_t *)dest, destCapacity, | |
57 | (const uint8_t *)src, srcLength, | |
58 | ucasemap_internalUTF8ToTitle, edits, errorCode); | |
59 | utext_close(&utext); | |
60 | return length; | |
61 | } | |
62 | ||
63 | U_NAMESPACE_END | |
4388f060 A |
64 | |
65 | U_NAMESPACE_USE | |
66 | ||
67 | U_CAPI const UBreakIterator * U_EXPORT2 | |
68 | ucasemap_getBreakIterator(const UCaseMap *csm) { | |
f3c0d7a5 | 69 | return reinterpret_cast<UBreakIterator *>(csm->iter); |
4388f060 A |
70 | } |
71 | ||
72 | U_CAPI void U_EXPORT2 | |
f3c0d7a5 A |
73 | ucasemap_setBreakIterator(UCaseMap *csm, UBreakIterator *iterToAdopt, UErrorCode *pErrorCode) { |
74 | if(U_FAILURE(*pErrorCode)) { | |
75 | return; | |
76 | } | |
77 | delete csm->iter; | |
78 | csm->iter=reinterpret_cast<BreakIterator *>(iterToAdopt); | |
4388f060 A |
79 | } |
80 | ||
81 | U_CAPI int32_t U_EXPORT2 | |
82 | ucasemap_utf8ToTitle(UCaseMap *csm, | |
83 | char *dest, int32_t destCapacity, | |
84 | const char *src, int32_t srcLength, | |
85 | UErrorCode *pErrorCode) { | |
f3c0d7a5 | 86 | if (U_FAILURE(*pErrorCode)) { |
4388f060 A |
87 | return 0; |
88 | } | |
f3c0d7a5 A |
89 | UText utext=UTEXT_INITIALIZER; |
90 | utext_openUTF8(&utext, (const char *)src, srcLength, pErrorCode); | |
4388f060 | 91 | if(csm->iter==NULL) { |
f3c0d7a5 A |
92 | csm->iter=BreakIterator::createWordInstance(Locale(csm->locale), *pErrorCode); |
93 | } | |
94 | if (U_FAILURE(*pErrorCode)) { | |
95 | return 0; | |
4388f060 | 96 | } |
f3c0d7a5 A |
97 | csm->iter->setText(&utext, *pErrorCode); |
98 | int32_t length=ucasemap_mapUTF8( | |
99 | csm->caseLocale, csm->options, csm->iter, | |
100 | (uint8_t *)dest, destCapacity, | |
101 | (const uint8_t *)src, srcLength, | |
102 | ucasemap_internalUTF8ToTitle, NULL, *pErrorCode); | |
4388f060 A |
103 | utext_close(&utext); |
104 | return length; | |
105 | } | |
106 | ||
107 | #endif // !UCONFIG_NO_BREAK_ITERATION |