intl/icu/source/common/unistr_case_locale.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/common/unistr_case_locale.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,70 @@
     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:  unistr_case_locale.cpp
    1.10 +*   encoding:   US-ASCII
    1.11 +*   tab size:   8 (not used)
    1.12 +*   indentation:4
    1.13 +*
    1.14 +*   created on: 2011may31
    1.15 +*   created by: Markus W. Scherer
    1.16 +*
    1.17 +*   Locale-sensitive case mapping functions (ones that call uloc_getDefault())
    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 +#include "unicode/locid.h"
    1.23 +#include "unicode/unistr.h"
    1.24 +#include "cmemory.h"
    1.25 +#include "ustr_imp.h"
    1.26 +
    1.27 +U_NAMESPACE_BEGIN
    1.28 +
    1.29 +//========================================
    1.30 +// Write implementation
    1.31 +//========================================
    1.32 +
    1.33 +/*
    1.34 + * Set parameters on an empty UCaseMap, for UCaseMap-less API functions.
    1.35 + * Do this fast because it is called with every function call.
    1.36 + */
    1.37 +static inline void
    1.38 +setTempCaseMap(UCaseMap *csm, const char *locale) {
    1.39 +    if(csm->csp==NULL) {
    1.40 +        csm->csp=ucase_getSingleton();
    1.41 +    }
    1.42 +    if(locale!=NULL && locale[0]==0) {
    1.43 +        csm->locale[0]=0;
    1.44 +    } else {
    1.45 +        ustrcase_setTempCaseMapLocale(csm, locale);
    1.46 +    }
    1.47 +}
    1.48 +
    1.49 +UnicodeString &
    1.50 +UnicodeString::toLower() {
    1.51 +  return toLower(Locale::getDefault());
    1.52 +}
    1.53 +
    1.54 +UnicodeString &
    1.55 +UnicodeString::toLower(const Locale &locale) {
    1.56 +  UCaseMap csm=UCASEMAP_INITIALIZER;
    1.57 +  setTempCaseMap(&csm, locale.getName());
    1.58 +  return caseMap(&csm, ustrcase_internalToLower);
    1.59 +}
    1.60 +
    1.61 +UnicodeString &
    1.62 +UnicodeString::toUpper() {
    1.63 +  return toUpper(Locale::getDefault());
    1.64 +}
    1.65 +
    1.66 +UnicodeString &
    1.67 +UnicodeString::toUpper(const Locale &locale) {
    1.68 +  UCaseMap csm=UCASEMAP_INITIALIZER;
    1.69 +  setTempCaseMap(&csm, locale.getName());
    1.70 +  return caseMap(&csm, ustrcase_internalToUpper);
    1.71 +}
    1.72 +
    1.73 +U_NAMESPACE_END

mercurial