From 739a75a9f8576aa4daabbdd0d88fe31af64254a7 Mon Sep 17 00:00:00 2001 From: Zibi Braniecki Date: Sat, 22 Feb 2020 00:19:35 +0000 Subject: [PATCH] Bug 1616999 - Move LocaleService::IsLocaleRTL to use unic_langid. r=jfkthame Differential Revision: https://phabricator.services.mozilla.com/D63562 --HG-- extra : moz-landing-system : lando --- intl/locale/LocaleService.cpp | 4 +--- intl/locale/rust/unic-langid-ffi/src/lib.rs | 10 +++++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/intl/locale/LocaleService.cpp b/intl/locale/LocaleService.cpp index 6708c4af4b5c..2bce3e948068 100644 --- a/intl/locale/LocaleService.cpp +++ b/intl/locale/LocaleService.cpp @@ -20,8 +20,6 @@ #include "nsXULAppAPI.h" #include "nsZipArchive.h" -#include "unicode/uloc.h" - #define INTL_SYSTEM_LOCALES_CHANGED "intl:system-locales-changed" #define REQUESTED_LOCALES_PREF "intl.locale.requested" @@ -244,7 +242,7 @@ bool LocaleService::IsLocaleRTL(const nsACString& aLocale) { return (pref > 0); } - return uloc_isRightToLeft(PromiseFlatCString(aLocale).get()); + return unic_langid_is_rtl(&aLocale); } bool LocaleService::IsAppLocaleRTL() { diff --git a/intl/locale/rust/unic-langid-ffi/src/lib.rs b/intl/locale/rust/unic-langid-ffi/src/lib.rs index 5d59d1925638..e4966f9d2bbb 100644 --- a/intl/locale/rust/unic-langid-ffi/src/lib.rs +++ b/intl/locale/rust/unic-langid-ffi/src/lib.rs @@ -5,7 +5,7 @@ use nsstring::nsACString; use nsstring::nsCString; use thin_vec::ThinVec; -pub use unic_langid::{LanguageIdentifier, LanguageIdentifierError}; +pub use unic_langid::{LanguageIdentifier, LanguageIdentifierError, CharacterDirection}; fn new_langid_for_mozilla(name: &nsACString) -> Result { if name.eq_ignore_ascii_case(b"ja-jp-mac") { @@ -162,3 +162,11 @@ pub unsafe extern "C" fn unic_langid_matches( pub unsafe extern "C" fn unic_langid_maximize(langid: &mut LanguageIdentifier) -> bool { langid.maximize() } + +#[no_mangle] +pub unsafe extern "C" fn unic_langid_is_rtl(name: &nsACString) -> bool { + match new_langid_for_mozilla(name) { + Ok(langid) => langid.character_direction() == CharacterDirection::RTL, + Err(_) => false + } +}