LocaleCanonicalizer.h (1444B)
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/Vector.h" 9 10 namespace mozilla::intl { 11 12 /** 13 * 32 is somewhat an arbitrary size, but it should fit most locales on the 14 * stack to avoid heap allocations. 15 */ 16 constexpr size_t INITIAL_LOCALE_CANONICALIZER_BUFFER_SIZE = 32; 17 18 /** 19 * Eventually this class will unify the behaviors of Locale Canonicalization. 20 * See Bug 1723586. 21 */ 22 class LocaleCanonicalizer { 23 public: 24 using Vector = 25 mozilla::Vector<char, INITIAL_LOCALE_CANONICALIZER_BUFFER_SIZE>; 26 27 /** 28 * This static method will canonicalize a locale string, per the Level 1 29 * canonicalization steps outlined in: 30 * http://userguide.icu-project.org/locale#TOC-Canonicalization 31 * 32 * For instance it will turn the string "en-US" to "en_US". It guarantees that 33 * the string span targeted will be in the ASCII range. The canonicalization 34 * process on ICU is somewhat permissive in what it accepts as input, but only 35 * ASCII locales are technically correct. 36 */ 37 static ICUResult CanonicalizeICULevel1( 38 const char* aLocale, LocaleCanonicalizer::Vector& aLocaleOut); 39 }; 40 41 } // namespace mozilla::intl 42 #endif