2017-01-20 00:20:31 +00:00
|
|
|
// © 2016 and later: Unicode, Inc. and others.
|
2016-06-15 18:58:17 +00:00
|
|
|
// License & terms of use: http://www.unicode.org/copyright.html
|
2011-06-03 05:23:57 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
2016-05-31 21:45:07 +00:00
|
|
|
* Copyright (C) 2011, International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
2011-06-03 05:23:57 +00:00
|
|
|
*******************************************************************************
|
|
|
|
* file name: ustr_titlecase_brkiter.cpp
|
2017-02-03 18:57:23 +00:00
|
|
|
* encoding: UTF-8
|
2011-06-03 05:23:57 +00:00
|
|
|
* tab size: 8 (not used)
|
|
|
|
* indentation:4
|
|
|
|
*
|
|
|
|
* created on: 2011may30
|
|
|
|
* created by: Markus W. Scherer
|
|
|
|
*
|
|
|
|
* Titlecasing functions that are based on BreakIterator
|
|
|
|
* were moved here to break dependency cycles among parts of the common library.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_BREAK_ITERATION
|
|
|
|
|
|
|
|
#include "unicode/brkiter.h"
|
2017-02-09 21:15:34 +00:00
|
|
|
#include "unicode/casemap.h"
|
2017-01-09 23:52:12 +00:00
|
|
|
#include "unicode/localpointer.h"
|
2011-06-03 05:23:57 +00:00
|
|
|
#include "unicode/ubrk.h"
|
|
|
|
#include "unicode/ucasemap.h"
|
|
|
|
#include "cmemory.h"
|
|
|
|
#include "ucase.h"
|
2017-02-09 21:15:34 +00:00
|
|
|
#include "ucasemap_imp.h"
|
2011-06-03 05:23:57 +00:00
|
|
|
|
2017-01-12 19:05:01 +00:00
|
|
|
U_NAMESPACE_USE
|
2011-06-03 05:23:57 +00:00
|
|
|
|
2017-01-12 19:05:01 +00:00
|
|
|
/* functions available in the common library (for unistr_case.cpp) */
|
2011-06-03 05:23:57 +00:00
|
|
|
|
|
|
|
/* public API functions */
|
|
|
|
|
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
u_strToTitle(UChar *dest, int32_t destCapacity,
|
|
|
|
const UChar *src, int32_t srcLength,
|
|
|
|
UBreakIterator *titleIter,
|
|
|
|
const char *locale,
|
|
|
|
UErrorCode *pErrorCode) {
|
2017-01-20 04:04:58 +00:00
|
|
|
LocalPointer<BreakIterator> ownedIter;
|
2017-01-12 19:05:01 +00:00
|
|
|
BreakIterator *iter;
|
2011-06-03 05:23:57 +00:00
|
|
|
if(titleIter!=NULL) {
|
2017-01-12 19:05:01 +00:00
|
|
|
iter=reinterpret_cast<BreakIterator *>(titleIter);
|
2011-06-03 05:23:57 +00:00
|
|
|
} else {
|
2017-01-20 04:04:58 +00:00
|
|
|
iter=BreakIterator::createWordInstance(Locale(locale), *pErrorCode);
|
|
|
|
ownedIter.adoptInstead(iter);
|
2011-06-03 05:23:57 +00:00
|
|
|
}
|
2017-01-09 23:52:12 +00:00
|
|
|
if(U_FAILURE(*pErrorCode)) {
|
|
|
|
return 0;
|
2011-06-03 05:23:57 +00:00
|
|
|
}
|
2017-01-12 19:05:01 +00:00
|
|
|
UnicodeString s(srcLength<0, src, srcLength);
|
2017-01-09 23:52:12 +00:00
|
|
|
iter->setText(s);
|
|
|
|
return ustrcase_mapWithOverlap(
|
2017-01-20 04:04:58 +00:00
|
|
|
ustrcase_getCaseLocale(locale), 0, iter,
|
2011-06-03 05:23:57 +00:00
|
|
|
dest, destCapacity,
|
|
|
|
src, srcLength,
|
2017-01-09 23:52:12 +00:00
|
|
|
ustrcase_internalToTitle, *pErrorCode);
|
|
|
|
}
|
|
|
|
|
2017-01-12 19:05:01 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2017-01-20 04:04:58 +00:00
|
|
|
int32_t CaseMap::toTitle(
|
|
|
|
const char *locale, uint32_t options, BreakIterator *iter,
|
|
|
|
const UChar *src, int32_t srcLength,
|
|
|
|
UChar *dest, int32_t destCapacity, Edits *edits,
|
|
|
|
UErrorCode &errorCode) {
|
2017-01-12 19:05:01 +00:00
|
|
|
LocalPointer<BreakIterator> ownedIter;
|
2017-01-20 04:04:58 +00:00
|
|
|
if(iter==NULL) {
|
|
|
|
iter=BreakIterator::createWordInstance(Locale(locale), errorCode);
|
|
|
|
ownedIter.adoptInstead(iter);
|
2017-01-09 23:52:12 +00:00
|
|
|
}
|
|
|
|
if(U_FAILURE(errorCode)) {
|
|
|
|
return 0;
|
2011-06-03 05:23:57 +00:00
|
|
|
}
|
2017-01-12 19:05:01 +00:00
|
|
|
UnicodeString s(srcLength<0, src, srcLength);
|
2017-01-20 04:04:58 +00:00
|
|
|
iter->setText(s);
|
2017-01-09 23:52:12 +00:00
|
|
|
return ustrcase_map(
|
2017-01-20 04:04:58 +00:00
|
|
|
ustrcase_getCaseLocale(locale), options, iter,
|
2017-01-09 23:52:12 +00:00
|
|
|
dest, destCapacity,
|
|
|
|
src, srcLength,
|
|
|
|
ustrcase_internalToTitle, edits, errorCode);
|
2011-06-03 05:23:57 +00:00
|
|
|
}
|
|
|
|
|
2017-01-12 19:05:01 +00:00
|
|
|
U_NAMESPACE_END
|
|
|
|
|
2011-06-03 05:23:57 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
ucasemap_toTitle(UCaseMap *csm,
|
|
|
|
UChar *dest, int32_t destCapacity,
|
|
|
|
const UChar *src, int32_t srcLength,
|
|
|
|
UErrorCode *pErrorCode) {
|
2017-01-12 19:05:01 +00:00
|
|
|
if (U_FAILURE(*pErrorCode)) {
|
|
|
|
return 0;
|
2017-01-09 23:52:12 +00:00
|
|
|
}
|
2017-01-20 04:04:58 +00:00
|
|
|
if (csm->iter == NULL) {
|
|
|
|
csm->iter = BreakIterator::createWordInstance(Locale(csm->locale), *pErrorCode);
|
2017-01-12 19:05:01 +00:00
|
|
|
}
|
|
|
|
if (U_FAILURE(*pErrorCode)) {
|
2017-01-09 23:52:12 +00:00
|
|
|
return 0;
|
2011-06-03 05:23:57 +00:00
|
|
|
}
|
2017-01-12 19:05:01 +00:00
|
|
|
UnicodeString s(srcLength<0, src, srcLength);
|
2017-01-20 04:04:58 +00:00
|
|
|
csm->iter->setText(s);
|
2011-06-03 05:23:57 +00:00
|
|
|
return ustrcase_map(
|
2017-01-20 06:27:47 +00:00
|
|
|
csm->caseLocale, csm->options, csm->iter,
|
2011-06-03 05:23:57 +00:00
|
|
|
dest, destCapacity,
|
|
|
|
src, srcLength,
|
2017-01-09 23:52:12 +00:00
|
|
|
ustrcase_internalToTitle, NULL, *pErrorCode);
|
2011-06-03 05:23:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // !UCONFIG_NO_BREAK_ITERATION
|