]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/ustr_titlecase_brkiter.cpp
2 *******************************************************************************
3 * Copyright (C) 2011, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 *******************************************************************************
6 * file name: ustr_titlecase_brkiter.cpp
8 * tab size: 8 (not used)
11 * created on: 2011may30
12 * created by: Markus W. Scherer
14 * Titlecasing functions that are based on BreakIterator
15 * were moved here to break dependency cycles among parts of the common library.
18 #include "unicode/utypes.h"
20 #if !UCONFIG_NO_BREAK_ITERATION
22 #include "unicode/brkiter.h"
23 #include "unicode/ubrk.h"
24 #include "unicode/ucasemap.h"
29 /* functions available in the common library (for unistr_case.cpp) */
32 * Set parameters on an empty UCaseMap, for UCaseMap-less API functions.
33 * Do this fast because it is called with every function call.
34 * Duplicate of the same function in ustrcase.cpp, to keep it inline.
37 setTempCaseMap(UCaseMap
*csm
, const char *locale
) {
39 csm
->csp
=ucase_getSingleton();
41 if(locale
!=NULL
&& locale
[0]==0) {
44 ustrcase_setTempCaseMapLocale(csm
, locale
);
48 /* public API functions */
50 U_CAPI
int32_t U_EXPORT2
51 u_strToTitle(UChar
*dest
, int32_t destCapacity
,
52 const UChar
*src
, int32_t srcLength
,
53 UBreakIterator
*titleIter
,
55 UErrorCode
*pErrorCode
) {
56 UCaseMap csm
=UCASEMAP_INITIALIZER
;
57 setTempCaseMap(&csm
, locale
);
59 ubrk_setText(csm
.iter
=titleIter
, src
, srcLength
, pErrorCode
);
61 csm
.iter
=ubrk_open(UBRK_WORD
, csm
.locale
, src
, srcLength
, pErrorCode
);
63 int32_t length
=ustrcase_map(
67 ustrcase_internalToTitle
, pErrorCode
);
68 if(titleIter
==NULL
&& csm
.iter
!=NULL
) {
74 U_CAPI
int32_t U_EXPORT2
75 ucasemap_toTitle(UCaseMap
*csm
,
76 UChar
*dest
, int32_t destCapacity
,
77 const UChar
*src
, int32_t srcLength
,
78 UErrorCode
*pErrorCode
) {
80 ubrk_setText(csm
->iter
, src
, srcLength
, pErrorCode
);
82 csm
->iter
=ubrk_open(UBRK_WORD
, csm
->locale
, src
, srcLength
, pErrorCode
);
88 ustrcase_internalToTitle
, pErrorCode
);
91 #endif // !UCONFIG_NO_BREAK_ITERATION