DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Header

Mercurial (a1669b599097)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "mozilla/intl/MozLocale.h"

using namespace mozilla::intl;
using namespace mozilla::intl::ffi;

/**
 * Note: The file name is `MozLocale` to avoid compilation problems on
 * case-insensitive Windows. The class name is `Locale`.
 */
Locale::Locale(const nsACString& aLocale)
    : mRaw(unic_langid_new(&aLocale, &mIsWellFormed)) {}

const nsCString Locale::AsString() const {
  nsCString tag;
  unic_langid_as_string(mRaw.get(), &tag);
  return tag;
}

const nsDependentCSubstring Locale::GetLanguage() const {
  uint32_t len;
  const uint8_t* chars = unic_langid_get_language(mRaw.get(), &len);
  return nsDependentCSubstring(reinterpret_cast<const char*>(chars), len);
}

const nsDependentCSubstring Locale::GetScript() const {
  uint32_t len;
  const uint8_t* chars = unic_langid_get_script(mRaw.get(), &len);
  return nsDependentCSubstring(reinterpret_cast<const char*>(chars), len);
}

const nsDependentCSubstring Locale::GetRegion() const {
  uint32_t len;
  const uint8_t* chars = unic_langid_get_region(mRaw.get(), &len);
  return nsDependentCSubstring(reinterpret_cast<const char*>(chars), len);
}

void Locale::GetVariants(nsTArray<nsCString>& aRetVal) const {
  unic_langid_get_variants(mRaw.get(), &aRetVal);
}

bool Locale::Matches(const Locale& aOther, bool aThisRange,
                     bool aOtherRange) const {
  if (!IsWellFormed() || !aOther.IsWellFormed()) {
    return false;
  }

  return unic_langid_matches(mRaw.get(), aOther.Raw(), aThisRange, aOtherRange);
}

bool Locale::AddLikelySubtags() {
  return unic_langid_add_likely_subtags(mRaw.get());
}

void Locale::ClearVariants() { unic_langid_clear_variants(mRaw.get()); }

void Locale::ClearRegion() { unic_langid_clear_region(mRaw.get()); }