diff --git a/Cargo.lock b/Cargo.lock index f16b0e31532e..defca944e26e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1545,9 +1545,9 @@ dependencies = [ [[package]] name = "fluent-pseudo" -version = "0.2.1" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3a870aefc42d175d11fb1ec089221ced8a160d66ca1e0c64a57b4ae90d2462" +checksum = "f028d6802c52903b3d8fa1cc37264ae5b8b630161e600eccfa68d4ee6ce5163a" dependencies = [ "regex", ] diff --git a/third_party/rust/fluent-pseudo/.cargo-checksum.json b/third_party/rust/fluent-pseudo/.cargo-checksum.json index f071ef12e0c2..15d876288461 100644 --- a/third_party/rust/fluent-pseudo/.cargo-checksum.json +++ b/third_party/rust/fluent-pseudo/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"CHANGELOG.md":"643031d0ea21e0539305186fa41c5fb57889f28c49f1fc27c75b4f659522773c","Cargo.toml":"7f0730a670b8ac4edf2e8ead2f5c7e4880b5cc70c87cc466ba7c3b96a36123c1","README.md":"2bde1fc990113ff261d65e107e4c2bda4de9337761a07b9d272959585f1e57cd","src/lib.rs":"ecb33d80c8351fd53dfbeee9f3456737db72d78f0f0fbbfc3603add76d8fdbb3"},"package":"ca3a870aefc42d175d11fb1ec089221ced8a160d66ca1e0c64a57b4ae90d2462"} \ No newline at end of file +{"files":{"Cargo.toml":"e8314d0278f83d921d2cf1777ddda0ea476621e6b217c60fef018d6555819553","README.md":"c724fbe817e1370765c91bd14e35486ff43a58214598202eafe70fd35f3a785d","src/lib.rs":"ae1cb5330baa8d6a875d834c614d7f42f8ab57dbcf5f2baf2276c90eb671c4f2"},"package":"f028d6802c52903b3d8fa1cc37264ae5b8b630161e600eccfa68d4ee6ce5163a"} \ No newline at end of file diff --git a/third_party/rust/fluent-pseudo/CHANGELOG.md b/third_party/rust/fluent-pseudo/CHANGELOG.md deleted file mode 100644 index b68d1a92a195..000000000000 --- a/third_party/rust/fluent-pseudo/CHANGELOG.md +++ /dev/null @@ -1,16 +0,0 @@ -# Changelog - -## Unreleased - - - … - -## fluent-pseudo 0.2.0 (December 13, 2019) - - Exclude access-keys and other single-char messages. - -## fluent-pseudo 0.1.0 (November 26, 2019) - - Update `regex` to 1.3. - -## fluent-pseudo 0.0.1 (August 1, 2019) - - - This is the first release to be listed in the CHANGELOG. - - Basic support for pseudo-localization matching the fluent.js capabilities. diff --git a/third_party/rust/fluent-pseudo/Cargo.toml b/third_party/rust/fluent-pseudo/Cargo.toml index 9fa403448767..e6094899da5b 100644 --- a/third_party/rust/fluent-pseudo/Cargo.toml +++ b/third_party/rust/fluent-pseudo/Cargo.toml @@ -13,8 +13,9 @@ [package] edition = "2018" name = "fluent-pseudo" -version = "0.2.1" +version = "0.2.3" authors = ["Zibi Braniecki ", "Staś Małolepszy "] +include = ["src/**/*", "benches/*.rs", "Cargo.toml", "README.md"] description = "Pseudolocalization transformation API for use with Project Fluent API.\n" homepage = "http://www.projectfluent.org" readme = "README.md" @@ -23,4 +24,4 @@ categories = ["localization", "internationalization"] license = "Apache-2.0/MIT" repository = "https://github.com/projectfluent/fluent-rs" [dependencies.regex] -version = "1.3" +version = "1" diff --git a/third_party/rust/fluent-pseudo/README.md b/third_party/rust/fluent-pseudo/README.md index c4f364184295..0507f0780c74 100644 --- a/third_party/rust/fluent-pseudo/README.md +++ b/third_party/rust/fluent-pseudo/README.md @@ -45,4 +45,4 @@ fn main() { assert_eq!(&value, "Ħḗḗŀŀǿǿ Ẇǿǿřŀḓ!"); } -``` \ No newline at end of file +``` diff --git a/third_party/rust/fluent-pseudo/src/lib.rs b/third_party/rust/fluent-pseudo/src/lib.rs index 00ab866f4e00..fb899afab7fa 100644 --- a/third_party/rust/fluent-pseudo/src/lib.rs +++ b/third_party/rust/fluent-pseudo/src/lib.rs @@ -3,12 +3,12 @@ use regex::Regex; use std::borrow::Cow; static TRANSFORM_SMALL_MAP: &[char] = &[ - 'ȧ', 'ƀ', 'ƈ', 'ḓ', 'ḗ', 'ƒ', 'ɠ', 'ħ', 'ī', 'ĵ', 'ķ', 'ŀ', 'ḿ', 'ƞ', 'ǿ', 'ƥ', 'ɋ', 'ř', 'ş', - 'ŧ', 'ŭ', 'ṽ', 'ẇ', 'ẋ', 'ẏ', 'ẑ', + 'a', 'ƀ', 'ƈ', 'ḓ', 'e', 'ƒ', 'ɠ', 'ħ', 'i', 'ĵ', 'ķ', 'ŀ', 'ḿ', 'ƞ', 'o', 'ƥ', 'ɋ', 'ř', 'ş', + 'ŧ', 'u', 'ṽ', 'ẇ', 'ẋ', 'ẏ', 'ẑ', ]; static TRANSFORM_CAPS_MAP: &[char] = &[ - 'Ȧ', 'Ɓ', 'Ƈ', 'Ḓ', 'Ḗ', 'Ƒ', 'Ɠ', 'Ħ', 'Ī', 'Ĵ', 'Ķ', 'Ŀ', 'Ḿ', 'Ƞ', 'Ǿ', 'Ƥ', 'Ɋ', 'Ř', 'Ş', - 'Ŧ', 'Ŭ', 'Ṽ', 'Ẇ', 'Ẋ', 'Ẏ', 'Ẑ', + 'A', 'Ɓ', 'Ƈ', 'Ḓ', 'E', 'Ƒ', 'Ɠ', 'Ħ', 'I', 'Ĵ', 'Ķ', 'Ŀ', 'Ḿ', 'Ƞ', 'O', 'Ƥ', 'Ɋ', 'Ř', 'Ş', + 'Ŧ', 'U', 'Ṽ', 'Ẇ', 'Ẋ', 'Ẏ', 'Ẑ', ]; static FLIPPED_SMALL_MAP: &[char] = &[ @@ -20,6 +20,9 @@ static FLIPPED_CAPS_MAP: &[char] = &[ '⊥', '∩', 'Ʌ', 'M', 'X', '⅄', 'Z', ]; +static mut RE_EXCLUDED: Option = None; +static mut RE_AZ: Option = None; + pub fn transform_dom(s: &str, flipped: bool, elongate: bool) -> Cow { // Exclude access-keys and other single-char messages if s.len() == 1 { @@ -27,7 +30,8 @@ pub fn transform_dom(s: &str, flipped: bool, elongate: bool) -> Cow { } // XML entities (‪) and XML tags. - let re_excluded = Regex::new(r"&[#\w]+;|<\s*.+?\s*>").unwrap(); + let re_excluded = + unsafe { RE_EXCLUDED.get_or_insert_with(|| Regex::new(r"&[#\w]+;|<\s*.+?\s*>").unwrap()) }; let mut result = Cow::from(s); @@ -51,15 +55,12 @@ pub fn transform_dom(s: &str, flipped: bool, elongate: bool) -> Cow { let range = pos..s.len(); let result_range = pos + diff..result.len(); let transform_sub = transform(&s[range], flipped, elongate); - result - .to_mut() - .replace_range(result_range, &transform_sub); + result.to_mut().replace_range(result_range, &transform_sub); result } pub fn transform(s: &str, flipped: bool, elongate: bool) -> Cow { - // XXX: avoid recreating it on each call. - let re_az = Regex::new(r"[a-zA-Z]").unwrap(); + let re_az = unsafe { RE_AZ.get_or_insert_with(|| Regex::new(r"[a-zA-Z]").unwrap()) }; let (small_map, caps_map) = if flipped { (FLIPPED_SMALL_MAP, FLIPPED_CAPS_MAP) @@ -68,11 +69,12 @@ pub fn transform(s: &str, flipped: bool, elongate: bool) -> Cow { }; re_az.replace_all(s, |caps: &Captures| { - let ch = caps[0].chars().nth(0).unwrap(); + let ch = caps[0].chars().next().unwrap(); let cc = ch as u8; if cc >= 97 && cc <= 122 { let pos = cc - 97; let new_char = small_map[pos as usize]; + // duplicate "a", "e", "o" and "u" to emulate ~30% longer text if elongate && (cc == 97 || cc == 101 || cc == 111 || cc == 117) { let mut s = new_char.to_string(); s.push(new_char); @@ -97,10 +99,10 @@ mod tests { #[test] fn it_works() { let x = transform("Hello World", false, true); - assert_eq!(x, "Ħḗḗŀŀǿǿ Ẇǿǿřŀḓ"); + assert_eq!(x, "Ħeeŀŀoo Ẇoořŀḓ"); let x = transform("Hello World", false, false); - assert_eq!(x, "Ħḗŀŀǿ Ẇǿřŀḓ"); + assert_eq!(x, "Ħeŀŀo Ẇořŀḓ"); let x = transform("Hello World", true, false); assert_eq!(x, "Hǝʅʅo Moɹʅp"); @@ -112,10 +114,10 @@ mod tests { #[test] fn dom_test() { let x = transform_dom("Hello World", false, true); - assert_eq!(x, "Ħḗḗŀŀǿǿ Ẇǿǿřŀḓ"); + assert_eq!(x, "Ħeeŀŀoo Ẇoořŀḓ"); let x = transform_dom("Hello World in my House.", false, true); - assert_eq!(x, "Ħḗḗŀŀǿǿ Ẇǿǿřŀḓ īƞ ḿẏ Ħǿǿŭŭşḗḗ."); + assert_eq!(x, "Ħeeŀŀoo Ẇoořŀḓḿẏ Ħoouuşee."); // Don't touch single character values. let x = transform_dom("f", false, true);