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 24 U_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 */ 34 static inline void 35 setTempCaseMap(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 46 UnicodeString & 47 UnicodeString::toLower() { 48 return toLower(Locale::getDefault()); 49 } 50 51 UnicodeString & 52 UnicodeString::toLower(const Locale &locale) { 53 UCaseMap csm=UCASEMAP_INITIALIZER; 54 setTempCaseMap(&csm, locale.getName()); 55 return caseMap(&csm, ustrcase_internalToLower); 56 } 57 58 UnicodeString & 59 UnicodeString::toUpper() { 60 return toUpper(Locale::getDefault()); 61 } 62 63 UnicodeString & 64 UnicodeString::toUpper(const Locale &locale) { 65 UCaseMap csm=UCASEMAP_INITIALIZER; 66 setTempCaseMap(&csm, locale.getName()); 67 return caseMap(&csm, ustrcase_internalToUpper); 68 } 69 70 U_NAMESPACE_END 71