intl/icu/source/common/ucasemap_titlecase_brkiter.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /*
     2 *******************************************************************************
     3 *   Copyright (C) 2011, International Business Machines
     4 *   Corporation and others.  All Rights Reserved.
     5 *******************************************************************************
     6 *   file name:  ucasemap_titlecase_brkiter.cpp
     7 *   encoding:   US-ASCII
     8 *   tab size:   8 (not used)
     9 *   indentation:4
    10 *
    11 *   created on: 2011jun02
    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 U_NAMESPACE_USE
    31 U_CAPI const UBreakIterator * U_EXPORT2
    32 ucasemap_getBreakIterator(const UCaseMap *csm) {
    33     return csm->iter;
    34 }
    36 U_CAPI void U_EXPORT2
    37 ucasemap_setBreakIterator(UCaseMap *csm, UBreakIterator *iterToAdopt, UErrorCode * /*pErrorCode*/) {
    38     // Do not call ubrk_close() so that we do not depend on all of the BreakIterator code.
    39     delete reinterpret_cast<BreakIterator *>(csm->iter);
    40     csm->iter=iterToAdopt;
    41 }
    43 U_CAPI int32_t U_EXPORT2
    44 ucasemap_utf8ToTitle(UCaseMap *csm,
    45                      char *dest, int32_t destCapacity,
    46                      const char *src, int32_t srcLength,
    47                      UErrorCode *pErrorCode) {
    48     UText utext=UTEXT_INITIALIZER;
    49     utext_openUTF8(&utext, (const char *)src, srcLength, pErrorCode);
    50     if(U_FAILURE(*pErrorCode)) {
    51         return 0;
    52     }
    53     if(csm->iter==NULL) {
    54         csm->iter=ubrk_open(UBRK_WORD, csm->locale,
    55                             NULL, 0,
    56                             pErrorCode);
    57     }
    58     ubrk_setUText(csm->iter, &utext, pErrorCode);
    59     int32_t length=ucasemap_mapUTF8(csm,
    60                    (uint8_t *)dest, destCapacity,
    61                    (const uint8_t *)src, srcLength,
    62                    ucasemap_internalUTF8ToTitle, pErrorCode);
    63     utext_close(&utext);
    64     return length;
    65 }
    67 #endif  // !UCONFIG_NO_BREAK_ITERATION

mercurial