Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* |
michael@0 | 2 | ******************************************************************************* |
michael@0 | 3 | * Copyright (C) 2011, International Business Machines |
michael@0 | 4 | * Corporation and others. All Rights Reserved. |
michael@0 | 5 | ******************************************************************************* |
michael@0 | 6 | * file name: ustr_titlecase_brkiter.cpp |
michael@0 | 7 | * encoding: US-ASCII |
michael@0 | 8 | * tab size: 8 (not used) |
michael@0 | 9 | * indentation:4 |
michael@0 | 10 | * |
michael@0 | 11 | * created on: 2011may30 |
michael@0 | 12 | * created by: Markus W. Scherer |
michael@0 | 13 | * |
michael@0 | 14 | * Titlecasing functions that are based on BreakIterator |
michael@0 | 15 | * were moved here to break dependency cycles among parts of the common library. |
michael@0 | 16 | */ |
michael@0 | 17 | |
michael@0 | 18 | #include "unicode/utypes.h" |
michael@0 | 19 | |
michael@0 | 20 | #if !UCONFIG_NO_BREAK_ITERATION |
michael@0 | 21 | |
michael@0 | 22 | #include "unicode/brkiter.h" |
michael@0 | 23 | #include "unicode/ubrk.h" |
michael@0 | 24 | #include "unicode/ucasemap.h" |
michael@0 | 25 | #include "cmemory.h" |
michael@0 | 26 | #include "ucase.h" |
michael@0 | 27 | #include "ustr_imp.h" |
michael@0 | 28 | |
michael@0 | 29 | /* functions available in the common library (for unistr_case.cpp) */ |
michael@0 | 30 | |
michael@0 | 31 | /* |
michael@0 | 32 | * Set parameters on an empty UCaseMap, for UCaseMap-less API functions. |
michael@0 | 33 | * Do this fast because it is called with every function call. |
michael@0 | 34 | * Duplicate of the same function in ustrcase.cpp, to keep it inline. |
michael@0 | 35 | */ |
michael@0 | 36 | static inline void |
michael@0 | 37 | setTempCaseMap(UCaseMap *csm, const char *locale) { |
michael@0 | 38 | if(csm->csp==NULL) { |
michael@0 | 39 | csm->csp=ucase_getSingleton(); |
michael@0 | 40 | } |
michael@0 | 41 | if(locale!=NULL && locale[0]==0) { |
michael@0 | 42 | csm->locale[0]=0; |
michael@0 | 43 | } else { |
michael@0 | 44 | ustrcase_setTempCaseMapLocale(csm, locale); |
michael@0 | 45 | } |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | /* public API functions */ |
michael@0 | 49 | |
michael@0 | 50 | U_CAPI int32_t U_EXPORT2 |
michael@0 | 51 | u_strToTitle(UChar *dest, int32_t destCapacity, |
michael@0 | 52 | const UChar *src, int32_t srcLength, |
michael@0 | 53 | UBreakIterator *titleIter, |
michael@0 | 54 | const char *locale, |
michael@0 | 55 | UErrorCode *pErrorCode) { |
michael@0 | 56 | UCaseMap csm=UCASEMAP_INITIALIZER; |
michael@0 | 57 | setTempCaseMap(&csm, locale); |
michael@0 | 58 | if(titleIter!=NULL) { |
michael@0 | 59 | ubrk_setText(csm.iter=titleIter, src, srcLength, pErrorCode); |
michael@0 | 60 | } else { |
michael@0 | 61 | csm.iter=ubrk_open(UBRK_WORD, csm.locale, src, srcLength, pErrorCode); |
michael@0 | 62 | } |
michael@0 | 63 | int32_t length=ustrcase_map( |
michael@0 | 64 | &csm, |
michael@0 | 65 | dest, destCapacity, |
michael@0 | 66 | src, srcLength, |
michael@0 | 67 | ustrcase_internalToTitle, pErrorCode); |
michael@0 | 68 | if(titleIter==NULL && csm.iter!=NULL) { |
michael@0 | 69 | ubrk_close(csm.iter); |
michael@0 | 70 | } |
michael@0 | 71 | return length; |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | U_CAPI int32_t U_EXPORT2 |
michael@0 | 75 | ucasemap_toTitle(UCaseMap *csm, |
michael@0 | 76 | UChar *dest, int32_t destCapacity, |
michael@0 | 77 | const UChar *src, int32_t srcLength, |
michael@0 | 78 | UErrorCode *pErrorCode) { |
michael@0 | 79 | if(csm->iter!=NULL) { |
michael@0 | 80 | ubrk_setText(csm->iter, src, srcLength, pErrorCode); |
michael@0 | 81 | } else { |
michael@0 | 82 | csm->iter=ubrk_open(UBRK_WORD, csm->locale, src, srcLength, pErrorCode); |
michael@0 | 83 | } |
michael@0 | 84 | return ustrcase_map( |
michael@0 | 85 | csm, |
michael@0 | 86 | dest, destCapacity, |
michael@0 | 87 | src, srcLength, |
michael@0 | 88 | ustrcase_internalToTitle, pErrorCode); |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | #endif // !UCONFIG_NO_BREAK_ITERATION |