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: ucasemap_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: 2011jun02
|
|
|
|
* 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"
|
|
|
|
#include "unicode/ubrk.h"
|
2017-03-14 23:55:29 +00:00
|
|
|
#include "unicode/casemap.h"
|
2011-06-03 05:23:57 +00:00
|
|
|
#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-03-14 23:55:29 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2017-09-18 21:45:11 +00:00
|
|
|
void CaseMap::utf8ToTitle(
|
|
|
|
const char *locale, uint32_t options, BreakIterator *iter,
|
|
|
|
StringPiece src, ByteSink &sink, Edits *edits,
|
|
|
|
UErrorCode &errorCode) {
|
|
|
|
if (U_FAILURE(errorCode)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
UText utext = UTEXT_INITIALIZER;
|
|
|
|
utext_openUTF8(&utext, src.data(), src.length(), &errorCode);
|
|
|
|
LocalPointer<BreakIterator> ownedIter;
|
|
|
|
iter = ustrcase_getTitleBreakIterator(nullptr, locale, options, iter, ownedIter, errorCode);
|
|
|
|
if (iter == nullptr) {
|
|
|
|
utext_close(&utext);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
iter->setText(&utext, errorCode);
|
|
|
|
ucasemap_mapUTF8(
|
|
|
|
ustrcase_getCaseLocale(locale), options, iter,
|
|
|
|
src.data(), src.length(),
|
|
|
|
ucasemap_internalUTF8ToTitle, sink, edits, errorCode);
|
|
|
|
utext_close(&utext);
|
|
|
|
}
|
|
|
|
|
2017-03-14 23:55:29 +00:00
|
|
|
int32_t CaseMap::utf8ToTitle(
|
|
|
|
const char *locale, uint32_t options, BreakIterator *iter,
|
|
|
|
const char *src, int32_t srcLength,
|
|
|
|
char *dest, int32_t destCapacity, Edits *edits,
|
|
|
|
UErrorCode &errorCode) {
|
|
|
|
if (U_FAILURE(errorCode)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
UText utext=UTEXT_INITIALIZER;
|
|
|
|
utext_openUTF8(&utext, src, srcLength, &errorCode);
|
|
|
|
LocalPointer<BreakIterator> ownedIter;
|
2017-06-09 23:04:03 +00:00
|
|
|
iter = ustrcase_getTitleBreakIterator(nullptr, locale, options, iter, ownedIter, errorCode);
|
2017-03-14 23:55:29 +00:00
|
|
|
if(iter==NULL) {
|
|
|
|
utext_close(&utext);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
iter->setText(&utext, errorCode);
|
|
|
|
int32_t length=ucasemap_mapUTF8(
|
|
|
|
ustrcase_getCaseLocale(locale), options, iter,
|
2017-09-18 21:45:11 +00:00
|
|
|
dest, destCapacity,
|
|
|
|
src, srcLength,
|
2017-03-14 23:55:29 +00:00
|
|
|
ucasemap_internalUTF8ToTitle, edits, errorCode);
|
|
|
|
utext_close(&utext);
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_NAMESPACE_END
|
|
|
|
|
2011-06-03 05:23:57 +00:00
|
|
|
U_NAMESPACE_USE
|
|
|
|
|
|
|
|
U_CAPI const UBreakIterator * U_EXPORT2
|
|
|
|
ucasemap_getBreakIterator(const UCaseMap *csm) {
|
2017-01-20 04:04:58 +00:00
|
|
|
return reinterpret_cast<UBreakIterator *>(csm->iter);
|
2011-06-03 05:23:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI void U_EXPORT2
|
2017-01-12 19:05:01 +00:00
|
|
|
ucasemap_setBreakIterator(UCaseMap *csm, UBreakIterator *iterToAdopt, UErrorCode *pErrorCode) {
|
|
|
|
if(U_FAILURE(*pErrorCode)) {
|
|
|
|
return;
|
|
|
|
}
|
2017-01-20 04:04:58 +00:00
|
|
|
delete csm->iter;
|
|
|
|
csm->iter=reinterpret_cast<BreakIterator *>(iterToAdopt);
|
2011-06-03 05:23:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
ucasemap_utf8ToTitle(UCaseMap *csm,
|
|
|
|
char *dest, int32_t destCapacity,
|
|
|
|
const char *src, int32_t srcLength,
|
|
|
|
UErrorCode *pErrorCode) {
|
2017-01-12 19:05:01 +00:00
|
|
|
if (U_FAILURE(*pErrorCode)) {
|
2011-06-03 05:23:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
UText utext=UTEXT_INITIALIZER;
|
|
|
|
utext_openUTF8(&utext, (const char *)src, srcLength, pErrorCode);
|
2017-01-12 19:05:01 +00:00
|
|
|
if (U_FAILURE(*pErrorCode)) {
|
2011-06-03 05:23:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2017-06-09 23:04:03 +00:00
|
|
|
if(csm->iter==NULL) {
|
|
|
|
LocalPointer<BreakIterator> ownedIter;
|
|
|
|
BreakIterator *iter = ustrcase_getTitleBreakIterator(
|
|
|
|
nullptr, csm->locale, csm->options, nullptr, ownedIter, *pErrorCode);
|
|
|
|
if (iter == nullptr) {
|
|
|
|
utext_close(&utext);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
csm->iter = ownedIter.orphan();
|
|
|
|
}
|
2017-01-20 04:04:58 +00:00
|
|
|
csm->iter->setText(&utext, *pErrorCode);
|
|
|
|
int32_t length=ucasemap_mapUTF8(
|
2017-01-20 06:27:47 +00:00
|
|
|
csm->caseLocale, csm->options, csm->iter,
|
2017-09-18 21:45:11 +00:00
|
|
|
dest, destCapacity,
|
|
|
|
src, srcLength,
|
2017-03-14 23:55:29 +00:00
|
|
|
ucasemap_internalUTF8ToTitle, NULL, *pErrorCode);
|
2011-06-03 05:23:57 +00:00
|
|
|
utext_close(&utext);
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // !UCONFIG_NO_BREAK_ITERATION
|