1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/common/ucasemap_titlecase_brkiter.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,67 @@ 1.4 +/* 1.5 +******************************************************************************* 1.6 +* Copyright (C) 2011, International Business Machines 1.7 +* Corporation and others. All Rights Reserved. 1.8 +******************************************************************************* 1.9 +* file name: ucasemap_titlecase_brkiter.cpp 1.10 +* encoding: US-ASCII 1.11 +* tab size: 8 (not used) 1.12 +* indentation:4 1.13 +* 1.14 +* created on: 2011jun02 1.15 +* created by: Markus W. Scherer 1.16 +* 1.17 +* Titlecasing functions that are based on BreakIterator 1.18 +* were moved here to break dependency cycles among parts of the common library. 1.19 +*/ 1.20 + 1.21 +#include "unicode/utypes.h" 1.22 + 1.23 +#if !UCONFIG_NO_BREAK_ITERATION 1.24 + 1.25 +#include "unicode/brkiter.h" 1.26 +#include "unicode/ubrk.h" 1.27 +#include "unicode/ucasemap.h" 1.28 +#include "cmemory.h" 1.29 +#include "ucase.h" 1.30 +#include "ustr_imp.h" 1.31 + 1.32 +U_NAMESPACE_USE 1.33 + 1.34 +U_CAPI const UBreakIterator * U_EXPORT2 1.35 +ucasemap_getBreakIterator(const UCaseMap *csm) { 1.36 + return csm->iter; 1.37 +} 1.38 + 1.39 +U_CAPI void U_EXPORT2 1.40 +ucasemap_setBreakIterator(UCaseMap *csm, UBreakIterator *iterToAdopt, UErrorCode * /*pErrorCode*/) { 1.41 + // Do not call ubrk_close() so that we do not depend on all of the BreakIterator code. 1.42 + delete reinterpret_cast<BreakIterator *>(csm->iter); 1.43 + csm->iter=iterToAdopt; 1.44 +} 1.45 + 1.46 +U_CAPI int32_t U_EXPORT2 1.47 +ucasemap_utf8ToTitle(UCaseMap *csm, 1.48 + char *dest, int32_t destCapacity, 1.49 + const char *src, int32_t srcLength, 1.50 + UErrorCode *pErrorCode) { 1.51 + UText utext=UTEXT_INITIALIZER; 1.52 + utext_openUTF8(&utext, (const char *)src, srcLength, pErrorCode); 1.53 + if(U_FAILURE(*pErrorCode)) { 1.54 + return 0; 1.55 + } 1.56 + if(csm->iter==NULL) { 1.57 + csm->iter=ubrk_open(UBRK_WORD, csm->locale, 1.58 + NULL, 0, 1.59 + pErrorCode); 1.60 + } 1.61 + ubrk_setUText(csm->iter, &utext, pErrorCode); 1.62 + int32_t length=ucasemap_mapUTF8(csm, 1.63 + (uint8_t *)dest, destCapacity, 1.64 + (const uint8_t *)src, srcLength, 1.65 + ucasemap_internalUTF8ToTitle, pErrorCode); 1.66 + utext_close(&utext); 1.67 + return length; 1.68 +} 1.69 + 1.70 +#endif // !UCONFIG_NO_BREAK_ITERATION