1 // Copyright (C) 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: unistr_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/ubrk.h"
26 #include "unicode/unistr.h"
27 #include "unicode/ustring.h"
31 static int32_t U_CALLCONV
32 unistr_case_internalToTitle(const UCaseMap *csm,
33 UChar *dest, int32_t destCapacity,
34 const UChar *src, int32_t srcLength,
35 UErrorCode *pErrorCode) {
36 ubrk_setText(csm->iter, src, srcLength, pErrorCode);
37 return ustrcase_internalToTitle(csm, dest, destCapacity, src, srcLength, pErrorCode);
41 * Set parameters on an empty UCaseMap, for UCaseMap-less API functions.
42 * Do this fast because it is called with every function call.
45 setTempCaseMap(UCaseMap *csm, const char *locale) {
47 csm->csp=ucase_getSingleton();
49 if(locale!=NULL && locale[0]==0) {
52 ustrcase_setTempCaseMapLocale(csm, locale);
59 UnicodeString::toTitle(BreakIterator *titleIter) {
60 return toTitle(titleIter, Locale::getDefault(), 0);
64 UnicodeString::toTitle(BreakIterator *titleIter, const Locale &locale) {
65 return toTitle(titleIter, locale, 0);
69 UnicodeString::toTitle(BreakIterator *titleIter, const Locale &locale, uint32_t options) {
70 UCaseMap csm=UCASEMAP_INITIALIZER;
72 setTempCaseMap(&csm, locale.getName());
73 BreakIterator *bi=titleIter;
75 UErrorCode errorCode=U_ZERO_ERROR;
76 bi=BreakIterator::createWordInstance(locale, errorCode);
77 if(U_FAILURE(errorCode)) {
82 csm.iter=reinterpret_cast<UBreakIterator *>(bi);
83 caseMap(&csm, unistr_case_internalToTitle);
92 #endif // !UCONFIG_NO_BREAK_ITERATION