зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1675789 - Run vendor rust; r=zbraniecki
Depends on D96853 Differential Revision: https://phabricator.services.mozilla.com/D96854
This commit is contained in:
Родитель
8e9648faef
Коммит
b4cfba2bcf
|
@ -1545,9 +1545,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fluent-pseudo"
|
name = "fluent-pseudo"
|
||||||
version = "0.2.1"
|
version = "0.2.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ca3a870aefc42d175d11fb1ec089221ced8a160d66ca1e0c64a57b4ae90d2462"
|
checksum = "f028d6802c52903b3d8fa1cc37264ae5b8b630161e600eccfa68d4ee6ce5163a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"regex",
|
"regex",
|
||||||
]
|
]
|
||||||
|
|
|
@ -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"}
|
|
@ -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.
|
|
|
@ -13,8 +13,9 @@
|
||||||
[package]
|
[package]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
name = "fluent-pseudo"
|
name = "fluent-pseudo"
|
||||||
version = "0.2.1"
|
version = "0.2.3"
|
||||||
authors = ["Zibi Braniecki <gandalf@mozilla.com>", "Staś Małolepszy <stas@mozilla.com>"]
|
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"
|
description = "Pseudolocalization transformation API for use with Project Fluent API.\n"
|
||||||
homepage = "http://www.projectfluent.org"
|
homepage = "http://www.projectfluent.org"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
@ -23,4 +24,4 @@ categories = ["localization", "internationalization"]
|
||||||
license = "Apache-2.0/MIT"
|
license = "Apache-2.0/MIT"
|
||||||
repository = "https://github.com/projectfluent/fluent-rs"
|
repository = "https://github.com/projectfluent/fluent-rs"
|
||||||
[dependencies.regex]
|
[dependencies.regex]
|
||||||
version = "1.3"
|
version = "1"
|
||||||
|
|
|
@ -45,4 +45,4 @@ fn main() {
|
||||||
|
|
||||||
assert_eq!(&value, "Ħḗḗŀŀǿǿ Ẇǿǿřŀḓ!");
|
assert_eq!(&value, "Ħḗḗŀŀǿǿ Ẇǿǿřŀḓ!");
|
||||||
}
|
}
|
||||||
```
|
```
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AP: &[char] = &[
|
||||||
|
@ -20,6 +20,9 @@ static FLIPPED_CAPS_MAP: &[char] = &[
|
||||||
'⊥', '∩', 'Ʌ', 'M', 'X', '⅄', 'Z',
|
'⊥', '∩', 'Ʌ', '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> {
|
pub fn transform_dom(s: &str, flipped: bool, elongate: bool) -> Cow<str> {
|
||||||
// Exclude access-keys and other single-char messages
|
// Exclude access-keys and other single-char messages
|
||||||
if s.len() == 1 {
|
if s.len() == 1 {
|
||||||
|
@ -27,7 +30,8 @@ pub fn transform_dom(s: &str, flipped: bool, elongate: bool) -> Cow<str> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// XML entities (‪) and XML tags.
|
// 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);
|
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 range = pos..s.len();
|
||||||
let result_range = pos + diff..result.len();
|
let result_range = pos + diff..result.len();
|
||||||
let transform_sub = transform(&s[range], flipped, elongate);
|
let transform_sub = transform(&s[range], flipped, elongate);
|
||||||
result
|
result.to_mut().replace_range(result_range, &transform_sub);
|
||||||
.to_mut()
|
|
||||||
.replace_range(result_range, &transform_sub);
|
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn transform(s: &str, flipped: bool, elongate: bool) -> Cow<str> {
|
pub fn transform(s: &str, flipped: bool, elongate: bool) -> Cow<str> {
|
||||||
// XXX: avoid recreating it on each call.
|
let re_az = unsafe { RE_AZ.get_or_insert_with(|| Regex::new(r"[a-zA-Z]").unwrap()) };
|
||||||
let re_az = Regex::new(r"[a-zA-Z]").unwrap();
|
|
||||||
|
|
||||||
let (small_map, caps_map) = if flipped {
|
let (small_map, caps_map) = if flipped {
|
||||||
(FLIPPED_SMALL_MAP, FLIPPED_CAPS_MAP)
|
(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| {
|
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;
|
let cc = ch as u8;
|
||||||
if cc >= 97 && cc <= 122 {
|
if cc >= 97 && cc <= 122 {
|
||||||
let pos = cc - 97;
|
let pos = cc - 97;
|
||||||
let new_char = small_map[pos as usize];
|
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) {
|
if elongate && (cc == 97 || cc == 101 || cc == 111 || cc == 117) {
|
||||||
let mut s = new_char.to_string();
|
let mut s = new_char.to_string();
|
||||||
s.push(new_char);
|
s.push(new_char);
|
||||||
|
@ -97,10 +99,10 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn it_works() {
|
fn it_works() {
|
||||||
let x = transform("Hello World", false, true);
|
let x = transform("Hello World", false, true);
|
||||||
assert_eq!(x, "Ħḗḗŀŀǿǿ Ẇǿǿřŀḓ");
|
assert_eq!(x, "Ħeeŀŀoo Ẇoořŀḓ");
|
||||||
|
|
||||||
let x = transform("Hello World", false, false);
|
let x = transform("Hello World", false, false);
|
||||||
assert_eq!(x, "Ħḗŀŀǿ Ẇǿřŀḓ");
|
assert_eq!(x, "Ħeŀŀo Ẇořŀḓ");
|
||||||
|
|
||||||
let x = transform("Hello World", true, false);
|
let x = transform("Hello World", true, false);
|
||||||
assert_eq!(x, "Hǝʅʅo Moɹʅp");
|
assert_eq!(x, "Hǝʅʅo Moɹʅp");
|
||||||
|
@ -112,10 +114,10 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn dom_test() {
|
fn dom_test() {
|
||||||
let x = transform_dom("Hello <a>World</a>", false, true);
|
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);
|
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.
|
// Don't touch single character values.
|
||||||
let x = transform_dom("f", false, true);
|
let x = transform_dom("f", false, true);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче