2 *******************************************************************************
3 * Copyright (C) 2011, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 *******************************************************************************
6 * file name: unistr_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/unistr.h"
25 #include "unicode/ustring.h"
29 static int32_t U_CALLCONV
30 unistr_case_internalToTitle(const UCaseMap
*csm
,
31 UChar
*dest
, int32_t destCapacity
,
32 const UChar
*src
, int32_t srcLength
,
33 UErrorCode
*pErrorCode
) {
34 ubrk_setText(csm
->iter
, src
, srcLength
, pErrorCode
);
35 return ustrcase_internalToTitle(csm
, dest
, destCapacity
, src
, srcLength
, pErrorCode
);
39 * Set parameters on an empty UCaseMap, for UCaseMap-less API functions.
40 * Do this fast because it is called with every function call.
43 setTempCaseMap(UCaseMap
*csm
, const char *locale
) {
45 csm
->csp
=ucase_getSingleton();
47 if(locale
!=NULL
&& locale
[0]==0) {
50 ustrcase_setTempCaseMapLocale(csm
, locale
);
57 UnicodeString::toTitle(BreakIterator
*titleIter
) {
58 return toTitle(titleIter
, Locale::getDefault(), 0);
62 UnicodeString::toTitle(BreakIterator
*titleIter
, const Locale
&locale
) {
63 return toTitle(titleIter
, locale
, 0);
67 UnicodeString::toTitle(BreakIterator
*titleIter
, const Locale
&locale
, uint32_t options
) {
68 UCaseMap csm
=UCASEMAP_INITIALIZER
;
70 setTempCaseMap(&csm
, locale
.getName());
71 BreakIterator
*bi
=titleIter
;
73 UErrorCode errorCode
=U_ZERO_ERROR
;
74 bi
=BreakIterator::createWordInstance(locale
, errorCode
);
75 if(U_FAILURE(errorCode
)) {
80 csm
.iter
=reinterpret_cast<UBreakIterator
*>(bi
);
81 caseMap(&csm
, unistr_case_internalToTitle
);
90 #endif // !UCONFIG_NO_BREAK_ITERATION