Debian Codegraph @

intl/components/src/LocaleCanonicalizer.cpp

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
5 #include "mozilla/intl/LocaleCanonicalizer.h"
6 #include <cstdio>
7 #include "unicode/uloc.h"
8
9 namespace mozilla::intl {
10
11 /* static */
12 ICUResult LocaleCanonicalizer::CanonicalizeICULevel1(
13 const char* aLocaleIn, LocaleCanonicalizer::Vector& aLocaleOut) {
14 auto result = FillBufferWithICUCall(
15 aLocaleOut,
16 [&aLocaleIn](char* target, int32_t length, UErrorCode* status) {
17 return uloc_canonicalize(aLocaleIn, target, length, status);
18 });
19
20 if (result.isErr()) {
21 return Err(result.unwrapErr());
22 }
23
24 // This step is not included in the normal ICU4C canonicalization step, but
25 // consumers were expecting the results to actually be ASCII. It seemed safer
26 // to include it.
27 for (auto byte : aLocaleOut) {
28 if (static_cast<unsigned char>(byte) > 127) {
29 return Err(ICUError::InternalError);
30 }
31 }
32
33 return Ok();
34 }
35
36 } // namespace mozilla::intl