]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/ustr_titlecase_brkiter.cpp
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
5 * Copyright (C) 2011, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
8 * file name: ustr_titlecase_brkiter.cpp
10 * tab size: 8 (not used)
13 * created on: 2011may30
14 * created by: Markus W. Scherer
16 * Titlecasing functions that are based on BreakIterator
17 * were moved here to break dependency cycles among parts of the common library.
20 #include "unicode/utypes.h"
22 #if !UCONFIG_NO_BREAK_ITERATION
24 #include "unicode/brkiter.h"
25 #include "unicode/casemap.h"
26 #include "unicode/localpointer.h"
27 #include "unicode/ubrk.h"
28 #include "unicode/ucasemap.h"
31 #include "ucasemap_imp.h"
35 /* functions available in the common library (for unistr_case.cpp) */
37 /* public API functions */
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
,
44 UErrorCode
*pErrorCode
) {
45 LocalPointer
<BreakIterator
> ownedIter
;
48 iter
=reinterpret_cast<BreakIterator
*>(titleIter
);
50 iter
=BreakIterator::createWordInstance(Locale(locale
), *pErrorCode
);
51 ownedIter
.adoptInstead(iter
);
53 if(U_FAILURE(*pErrorCode
)) {
56 UnicodeString
s(srcLength
<0, src
, srcLength
);
58 return ustrcase_mapWithOverlap(
59 ustrcase_getCaseLocale(locale
), 0, iter
,
62 ustrcase_internalToTitle
, *pErrorCode
);
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
;
74 iter
=BreakIterator::createWordInstance(Locale(locale
), errorCode
);
75 ownedIter
.adoptInstead(iter
);
77 if(U_FAILURE(errorCode
)) {
80 UnicodeString
s(srcLength
<0, src
, srcLength
);
83 ustrcase_getCaseLocale(locale
), options
, iter
,
86 ustrcase_internalToTitle
, edits
, errorCode
);
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
) {
96 if (U_FAILURE(*pErrorCode
)) {
99 if (csm
->iter
== NULL
) {
100 csm
->iter
= BreakIterator::createWordInstance(Locale(csm
->locale
), *pErrorCode
);
102 if (U_FAILURE(*pErrorCode
)) {
105 UnicodeString
s(srcLength
<0, src
, srcLength
);
106 csm
->iter
->setText(s
);
108 csm
->caseLocale
, csm
->options
, csm
->iter
,
111 ustrcase_internalToTitle
, NULL
, *pErrorCode
);
114 #endif // !UCONFIG_NO_BREAK_ITERATION