michael@0: /* michael@0: ******************************************************************************* michael@0: * Copyright (C) 2011, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: ******************************************************************************* michael@0: * file name: ucasemap_titlecase_brkiter.cpp michael@0: * encoding: US-ASCII michael@0: * tab size: 8 (not used) michael@0: * indentation:4 michael@0: * michael@0: * created on: 2011jun02 michael@0: * created by: Markus W. Scherer michael@0: * michael@0: * Titlecasing functions that are based on BreakIterator michael@0: * were moved here to break dependency cycles among parts of the common library. michael@0: */ michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: #if !UCONFIG_NO_BREAK_ITERATION michael@0: michael@0: #include "unicode/brkiter.h" michael@0: #include "unicode/ubrk.h" michael@0: #include "unicode/ucasemap.h" michael@0: #include "cmemory.h" michael@0: #include "ucase.h" michael@0: #include "ustr_imp.h" michael@0: michael@0: U_NAMESPACE_USE michael@0: michael@0: U_CAPI const UBreakIterator * U_EXPORT2 michael@0: ucasemap_getBreakIterator(const UCaseMap *csm) { michael@0: return csm->iter; michael@0: } michael@0: michael@0: U_CAPI void U_EXPORT2 michael@0: ucasemap_setBreakIterator(UCaseMap *csm, UBreakIterator *iterToAdopt, UErrorCode * /*pErrorCode*/) { michael@0: // Do not call ubrk_close() so that we do not depend on all of the BreakIterator code. michael@0: delete reinterpret_cast(csm->iter); michael@0: csm->iter=iterToAdopt; michael@0: } michael@0: michael@0: U_CAPI int32_t U_EXPORT2 michael@0: ucasemap_utf8ToTitle(UCaseMap *csm, michael@0: char *dest, int32_t destCapacity, michael@0: const char *src, int32_t srcLength, michael@0: UErrorCode *pErrorCode) { michael@0: UText utext=UTEXT_INITIALIZER; michael@0: utext_openUTF8(&utext, (const char *)src, srcLength, pErrorCode); michael@0: if(U_FAILURE(*pErrorCode)) { michael@0: return 0; michael@0: } michael@0: if(csm->iter==NULL) { michael@0: csm->iter=ubrk_open(UBRK_WORD, csm->locale, michael@0: NULL, 0, michael@0: pErrorCode); michael@0: } michael@0: ubrk_setUText(csm->iter, &utext, pErrorCode); michael@0: int32_t length=ucasemap_mapUTF8(csm, michael@0: (uint8_t *)dest, destCapacity, michael@0: (const uint8_t *)src, srcLength, michael@0: ucasemap_internalUTF8ToTitle, pErrorCode); michael@0: utext_close(&utext); michael@0: return length; michael@0: } michael@0: michael@0: #endif // !UCONFIG_NO_BREAK_ITERATION