michael@0: /* michael@0: ******************************************************************************* michael@0: * Copyright (C) 2011, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: ******************************************************************************* michael@0: * file name: unistr_case_locale.cpp michael@0: * encoding: US-ASCII michael@0: * tab size: 8 (not used) michael@0: * indentation:4 michael@0: * michael@0: * created on: 2011may31 michael@0: * created by: Markus W. Scherer michael@0: * michael@0: * Locale-sensitive case mapping functions (ones that call uloc_getDefault()) michael@0: * were moved here to break dependency cycles among parts of the common library. michael@0: */ michael@0: michael@0: #include "unicode/utypes.h" michael@0: #include "unicode/locid.h" michael@0: #include "unicode/unistr.h" michael@0: #include "cmemory.h" michael@0: #include "ustr_imp.h" michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: //======================================== michael@0: // Write implementation michael@0: //======================================== michael@0: michael@0: /* michael@0: * Set parameters on an empty UCaseMap, for UCaseMap-less API functions. michael@0: * Do this fast because it is called with every function call. michael@0: */ michael@0: static inline void michael@0: setTempCaseMap(UCaseMap *csm, const char *locale) { michael@0: if(csm->csp==NULL) { michael@0: csm->csp=ucase_getSingleton(); michael@0: } michael@0: if(locale!=NULL && locale[0]==0) { michael@0: csm->locale[0]=0; michael@0: } else { michael@0: ustrcase_setTempCaseMapLocale(csm, locale); michael@0: } michael@0: } michael@0: michael@0: UnicodeString & michael@0: UnicodeString::toLower() { michael@0: return toLower(Locale::getDefault()); michael@0: } michael@0: michael@0: UnicodeString & michael@0: UnicodeString::toLower(const Locale &locale) { michael@0: UCaseMap csm=UCASEMAP_INITIALIZER; michael@0: setTempCaseMap(&csm, locale.getName()); michael@0: return caseMap(&csm, ustrcase_internalToLower); michael@0: } michael@0: michael@0: UnicodeString & michael@0: UnicodeString::toUpper() { michael@0: return toUpper(Locale::getDefault()); michael@0: } michael@0: michael@0: UnicodeString & michael@0: UnicodeString::toUpper(const Locale &locale) { michael@0: UCaseMap csm=UCASEMAP_INITIALIZER; michael@0: setTempCaseMap(&csm, locale.getName()); michael@0: return caseMap(&csm, ustrcase_internalToUpper); michael@0: } michael@0: michael@0: U_NAMESPACE_END