]> git.saurik.com Git - apple/icu.git/blame - icuSources/common/unistr_case_locale.cpp
ICU-491.11.3.tar.gz
[apple/icu.git] / icuSources / common / unistr_case_locale.cpp
CommitLineData
4388f060
A
1/*
2*******************************************************************************
3* Copyright (C) 2011, International Business Machines
4* Corporation and others. All Rights Reserved.
5*******************************************************************************
6* file name: unistr_case_locale.cpp
7* encoding: US-ASCII
8* tab size: 8 (not used)
9* indentation:4
10*
11* created on: 2011may31
12* created by: Markus W. Scherer
13*
14* Locale-sensitive case mapping functions (ones that call uloc_getDefault())
15* were moved here to break dependency cycles among parts of the common library.
16*/
17
18#include "unicode/utypes.h"
19#include "unicode/locid.h"
20#include "unicode/unistr.h"
21#include "cmemory.h"
22#include "ustr_imp.h"
23
24U_NAMESPACE_BEGIN
25
26//========================================
27// Write implementation
28//========================================
29
30/*
31 * Set parameters on an empty UCaseMap, for UCaseMap-less API functions.
32 * Do this fast because it is called with every function call.
33 */
34static inline void
35setTempCaseMap(UCaseMap *csm, const char *locale) {
36 if(csm->csp==NULL) {
37 csm->csp=ucase_getSingleton();
38 }
39 if(locale!=NULL && locale[0]==0) {
40 csm->locale[0]=0;
41 } else {
42 ustrcase_setTempCaseMapLocale(csm, locale);
43 }
44}
45
46UnicodeString &
47UnicodeString::toLower() {
48 return toLower(Locale::getDefault());
49}
50
51UnicodeString &
52UnicodeString::toLower(const Locale &locale) {
53 UCaseMap csm=UCASEMAP_INITIALIZER;
54 setTempCaseMap(&csm, locale.getName());
55 return caseMap(&csm, ustrcase_internalToLower);
56}
57
58UnicodeString &
59UnicodeString::toUpper() {
60 return toUpper(Locale::getDefault());
61}
62
63UnicodeString &
64UnicodeString::toUpper(const Locale &locale) {
65 UCaseMap csm=UCASEMAP_INITIALIZER;
66 setTempCaseMap(&csm, locale.getName());
67 return caseMap(&csm, ustrcase_internalToUpper);
68}
69
70U_NAMESPACE_END