Bug 1675789 - Run vendor rust; r=zbraniecki

Differential Revision: https://phabricator.services.mozilla.com/D96854
This commit is contained in:
Dan Minor 2020-11-13 13:23:10 +00:00
parent 74258d96fc
commit bc574a5dfa
6 changed files with 24 additions and 37 deletions

4
Cargo.lock generated
View File

@ -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",
]

View File

@ -1 +1 @@
{"files":{"CHANGELOG.md":"643031d0ea21e0539305186fa41c5fb57889f28c49f1fc27c75b4f659522773c","Cargo.toml":"7f0730a670b8ac4edf2e8ead2f5c7e4880b5cc70c87cc466ba7c3b96a36123c1","README.md":"2bde1fc990113ff261d65e107e4c2bda4de9337761a07b9d272959585f1e57cd","src/lib.rs":"ecb33d80c8351fd53dfbeee9f3456737db72d78f0f0fbbfc3603add76d8fdbb3"},"package":"ca3a870aefc42d175d11fb1ec089221ced8a160d66ca1e0c64a57b4ae90d2462"}
{"files":{"Cargo.toml":"e8314d0278f83d921d2cf1777ddda0ea476621e6b217c60fef018d6555819553","README.md":"c724fbe817e1370765c91bd14e35486ff43a58214598202eafe70fd35f3a785d","src/lib.rs":"ae1cb5330baa8d6a875d834c614d7f42f8ab57dbcf5f2baf2276c90eb671c4f2"},"package":"f028d6802c52903b3d8fa1cc37264ae5b8b630161e600eccfa68d4ee6ce5163a"}

View File

@ -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.

View File

@ -13,8 +13,9 @@
[package]
edition = "2018"
name = "fluent-pseudo"
version = "0.2.1"
version = "0.2.3"
authors = ["Zibi Braniecki <gandalf@mozilla.com>", "Staś Małolepszy <stas@mozilla.com>"]
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"

View File

@ -45,4 +45,4 @@ fn main() {
assert_eq!(&value, "Ħḗḗŀŀǿǿ Ẇǿǿřŀḓ!");
}
```
```

View File

@ -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<Regex> = None;
static mut RE_AZ: Option<Regex> = None;
pub fn transform_dom(s: &str, flipped: bool, elongate: bool) -> Cow<str> {
// 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<str> {
}
// XML entities (&#x202a;) 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<str> {
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<str> {
// 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<str> {
};
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 <a>World</a>", false, true);
assert_eq!(x, "Ħḗḗŀŀǿǿ <a>Ẇǿǿřŀḓ</a>");
assert_eq!(x, "Ħeeŀŀoo <a>Ẇoořŀḓ</a>");
let x = transform_dom("Hello <a>World</a> in <b>my</b> House.", false, true);
assert_eq!(x, "Ħḗḗŀŀǿǿ <a>Ẇǿǿřŀḓ</a> īƞ <b>ḿẏ</b> Ħǿǿŭŭşḗḗ.");
assert_eq!(x, "Ħeeŀŀoo <a>Ẇoořŀḓ</a> iƞ <b>ḿẏ</b> Ħoouuşee.");
// Don't touch single character values.
let x = transform_dom("f", false, true);