]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/ustrcase_locale.cpp
2 *******************************************************************************
3 * Copyright (C) 2011, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 *******************************************************************************
6 * file name: ustrcase_locale.cpp
8 * tab size: 8 (not used)
11 * created on: 2011may31
12 * created by: Markus W. Scherer
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.
18 #include "unicode/utypes.h"
19 #include "unicode/ucasemap.h"
20 #include "unicode/uloc.h"
21 #include "unicode/ustring.h"
26 ustrcase_setTempCaseMapLocale(UCaseMap
*csm
, const char *locale
) {
28 * We could call ucasemap_setLocale(), but here we really only care about
29 * the initial language subtag, we need not return the real string via
30 * ucasemap_getLocale(), and we don't care about only getting "x" from
33 * We ignore locales with a longer-than-3 initial subtag.
35 * We also do not fill in the locCache because it is rarely used,
36 * and not worth setting unless we reuse it for many case mapping operations.
37 * (That's why UCaseMap was created.)
42 /* the internal functions require locale!=NULL */
44 // Do not call uprv_getDefaultLocaleID() because that does not see
45 // changes to the default locale via uloc_setDefault().
46 // It would also be inefficient if used frequently because uprv_getDefaultLocaleID()
47 // does not cache the locale ID.
49 // Unfortunately, uloc_getDefault() has many dependencies.
50 // We only care about a small set of language subtags,
51 // and we do not need the locale ID to be canonicalized.
53 // Best is to not call case mapping functions with a NULL locale ID.
54 locale
=uloc_getDefault();
56 for(i
=0; i
<4 && (c
=locale
[i
])!=0 && c
!='-' && c
!='_'; ++i
) {
60 csm
->locale
[i
]=0; /* Up to 3 non-separator characters. */
62 csm
->locale
[0]=0; /* Longer-than-3 initial subtag: Ignore. */
67 * Set parameters on an empty UCaseMap, for UCaseMap-less API functions.
68 * Do this fast because it is called with every function call.
71 setTempCaseMap(UCaseMap
*csm
, const char *locale
) {
73 csm
->csp
=ucase_getSingleton();
75 if(locale
!=NULL
&& locale
[0]==0) {
78 ustrcase_setTempCaseMapLocale(csm
, locale
);
82 /* public API functions */
84 U_CAPI
int32_t U_EXPORT2
85 u_strToLower(UChar
*dest
, int32_t destCapacity
,
86 const UChar
*src
, int32_t srcLength
,
88 UErrorCode
*pErrorCode
) {
89 UCaseMap csm
=UCASEMAP_INITIALIZER
;
90 setTempCaseMap(&csm
, locale
);
95 ustrcase_internalToLower
, pErrorCode
);
98 U_CAPI
int32_t U_EXPORT2
99 u_strToUpper(UChar
*dest
, int32_t destCapacity
,
100 const UChar
*src
, int32_t srcLength
,
102 UErrorCode
*pErrorCode
) {
103 UCaseMap csm
=UCASEMAP_INITIALIZER
;
104 setTempCaseMap(&csm
, locale
);
109 ustrcase_internalToUpper
, pErrorCode
);