Bug 1616999 - Use unic-langid-ffi new_langid_for_mozilla in fluent-langneg. r=jfkthame
authorZibi Braniecki <zbraniecki@mozilla.com>
Fri, 21 Feb 2020 15:36:15 +0000
changeset 515090 c5a54dd0284e06265691100b8e53caec9453d8ee
parent 515089 8a875e45bcf1baa361c5e900083a1a7c2b3ff753
child 515091 908b192e5bd660cbb74f98f8b6d8ec05a4c9181c
push id37149
push userdvarga@mozilla.com
push dateSat, 22 Feb 2020 09:52:08 +0000
treeherdermozilla-central@bd65ac107627 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame
bugs1616999
milestone75.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1616999 - Use unic-langid-ffi new_langid_for_mozilla in fluent-langneg. r=jfkthame Depends on D63562 Differential Revision: https://phabricator.services.mozilla.com/D63563
Cargo.lock
intl/locale/rust/fluent-langneg-ffi/Cargo.toml
intl/locale/rust/fluent-langneg-ffi/src/lib.rs
intl/locale/rust/unic-langid-ffi/src/lib.rs
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1267,17 +1267,16 @@ dependencies = [
 name = "fluent-langneg-ffi"
 version = "0.1.0"
 dependencies = [
  "fluent-langneg",
  "nserror",
  "nsstring",
  "thin-vec",
  "unic-langid",
- "unic-langid-ffi",
  "xpcom",
 ]
 
 [[package]]
 name = "fnv"
 version = "1.0.6"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
--- a/intl/locale/rust/fluent-langneg-ffi/Cargo.toml
+++ b/intl/locale/rust/fluent-langneg-ffi/Cargo.toml
@@ -7,8 +7,9 @@ edition = "2018"
 
 [dependencies]
 nserror = { path = "../../../../xpcom/rust/nserror" }
 nsstring = { path = "../../../../xpcom/rust/nsstring" }
 xpcom = { path = "../../../../xpcom/rust/xpcom" }
 thin-vec = { version = "0.1.0", features = ["gecko-ffi"] }
 fluent-langneg = { version = "0.12.1", features = ["cldr"] }
 unic-langid = "0.8"
+unic-langid-ffi = { path = "../unic-langid-ffi" }
--- a/intl/locale/rust/fluent-langneg-ffi/src/lib.rs
+++ b/intl/locale/rust/fluent-langneg-ffi/src/lib.rs
@@ -3,42 +3,31 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 use fluent_langneg::negotiate::NegotiationStrategy as LangNegNegotiationStrategy;
 use fluent_langneg::negotiate_languages;
 use nsstring::nsACString;
 use nsstring::nsCString;
 use thin_vec::ThinVec;
 use unic_langid::{LanguageIdentifier, LanguageIdentifierError};
-
-/// We need to one-off `ja-jp-mac` since we still support it as a locale, so we'll
-/// convert it into a correct Language Identifier `ja-JP-macos`.
-fn create_langid_from_str(
-    name: &nsACString,
-) -> Result<LanguageIdentifier, LanguageIdentifierError> {
-    if name.eq_ignore_ascii_case(b"ja-jp-mac") {
-        "ja-JP-macos".parse()
-    } else {
-        LanguageIdentifier::from_bytes(name)
-    }
-}
+use unic_langid_ffi::new_langid_for_mozilla;
 
 /// We want to return the exact strings that were passed to us out of the
 /// available and default pool. Since for the negotiation we canonicalize them
 /// in `LanguageIdentifier`, this struct will preserve the original, non-canonicalized
 /// string, and then use it to populate return array.
 #[derive(Debug, PartialEq)]
 struct LangIdString<'l> {
     pub source: &'l nsCString,
     pub langid: LanguageIdentifier,
 }
 
 impl<'l> LangIdString<'l> {
     pub fn try_new(s: &'l nsCString) -> Result<Self, LanguageIdentifierError> {
-        create_langid_from_str(s).map(|l| LangIdString {
+        new_langid_for_mozilla(s).map(|l| LangIdString {
             source: s,
             langid: l,
         })
     }
 }
 
 impl<'l> AsRef<LanguageIdentifier> for LangIdString<'l> {
     fn as_ref(&self) -> &LanguageIdentifier {
@@ -66,17 +55,17 @@ pub unsafe extern "C" fn fluent_langneg_
     requested: &ThinVec<nsCString>,
     available: &ThinVec<nsCString>,
     default: &nsACString,
     strategy: NegotiationStrategy,
     result: &mut ThinVec<nsCString>,
 ) {
     let requested = requested
         .iter()
-        .filter_map(|s| create_langid_from_str(s).ok())
+        .filter_map(|s| new_langid_for_mozilla(s).ok())
         .collect::<Vec<_>>();
 
     let available = available
         .iter()
         .filter_map(|s| LangIdString::try_new(s).ok())
         .collect::<Vec<_>>();
 
     let d: nsCString = default.into();
--- a/intl/locale/rust/unic-langid-ffi/src/lib.rs
+++ b/intl/locale/rust/unic-langid-ffi/src/lib.rs
@@ -2,17 +2,17 @@
  * 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/. */
 
 use nsstring::nsACString;
 use nsstring::nsCString;
 use thin_vec::ThinVec;
 pub use unic_langid::{LanguageIdentifier, LanguageIdentifierError, CharacterDirection};
 
-fn new_langid_for_mozilla(name: &nsACString) -> Result<LanguageIdentifier, LanguageIdentifierError> {
+pub fn new_langid_for_mozilla(name: &nsACString) -> Result<LanguageIdentifier, LanguageIdentifierError> {
     if name.eq_ignore_ascii_case(b"ja-jp-mac") {
         "ja-JP-macos".parse()
     } else {
         // Cut out any `.FOO` like `en-US.POSIX`.
         let mut name: &[u8] = name.as_ref();
         if let Some(ptr) = name.iter().position(|b| b == &b'.') {
             name = &name[..ptr];
         }