tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

LocaleCanonicalizer.cpp (1079B)


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