intl/icu/source/common/ustr_titlecase_brkiter.cpp

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

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

mercurial