2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2018-01-06 11:23:09 +03:00
|
|
|
/* 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;
|
2019-11-20 02:04:06 +03:00
|
|
|
using namespace mozilla::intl::ffi;
|
2018-01-06 11:23:09 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Note: The file name is `MozLocale` to avoid compilation problems on
|
|
|
|
* case-insensitive Windows. The class name is `Locale`.
|
|
|
|
*/
|
2019-11-20 02:04:06 +03:00
|
|
|
Locale::Locale(const nsACString& aLocale)
|
|
|
|
: mRaw(unic_langid_new(&aLocale, &mIsWellFormed)) {}
|
2018-01-06 11:23:09 +03:00
|
|
|
|
2018-01-31 23:28:51 +03:00
|
|
|
const nsCString Locale::AsString() const {
|
2018-01-26 01:50:32 +03:00
|
|
|
nsCString tag;
|
2019-11-20 02:04:06 +03:00
|
|
|
unic_langid_as_string(mRaw.get(), &tag);
|
2018-01-26 01:50:32 +03:00
|
|
|
return tag;
|
2018-01-06 11:23:09 +03:00
|
|
|
}
|
|
|
|
|
2019-11-20 02:04:06 +03:00
|
|
|
const nsDependentCSubstring Locale::GetLanguage() const {
|
2020-11-04 19:17:30 +03:00
|
|
|
nsDependentCSubstring sub;
|
|
|
|
unic_langid_get_language(mRaw.get(), &sub);
|
|
|
|
return sub;
|
2019-11-20 02:04:06 +03:00
|
|
|
}
|
2018-01-06 11:23:09 +03:00
|
|
|
|
2019-11-20 02:04:06 +03:00
|
|
|
const nsDependentCSubstring Locale::GetScript() const {
|
2020-11-04 19:17:30 +03:00
|
|
|
nsDependentCSubstring sub;
|
|
|
|
unic_langid_get_script(mRaw.get(), &sub);
|
|
|
|
return sub;
|
2019-11-20 02:04:06 +03:00
|
|
|
}
|
2018-01-06 11:23:09 +03:00
|
|
|
|
2019-11-20 02:04:06 +03:00
|
|
|
const nsDependentCSubstring Locale::GetRegion() const {
|
2020-11-04 19:17:30 +03:00
|
|
|
nsDependentCSubstring sub;
|
|
|
|
unic_langid_get_region(mRaw.get(), &sub);
|
|
|
|
return sub;
|
2019-11-20 02:04:06 +03:00
|
|
|
}
|
2018-01-06 11:23:09 +03:00
|
|
|
|
2019-11-20 02:04:06 +03:00
|
|
|
void Locale::GetVariants(nsTArray<nsCString>& aRetVal) const {
|
|
|
|
unic_langid_get_variants(mRaw.get(), &aRetVal);
|
|
|
|
}
|
2018-01-06 11:23:09 +03:00
|
|
|
|
2018-01-26 01:50:32 +03:00
|
|
|
bool Locale::Matches(const Locale& aOther, bool aThisRange,
|
|
|
|
bool aOtherRange) const {
|
2018-08-23 21:21:38 +03:00
|
|
|
if (!IsWellFormed() || !aOther.IsWellFormed()) {
|
2018-01-31 23:28:51 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-11-20 02:04:06 +03:00
|
|
|
return unic_langid_matches(mRaw.get(), aOther.Raw(), aThisRange, aOtherRange);
|
2018-01-06 11:23:09 +03:00
|
|
|
}
|
|
|
|
|
2020-02-22 00:03:15 +03:00
|
|
|
bool Locale::Maximize() { return unic_langid_maximize(mRaw.get()); }
|
2018-01-26 01:50:32 +03:00
|
|
|
|
2019-11-20 02:04:06 +03:00
|
|
|
void Locale::ClearVariants() { unic_langid_clear_variants(mRaw.get()); }
|
2018-01-26 01:50:32 +03:00
|
|
|
|
2019-11-20 02:04:06 +03:00
|
|
|
void Locale::ClearRegion() { unic_langid_clear_region(mRaw.get()); }
|