]>
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: unistr_titlecase_brkiter.cpp | |
f3c0d7a5 | 9 | * encoding: UTF-8 |
4388f060 A |
10 | * tab size: 8 (not used) |
11 | * indentation:2 | |
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/locid.h" |
26 | #include "unicode/ucasemap.h" | |
4388f060 | 27 | #include "unicode/unistr.h" |
f3c0d7a5 | 28 | #include "ucasemap_imp.h" |
4388f060 A |
29 | |
30 | U_NAMESPACE_BEGIN | |
31 | ||
32 | UnicodeString & | |
33 | UnicodeString::toTitle(BreakIterator *titleIter) { | |
34 | return toTitle(titleIter, Locale::getDefault(), 0); | |
35 | } | |
36 | ||
37 | UnicodeString & | |
38 | UnicodeString::toTitle(BreakIterator *titleIter, const Locale &locale) { | |
39 | return toTitle(titleIter, locale, 0); | |
40 | } | |
41 | ||
42 | UnicodeString & | |
43 | UnicodeString::toTitle(BreakIterator *titleIter, const Locale &locale, uint32_t options) { | |
4388f060 A |
44 | BreakIterator *bi=titleIter; |
45 | if(bi==NULL) { | |
46 | UErrorCode errorCode=U_ZERO_ERROR; | |
47 | bi=BreakIterator::createWordInstance(locale, errorCode); | |
48 | if(U_FAILURE(errorCode)) { | |
49 | setToBogus(); | |
50 | return *this; | |
51 | } | |
52 | } | |
f3c0d7a5 A |
53 | // Because the "this" string is both the source and the destination, |
54 | // make a copy of the original source for use by the break iterator. | |
55 | // See tickets #13127 and #13128 | |
56 | UnicodeString copyOfInput(*this); | |
57 | bi->setText(copyOfInput); | |
58 | caseMap(ustrcase_getCaseLocale(locale.getBaseName()), options, bi, ustrcase_internalToTitle); | |
4388f060 A |
59 | if(titleIter==NULL) { |
60 | delete bi; | |
61 | } | |
62 | return *this; | |
63 | } | |
64 | ||
65 | U_NAMESPACE_END | |
66 | ||
67 | #endif // !UCONFIG_NO_BREAK_ITERATION |