summaryrefslogtreecommitdiffstats
path: root/intl/icu/source/common/ustrcase_locale.cpp
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /intl/icu/source/common/ustrcase_locale.cpp
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'intl/icu/source/common/ustrcase_locale.cpp')
-rw-r--r--intl/icu/source/common/ustrcase_locale.cpp112
1 files changed, 112 insertions, 0 deletions
diff --git a/intl/icu/source/common/ustrcase_locale.cpp b/intl/icu/source/common/ustrcase_locale.cpp
new file mode 100644
index 000000000..78f4bbd7a
--- /dev/null
+++ b/intl/icu/source/common/ustrcase_locale.cpp
@@ -0,0 +1,112 @@
+// Copyright (C) 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2011, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* file name: ustrcase_locale.cpp
+* encoding: US-ASCII
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2011may31
+* created by: Markus W. Scherer
+*
+* Locale-sensitive case mapping functions (ones that call uloc_getDefault())
+* were moved here to break dependency cycles among parts of the common library.
+*/
+
+#include "unicode/utypes.h"
+#include "unicode/ucasemap.h"
+#include "unicode/uloc.h"
+#include "unicode/ustring.h"
+#include "ucase.h"
+#include "ustr_imp.h"
+
+U_CFUNC void
+ustrcase_setTempCaseMapLocale(UCaseMap *csm, const char *locale) {
+ /*
+ * We could call ucasemap_setLocale(), but here we really only care about
+ * the initial language subtag, we need not return the real string via
+ * ucasemap_getLocale(), and we don't care about only getting "x" from
+ * "x-some-thing" etc.
+ *
+ * We ignore locales with a longer-than-3 initial subtag.
+ *
+ * We also do not fill in the locCache because it is rarely used,
+ * and not worth setting unless we reuse it for many case mapping operations.
+ * (That's why UCaseMap was created.)
+ */
+ int i;
+ char c;
+
+ /* the internal functions require locale!=NULL */
+ if(locale==NULL) {
+ // Do not call uprv_getDefaultLocaleID() because that does not see
+ // changes to the default locale via uloc_setDefault().
+ // It would also be inefficient if used frequently because uprv_getDefaultLocaleID()
+ // does not cache the locale ID.
+ //
+ // Unfortunately, uloc_getDefault() has many dependencies.
+ // We only care about a small set of language subtags,
+ // and we do not need the locale ID to be canonicalized.
+ //
+ // Best is to not call case mapping functions with a NULL locale ID.
+ locale=uloc_getDefault();
+ }
+ for(i=0; i<4 && (c=locale[i])!=0 && c!='-' && c!='_'; ++i) {
+ csm->locale[i]=c;
+ }
+ if(i<=3) {
+ csm->locale[i]=0; /* Up to 3 non-separator characters. */
+ } else {
+ csm->locale[0]=0; /* Longer-than-3 initial subtag: Ignore. */
+ }
+}
+
+/*
+ * Set parameters on an empty UCaseMap, for UCaseMap-less API functions.
+ * Do this fast because it is called with every function call.
+ */
+static inline void
+setTempCaseMap(UCaseMap *csm, const char *locale) {
+ if(csm->csp==NULL) {
+ csm->csp=ucase_getSingleton();
+ }
+ if(locale!=NULL && locale[0]==0) {
+ csm->locale[0]=0;
+ } else {
+ ustrcase_setTempCaseMapLocale(csm, locale);
+ }
+}
+
+/* public API functions */
+
+U_CAPI int32_t U_EXPORT2
+u_strToLower(UChar *dest, int32_t destCapacity,
+ const UChar *src, int32_t srcLength,
+ const char *locale,
+ UErrorCode *pErrorCode) {
+ UCaseMap csm=UCASEMAP_INITIALIZER;
+ setTempCaseMap(&csm, locale);
+ return ustrcase_map(
+ &csm,
+ dest, destCapacity,
+ src, srcLength,
+ ustrcase_internalToLower, pErrorCode);
+}
+
+U_CAPI int32_t U_EXPORT2
+u_strToUpper(UChar *dest, int32_t destCapacity,
+ const UChar *src, int32_t srcLength,
+ const char *locale,
+ UErrorCode *pErrorCode) {
+ UCaseMap csm=UCASEMAP_INITIALIZER;
+ setTempCaseMap(&csm, locale);
+ return ustrcase_map(
+ &csm,
+ dest, destCapacity,
+ src, srcLength,
+ ustrcase_internalToUpper, pErrorCode);
+}