Debian Codegraph @

intl/components/src/LocaleCanonicalizer.h

raw
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 #ifndef intl_components_LocaleCanonicalizer_h_
5 #define intl_components_LocaleCanonicalizer_h_
6
7 #include "mozilla/intl/ICU4CGlue.h"
8 #include "mozilla/Span.h"
9 #include "mozilla/Vector.h"
10
11 namespace mozilla::intl {
12
13 /**
14 * 32 is somewhat an arbitrary size, but it should fit most locales on the
15 * stack to avoid heap allocations.
16 */
17 constexpr size_t INITIAL_LOCALE_CANONICALIZER_BUFFER_SIZE = 32;
18
19 /**
20 * Eventually this class will unify the behaviors of Locale Canonicalization.
21 * See Bug 1723586.
22 */
23 class LocaleCanonicalizer {
24 public:
25 using Vector =
26 mozilla::Vector<char, INITIAL_LOCALE_CANONICALIZER_BUFFER_SIZE>;
27
28 /**
29 * This static method will canonicalize a locale string, per the Level 1
30 * canonicalization steps outlined in:
31 * http://userguide.icu-project.org/locale#TOC-Canonicalization
32 *
33 * For instance it will turn the string "en-US" to "en_US". It guarantees that
34 * the string span targeted will be in the ASCII range. The canonicalization
35 * process on ICU is somewhat permissive in what it accepts as input, but only
36 * ASCII locales are technically correct.
37 */
38 static ICUResult CanonicalizeICULevel1(
39 const char* aLocale, LocaleCanonicalizer::Vector& aLocaleOut);
40 };
41
42 } // namespace mozilla::intl
43 #endif