intl/icu/source/common/ucasemap_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.

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: ucasemap_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: 2011jun02
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 U_NAMESPACE_USE
michael@0 30
michael@0 31 U_CAPI const UBreakIterator * U_EXPORT2
michael@0 32 ucasemap_getBreakIterator(const UCaseMap *csm) {
michael@0 33 return csm->iter;
michael@0 34 }
michael@0 35
michael@0 36 U_CAPI void U_EXPORT2
michael@0 37 ucasemap_setBreakIterator(UCaseMap *csm, UBreakIterator *iterToAdopt, UErrorCode * /*pErrorCode*/) {
michael@0 38 // Do not call ubrk_close() so that we do not depend on all of the BreakIterator code.
michael@0 39 delete reinterpret_cast<BreakIterator *>(csm->iter);
michael@0 40 csm->iter=iterToAdopt;
michael@0 41 }
michael@0 42
michael@0 43 U_CAPI int32_t U_EXPORT2
michael@0 44 ucasemap_utf8ToTitle(UCaseMap *csm,
michael@0 45 char *dest, int32_t destCapacity,
michael@0 46 const char *src, int32_t srcLength,
michael@0 47 UErrorCode *pErrorCode) {
michael@0 48 UText utext=UTEXT_INITIALIZER;
michael@0 49 utext_openUTF8(&utext, (const char *)src, srcLength, pErrorCode);
michael@0 50 if(U_FAILURE(*pErrorCode)) {
michael@0 51 return 0;
michael@0 52 }
michael@0 53 if(csm->iter==NULL) {
michael@0 54 csm->iter=ubrk_open(UBRK_WORD, csm->locale,
michael@0 55 NULL, 0,
michael@0 56 pErrorCode);
michael@0 57 }
michael@0 58 ubrk_setUText(csm->iter, &utext, pErrorCode);
michael@0 59 int32_t length=ucasemap_mapUTF8(csm,
michael@0 60 (uint8_t *)dest, destCapacity,
michael@0 61 (const uint8_t *)src, srcLength,
michael@0 62 ucasemap_internalUTF8ToTitle, pErrorCode);
michael@0 63 utext_close(&utext);
michael@0 64 return length;
michael@0 65 }
michael@0 66
michael@0 67 #endif // !UCONFIG_NO_BREAK_ITERATION

mercurial