Bug 1686275 - Update fluent-rs to 0.14. r=dminor

Differential Revision: https://phabricator.services.mozilla.com/D101474
This commit is contained in:
Zibi Braniecki 2021-01-13 02:50:44 +00:00
Родитель eea573de3b
Коммит 1c1851d0fa
77 изменённых файлов: 8026 добавлений и 381 удалений

54
Cargo.lock сгенерированный
Просмотреть файл

@ -1,5 +1,15 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "Inflector"
version = "0.11.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3"
dependencies = [
"lazy_static",
"regex",
]
[[package]]
name = "adler"
version = "0.2.3"
@ -1497,9 +1507,9 @@ dependencies = [
[[package]]
name = "fluent"
version = "0.13.1"
version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef9e54ec7b674ae3477d948ae790e90ae24d54fb31c2e7173252978d9b09bdfa"
checksum = "e4f3359832f932e4ddbb4c56851623cb50bd08d1ae36e9ec80cfc44f412e1400"
dependencies = [
"fluent-bundle",
"fluent-pseudo",
@ -1508,15 +1518,15 @@ dependencies = [
[[package]]
name = "fluent-bundle"
version = "0.13.1"
version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a79916560098f0a57215a489e37b7fc83088949eab7f7977dcc329b254d50c17"
checksum = "4c0cd40fee9f6eb74dfb38f0fa700a92ac4fe702868b04e52018ead90d415332"
dependencies = [
"fluent-langneg",
"fluent-syntax",
"intl-memoizer",
"intl_pluralrules",
"rental",
"ouroboros",
"smallvec",
"unic-langid",
]
@ -1566,9 +1576,9 @@ dependencies = [
[[package]]
name = "fluent-syntax"
version = "0.10.0"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9389354f858e38f37d9a249133611a1fcaec469f44773b04ddbd82f4f08d49eb"
checksum = "edb1016e8c600060e0099218442fff329a204f6316d6ec974d590d3281517a52"
[[package]]
name = "fnv"
@ -2526,9 +2536,9 @@ dependencies = [
[[package]]
name = "intl_pluralrules"
version = "7.0.0"
version = "7.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c271cdb1f12a9feb3a017619c3ee681f971f270f6757341d6abe1f9f7a98bc3"
checksum = "b18f988384267d7066cc2be425e6faf352900652c046b6971d2e228d3b1c5ecf"
dependencies = [
"tinystr",
"unic-langid",
@ -3710,6 +3720,28 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "ouroboros"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0b666c900ea45a357bc7915a4dc8fab7e295f2e756e843aa3c0788d94aa3a29"
dependencies = [
"ouroboros_macro",
"stable_deref_trait",
]
[[package]]
name = "ouroboros_macro"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfc618f205c0adc415923c74369d45f5f298462fc473711dfc33056a23f23619"
dependencies = [
"Inflector",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "owning_ref"
version = "0.4.0"
@ -4820,9 +4852,9 @@ dependencies = [
[[package]]
name = "stable_deref_trait"
version = "1.0.0"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15132e0e364248108c5e2c02e3ab539be8d6f5d52a01ca9bbf27ed657316f02b"
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
[[package]]
name = "static_assertions"

Просмотреть файл

@ -5,7 +5,7 @@ authors = ["Zibi Braniecki <zibi@braniecki.net>"]
edition = "2018"
[dependencies]
fluent = { version = "0.13.1", features = ["fluent-pseudo"] }
fluent = { version = "0.14.1", features = ["fluent-pseudo"] }
fluent-pseudo = "0.2.3"
intl-memoizer = "0.5"
unic-langid = "0.9"

Просмотреть файл

@ -92,7 +92,7 @@ fn fluent_bundle_new_internal(
use_isolating: bool,
pseudo_strategy: &nsACString,
) -> Box<FluentBundleRc> {
let mut bundle = FluentBundle::new(langids.iter());
let mut bundle = FluentBundle::new(langids.to_vec());
bundle.set_use_isolating(use_isolating);
bundle.set_formatter(Some(format_numbers));
@ -265,40 +265,6 @@ fn convert_args<'a>(
fn append_fluent_errors_to_ret_errors(ret_errors: &mut ThinVec<nsCString>, errors: &[FluentError]) {
for error in errors {
match error {
FluentError::ResolverError(ref err) => match err {
ResolverError::Reference(ref s) => {
let error = format!("ReferenceError: {}", s);
ret_errors.push(error.into());
}
ResolverError::MissingDefault => {
let error = "RangeError: No default value for selector";
ret_errors.push(error.into());
}
ResolverError::Cyclic => {
let error =
"RangeError: Cyclic reference encountered while resolving a message";
ret_errors.push(error.into());
}
ResolverError::TooManyPlaceables => {
let error = "RangeError: Too many placeables in a message";
ret_errors.push(error.into());
}
},
FluentError::Overriding { kind, id } => {
let error = format!(
"OverrideError: An entry {} of type {} is already defined in this bundle",
id, kind
);
ret_errors.push(error.into());
}
FluentError::ParserError(pe) => {
let error = format!(
"ParserError: Error of kind {:#?} in position: ({}, {})",
pe.kind, pe.pos.0, pe.pos.1
);
ret_errors.push(error.into());
}
}
ret_errors.push(error.to_string().into());
}
}

1
third_party/rust/Inflector/.cargo-checksum.json поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
{"files":{"Cargo.toml":"8fb633b01ea17947fd1f76e0a447b027ddf48c019671f09e39c1338ab715605d","README.md":"3c7136fc446143eecf9668e6daf7f096eb5eb3a3e312cc674571719cb4c83bcc","src/cases/camelcase/mod.rs":"8e65fca78ea88acb32c0f214cafde39b849aef253253c3681e316f2559b26977","src/cases/case/mod.rs":"16323191c983d316debd50af11f94f4c525bb70d4d1a02db06a9aed67d4ba2a9","src/cases/classcase/mod.rs":"5b6b74530a2a693bf1ac89342f1b25f58f39336b1ee3242547c3d6ef468a878f","src/cases/kebabcase/mod.rs":"b317ebd42f22daab4b23bb4b83ce85f053d7088680d3a32eecbd13bd5331587a","src/cases/mod.rs":"e272853bcc1c5f6eb02594038febb9dcebb6eca8eac744d6e503db5082e585c6","src/cases/pascalcase/mod.rs":"a44feed6d8877fd8a31160076befe826960aa001d859587aef2dddc1aedc397b","src/cases/screamingsnakecase/mod.rs":"21582eb1ec2170d379bf3536c6ffb39b8bdc096efe2d493674458ee27b86e985","src/cases/sentencecase/mod.rs":"eb21d7d5bf0b23e1325d429dfdc149081d233a8b950c1fdfe04b4bebcc2c0ddb","src/cases/snakecase/mod.rs":"369739e37e700c028022f308aa78504873c10a5e88768f05249c1c8481b30c9d","src/cases/tablecase/mod.rs":"a6a50a397059d775a517d5dce6ba612b107919e209a9eb56871a5c1d42314664","src/cases/titlecase/mod.rs":"3f0dac5e5b434da9234d6c389f67bb2d3c8f138dc521fa29dbe3791f8eaf5341","src/cases/traincase/mod.rs":"4e2493d6594d3c505de293c69390b3f672c0fd4d35603ae1a1aae48166bc18c2","src/lib.rs":"6c5cf60f5c2f8778a3ad7638f37064527b8a86f164117d867b8b6532e2cc655e","src/numbers/deordinalize/mod.rs":"a3930b0315d20d2d86747bc4ae653a0fb7f7d80de497b0aaa9873aadd1459d18","src/numbers/mod.rs":"fed4e090f8b64a34ae64ddcb68d899cfa4dd8e8422a060be01a70dbdb71b85e0","src/numbers/ordinalize/mod.rs":"ce0d88977efaa50792e7311c0e0a73a3115928f9f7be77f914824c3d80eab66c","src/string/constants/mod.rs":"38de3d5060a5d224d28d184eab8af02203c65d74c1d380720c3260ea205f3e05","src/string/deconstantize/mod.rs":"c79f2170dc41bd6abb89a6e74fbdd87bf011f62cfe1f34d8886fda0724ade6fa","src/string/demodulize/mod.rs":"bbcb5314473e4ca02feee4903e31a332caaa912ed2cbca0f49c2fe411a826215","src/string/mod.rs":"570f7ea4dd646f2d633ddd67079db922cc2cadf916719fa19c2f59b4d522ee89","src/string/pluralize/mod.rs":"5f07fab8b5f4e7af546f1e907426724714b9b27af1ecb59a91e57dccd0833a6e","src/string/singularize/mod.rs":"9c2d833cbcdc1489013642de22578d51f558a31e8d2fea4536a27f8fa1114169","src/suffix/foreignkey/mod.rs":"e7ad9a9a0a21fcb53becb36306a15eedf67958e2da18ae928ae592177e70e7a3","src/suffix/mod.rs":"f6f99ce6fc8794d5411d91533b67be5d4a2bc5994317d32f405b2fa3c5ec660d","tests/lib.rs":"e1cfcea8a146291396ff72b0a2e84c2b9ddaa0103717442c4921c165a2ab470d"},"package":"fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3"}

42
third_party/rust/Inflector/Cargo.toml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,42 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g. crates.io) dependencies
#
# If you believe there's an error in this file please file an
# issue against the rust-lang/cargo repository. If you're
# editing this file be aware that the upstream Cargo.toml
# will likely look very different (and much more reasonable)
[package]
name = "Inflector"
version = "0.11.4"
authors = ["Josh Teeter<joshteeter@gmail.com>"]
include = ["**/*.rs", "Cargo.toml", "README.md"]
description = "Adds String based inflections for Rust. Snake, kebab, camel, sentence, class, title and table cases as well as ordinalize, deordinalize, demodulize, foreign key, and pluralize/singularize are supported as both traits and pure functions acting on String types.\n"
homepage = "https://github.com/whatisinternet/inflector"
documentation = "https://docs.rs/Inflector"
readme = "README.md"
keywords = ["pluralize", "Inflector", "camel", "snake", "inflection"]
categories = ["text-processing", "value-formatting"]
license = "BSD-2-Clause"
repository = "https://github.com/whatisinternet/inflector"
[lib]
name = "inflector"
[dependencies.lazy_static]
version = "1.2.0"
optional = true
[dependencies.regex]
version = "1.1"
optional = true
[features]
default = ["heavyweight"]
heavyweight = ["regex", "lazy_static"]
unstable = []
[badges.travis-ci]
repository = "whatisinternet/Inflector"

136
third_party/rust/Inflector/README.md поставляемый Normal file
Просмотреть файл

@ -0,0 +1,136 @@
# Rust Inflector
[![Build Status](https://travis-ci.org/whatisinternet/Inflector.svg?branch=master)](https://travis-ci.org/whatisinternet/Inflector) [![Crates.io](https://img.shields.io/crates/v/Inflector.svg)](https://crates.io/crates/inflector)[![Crate downloads](https://img.shields.io/crates/d/Inflector.svg)](https://crates.io/crates/inflector)
Adds String based inflections for Rust. Snake, kebab, train, camel,
sentence, class, and title cases as well as ordinalize,
deordinalize, demodulize, deconstantize, foreign key, table case, and pluralize/singularize are supported as both traits and pure functions
acting on &str and String types.
-----
## Documentation:
Documentation can be found here at the README or via rust docs below.
[Rust docs with examples](https://docs.rs/Inflector)
-----
## Installation:
### As a [crate](http://crates.io)
```toml
[dependencies]
Inflector = "*"
```
### Compile yourself:
1. Install [Rust and cargo](http://doc.crates.io/)
2. git clone https://github.com/whatisinternet/Inflector
3. Library: cd inflector && cargo build --release --lib
4. You can find the library in target/release
## Usage / Example:
```rust
...
// to use methods like String.to_lower_case();
extern crate inflector;
use inflector::Inflector;
...
fn main() {
...
let camel_case_string: String = "some_string".to_camel_case();
...
}
```
Or
```rust
...
// to use methods like to_snake_case(&str);
extern crate inflector;
// use inflector::cases::classcase::to_class_case;
// use inflector::cases::classcase::is_class_case;
// use inflector::cases::camelcase::to_camel_case;
// use inflector::cases::camelcase::is_camel_case;
// use inflector::cases::pascalcase::to_pascal_case;
// use inflector::cases::pascalcase::is_pascal_case;
// use inflector::cases::screamingsnakecase::to_screamingsnake_case;
// use inflector::cases::screamingsnakecase::is_screamingsnake_case;
// use inflector::cases::snakecase::to_snake_case;
// use inflector::cases::snakecase::is_snake_case;
// use inflector::cases::kebabcase::to_kebab_case;
// use inflector::cases::kebabcase::is_kebab_case;
// use inflector::cases::traincase::to_train_case;
// use inflector::cases::traincase::is_train_case;
// use inflector::cases::sentencecase::to_sentence_case;
// use inflector::cases::sentencecase::is_sentence_case;
// use inflector::cases::titlecase::to_title_case;
// use inflector::cases::titlecase::is_title_case;
// use inflector::cases::tablecase::to_table_case;
// use inflector::cases::tablecase::is_table_case;
// use inflector::numbers::ordinalize::ordinalize;
// use inflector::numbers::deordinalize::deordinalize;
// use inflector::suffix::foreignkey::to_foreign_key;
// use inflector::suffix::foreignkey::is_foreign_key;
// use inflector::string::demodulize::demodulize;
// use inflector::string::deconstantize::deconstantize;
// use inflector::string::pluralize::to_plural;
// use inflector::string::singularize::to_singular;
...
fn main() {
...
let camel_case_string: String = to_camel_case("some_string");
...
}
```
## Advanced installation and usage:
If the project doesn't require singularize, pluralize, class, table, demodulize,
deconstantize. Then in your `cargo.toml` you may wish to specify:
```toml
[dependencies.Inflector]
version = "*"
default-features = false
```
Or
```toml
Inflector = {version="*", default-features=false}
```
To test this crate locally with features off try:
```shell
cargo test --no-default-features
```
## [Contributing](CONTRIBUTING.md)
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.

370
third_party/rust/Inflector/src/cases/camelcase/mod.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,370 @@
#![deny(warnings)]
use cases::case::*;
/// Converts a `&str` to camelCase `String`
///
/// ```
/// use inflector::cases::camelcase::to_camel_case;
/// let mock_string: &str = "fooBar";
/// let expected_string: String = "fooBar".to_string();
/// let asserted_string: String = to_camel_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::camelcase::to_camel_case;
/// let mock_string: &str = "FOO_BAR";
/// let expected_string: String = "fooBar".to_string();
/// let asserted_string: String = to_camel_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::camelcase::to_camel_case;
/// let mock_string: &str = "Foo Bar";
/// let expected_string: String = "fooBar".to_string();
/// let asserted_string: String = to_camel_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::camelcase::to_camel_case;
/// let mock_string: &str = "foo_bar";
/// let expected_string: String = "fooBar".to_string();
/// let asserted_string: String = to_camel_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::camelcase::to_camel_case;
/// let mock_string: &str = "Foo bar";
/// let expected_string: String = "fooBar".to_string();
/// let asserted_string: String = to_camel_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::camelcase::to_camel_case;
/// let mock_string: &str = "foo-bar";
/// let expected_string: String = "fooBar".to_string();
/// let asserted_string: String = to_camel_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::camelcase::to_camel_case;
/// let mock_string: &str = "FooBar";
/// let expected_string: String = "fooBar".to_string();
/// let asserted_string: String = to_camel_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::camelcase::to_camel_case;
/// let mock_string: &str = "FooBar3";
/// let expected_string: String = "fooBar3".to_string();
/// let asserted_string: String = to_camel_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::camelcase::to_camel_case;
/// let mock_string: &str = "Foo-Bar";
/// let expected_string: String = "fooBar".to_string();
/// let asserted_string: String = to_camel_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
pub fn to_camel_case(non_camelized_string: &str) -> String {
let options = CamelOptions {
new_word: false,
last_char: ' ',
first_word: false,
injectable_char: ' ',
has_seperator: false,
inverted: false,
};
to_case_camel_like(&non_camelized_string, options)
}
/// Determines if a `&str` is camelCase bool``
///
/// ```
/// use inflector::cases::camelcase::is_camel_case;
/// let mock_string: &str = "Foo";
/// let asserted_bool: bool = is_camel_case(mock_string);
/// assert!(asserted_bool == false);
///
///
/// ```
/// ```
/// use inflector::cases::camelcase::is_camel_case;
/// let mock_string: &str = "foo";
/// let asserted_bool: bool = is_camel_case(mock_string);
/// assert!(asserted_bool == true);
///
///
/// ```
/// ```
/// use inflector::cases::camelcase::is_camel_case;
/// let mock_string: &str = "foo-bar-string-that-is-really-really-long";
/// let asserted_bool: bool = is_camel_case(mock_string);
/// assert!(asserted_bool == false);
///
///
/// ```
/// ```
/// use inflector::cases::camelcase::is_camel_case;
/// let mock_string: &str = "FooBarIsAReallyReallyLongString";
/// let asserted_bool: bool = is_camel_case(mock_string);
/// assert!(asserted_bool == false);
///
///
/// ```
/// ```
/// use inflector::cases::camelcase::is_camel_case;
/// let mock_string: &str = "fooBarIsAReallyReally3LongString";
/// let asserted_bool: bool = is_camel_case(mock_string);
/// assert!(asserted_bool == true);
///
///
/// ```
/// ```
/// use inflector::cases::camelcase::is_camel_case;
/// let mock_string: &str = "fooBarIsAReallyReallyLongString";
/// let asserted_bool: bool = is_camel_case(mock_string);
/// assert!(asserted_bool == true);
///
///
/// ```
/// ```
/// use inflector::cases::camelcase::is_camel_case;
/// let mock_string: &str = "FOO_BAR_STRING_THAT_IS_REALLY_REALLY_LONG";
/// let asserted_bool: bool = is_camel_case(mock_string);
/// assert!(asserted_bool == false);
///
///
/// ```
/// ```
/// use inflector::cases::camelcase::is_camel_case;
/// let mock_string: &str = "foo_bar_string_that_is_really_really_long";
/// let asserted_bool: bool = is_camel_case(mock_string);
/// assert!(asserted_bool == false);
///
///
/// ```
/// ```
/// use inflector::cases::camelcase::is_camel_case;
/// let mock_string: &str = "Foo bar string that is really really long";
/// let asserted_bool: bool = is_camel_case(mock_string);
/// assert!(asserted_bool == false);
///
///
/// ```
/// ```
/// use inflector::cases::camelcase::is_camel_case;
/// let mock_string: &str = "Foo Bar Is A Really Really Long String";
/// let asserted_bool: bool = is_camel_case(mock_string);
/// assert!(asserted_bool == false);
/// ```
pub fn is_camel_case(test_string: &str) -> bool {
to_camel_case(&test_string.clone()) == test_string
}
#[cfg(all(feature = "unstable", test))]
mod benchmarks {
extern crate test;
use self::test::Bencher;
#[bench]
fn bench_camel0(b: &mut Bencher) {
b.iter(|| {
let test_string = "Foo bar";
super::to_camel_case(test_string)
});
}
#[bench]
fn bench_camel1(b: &mut Bencher) {
b.iter(|| {
let test_string = "foo_bar";
super::to_camel_case(test_string)
});
}
#[bench]
fn bench_camel2(b: &mut Bencher) {
b.iter(|| {
let test_string = "fooBar";
super::to_camel_case(test_string)
});
}
#[bench]
fn bench_is_camel(b: &mut Bencher) {
b.iter(|| {
let test_string: &str = "Foo bar";
super::is_camel_case(test_string)
});
}
}
#[cfg(test)]
mod tests {
use ::to_camel_case;
use ::is_camel_case;
#[test]
fn from_camel_case() {
let convertable_string: String = "fooBar".to_owned();
let expected: String = "fooBar".to_owned();
assert_eq!(to_camel_case(&convertable_string), expected)
}
#[test]
fn from_pascal_case() {
let convertable_string: String = "FooBar".to_owned();
let expected: String = "fooBar".to_owned();
assert_eq!(to_camel_case(&convertable_string), expected)
}
#[test]
fn from_kebab_case() {
let convertable_string: String = "foo-bar".to_owned();
let expected: String = "fooBar".to_owned();
assert_eq!(to_camel_case(&convertable_string), expected)
}
#[test]
fn from_sentence_case() {
let convertable_string: String = "Foo bar".to_owned();
let expected: String = "fooBar".to_owned();
assert_eq!(to_camel_case(&convertable_string), expected)
}
#[test]
fn from_title_case() {
let convertable_string: String = "Foo Bar".to_owned();
let expected: String = "fooBar".to_owned();
assert_eq!(to_camel_case(&convertable_string), expected)
}
#[test]
fn from_train_case() {
let convertable_string: String = "Foo-Bar".to_owned();
let expected: String = "fooBar".to_owned();
assert_eq!(to_camel_case(&convertable_string), expected)
}
#[test]
fn from_screaming_snake_case() {
let convertable_string: String = "FOO_BAR".to_owned();
let expected: String = "fooBar".to_owned();
assert_eq!(to_camel_case(&convertable_string), expected)
}
#[test]
fn from_snake_case() {
let convertable_string: String = "foo_bar".to_owned();
let expected: String = "fooBar".to_owned();
assert_eq!(to_camel_case(&convertable_string), expected)
}
#[test]
fn from_case_with_loads_of_space() {
let convertable_string: String = "foo bar".to_owned();
let expected: String = "fooBar".to_owned();
assert_eq!(to_camel_case(&convertable_string), expected)
}
#[test]
fn a_name_with_a_dot() {
let convertable_string: String = "Robert C. Martin".to_owned();
let expected: String = "robertCMartin".to_owned();
assert_eq!(to_camel_case(&convertable_string), expected)
}
#[test]
fn random_text_with_bad_chars() {
let convertable_string: String = "Random text with *(bad) chars".to_owned();
let expected: String = "randomTextWithBadChars".to_owned();
assert_eq!(to_camel_case(&convertable_string), expected)
}
#[test]
fn trailing_bad_chars() {
let convertable_string: String = "trailing bad_chars*(()())".to_owned();
let expected: String = "trailingBadChars".to_owned();
assert_eq!(to_camel_case(&convertable_string), expected)
}
#[test]
fn leading_bad_chars() {
let convertable_string: String = "-!#$%leading bad chars".to_owned();
let expected: String = "leadingBadChars".to_owned();
assert_eq!(to_camel_case(&convertable_string), expected)
}
#[test]
fn wrapped_in_bad_chars() {
let convertable_string: String = "-!#$%wrapped in bad chars&*^*&(&*^&(<><?>><?><>))".to_owned();
let expected: String = "wrappedInBadChars".to_owned();
assert_eq!(to_camel_case(&convertable_string), expected)
}
#[test]
fn has_a_sign() {
let convertable_string: String = "has a + sign".to_owned();
let expected: String = "hasASign".to_owned();
assert_eq!(to_camel_case(&convertable_string), expected)
}
#[test]
fn is_correct_from_camel_case() {
let convertable_string: String = "fooBar".to_owned();
assert_eq!(is_camel_case(&convertable_string), true)
}
#[test]
fn is_correct_from_pascal_case() {
let convertable_string: String = "FooBar".to_owned();
assert_eq!(is_camel_case(&convertable_string), false)
}
#[test]
fn is_correct_from_kebab_case() {
let convertable_string: String = "foo-bar".to_owned();
assert_eq!(is_camel_case(&convertable_string), false)
}
#[test]
fn is_correct_from_sentence_case() {
let convertable_string: String = "Foo bar".to_owned();
assert_eq!(is_camel_case(&convertable_string), false)
}
#[test]
fn is_correct_from_title_case() {
let convertable_string: String = "Foo Bar".to_owned();
assert_eq!(is_camel_case(&convertable_string), false)
}
#[test]
fn is_correct_from_train_case() {
let convertable_string: String = "Foo-Bar".to_owned();
assert_eq!(is_camel_case(&convertable_string), false)
}
#[test]
fn is_correct_from_screaming_snake_case() {
let convertable_string: String = "FOO_BAR".to_owned();
assert_eq!(is_camel_case(&convertable_string), false)
}
#[test]
fn is_correct_from_snake_case() {
let convertable_string: String = "foo_bar".to_owned();
assert_eq!(is_camel_case(&convertable_string), false)
}
}

303
third_party/rust/Inflector/src/cases/case/mod.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,303 @@
#![deny(warnings)]
#[allow(unknown_lints)]
#[allow(unused_imports)]
use std::ascii::*;
pub struct CamelOptions {
pub new_word: bool,
pub last_char: char,
pub first_word: bool,
pub injectable_char: char,
pub has_seperator: bool,
pub inverted: bool,
}
pub fn to_case_snake_like(convertable_string: &str, replace_with: &str, case: &str) -> String {
let mut first_character: bool = true;
let mut result: String = String::with_capacity(convertable_string.len() * 2);
for char_with_index in trim_right(convertable_string).char_indices() {
if char_is_seperator(&char_with_index.1) {
if !first_character {
first_character = true;
result.push(replace_with.chars().nth(0).unwrap_or('_'));
}
} else if requires_seperator(char_with_index, first_character, &convertable_string) {
first_character = false;
result = snake_like_with_seperator(result, replace_with, &char_with_index.1, case)
} else {
first_character = false;
result = snake_like_no_seperator(result, &char_with_index.1, case)
}
}
result
}
pub fn to_case_camel_like(convertable_string: &str, camel_options: CamelOptions) -> String {
let mut new_word: bool = camel_options.new_word;
let mut first_word: bool = camel_options.first_word;
let mut last_char: char = camel_options.last_char;
let mut found_real_char: bool = false;
let mut result: String = String::with_capacity(convertable_string.len() * 2);
for character in trim_right(convertable_string).chars() {
if char_is_seperator(&character) && found_real_char {
new_word = true;
} else if !found_real_char && is_not_alphanumeric(character) {
continue;
} else if character.is_numeric() {
found_real_char = true;
new_word = true;
result.push(character);
} else if last_char_lower_current_is_upper_or_new_word(new_word, last_char, character) {
found_real_char = true;
new_word = false;
result = append_on_new_word(result, first_word, character, &camel_options);
first_word = false;
} else {
found_real_char = true;
last_char = character;
result.push(character.to_ascii_lowercase());
}
}
result
}
#[inline]
fn append_on_new_word(mut result: String, first_word: bool, character: char, camel_options: &CamelOptions) -> String {
if not_first_word_and_has_seperator(first_word, camel_options.has_seperator) {
result.push(camel_options.injectable_char);
}
if first_word_or_not_inverted(first_word, camel_options.inverted) {
result.push(character.to_ascii_uppercase());
} else {
result.push(character.to_ascii_lowercase());
}
result
}
fn not_first_word_and_has_seperator(first_word: bool, has_seperator: bool) -> bool {
has_seperator && !first_word
}
fn first_word_or_not_inverted(first_word: bool, inverted: bool) -> bool {
!inverted || first_word
}
fn last_char_lower_current_is_upper_or_new_word(new_word: bool, last_char: char, character: char) -> bool{
new_word ||
((last_char.is_lowercase() && character.is_uppercase()) &&
(last_char != ' '))
}
fn char_is_seperator(character: &char) -> bool {
is_not_alphanumeric(*character)
}
fn trim_right(convertable_string: &str) -> &str {
convertable_string.trim_end_matches(is_not_alphanumeric)
}
fn is_not_alphanumeric(character: char) -> bool {
!character.is_alphanumeric()
}
#[inline]
fn requires_seperator(char_with_index: (usize, char), first_character: bool, convertable_string: &str) -> bool {
!first_character &&
char_is_uppercase(char_with_index.1) &&
next_or_previous_char_is_lowercase(convertable_string, char_with_index.0)
}
#[inline]
fn snake_like_no_seperator(mut accumlator: String, current_char: &char, case: &str) -> String {
if case == "lower" {
accumlator.push(current_char.to_ascii_lowercase());
accumlator
} else {
accumlator.push(current_char.to_ascii_uppercase());
accumlator
}
}
#[inline]
fn snake_like_with_seperator(mut accumlator: String, replace_with: &str, current_char: &char, case: &str) -> String {
if case == "lower" {
accumlator.push(replace_with.chars().nth(0).unwrap_or('_'));
accumlator.push(current_char.to_ascii_lowercase());
accumlator
} else {
accumlator.push(replace_with.chars().nth(0).unwrap_or('_'));
accumlator.push(current_char.to_ascii_uppercase());
accumlator
}
}
fn next_or_previous_char_is_lowercase(convertable_string: &str, char_with_index: usize) -> bool {
convertable_string.chars().nth(char_with_index + 1).unwrap_or('A').is_lowercase() ||
convertable_string.chars().nth(char_with_index - 1).unwrap_or('A').is_lowercase()
}
fn char_is_uppercase(test_char: char) -> bool {
test_char == test_char.to_ascii_uppercase()
}
#[test]
fn test_trim_bad_chars() {
assert_eq!("abc", trim_right("abc----^"))
}
#[test]
fn test_trim_bad_chars_when_none_are_bad() {
assert_eq!("abc", trim_right("abc"))
}
#[test]
fn test_is_not_alphanumeric_on_is_alphanumeric() {
assert!(!is_not_alphanumeric('a'))
}
#[test]
fn test_is_not_alphanumeric_on_is_not_alphanumeric() {
assert!(is_not_alphanumeric('_'))
}
#[test]
fn test_char_is_uppercase_when_it_is() {
assert_eq!(char_is_uppercase('A'), true)
}
#[test]
fn test_char_is_uppercase_when_it_is_not() {
assert_eq!(char_is_uppercase('a'), false)
}
#[test]
fn test_next_or_previous_char_is_lowercase_true() {
assert_eq!(next_or_previous_char_is_lowercase("TestWWW", 3), true)
}
#[test]
fn test_next_or_previous_char_is_lowercase_false() {
assert_eq!(next_or_previous_char_is_lowercase("TestWWW", 5), false)
}
#[test]
fn snake_like_with_seperator_lowers() {
assert_eq!(snake_like_with_seperator("".to_owned(), "^", &'c', "lower"), "^c".to_string())
}
#[test]
fn snake_like_with_seperator_upper() {
assert_eq!(snake_like_with_seperator("".to_owned(), "^", &'c', "upper"), "^C".to_string())
}
#[test]
fn snake_like_no_seperator_lower() {
assert_eq!(snake_like_no_seperator("".to_owned(), &'C', "lower"), "c".to_string())
}
#[test]
fn snake_like_no_seperator_upper() {
assert_eq!(snake_like_no_seperator("".to_owned(), &'c', "upper"), "C".to_string())
}
#[test]
fn requires_seperator_upper_not_first_wrap_is_safe_current_upper() {
assert_eq!(requires_seperator((2, 'C'), false, "test"), true)
}
#[test]
fn requires_seperator_upper_not_first_wrap_is_safe_current_lower() {
assert_eq!(requires_seperator((2, 'c'), false, "test"), false)
}
#[test]
fn requires_seperator_upper_first_wrap_is_safe_current_upper() {
assert_eq!(requires_seperator((0, 'T'), true, "Test"), false)
}
#[test]
fn requires_seperator_upper_first_wrap_is_safe_current_lower() {
assert_eq!(requires_seperator((0, 't'), true, "Test"), false)
}
#[test]
fn requires_seperator_upper_first_wrap_is_safe_current_lower_next_is_too() {
assert_eq!(requires_seperator((0, 't'), true, "test"), false)
}
#[test]
fn test_char_is_seperator_dash() {
assert_eq!(char_is_seperator(&'-'), true)
}
#[test]
fn test_char_is_seperator_underscore() {
assert_eq!(char_is_seperator(&'_'), true)
}
#[test]
fn test_char_is_seperator_space() {
assert_eq!(char_is_seperator(&' '), true)
}
#[test]
fn test_char_is_seperator_when_not() {
assert_eq!(char_is_seperator(&'A'), false)
}
#[test]
fn test_last_char_lower_current_is_upper_or_new_word_with_new_word() {
assert_eq!(last_char_lower_current_is_upper_or_new_word(true, ' ', '-'), true)
}
#[test]
fn test_last_char_lower_current_is_upper_or_new_word_last_char_space() {
assert_eq!(last_char_lower_current_is_upper_or_new_word(false, ' ', '-'), false)
}
#[test]
fn test_last_char_lower_current_is_upper_or_new_word_last_char_lower_current_upper() {
assert_eq!(last_char_lower_current_is_upper_or_new_word(false, 'a', 'A'), true)
}
#[test]
fn test_last_char_lower_current_is_upper_or_new_word_last_char_upper_current_upper() {
assert_eq!(last_char_lower_current_is_upper_or_new_word(false, 'A', 'A'), false)
}
#[test]
fn test_last_char_lower_current_is_upper_or_new_word_last_char_upper_current_lower() {
assert_eq!(last_char_lower_current_is_upper_or_new_word(false, 'A', 'a'), false)
}
#[test]
fn test_first_word_or_not_inverted_with_first_word() {
assert_eq!(first_word_or_not_inverted(true, false), true)
}
#[test]
fn test_first_word_or_not_inverted_not_first_word_not_inverted() {
assert_eq!(first_word_or_not_inverted(false, false), true)
}
#[test]
fn test_first_word_or_not_inverted_not_first_word_is_inverted() {
assert_eq!(first_word_or_not_inverted(false, true), false)
}
#[test]
fn test_not_first_word_and_has_seperator_is_first_and_not_seperator() {
assert_eq!(not_first_word_and_has_seperator(true, false), false)
}
#[test]
fn test_not_first_word_and_has_seperator_not_first_and_not_seperator() {
assert_eq!(not_first_word_and_has_seperator(false, false), false)
}
#[test]
fn test_not_first_word_and_has_seperator_not_first_and_has_seperator() {
assert_eq!(not_first_word_and_has_seperator(false, true), true)
}

393
third_party/rust/Inflector/src/cases/classcase/mod.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,393 @@
#![deny(warnings)]
use cases::case::*;
#[cfg(feature = "heavyweight")]
use string::singularize::to_singular;
#[cfg(feature = "heavyweight")]
/// Converts a `&str` to `ClassCase` `String`
///
/// ```
/// use inflector::cases::classcase::to_class_case;
/// let mock_string: &str = "FooBar";
/// let expected_string: String = "FooBar".to_string();
/// let asserted_string: String = to_class_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
///
/// ```
/// use inflector::cases::classcase::to_class_case;
/// let mock_string: &str = "FooBars";
/// let expected_string: String = "FooBar".to_string();
/// let asserted_string: String = to_class_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
///
/// ```
/// use inflector::cases::classcase::to_class_case;
/// let mock_string: &str = "Foo Bar";
/// let expected_string: String = "FooBar".to_string();
/// let asserted_string: String = to_class_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
///
/// ```
/// use inflector::cases::classcase::to_class_case;
/// let mock_string: &str = "foo-bar";
/// let expected_string: String = "FooBar".to_string();
/// let asserted_string: String = to_class_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
///
/// ```
/// use inflector::cases::classcase::to_class_case;
/// let mock_string: &str = "fooBar";
/// let expected_string: String = "FooBar".to_string();
/// let asserted_string: String = to_class_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
///
/// ```
/// use inflector::cases::classcase::to_class_case;
/// let mock_string: &str = "FOO_BAR";
/// let expected_string: String = "FooBar".to_string();
/// let asserted_string: String = to_class_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
///
/// ```
/// use inflector::cases::classcase::to_class_case;
/// let mock_string: &str = "foo_bar";
/// let expected_string: String = "FooBar".to_string();
/// let asserted_string: String = to_class_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
///
/// ```
/// use inflector::cases::classcase::to_class_case;
/// let mock_string: &str = "foo_bars";
/// let expected_string: String = "FooBar".to_string();
/// let asserted_string: String = to_class_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
///
/// ```
/// use inflector::cases::classcase::to_class_case;
/// let mock_string: &str = "Foo bar";
/// let expected_string: String = "FooBar".to_string();
/// let asserted_string: String = to_class_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
pub fn to_class_case(non_class_case_string: &str) -> String {
let options = CamelOptions {
new_word: true,
last_char: ' ',
first_word: false,
injectable_char: ' ',
has_seperator: false,
inverted: false,
};
let class_plural = to_case_camel_like(non_class_case_string, options);
let split: (&str, &str) =
class_plural.split_at(class_plural.rfind(char::is_uppercase).unwrap_or(0));
format!("{}{}", split.0, to_singular(split.1))
}
#[cfg(feature = "heavyweight")]
/// Determines if a `&str` is `ClassCase` `bool`
///
/// ```
/// use inflector::cases::classcase::is_class_case;
/// let mock_string: &str = "Foo";
/// let asserted_bool: bool = is_class_case(mock_string);
/// assert!(asserted_bool == true);
///
/// ```
///
/// ```
/// use inflector::cases::classcase::is_class_case;
/// let mock_string: &str = "foo";
/// let asserted_bool: bool = is_class_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
///
/// ```
/// use inflector::cases::classcase::is_class_case;
/// let mock_string: &str = "FooBarIsAReallyReallyLongStrings";
/// let asserted_bool: bool = is_class_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
///
///
/// ```
/// use inflector::cases::classcase::is_class_case;
/// let mock_string: &str = "FooBarIsAReallyReallyLongString";
/// let asserted_bool: bool = is_class_case(mock_string);
/// assert!(asserted_bool == true);
///
/// ```
///
/// ```
/// use inflector::cases::classcase::is_class_case;
/// let mock_string: &str = "foo-bar-string-that-is-really-really-long";
/// let asserted_bool: bool = is_class_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
///
/// ```
/// use inflector::cases::classcase::is_class_case;
/// let mock_string: &str = "foo_bar_is_a_really_really_long_strings";
/// let asserted_bool: bool = is_class_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
///
///
/// ```
/// use inflector::cases::classcase::is_class_case;
/// let mock_string: &str = "fooBarIsAReallyReallyLongString";
/// let asserted_bool: bool = is_class_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
///
/// ```
/// use inflector::cases::classcase::is_class_case;
/// let mock_string: &str = "FOO_BAR_STRING_THAT_IS_REALLY_REALLY_LONG";
/// let asserted_bool: bool = is_class_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
///
/// ```
/// use inflector::cases::classcase::is_class_case;
/// let mock_string: &str = "foo_bar_string_that_is_really_really_long";
/// let asserted_bool: bool = is_class_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
///
/// ```
/// use inflector::cases::classcase::is_class_case;
/// let mock_string: &str = "Foo bar string that is really really long";
/// let asserted_bool: bool = is_class_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
///
/// ```
/// use inflector::cases::classcase::is_class_case;
/// let mock_string: &str = "Foo Bar Is A Really Really Long String";
/// let asserted_bool: bool = is_class_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
pub fn is_class_case(test_string: &str) -> bool {
to_class_case(&test_string.clone()) == test_string
}
#[cfg(all(feature = "unstable", test))]
#[cfg(feature = "heavyweight")]
mod benchmarks {
extern crate test;
use self::test::Bencher;
#[bench]
fn bench_class_case(b: &mut Bencher) {
b.iter(|| super::to_class_case("Foo bar"));
}
#[bench]
fn bench_is_class(b: &mut Bencher) {
b.iter(|| super::is_class_case("Foo bar"));
}
#[bench]
fn bench_class_from_snake(b: &mut Bencher) {
b.iter(|| super::to_class_case("foo_bar"));
}
}
#[cfg(test)]
#[cfg(feature = "heavyweight")]
mod tests {
use ::to_class_case;
use ::is_class_case;
#[test]
fn from_camel_case() {
let convertable_string: String = "fooBar".to_owned();
let expected: String = "FooBar".to_owned();
assert_eq!(to_class_case(&convertable_string), expected)
}
#[test]
fn from_pascal_case() {
let convertable_string: String = "FooBar".to_owned();
let expected: String = "FooBar".to_owned();
assert_eq!(to_class_case(&convertable_string), expected)
}
#[test]
fn from_kebab_case() {
let convertable_string: String = "foo-bar".to_owned();
let expected: String = "FooBar".to_owned();
assert_eq!(to_class_case(&convertable_string), expected)
}
#[test]
fn from_sentence_case() {
let convertable_string: String = "Foo bar".to_owned();
let expected: String = "FooBar".to_owned();
assert_eq!(to_class_case(&convertable_string), expected)
}
#[test]
fn from_title_case() {
let convertable_string: String = "Foo Bar".to_owned();
let expected: String = "FooBar".to_owned();
assert_eq!(to_class_case(&convertable_string), expected)
}
#[test]
fn from_train_case() {
let convertable_string: String = "Foo-Bar".to_owned();
let expected: String = "FooBar".to_owned();
assert_eq!(to_class_case(&convertable_string), expected)
}
#[test]
fn from_screaming_class_case() {
let convertable_string: String = "FOO_BAR".to_owned();
let expected: String = "FooBar".to_owned();
assert_eq!(to_class_case(&convertable_string), expected)
}
#[test]
fn from_snake_case() {
let convertable_string: String = "foo_bar".to_owned();
let expected: String = "FooBar".to_owned();
assert_eq!(to_class_case(&convertable_string), expected)
}
#[test]
fn from_table_case() {
let convertable_string: String = "foo_bars".to_owned();
let expected: String = "FooBar".to_owned();
assert_eq!(to_class_case(&convertable_string), expected)
}
#[test]
fn from_case_with_loads_of_space() {
let convertable_string: String = "foo bar".to_owned();
let expected: String = "FooBar".to_owned();
assert_eq!(to_class_case(&convertable_string), expected)
}
#[test]
fn a_name_with_a_dot() {
let convertable_string: String = "Robert C. Martin".to_owned();
let expected: String = "RobertCMartin".to_owned();
assert_eq!(to_class_case(&convertable_string), expected)
}
#[test]
fn random_text_with_bad_chars() {
let convertable_string: String = "Random text with *(bad) chars".to_owned();
let expected: String = "RandomTextWithBadChar".to_owned();
assert_eq!(to_class_case(&convertable_string), expected)
}
#[test]
fn trailing_bad_chars() {
let convertable_string: String = "trailing bad_chars*(()())".to_owned();
let expected: String = "TrailingBadChar".to_owned();
assert_eq!(to_class_case(&convertable_string), expected)
}
#[test]
fn leading_bad_chars() {
let convertable_string: String = "-!#$%leading bad chars".to_owned();
let expected: String = "LeadingBadChar".to_owned();
assert_eq!(to_class_case(&convertable_string), expected)
}
#[test]
fn wrapped_in_bad_chars() {
let convertable_string: String = "-!#$%wrapped in bad chars&*^*&(&*^&(<><?>><?><>))".to_owned();
let expected: String = "WrappedInBadChar".to_owned();
assert_eq!(to_class_case(&convertable_string), expected)
}
#[test]
fn has_a_sign() {
let convertable_string: String = "has a + sign".to_owned();
let expected: String = "HasASign".to_owned();
assert_eq!(to_class_case(&convertable_string), expected)
}
#[test]
fn is_correct_from_class_case() {
let convertable_string: String = "fooBar".to_owned();
assert_eq!(is_class_case(&convertable_string), false)
}
#[test]
fn is_correct_from_pascal_case() {
let convertable_string: String = "FooBar".to_owned();
assert_eq!(is_class_case(&convertable_string), true)
}
#[test]
fn is_correct_from_kebab_case() {
let convertable_string: String = "foo-bar".to_owned();
assert_eq!(is_class_case(&convertable_string), false)
}
#[test]
fn is_correct_from_sentence_case() {
let convertable_string: String = "Foo bar".to_owned();
assert_eq!(is_class_case(&convertable_string), false)
}
#[test]
fn is_correct_from_title_case() {
let convertable_string: String = "Foo Bar".to_owned();
assert_eq!(is_class_case(&convertable_string), false)
}
#[test]
fn is_correct_from_train_case() {
let convertable_string: String = "Foo-Bar".to_owned();
assert_eq!(is_class_case(&convertable_string), false)
}
#[test]
fn is_correct_from_screaming_snake_case() {
let convertable_string: String = "FOO_BAR".to_owned();
assert_eq!(is_class_case(&convertable_string), false)
}
#[test]
fn is_correct_from_snake_case() {
let convertable_string: String = "foo_bar".to_owned();
assert_eq!(is_class_case(&convertable_string), false)
}
#[test]
fn is_correct_from_table_case() {
let convertable_string: String = "FooBar".to_owned();
assert_eq!(is_class_case(&convertable_string), true)
}
}

262
third_party/rust/Inflector/src/cases/kebabcase/mod.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,262 @@
#![deny(warnings)]
use cases::case::*;
/// Determines if a `&str` is `kebab-case`
///
/// ```
/// use inflector::cases::kebabcase::is_kebab_case;
/// let mock_string: &str = "foo-bar-string-that-is-really-really-long";
/// let asserted_bool: bool = is_kebab_case(mock_string);
/// assert!(asserted_bool == true);
///
/// ```
///
/// ```
/// use inflector::cases::kebabcase::is_kebab_case;
/// let mock_string: &str = "FooBarIsAReallyReallyLongString";
/// let asserted_bool: bool = is_kebab_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
///
/// ```
/// use inflector::cases::kebabcase::is_kebab_case;
/// let mock_string: &str = "fooBarIsAReallyReallyLongString";
/// let asserted_bool: bool = is_kebab_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
///
/// ```
/// use inflector::cases::kebabcase::is_kebab_case;
/// let mock_string: &str = "FOO_BAR_STRING_THAT_IS_REALLY_REALLY_LONG";
/// let asserted_bool: bool = is_kebab_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
///
/// ```
/// use inflector::cases::kebabcase::is_kebab_case;
/// let mock_string: &str = "foo_bar_string_that_is_really_really_long";
/// let asserted_bool: bool = is_kebab_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
///
/// ```
/// use inflector::cases::kebabcase::is_kebab_case;
/// let mock_string: &str = "Foo bar string that is really really long";
/// let asserted_bool: bool = is_kebab_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
///
/// ```
/// use inflector::cases::kebabcase::is_kebab_case;
/// let mock_string: &str = "Foo Bar Is A Really Really Long String";
/// let asserted_bool: bool = is_kebab_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
pub fn is_kebab_case(test_string: &str) -> bool {
test_string == to_kebab_case(test_string.clone())
}
/// Converts a `&str` to `kebab-case` `String`
///
/// ```
/// use inflector::cases::kebabcase::to_kebab_case;
/// let mock_string: &str = "foo-bar";
/// let expected_string: String = "foo-bar".to_string();
/// let asserted_string: String = to_kebab_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
///
/// ```
/// use inflector::cases::kebabcase::to_kebab_case;
/// let mock_string: &str = "FOO_BAR";
/// let expected_string: String = "foo-bar".to_string();
/// let asserted_string: String = to_kebab_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
///
/// ```
/// use inflector::cases::kebabcase::to_kebab_case;
/// let mock_string: &str = "foo_bar";
/// let expected_string: String = "foo-bar".to_string();
/// let asserted_string: String = to_kebab_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
///
/// ```
/// use inflector::cases::kebabcase::to_kebab_case;
/// let mock_string: &str = "Foo Bar";
/// let expected_string: String = "foo-bar".to_string();
/// let asserted_string: String = to_kebab_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
///
/// ```
/// use inflector::cases::kebabcase::to_kebab_case;
/// let mock_string: &str = "Foo bar";
/// let expected_string: String = "foo-bar".to_string();
/// let asserted_string: String = to_kebab_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
///
/// ```
/// use inflector::cases::kebabcase::to_kebab_case;
/// let mock_string: &str = "FooBar";
/// let expected_string: String = "foo-bar".to_string();
/// let asserted_string: String = to_kebab_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
///
/// ```
/// use inflector::cases::kebabcase::to_kebab_case;
/// let mock_string: &str = "fooBar";
/// let expected_string: String = "foo-bar".to_string();
/// let asserted_string: String = to_kebab_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
pub fn to_kebab_case(non_kebab_case_string: &str) -> String {
to_case_snake_like(non_kebab_case_string, "-", "lower")
}
#[cfg(all(feature = "unstable", test))]
mod benchmarks {
extern crate test;
use self::test::Bencher;
#[bench]
fn bench_kebab(b: &mut Bencher) {
b.iter(|| super::to_kebab_case("Foo bar"));
}
#[bench]
fn bench_is_kebab(b: &mut Bencher) {
b.iter(|| super::is_kebab_case("Foo bar"));
}
#[bench]
fn bench_kebab_from_snake(b: &mut Bencher) {
b.iter(|| super::to_kebab_case("test_test_test"));
}
}
#[cfg(test)]
mod tests {
use ::to_kebab_case;
use ::is_kebab_case;
#[test]
fn from_camel_case() {
let convertable_string: String = "fooBar".to_owned();
let expected: String = "foo-bar".to_owned();
assert_eq!(to_kebab_case(&convertable_string), expected)
}
#[test]
fn from_pascal_case() {
let convertable_string: String = "FooBar".to_owned();
let expected: String = "foo-bar".to_owned();
assert_eq!(to_kebab_case(&convertable_string), expected)
}
#[test]
fn from_kebab_case() {
let convertable_string: String = "foo-bar".to_owned();
let expected: String = "foo-bar".to_owned();
assert_eq!(to_kebab_case(&convertable_string), expected)
}
#[test]
fn from_sentence_case() {
let convertable_string: String = "Foo bar".to_owned();
let expected: String = "foo-bar".to_owned();
assert_eq!(to_kebab_case(&convertable_string), expected)
}
#[test]
fn from_title_case() {
let convertable_string: String = "Foo Bar".to_owned();
let expected: String = "foo-bar".to_owned();
assert_eq!(to_kebab_case(&convertable_string), expected)
}
#[test]
fn from_train_case() {
let convertable_string: String = "Foo-Bar".to_owned();
let expected: String = "foo-bar".to_owned();
assert_eq!(to_kebab_case(&convertable_string), expected)
}
#[test]
fn from_screaming_snake_case() {
let convertable_string: String = "FOO_BAR".to_owned();
let expected: String = "foo-bar".to_owned();
assert_eq!(to_kebab_case(&convertable_string), expected)
}
#[test]
fn from_snake_case() {
let convertable_string: String = "foo_bar".to_owned();
let expected: String = "foo-bar".to_owned();
assert_eq!(to_kebab_case(&convertable_string), expected)
}
#[test]
fn is_correct_from_camel_case() {
let convertable_string: String = "fooBar".to_owned();
assert_eq!(is_kebab_case(&convertable_string), false)
}
#[test]
fn is_correct_from_pascal_case() {
let convertable_string: String = "FooBar".to_owned();
assert_eq!(is_kebab_case(&convertable_string), false)
}
#[test]
fn is_correct_from_kebab_case() {
let convertable_string: String = "foo-bar".to_owned();
assert_eq!(is_kebab_case(&convertable_string), true)
}
#[test]
fn is_correct_from_sentence_case() {
let convertable_string: String = "Foo bar".to_owned();
assert_eq!(is_kebab_case(&convertable_string), false)
}
#[test]
fn is_correct_from_title_case() {
let convertable_string: String = "Foo Bar".to_owned();
assert_eq!(is_kebab_case(&convertable_string), false)
}
#[test]
fn is_correct_from_train_case() {
let convertable_string: String = "Foo-Bar".to_owned();
assert_eq!(is_kebab_case(&convertable_string), false)
}
#[test]
fn is_correct_from_screaming_snake_case() {
let convertable_string: String = "FOO_BAR".to_owned();
assert_eq!(is_kebab_case(&convertable_string), false)
}
#[test]
fn is_correct_from_snake_case() {
let convertable_string: String = "foo_bar".to_owned();
assert_eq!(is_kebab_case(&convertable_string), false)
}
}

52
third_party/rust/Inflector/src/cases/mod.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,52 @@
mod case;
/// Provides conversion to and detection of class case strings.
///
/// This version singularizes strings.
///
/// Example string `ClassCase`
pub mod classcase;
/// Provides conversion to and detection of camel case strings.
///
/// Example string `camelCase`
pub mod camelcase;
/// Provides conversion to and detection of snake case strings.
///
/// Example string `snake_case`
pub mod snakecase;
/// Provides conversion to and detection of screaming snake case strings.
///
/// Example string `SCREAMING_SNAKE_CASE`
pub mod screamingsnakecase;
/// Provides conversion to and detection of kebab case strings.
///
/// Example string `kebab-case`
pub mod kebabcase;
/// Provides conversion to and detection of train case strings.
///
/// Example string `Train-Case`
pub mod traincase;
/// Provides conversion to and detection of sentence case strings.
///
/// Example string `Sentence case`
pub mod sentencecase;
/// Provides conversion to and detection of title case strings.
///
/// Example string `Title Case`
pub mod titlecase;
/// Provides conversion to and detection of table case strings.
///
/// Example string `table_cases`
pub mod tablecase;
/// Provides conversion to pascal case strings.
///
/// Example string `PascalCase`
pub mod pascalcase;

360
third_party/rust/Inflector/src/cases/pascalcase/mod.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,360 @@
#![deny(warnings)]
use cases::case::*;
/// Converts a `&str` to pascalCase `String`
///
/// ```
/// use inflector::cases::pascalcase::to_pascal_case;
/// let mock_string: &str = "fooBar";
/// let expected_string: String = "FooBar".to_string();
/// let asserted_string: String = to_pascal_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::pascalcase::to_pascal_case;
/// let mock_string: &str = "FOO_BAR";
/// let expected_string: String = "FooBar".to_string();
/// let asserted_string: String = to_pascal_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::pascalcase::to_pascal_case;
/// let mock_string: &str = "Foo Bar";
/// let expected_string: String = "FooBar".to_string();
/// let asserted_string: String = to_pascal_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::pascalcase::to_pascal_case;
/// let mock_string: &str = "foo_bar";
/// let expected_string: String = "FooBar".to_string();
/// let asserted_string: String = to_pascal_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::pascalcase::to_pascal_case;
/// let mock_string: &str = "Foo bar";
/// let expected_string: String = "FooBar".to_string();
/// let asserted_string: String = to_pascal_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::pascalcase::to_pascal_case;
/// let mock_string: &str = "foo-bar";
/// let expected_string: String = "FooBar".to_string();
/// let asserted_string: String = to_pascal_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::pascalcase::to_pascal_case;
/// let mock_string: &str = "FooBar";
/// let expected_string: String = "FooBar".to_string();
/// let asserted_string: String = to_pascal_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::pascalcase::to_pascal_case;
/// let mock_string: &str = "FooBar3";
/// let expected_string: String = "FooBar3".to_string();
/// let asserted_string: String = to_pascal_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
pub fn to_pascal_case(non_pascalized_string: &str) -> String {
let options = CamelOptions {
new_word: true,
last_char: ' ',
first_word: false,
injectable_char: ' ',
has_seperator: false,
inverted: false,
};
to_case_camel_like(non_pascalized_string, options)
}
/// Determines if a `&str` is pascalCase bool``
///
/// ```
/// use inflector::cases::pascalcase::is_pascal_case;
/// let mock_string: &str = "Foo";
/// let asserted_bool: bool = is_pascal_case(mock_string);
/// assert!(asserted_bool == true);
///
///
/// ```
/// ```
/// use inflector::cases::pascalcase::is_pascal_case;
/// let mock_string: &str = "foo";
/// let asserted_bool: bool = is_pascal_case(mock_string);
/// assert!(asserted_bool == false);
///
///
/// ```
/// ```
/// use inflector::cases::pascalcase::is_pascal_case;
/// let mock_string: &str = "foo-bar-string-that-is-really-really-long";
/// let asserted_bool: bool = is_pascal_case(mock_string);
/// assert!(asserted_bool == false);
///
///
/// ```
/// ```
/// use inflector::cases::pascalcase::is_pascal_case;
/// let mock_string: &str = "FooBarIsAReallyReallyLongString";
/// let asserted_bool: bool = is_pascal_case(mock_string);
/// assert!(asserted_bool == true);
///
///
/// ```
/// ```
/// use inflector::cases::pascalcase::is_pascal_case;
/// let mock_string: &str = "FooBarIsAReallyReally3LongString";
/// let asserted_bool: bool = is_pascal_case(mock_string);
/// assert!(asserted_bool == true);
///
///
/// ```
/// ```
/// use inflector::cases::pascalcase::is_pascal_case;
/// let mock_string: &str = "FooBarIsAReallyReallyLongString";
/// let asserted_bool: bool = is_pascal_case(mock_string);
/// assert!(asserted_bool == true);
///
///
/// ```
/// ```
/// use inflector::cases::pascalcase::is_pascal_case;
/// let mock_string: &str = "FOO_BAR_STRING_THAT_IS_REALLY_REALLY_LONG";
/// let asserted_bool: bool = is_pascal_case(mock_string);
/// assert!(asserted_bool == false);
///
///
/// ```
/// ```
/// use inflector::cases::pascalcase::is_pascal_case;
/// let mock_string: &str = "foo_bar_string_that_is_really_really_long";
/// let asserted_bool: bool = is_pascal_case(mock_string);
/// assert!(asserted_bool == false);
///
///
/// ```
/// ```
/// use inflector::cases::pascalcase::is_pascal_case;
/// let mock_string: &str = "Foo bar string that is really really long";
/// let asserted_bool: bool = is_pascal_case(mock_string);
/// assert!(asserted_bool == false);
///
///
/// ```
/// ```
/// use inflector::cases::pascalcase::is_pascal_case;
/// let mock_string: &str = "Foo Bar Is A Really Really Long String";
/// let asserted_bool: bool = is_pascal_case(mock_string);
/// assert!(asserted_bool == false);
/// ```
pub fn is_pascal_case(test_string: &str) -> bool {
to_pascal_case(test_string.clone()) == test_string
}
#[cfg(all(feature = "unstable", test))]
mod benchmarks {
extern crate test;
use self::test::Bencher;
#[bench]
fn bench_pascal0(b: &mut Bencher) {
b.iter(|| {
let test_string = "Foo bar";
super::to_pascal_case(test_string)
});
}
#[bench]
fn bench_pascal1(b: &mut Bencher) {
b.iter(|| {
let test_string = "foo_bar";
super::to_pascal_case(test_string)
});
}
#[bench]
fn bench_pascal2(b: &mut Bencher) {
b.iter(|| {
let test_string = "fooBar";
super::to_pascal_case(test_string)
});
}
#[bench]
fn bench_is_pascal(b: &mut Bencher) {
b.iter(|| {
let test_string: &str = "Foo bar";
super::is_pascal_case(test_string)
});
}
}
#[cfg(test)]
mod tests {
use ::to_pascal_case;
use ::is_pascal_case;
#[test]
fn from_camel_case() {
let convertable_string: String = "fooBar".to_owned();
let expected: String = "FooBar".to_owned();
assert_eq!(to_pascal_case(&convertable_string), expected)
}
#[test]
fn from_pascal_case() {
let convertable_string: String = "FooBar".to_owned();
let expected: String = "FooBar".to_owned();
assert_eq!(to_pascal_case(&convertable_string), expected)
}
#[test]
fn from_kebab_case() {
let convertable_string: String = "foo-bar".to_owned();
let expected: String = "FooBar".to_owned();
assert_eq!(to_pascal_case(&convertable_string), expected)
}
#[test]
fn from_sentence_case() {
let convertable_string: String = "Foo bar".to_owned();
let expected: String = "FooBar".to_owned();
assert_eq!(to_pascal_case(&convertable_string), expected)
}
#[test]
fn from_title_case() {
let convertable_string: String = "Foo Bar".to_owned();
let expected: String = "FooBar".to_owned();
assert_eq!(to_pascal_case(&convertable_string), expected)
}
#[test]
fn from_train_case() {
let convertable_string: String = "Foo-Bar".to_owned();
let expected: String = "FooBar".to_owned();
assert_eq!(to_pascal_case(&convertable_string), expected)
}
#[test]
fn from_screaming_snake_case() {
let convertable_string: String = "FOO_BAR".to_owned();
let expected: String = "FooBar".to_owned();
assert_eq!(to_pascal_case(&convertable_string), expected)
}
#[test]
fn from_snake_case() {
let convertable_string: String = "foo_bar".to_owned();
let expected: String = "FooBar".to_owned();
assert_eq!(to_pascal_case(&convertable_string), expected)
}
#[test]
fn from_case_with_loads_of_space() {
let convertable_string: String = "foo bar".to_owned();
let expected: String = "FooBar".to_owned();
assert_eq!(to_pascal_case(&convertable_string), expected)
}
#[test]
fn a_name_with_a_dot() {
let convertable_string: String = "Robert C. Martin".to_owned();
let expected: String = "RobertCMartin".to_owned();
assert_eq!(to_pascal_case(&convertable_string), expected)
}
#[test]
fn random_text_with_bad_chars() {
let convertable_string: String = "Random text with *(bad) chars".to_owned();
let expected: String = "RandomTextWithBadChars".to_owned();
assert_eq!(to_pascal_case(&convertable_string), expected)
}
#[test]
fn trailing_bad_chars() {
let convertable_string: String = "trailing bad_chars*(()())".to_owned();
let expected: String = "TrailingBadChars".to_owned();
assert_eq!(to_pascal_case(&convertable_string), expected)
}
#[test]
fn leading_bad_chars() {
let convertable_string: String = "-!#$%leading bad chars".to_owned();
let expected: String = "LeadingBadChars".to_owned();
assert_eq!(to_pascal_case(&convertable_string), expected)
}
#[test]
fn wrapped_in_bad_chars() {
let convertable_string: String = "-!#$%wrapped in bad chars&*^*&(&*^&(<><?>><?><>))".to_owned();
let expected: String = "WrappedInBadChars".to_owned();
assert_eq!(to_pascal_case(&convertable_string), expected)
}
#[test]
fn has_a_sign() {
let convertable_string: String = "has a + sign".to_owned();
let expected: String = "HasASign".to_owned();
assert_eq!(to_pascal_case(&convertable_string), expected)
}
#[test]
fn is_correct_from_camel_case() {
let convertable_string: String = "fooBar".to_owned();
assert_eq!(is_pascal_case(&convertable_string), false)
}
#[test]
fn is_correct_from_pascal_case() {
let convertable_string: String = "FooBar".to_owned();
assert_eq!(is_pascal_case(&convertable_string), true)
}
#[test]
fn is_correct_from_kebab_case() {
let convertable_string: String = "foo-bar".to_owned();
assert_eq!(is_pascal_case(&convertable_string), false)
}
#[test]
fn is_correct_from_sentence_case() {
let convertable_string: String = "Foo bar".to_owned();
assert_eq!(is_pascal_case(&convertable_string), false)
}
#[test]
fn is_correct_from_title_case() {
let convertable_string: String = "Foo Bar".to_owned();
assert_eq!(is_pascal_case(&convertable_string), false)
}
#[test]
fn is_correct_from_train_case() {
let convertable_string: String = "Foo-Bar".to_owned();
assert_eq!(is_pascal_case(&convertable_string), false)
}
#[test]
fn is_correct_from_screaming_snake_case() {
let convertable_string: String = "FOO_BAR".to_owned();
assert_eq!(is_pascal_case(&convertable_string), false)
}
#[test]
fn is_correct_from_snake_case() {
let convertable_string: String = "foo_bar".to_owned();
assert_eq!(is_pascal_case(&convertable_string), false)
}
}

253
third_party/rust/Inflector/src/cases/screamingsnakecase/mod.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,253 @@
#![deny(warnings)]
use cases::case::*;
/// Converts a `&str` to `SCREAMING_SNAKE_CASE` `String`
///
/// ```
/// use inflector::cases::screamingsnakecase::to_screaming_snake_case;
/// let mock_string: &str = "foo_bar";
/// let expected_string: String = "FOO_BAR".to_string();
/// let asserted_string: String = to_screaming_snake_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::screamingsnakecase::to_screaming_snake_case;
/// let mock_string: &str = "HTTP Foo bar";
/// let expected_string: String = "HTTP_FOO_BAR".to_string();
/// let asserted_string: String = to_screaming_snake_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::screamingsnakecase::to_screaming_snake_case;
/// let mock_string: &str = "Foo bar";
/// let expected_string: String = "FOO_BAR".to_string();
/// let asserted_string: String = to_screaming_snake_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::screamingsnakecase::to_screaming_snake_case;
/// let mock_string: &str = "Foo Bar";
/// let expected_string: String = "FOO_BAR".to_string();
/// let asserted_string: String = to_screaming_snake_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::screamingsnakecase::to_screaming_snake_case;
/// let mock_string: &str = "FooBar";
/// let expected_string: String = "FOO_BAR".to_string();
/// let asserted_string: String = to_screaming_snake_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::screamingsnakecase::to_screaming_snake_case;
/// let mock_string: &str = "fooBar";
/// let expected_string: String = "FOO_BAR".to_string();
/// let asserted_string: String = to_screaming_snake_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::screamingsnakecase::to_screaming_snake_case;
/// let mock_string: &str = "fooBar3";
/// let expected_string: String = "FOO_BAR_3".to_string();
/// let asserted_string: String = to_screaming_snake_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
pub fn to_screaming_snake_case(non_snake_case_string: &str) -> String {
to_case_snake_like(non_snake_case_string, "_", "upper")
}
/// Determines of a `&str` is `SCREAMING_SNAKE_CASE`
///
/// ```
/// use inflector::cases::screamingsnakecase::is_screaming_snake_case;
/// let mock_string: &str = "Foo bar string that is really really long";
/// let asserted_bool: bool = is_screaming_snake_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
/// ```
/// use inflector::cases::screamingsnakecase::is_screaming_snake_case;
/// let mock_string: &str = "foo-bar-string-that-is-really-really-long";
/// let asserted_bool: bool = is_screaming_snake_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
/// ```
/// use inflector::cases::screamingsnakecase::is_screaming_snake_case;
/// let mock_string: &str = "FooBarIsAReallyReallyLongString";
/// let asserted_bool: bool = is_screaming_snake_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
/// ```
/// use inflector::cases::screamingsnakecase::is_screaming_snake_case;
/// let mock_string: &str = "Foo Bar Is A Really Really Long String";
/// let asserted_bool: bool = is_screaming_snake_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
/// ```
/// use inflector::cases::screamingsnakecase::is_screaming_snake_case;
/// let mock_string: &str = "fooBarIsAReallyReallyLongString";
/// let asserted_bool: bool = is_screaming_snake_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
/// ```
/// use inflector::cases::screamingsnakecase::is_screaming_snake_case;
/// let mock_string: &str = "FOO_BAR_STRING_THAT_IS_REALLY_REALLY_LONG";
/// let asserted_bool: bool = is_screaming_snake_case(mock_string);
/// assert!(asserted_bool == true);
///
/// ```
/// ```
/// use inflector::cases::screamingsnakecase::is_screaming_snake_case;
/// let mock_string: &str = "FOO_BAR1_STRING_THAT_IS_REALLY_REALLY_LONG";
/// let asserted_bool: bool = is_screaming_snake_case(mock_string);
/// assert!(asserted_bool == true);
///
/// ```
/// ```
/// use inflector::cases::screamingsnakecase::is_screaming_snake_case;
/// let mock_string: &str = "FOO_BAR_1_STRING_THAT_IS_REALLY_REALLY_LONG";
/// let asserted_bool: bool = is_screaming_snake_case(mock_string);
/// assert!(asserted_bool == true);
///
/// ```
pub fn is_screaming_snake_case(test_string: &str) -> bool {
test_string == to_screaming_snake_case(test_string.clone())
}
#[cfg(all(feature = "unstable", test))]
mod benchmarks {
extern crate test;
use self::test::Bencher;
#[bench]
fn bench_screaming_snake(b: &mut Bencher) {
b.iter(|| super::to_screaming_snake_case("Foo bar"));
}
#[bench]
fn bench_is_screaming_snake(b: &mut Bencher) {
b.iter(|| super::is_screaming_snake_case("Foo bar"));
}
}
#[cfg(test)]
mod tests {
use ::to_screaming_snake_case;
use ::is_screaming_snake_case;
#[test]
fn from_camel_case() {
let convertable_string: String = "fooBar".to_owned();
let expected: String = "FOO_BAR".to_owned();
assert_eq!(to_screaming_snake_case(&convertable_string), expected)
}
#[test]
fn from_pascal_case() {
let convertable_string: String = "FooBar".to_owned();
let expected: String = "FOO_BAR".to_owned();
assert_eq!(to_screaming_snake_case(&convertable_string), expected)
}
#[test]
fn from_kebab_case() {
let convertable_string: String = "foo-bar".to_owned();
let expected: String = "FOO_BAR".to_owned();
assert_eq!(to_screaming_snake_case(&convertable_string), expected)
}
#[test]
fn from_sentence_case() {
let convertable_string: String = "Foo bar".to_owned();
let expected: String = "FOO_BAR".to_owned();
assert_eq!(to_screaming_snake_case(&convertable_string), expected)
}
#[test]
fn from_title_case() {
let convertable_string: String = "Foo Bar".to_owned();
let expected: String = "FOO_BAR".to_owned();
assert_eq!(to_screaming_snake_case(&convertable_string), expected)
}
#[test]
fn from_train_case() {
let convertable_string: String = "Foo-Bar".to_owned();
let expected: String = "FOO_BAR".to_owned();
assert_eq!(to_screaming_snake_case(&convertable_string), expected)
}
#[test]
fn from_screaming_screaming_snake_case() {
let convertable_string: String = "FOO_BAR".to_owned();
let expected: String = "FOO_BAR".to_owned();
assert_eq!(to_screaming_snake_case(&convertable_string), expected)
}
#[test]
fn from_snake_case() {
let convertable_string: String = "foo_bar".to_owned();
let expected: String = "FOO_BAR".to_owned();
assert_eq!(to_screaming_snake_case(&convertable_string), expected)
}
#[test]
fn is_correct_from_camel_case() {
let convertable_string: String = "fooBar".to_owned();
assert_eq!(is_screaming_snake_case(&convertable_string), false)
}
#[test]
fn is_correct_from_pascal_case() {
let convertable_string: String = "FooBar".to_owned();
assert_eq!(is_screaming_snake_case(&convertable_string), false)
}
#[test]
fn is_correct_from_kebab_case() {
let convertable_string: String = "foo-bar".to_owned();
assert_eq!(is_screaming_snake_case(&convertable_string), false)
}
#[test]
fn is_correct_from_sentence_case() {
let convertable_string: String = "Foo bar".to_owned();
assert_eq!(is_screaming_snake_case(&convertable_string), false)
}
#[test]
fn is_correct_from_title_case() {
let convertable_string: String = "Foo Bar".to_owned();
assert_eq!(is_screaming_snake_case(&convertable_string), false)
}
#[test]
fn is_correct_from_train_case() {
let convertable_string: String = "Foo-Bar".to_owned();
assert_eq!(is_screaming_snake_case(&convertable_string), false)
}
#[test]
fn is_correct_from_screaming_screaming_snake_case() {
let convertable_string: String = "FOO_BAR".to_owned();
assert_eq!(is_screaming_snake_case(&convertable_string), true)
}
#[test]
fn is_correct_from_snake_case() {
let convertable_string: String = "foo_bar".to_owned();
assert_eq!(is_screaming_snake_case(&convertable_string), false)
}
}

313
third_party/rust/Inflector/src/cases/sentencecase/mod.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,313 @@
#![deny(warnings)]
use cases::case::*;
/// Converts a `&str` to `Sentence case` `String`
///
/// ```
/// use inflector::cases::sentencecase::to_sentence_case;
/// let mock_string: &str = "Foo bar";
/// let expected_string: String = "Foo bar".to_string();
/// let asserted_string: String = to_sentence_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::sentencecase::to_sentence_case;
/// let mock_string: &str = "FooBar";
/// let expected_string: String = "Foo bar".to_string();
/// let asserted_string: String = to_sentence_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::sentencecase::to_sentence_case;
/// let mock_string: &str = "fooBar";
/// let expected_string: String = "Foo bar".to_string();
/// let asserted_string: String = to_sentence_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::sentencecase::to_sentence_case;
/// let mock_string: &str = "FOO_BAR";
/// let expected_string: String = "Foo bar".to_string();
/// let asserted_string: String = to_sentence_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::sentencecase::to_sentence_case;
/// let mock_string: &str = "foo_bar";
/// let expected_string: String = "Foo bar".to_string();
/// let asserted_string: String = to_sentence_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::sentencecase::to_sentence_case;
/// let mock_string: &str = "foo-bar";
/// let expected_string: String = "Foo bar".to_string();
/// let asserted_string: String = to_sentence_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
pub fn to_sentence_case(non_sentence_case_string: &str) -> String {
let options = CamelOptions {
new_word: true,
last_char: ' ',
first_word: true,
injectable_char: ' ',
has_seperator: true,
inverted: true,
};
to_case_camel_like(non_sentence_case_string, options)
}
/// Determines of a `&str` is `Sentence case`
///
/// ```
/// use inflector::cases::sentencecase::is_sentence_case;
/// let mock_string: &str = "foo-bar-string-that-is-really-really-long";
/// let asserted_bool: bool = is_sentence_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
/// ```
/// use inflector::cases::sentencecase::is_sentence_case;
/// let mock_string: &str = "FooBarIsAReallyReallyLongString";
/// let asserted_bool: bool = is_sentence_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
/// ```
/// use inflector::cases::sentencecase::is_sentence_case;
/// let mock_string: &str = "fooBarIsAReallyReallyLongString";
/// let asserted_bool: bool = is_sentence_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
/// ```
/// use inflector::cases::sentencecase::is_sentence_case;
/// let mock_string: &str = "Foo Bar Is A Really Really Long String";
/// let asserted_bool: bool = is_sentence_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
/// ```
/// use inflector::cases::sentencecase::is_sentence_case;
/// let mock_string: &str = "FOO_BAR_STRING_THAT_IS_REALLY_REALLY_LONG";
/// let asserted_bool: bool = is_sentence_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
/// ```
/// use inflector::cases::sentencecase::is_sentence_case;
/// let mock_string: &str = "foo_bar_string_that_is_really_really_long";
/// let asserted_bool: bool = is_sentence_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
/// ```
/// use inflector::cases::sentencecase::is_sentence_case;
/// let mock_string: &str = "Foo";
/// let asserted_bool: bool = is_sentence_case(mock_string);
/// assert!(asserted_bool == true);
///
/// ```
/// ```
/// use inflector::cases::sentencecase::is_sentence_case;
/// let mock_string: &str = "foo";
/// let asserted_bool: bool = is_sentence_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
/// ```
/// use inflector::cases::sentencecase::is_sentence_case;
/// let mock_string: &str = "Foo bar string that is really really long";
/// let asserted_bool: bool = is_sentence_case(mock_string);
/// assert!(asserted_bool == true);
///
/// ```
pub fn is_sentence_case(test_string: &str) -> bool {
test_string == to_sentence_case(test_string.clone())
}
#[cfg(all(feature = "unstable", test))]
mod benchmarks {
extern crate test;
use self::test::Bencher;
#[bench]
fn bench_sentence(b: &mut Bencher) {
b.iter(|| super::to_sentence_case("Foo BAR"));
}
#[bench]
fn bench_is_sentence(b: &mut Bencher) {
b.iter(|| super::is_sentence_case("Foo bar"));
}
#[bench]
fn bench_sentence_from_snake(b: &mut Bencher) {
b.iter(|| super::to_sentence_case("foo_bar"));
}
}
#[cfg(test)]
mod tests {
use ::to_sentence_case;
use ::is_sentence_case;
#[test]
fn from_camel_case() {
let convertable_string: String = "fooBar".to_owned();
let expected: String = "Foo bar".to_owned();
assert_eq!(to_sentence_case(&convertable_string), expected)
}
#[test]
fn from_pascal_case() {
let convertable_string: String = "FooBar".to_owned();
let expected: String = "Foo bar".to_owned();
assert_eq!(to_sentence_case(&convertable_string), expected)
}
#[test]
fn from_kebab_case() {
let convertable_string: String = "foo-bar".to_owned();
let expected: String = "Foo bar".to_owned();
assert_eq!(to_sentence_case(&convertable_string), expected)
}
#[test]
fn from_sentence_case() {
let convertable_string: String = "Foo bar".to_owned();
let expected: String = "Foo bar".to_owned();
assert_eq!(to_sentence_case(&convertable_string), expected)
}
#[test]
fn from_title_case() {
let convertable_string: String = "Foo Bar".to_owned();
let expected: String = "Foo bar".to_owned();
assert_eq!(to_sentence_case(&convertable_string), expected)
}
#[test]
fn from_train_case() {
let convertable_string: String = "Foo-Bar".to_owned();
let expected: String = "Foo bar".to_owned();
assert_eq!(to_sentence_case(&convertable_string), expected)
}
#[test]
fn from_screaming_snake_case() {
let convertable_string: String = "FOO_BAR".to_owned();
let expected: String = "Foo bar".to_owned();
assert_eq!(to_sentence_case(&convertable_string), expected)
}
#[test]
fn from_snake_case() {
let convertable_string: String = "foo_bar".to_owned();
let expected: String = "Foo bar".to_owned();
assert_eq!(to_sentence_case(&convertable_string), expected)
}
#[test]
fn from_case_with_loads_of_space() {
let convertable_string: String = "foo bar".to_owned();
let expected: String = "Foo bar".to_owned();
assert_eq!(to_sentence_case(&convertable_string), expected)
}
#[test]
fn a_name_with_a_dot() {
let convertable_string: String = "Robert C. Martin".to_owned();
let expected: String = "Robert c martin".to_owned();
assert_eq!(to_sentence_case(&convertable_string), expected)
}
#[test]
fn random_text_with_bad_chars() {
let convertable_string: String = "Random text with *(bad) chars".to_owned();
let expected: String = "Random text with bad chars".to_owned();
assert_eq!(to_sentence_case(&convertable_string), expected)
}
#[test]
fn trailing_bad_chars() {
let convertable_string: String = "trailing bad_chars*(()())".to_owned();
let expected: String = "Trailing bad chars".to_owned();
assert_eq!(to_sentence_case(&convertable_string), expected)
}
#[test]
fn leading_bad_chars() {
let convertable_string: String = "-!#$%leading bad chars".to_owned();
let expected: String = "Leading bad chars".to_owned();
assert_eq!(to_sentence_case(&convertable_string), expected)
}
#[test]
fn wrapped_in_bad_chars() {
let convertable_string: String = "-!#$%wrapped in bad chars&*^*&(&*^&(<><?>><?><>))".to_owned();
let expected: String = "Wrapped in bad chars".to_owned();
assert_eq!(to_sentence_case(&convertable_string), expected)
}
#[test]
fn has_a_sign() {
let convertable_string: String = "has a + sign".to_owned();
let expected: String = "Has a sign".to_owned();
assert_eq!(to_sentence_case(&convertable_string), expected)
}
#[test]
fn is_correct_from_camel_case() {
let convertable_string: String = "fooBar".to_owned();
assert_eq!(is_sentence_case(&convertable_string), false)
}
#[test]
fn is_correct_from_pascal_case() {
let convertable_string: String = "FooBar".to_owned();
assert_eq!(is_sentence_case(&convertable_string), false)
}
#[test]
fn is_correct_from_kebab_case() {
let convertable_string: String = "foo-bar".to_owned();
assert_eq!(is_sentence_case(&convertable_string), false)
}
#[test]
fn is_correct_from_sentence_case() {
let convertable_string: String = "Foo bar".to_owned();
assert_eq!(is_sentence_case(&convertable_string), true)
}
#[test]
fn is_correct_from_title_case() {
let convertable_string: String = "Foo Bar".to_owned();
assert_eq!(is_sentence_case(&convertable_string), false)
}
#[test]
fn is_correct_from_train_case() {
let convertable_string: String = "Foo-Bar".to_owned();
assert_eq!(is_sentence_case(&convertable_string), false)
}
#[test]
fn is_correct_from_screaming_snake_case() {
let convertable_string: String = "FOO_BAR".to_owned();
assert_eq!(is_sentence_case(&convertable_string), false)
}
#[test]
fn is_correct_from_snake_case() {
let convertable_string: String = "foo_bar".to_owned();
assert_eq!(is_sentence_case(&convertable_string), false)
}
}

334
third_party/rust/Inflector/src/cases/snakecase/mod.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,334 @@
#![deny(warnings)]
use cases::case::*;
/// Converts a `&str` to `snake_case` `String`
///
/// ```
/// use inflector::cases::snakecase::to_snake_case;
/// let mock_string: &str = "foo_bar";
/// let expected_string: String = "foo_bar".to_string();
/// let asserted_string: String = to_snake_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::snakecase::to_snake_case;
/// let mock_string: &str = "HTTP Foo bar";
/// let expected_string: String = "http_foo_bar".to_string();
/// let asserted_string: String = to_snake_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::snakecase::to_snake_case;
/// let mock_string: &str = "HTTPFooBar";
/// let expected_string: String = "http_foo_bar".to_string();
/// let asserted_string: String = to_snake_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::snakecase::to_snake_case;
/// let mock_string: &str = "Foo bar";
/// let expected_string: String = "foo_bar".to_string();
/// let asserted_string: String = to_snake_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::snakecase::to_snake_case;
/// let mock_string: &str = "Foo Bar";
/// let expected_string: String = "foo_bar".to_string();
/// let asserted_string: String = to_snake_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::snakecase::to_snake_case;
/// let mock_string: &str = "FooBar";
/// let expected_string: String = "foo_bar".to_string();
/// let asserted_string: String = to_snake_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::snakecase::to_snake_case;
/// let mock_string: &str = "FOO_BAR";
/// let expected_string: String = "foo_bar".to_string();
/// let asserted_string: String = to_snake_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::snakecase::to_snake_case;
/// let mock_string: &str = "fooBar";
/// let expected_string: String = "foo_bar".to_string();
/// let asserted_string: String = to_snake_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::snakecase::to_snake_case;
/// let mock_string: &str = "fooBar3";
/// let expected_string: String = "foo_bar_3".to_string();
/// let asserted_string: String = to_snake_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
pub fn to_snake_case(non_snake_case_string: &str) -> String {
to_case_snake_like(non_snake_case_string, "_", "lower")
}
/// Determines of a `&str` is `snake_case`
///
/// ```
/// use inflector::cases::snakecase::is_snake_case;
/// let mock_string: &str = "Foo bar string that is really really long";
/// let asserted_bool: bool = is_snake_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
/// ```
/// use inflector::cases::snakecase::is_snake_case;
/// let mock_string: &str = "foo-bar-string-that-is-really-really-long";
/// let asserted_bool: bool = is_snake_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
/// ```
/// use inflector::cases::snakecase::is_snake_case;
/// let mock_string: &str = "FooBarIsAReallyReallyLongString";
/// let asserted_bool: bool = is_snake_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
/// ```
/// use inflector::cases::snakecase::is_snake_case;
/// let mock_string: &str = "Foo Bar Is A Really Really Long String";
/// let asserted_bool: bool = is_snake_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
/// ```
/// use inflector::cases::snakecase::is_snake_case;
/// let mock_string: &str = "FOO_BAR_IS_A_REALLY_REALLY_LONG_STRING";
/// let asserted_bool: bool = is_snake_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
/// ```
/// use inflector::cases::snakecase::is_snake_case;
/// let mock_string: &str = "fooBarIsAReallyReallyLongString";
/// let asserted_bool: bool = is_snake_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
/// ```
/// use inflector::cases::snakecase::is_snake_case;
/// let mock_string: &str = "foo_bar_string_that_is_really_really_long";
/// let asserted_bool: bool = is_snake_case(mock_string);
/// assert!(asserted_bool == true);
///
/// ```
/// ```
/// use inflector::cases::snakecase::is_snake_case;
/// let mock_string: &str = "foo_bar1_string_that_is_really_really_long";
/// let asserted_bool: bool = is_snake_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
/// ```
/// use inflector::cases::snakecase::is_snake_case;
/// let mock_string: &str = "foo_bar_1_string_that_is_really_really_long";
/// let asserted_bool: bool = is_snake_case(mock_string);
/// assert!(asserted_bool == true);
///
/// ```
pub fn is_snake_case(test_string: &str) -> bool {
test_string == to_snake_case(test_string.clone())
}
#[cfg(all(feature = "unstable", test))]
mod benchmarks {
extern crate test;
use self::test::Bencher;
#[bench]
fn bench_snake_from_title(b: &mut Bencher) {
b.iter(|| super::to_snake_case("Foo bar"));
}
#[bench]
fn bench_snake_from_camel(b: &mut Bencher) {
b.iter(|| super::to_snake_case("fooBar"));
}
#[bench]
fn bench_snake_from_snake(b: &mut Bencher) {
b.iter(|| super::to_snake_case("foo_bar_bar_bar"));
}
#[bench]
fn bench_is_snake(b: &mut Bencher) {
b.iter(|| super::is_snake_case("Foo bar"));
}
}
#[cfg(test)]
mod tests {
use ::to_snake_case;
use ::is_snake_case;
#[test]
fn from_camel_case() {
let convertable_string: String = "fooBar".to_owned();
let expected: String = "foo_bar".to_owned();
assert_eq!(to_snake_case(&convertable_string), expected)
}
#[test]
fn from_pascal_case() {
let convertable_string: String = "FooBar".to_owned();
let expected: String = "foo_bar".to_owned();
assert_eq!(to_snake_case(&convertable_string), expected)
}
#[test]
fn from_kebab_case() {
let convertable_string: String = "foo-bar".to_owned();
let expected: String = "foo_bar".to_owned();
assert_eq!(to_snake_case(&convertable_string), expected)
}
#[test]
fn from_sentence_case() {
let convertable_string: String = "Foo bar".to_owned();
let expected: String = "foo_bar".to_owned();
assert_eq!(to_snake_case(&convertable_string), expected)
}
#[test]
fn from_title_case() {
let convertable_string: String = "Foo Bar".to_owned();
let expected: String = "foo_bar".to_owned();
assert_eq!(to_snake_case(&convertable_string), expected)
}
#[test]
fn from_train_case() {
let convertable_string: String = "Foo-Bar".to_owned();
let expected: String = "foo_bar".to_owned();
assert_eq!(to_snake_case(&convertable_string), expected)
}
#[test]
fn from_screaming_snake_case() {
let convertable_string: String = "FOO_BAR".to_owned();
let expected: String = "foo_bar".to_owned();
assert_eq!(to_snake_case(&convertable_string), expected)
}
#[test]
fn from_snake_case() {
let convertable_string: String = "foo_bar".to_owned();
let expected: String = "foo_bar".to_owned();
assert_eq!(to_snake_case(&convertable_string), expected)
}
#[test]
fn from_case_with_loads_of_space() {
let convertable_string: String = "foo bar".to_owned();
let expected: String = "foo_bar".to_owned();
assert_eq!(to_snake_case(&convertable_string), expected)
}
#[test]
fn a_name_with_a_dot() {
let convertable_string: String = "Robert C. Martin".to_owned();
let expected: String = "robert_c_martin".to_owned();
assert_eq!(to_snake_case(&convertable_string), expected)
}
#[test]
fn random_text_with_bad_chars() {
let convertable_string: String = "Random text with *(bad) chars".to_owned();
let expected: String = "random_text_with_bad_chars".to_owned();
assert_eq!(to_snake_case(&convertable_string), expected)
}
#[test]
fn trailing_bad_chars() {
let convertable_string: String = "trailing bad_chars*(()())".to_owned();
let expected: String = "trailing_bad_chars".to_owned();
assert_eq!(to_snake_case(&convertable_string), expected)
}
#[test]
fn leading_bad_chars() {
let convertable_string: String = "-!#$%leading bad chars".to_owned();
let expected: String = "leading_bad_chars".to_owned();
assert_eq!(to_snake_case(&convertable_string), expected)
}
#[test]
fn wrapped_in_bad_chars() {
let convertable_string: String = "-!#$%wrapped in bad chars&*^*&(&*^&(<><?>><?><>))".to_owned();
let expected: String = "wrapped_in_bad_chars".to_owned();
assert_eq!(to_snake_case(&convertable_string), expected)
}
#[test]
fn has_a_sign() {
let convertable_string: String = "has a + sign".to_owned();
let expected: String = "has_a_sign".to_owned();
assert_eq!(to_snake_case(&convertable_string), expected)
}
#[test]
fn is_correct_from_camel_case() {
let convertable_string: String = "fooBar".to_owned();
assert_eq!(is_snake_case(&convertable_string), false)
}
#[test]
fn is_correct_from_pascal_case() {
let convertable_string: String = "FooBar".to_owned();
assert_eq!(is_snake_case(&convertable_string), false)
}
#[test]
fn is_correct_from_kebab_case() {
let convertable_string: String = "foo-bar".to_owned();
assert_eq!(is_snake_case(&convertable_string), false)
}
#[test]
fn is_correct_from_sentence_case() {
let convertable_string: String = "Foo bar".to_owned();
assert_eq!(is_snake_case(&convertable_string), false)
}
#[test]
fn is_correct_from_title_case() {
let convertable_string: String = "Foo Bar".to_owned();
assert_eq!(is_snake_case(&convertable_string), false)
}
#[test]
fn is_correct_from_train_case() {
let convertable_string: String = "Foo-Bar".to_owned();
assert_eq!(is_snake_case(&convertable_string), false)
}
#[test]
fn is_correct_from_screaming_snake_case() {
let convertable_string: String = "FOO_BAR".to_owned();
assert_eq!(is_snake_case(&convertable_string), false)
}
#[test]
fn is_correct_from_snake_case() {
let convertable_string: String = "foo_bar".to_owned();
assert_eq!(is_snake_case(&convertable_string), true)
}
}

271
third_party/rust/Inflector/src/cases/tablecase/mod.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,271 @@
#![deny(warnings)]
#[cfg(feature = "heavyweight")]
use string::pluralize::to_plural;
#[cfg(feature = "heavyweight")]
use cases::case::*;
#[cfg(feature = "heavyweight")]
/// Converts a `&str` to `table-case` `String`
///
/// ```
/// use inflector::cases::tablecase::to_table_case;
/// let mock_string: &str = "foo-bar";
/// let expected_string: String = "foo_bars".to_string();
/// let asserted_string: String = to_table_case(mock_string);
/// assert!(asserted_string == expected_string);
/// ```
///
/// ```
/// use inflector::cases::tablecase::to_table_case;
/// let mock_string: &str = "FOO_BAR";
/// let expected_string: String = "foo_bars".to_string();
/// let asserted_string: String = to_table_case(mock_string);
/// assert!(asserted_string == expected_string);
/// ```
///
/// ```
/// use inflector::cases::tablecase::to_table_case;
/// let mock_string: &str = "foo_bar";
/// let expected_string: String = "foo_bars".to_string();
/// let asserted_string: String = to_table_case(mock_string);
/// assert!(asserted_string == expected_string);
/// ```
///
/// ```
/// use inflector::cases::tablecase::to_table_case;
/// let mock_string: &str = "Foo Bar";
/// let expected_string: String = "foo_bars".to_string();
/// let asserted_string: String = to_table_case(mock_string);
/// assert!(asserted_string == expected_string);
/// ```
///
/// ```
/// use inflector::cases::tablecase::to_table_case;
/// let mock_string: &str = "Foo bar";
/// let expected_string: String = "foo_bars".to_string();
/// let asserted_string: String = to_table_case(mock_string);
/// assert!(asserted_string == expected_string);
/// ```
///
/// ```
/// use inflector::cases::tablecase::to_table_case;
/// let mock_string: &str = "FooBar";
/// let expected_string: String = "foo_bars".to_string();
/// let asserted_string: String = to_table_case(mock_string);
/// assert!(asserted_string == expected_string);
/// ```
///
/// ```
/// use inflector::cases::tablecase::to_table_case;
/// let mock_string: &str = "fooBar";
/// let expected_string: String = "foo_bars".to_string();
/// let asserted_string: String = to_table_case(mock_string);
/// assert!(asserted_string == expected_string);
/// ```
pub fn to_table_case(non_table_case_string: &str) -> String {
let snaked: String = to_case_snake_like(non_table_case_string, "_", "lower");
let split: (&str, &str) = snaked.split_at(snaked.rfind('_').unwrap_or(0));
format!("{}{}", split.0, to_plural(split.1))
}
#[cfg(feature = "heavyweight")]
/// Determines if a `&str` is `table-case`
///
/// ```
/// use inflector::cases::tablecase::is_table_case;
/// let mock_string: &str = "foo_bar_strings";
/// let asserted_bool: bool = is_table_case(mock_string);
/// assert!(asserted_bool == true);
/// ```
///
/// ```
/// use inflector::cases::tablecase::is_table_case;
/// let mock_string: &str = "foo-bar-string-that-is-really-really-long";
/// let asserted_bool: bool = is_table_case(mock_string);
/// assert!(asserted_bool == false);
/// ```
///
/// ```
/// use inflector::cases::tablecase::is_table_case;
/// let mock_string: &str = "FooBarIsAReallyReallyLongString";
/// let asserted_bool: bool = is_table_case(mock_string);
/// assert!(asserted_bool == false);
/// ```
///
/// ```
/// use inflector::cases::tablecase::is_table_case;
/// let mock_string: &str = "fooBarIsAReallyReallyLongString";
/// let asserted_bool: bool = is_table_case(mock_string);
/// assert!(asserted_bool == false);
/// ```
///
/// ```
/// use inflector::cases::tablecase::is_table_case;
/// let mock_string: &str = "FOO_BAR_STRING_THAT_IS_REALLY_REALLY_LONG";
/// let asserted_bool: bool = is_table_case(mock_string);
/// assert!(asserted_bool == false);
/// ```
///
/// ```
/// use inflector::cases::tablecase::is_table_case;
/// let mock_string: &str = "foo_bar_string_that_is_really_really_long";
/// let asserted_bool: bool = is_table_case(mock_string);
/// assert!(asserted_bool == false);
/// ```
///
/// ```
/// use inflector::cases::tablecase::is_table_case;
/// let mock_string: &str = "Foo bar string that is really really long";
/// let asserted_bool: bool = is_table_case(mock_string);
/// assert!(asserted_bool == false);
/// ```
///
/// ```
/// use inflector::cases::tablecase::is_table_case;
/// let mock_string: &str = "Foo Bar Is A Really Really Long String";
/// let asserted_bool: bool = is_table_case(mock_string);
/// assert!(asserted_bool == false);
/// ```
pub fn is_table_case(test_string: &str) -> bool {
to_table_case(&test_string.clone()) == test_string
}
#[cfg(all(feature = "unstable", test))]
#[cfg(feature = "heavyweight")]
mod benchmarks {
extern crate test;
use self::test::Bencher;
#[bench]
fn bench_table_case(b: &mut Bencher) {
b.iter(|| super::to_table_case("Foo bar"));
}
#[bench]
fn bench_is_table_case(b: &mut Bencher) {
b.iter(|| super::is_table_case("Foo bar"));
}
}
#[cfg(test)]
#[cfg(feature = "heavyweight")]
mod tests {
use ::to_table_case;
use ::is_table_case;
#[test]
fn from_camel_case() {
let convertable_string: String = "fooBar".to_owned();
let expected: String = "foo_bars".to_owned();
assert_eq!(to_table_case(&convertable_string), expected)
}
#[test]
fn from_pascal_case() {
let convertable_string: String = "FooBar".to_owned();
let expected: String = "foo_bars".to_owned();
assert_eq!(to_table_case(&convertable_string), expected)
}
#[test]
fn from_kebab_case() {
let convertable_string: String = "foo-bar".to_owned();
let expected: String = "foo_bars".to_owned();
assert_eq!(to_table_case(&convertable_string), expected)
}
#[test]
fn from_sentence_case() {
let convertable_string: String = "Foo bar".to_owned();
let expected: String = "foo_bars".to_owned();
assert_eq!(to_table_case(&convertable_string), expected)
}
#[test]
fn from_title_case() {
let convertable_string: String = "Foo Bar".to_owned();
let expected: String = "foo_bars".to_owned();
assert_eq!(to_table_case(&convertable_string), expected)
}
#[test]
fn from_train_case() {
let convertable_string: String = "Foo-Bar".to_owned();
let expected: String = "foo_bars".to_owned();
assert_eq!(to_table_case(&convertable_string), expected)
}
#[test]
fn from_screaming_snake_case() {
let convertable_string: String = "FOO_BAR".to_owned();
let expected: String = "foo_bars".to_owned();
assert_eq!(to_table_case(&convertable_string), expected)
}
#[test]
fn from_snake_case() {
let convertable_string: String = "foo_bar".to_owned();
let expected: String = "foo_bars".to_owned();
assert_eq!(to_table_case(&convertable_string), expected)
}
#[test]
fn from_table_case() {
let convertable_string: String = "foo_bars".to_owned();
let expected: String = "foo_bars".to_owned();
assert_eq!(to_table_case(&convertable_string), expected)
}
#[test]
fn is_correct_from_camel_case() {
let convertable_string: String = "fooBar".to_owned();
assert_eq!(is_table_case(&convertable_string), false)
}
#[test]
fn is_correct_from_pascal_case() {
let convertable_string: String = "FooBar".to_owned();
assert_eq!(is_table_case(&convertable_string), false)
}
#[test]
fn is_correct_from_kebab_case() {
let convertable_string: String = "foo-bar".to_owned();
assert_eq!(is_table_case(&convertable_string), false)
}
#[test]
fn is_correct_from_sentence_case() {
let convertable_string: String = "Foo bar".to_owned();
assert_eq!(is_table_case(&convertable_string), false)
}
#[test]
fn is_correct_from_title_case() {
let convertable_string: String = "Foo Bar".to_owned();
assert_eq!(is_table_case(&convertable_string), false)
}
#[test]
fn is_correct_from_train_case() {
let convertable_string: String = "Foo-Bar".to_owned();
assert_eq!(is_table_case(&convertable_string), false)
}
#[test]
fn is_correct_from_screaming_snake_case() {
let convertable_string: String = "FOO_BAR".to_owned();
assert_eq!(is_table_case(&convertable_string), false)
}
#[test]
fn is_correct_from_snake_case() {
let convertable_string: String = "foo_bar".to_owned();
assert_eq!(is_table_case(&convertable_string), false)
}
#[test]
fn is_correct_from_table_case() {
let convertable_string: String = "foo_bars".to_owned();
assert_eq!(is_table_case(&convertable_string), true)
}
}

308
third_party/rust/Inflector/src/cases/titlecase/mod.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,308 @@
#![deny(warnings)]
use cases::case::*;
/// Converts a `&str` to `Title Case` `String`
///
/// ```
/// use inflector::cases::titlecase::to_title_case;
/// let mock_string: &str = "Foo bar";
/// let expected_string: String = "Foo Bar".to_string();
/// let asserted_string: String = to_title_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::titlecase::to_title_case;
/// let mock_string: &str = "FooBar";
/// let expected_string: String = "Foo Bar".to_string();
/// let asserted_string: String = to_title_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::titlecase::to_title_case;
/// let mock_string: &str = "fooBar";
/// let expected_string: String = "Foo Bar".to_string();
/// let asserted_string: String = to_title_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::titlecase::to_title_case;
/// let mock_string: &str = "FOO_BAR";
/// let expected_string: String = "Foo Bar".to_string();
/// let asserted_string: String = to_title_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::titlecase::to_title_case;
/// let mock_string: &str = "foo_bar";
/// let expected_string: String = "Foo Bar".to_string();
/// let asserted_string: String = to_title_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::cases::titlecase::to_title_case;
/// let mock_string: &str = "foo-bar";
/// let expected_string: String = "Foo Bar".to_string();
/// let asserted_string: String = to_title_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
pub fn to_title_case(non_title_case_string: &str) -> String {
let options = CamelOptions {
new_word: true,
last_char: ' ',
first_word: true,
injectable_char: ' ',
has_seperator: true,
inverted: false,
};
to_case_camel_like(non_title_case_string, options)
}
/// Determines if a `&str` is `Title Case`
///
/// ```
/// use inflector::cases::titlecase::is_title_case;
/// let mock_string: &str = "foo-bar-string-that-is-really-really-long";
/// let asserted_bool: bool = is_title_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
/// ```
/// use inflector::cases::titlecase::is_title_case;
/// let mock_string: &str = "FooBarIsAReallyReallyLongString";
/// let asserted_bool: bool = is_title_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
/// ```
/// use inflector::cases::titlecase::is_title_case;
/// let mock_string: &str = "fooBarIsAReallyReallyLongString";
/// let asserted_bool: bool = is_title_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
/// ```
/// use inflector::cases::titlecase::is_title_case;
/// let mock_string: &str = "FOO_BAR_STRING_THAT_IS_REALLY_REALLY_LONG";
/// let asserted_bool: bool = is_title_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
/// ```
/// use inflector::cases::titlecase::is_title_case;
/// let mock_string: &str = "foo_bar_string_that_is_really_really_long";
/// let asserted_bool: bool = is_title_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
/// ```
/// use inflector::cases::titlecase::is_title_case;
/// let mock_string: &str = "Foo bar string that is really really long";
/// let asserted_bool: bool = is_title_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
/// ```
/// use inflector::cases::titlecase::is_title_case;
/// let mock_string: &str = "foo";
/// let asserted_bool: bool = is_title_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
/// ```
/// use inflector::cases::titlecase::is_title_case;
/// let mock_string: &str = "Foo Bar String That Is Really Really Long";
/// let asserted_bool: bool = is_title_case(mock_string);
/// assert!(asserted_bool == true);
///
/// ```
pub fn is_title_case(test_string: &str) -> bool {
test_string == to_title_case(test_string.clone())
}
#[cfg(all(feature = "unstable", test))]
mod benchmarks {
extern crate test;
use self::test::Bencher;
#[bench]
fn bench_title(b: &mut Bencher) {
b.iter(|| super::to_title_case("Foo BAR"));
}
#[bench]
fn bench_is_title(b: &mut Bencher) {
b.iter(|| super::is_title_case("Foo bar"));
}
#[bench]
fn bench_title_from_snake(b: &mut Bencher) {
b.iter(|| super::to_title_case("foo_bar"));
}
}
#[cfg(test)]
mod tests {
use ::to_title_case;
use ::is_title_case;
#[test]
fn from_camel_case() {
let convertable_string: String = "fooBar".to_owned();
let expected: String = "Foo Bar".to_owned();
assert_eq!(to_title_case(&convertable_string), expected)
}
#[test]
fn from_pascal_case() {
let convertable_string: String = "FooBar".to_owned();
let expected: String = "Foo Bar".to_owned();
assert_eq!(to_title_case(&convertable_string), expected)
}
#[test]
fn from_kebab_case() {
let convertable_string: String = "foo-bar".to_owned();
let expected: String = "Foo Bar".to_owned();
assert_eq!(to_title_case(&convertable_string), expected)
}
#[test]
fn from_sentence_case() {
let convertable_string: String = "Foo bar".to_owned();
let expected: String = "Foo Bar".to_owned();
assert_eq!(to_title_case(&convertable_string), expected)
}
#[test]
fn from_title_case() {
let convertable_string: String = "Foo Bar".to_owned();
let expected: String = "Foo Bar".to_owned();
assert_eq!(to_title_case(&convertable_string), expected)
}
#[test]
fn from_train_case() {
let convertable_string: String = "Foo-Bar".to_owned();
let expected: String = "Foo Bar".to_owned();
assert_eq!(to_title_case(&convertable_string), expected)
}
#[test]
fn from_screaming_snake_case() {
let convertable_string: String = "FOO_BAR".to_owned();
let expected: String = "Foo Bar".to_owned();
assert_eq!(to_title_case(&convertable_string), expected)
}
#[test]
fn from_snake_case() {
let convertable_string: String = "foo_bar".to_owned();
let expected: String = "Foo Bar".to_owned();
assert_eq!(to_title_case(&convertable_string), expected)
}
#[test]
fn from_case_with_loads_of_space() {
let convertable_string: String = "foo bar".to_owned();
let expected: String = "Foo Bar".to_owned();
assert_eq!(to_title_case(&convertable_string), expected)
}
#[test]
fn a_name_with_a_dot() {
let convertable_string: String = "Robert C. Martin".to_owned();
let expected: String = "Robert C Martin".to_owned();
assert_eq!(to_title_case(&convertable_string), expected)
}
#[test]
fn random_text_with_bad_chars() {
let convertable_string: String = "Random text with *(bad) chars".to_owned();
let expected: String = "Random Text With Bad Chars".to_owned();
assert_eq!(to_title_case(&convertable_string), expected)
}
#[test]
fn trailing_bad_chars() {
let convertable_string: String = "trailing bad_chars*(()())".to_owned();
let expected: String = "Trailing Bad Chars".to_owned();
assert_eq!(to_title_case(&convertable_string), expected)
}
#[test]
fn leading_bad_chars() {
let convertable_string: String = "-!#$%leading bad chars".to_owned();
let expected: String = "Leading Bad Chars".to_owned();
assert_eq!(to_title_case(&convertable_string), expected)
}
#[test]
fn wrapped_in_bad_chars() {
let convertable_string: String = "-!#$%wrapped in bad chars&*^*&(&*^&(<><?>><?><>))".to_owned();
let expected: String = "Wrapped In Bad Chars".to_owned();
assert_eq!(to_title_case(&convertable_string), expected)
}
#[test]
fn has_a_sign() {
let convertable_string: String = "has a + sign".to_owned();
let expected: String = "Has A Sign".to_owned();
assert_eq!(to_title_case(&convertable_string), expected)
}
#[test]
fn is_correct_from_camel_case() {
let convertable_string: String = "fooBar".to_owned();
assert_eq!(is_title_case(&convertable_string), false)
}
#[test]
fn is_correct_from_pascal_case() {
let convertable_string: String = "FooBar".to_owned();
assert_eq!(is_title_case(&convertable_string), false)
}
#[test]
fn is_correct_from_kebab_case() {
let convertable_string: String = "foo-bar".to_owned();
assert_eq!(is_title_case(&convertable_string), false)
}
#[test]
fn is_correct_from_sentence_case() {
let convertable_string: String = "Foo bar".to_owned();
assert_eq!(is_title_case(&convertable_string), false)
}
#[test]
fn is_correct_from_title_case() {
let convertable_string: String = "Foo Bar".to_owned();
assert_eq!(is_title_case(&convertable_string), true)
}
#[test]
fn is_correct_from_train_case() {
let convertable_string: String = "Foo-Bar".to_owned();
assert_eq!(is_title_case(&convertable_string), false)
}
#[test]
fn is_correct_from_screaming_snake_case() {
let convertable_string: String = "FOO_BAR".to_owned();
assert_eq!(is_title_case(&convertable_string), false)
}
#[test]
fn is_correct_from_snake_case() {
let convertable_string: String = "foo_bar".to_owned();
assert_eq!(is_title_case(&convertable_string), false)
}
}

320
third_party/rust/Inflector/src/cases/traincase/mod.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,320 @@
#![deny(warnings)]
use cases::case::*;
/// Determines if a `&str` is `Train-Case`
///
/// ```
/// use inflector::cases::traincase::is_train_case;
/// let mock_string: &str = "Foo-Bar-String-That-Is-Really-Really-Long";
/// let asserted_bool: bool = is_train_case(mock_string);
/// assert!(asserted_bool == true);
///
/// ```
///
/// ```
/// use inflector::cases::traincase::is_train_case;
/// let mock_string: &str = "foo-bar-string-that-is-really-really-long";
/// let asserted_bool: bool = is_train_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
///
/// ```
/// use inflector::cases::traincase::is_train_case;
/// let mock_string: &str = "FooBarIsAReallyReallyLongString";
/// let asserted_bool: bool = is_train_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
///
/// ```
/// use inflector::cases::traincase::is_train_case;
/// let mock_string: &str = "fooBarIsAReallyReallyLongString";
/// let asserted_bool: bool = is_train_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
///
/// ```
/// use inflector::cases::traincase::is_train_case;
/// let mock_string: &str = "foo_bar_string_that_is_really_really_long";
/// let asserted_bool: bool = is_train_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
///
/// ```
/// use inflector::cases::traincase::is_train_case;
/// let mock_string: &str = "Foo bar string that is really really long";
/// let asserted_bool: bool = is_train_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
///
/// ```
/// use inflector::cases::traincase::is_train_case;
/// let mock_string: &str = "Foo Bar Is A Really Really Long String";
/// let asserted_bool: bool = is_train_case(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
pub fn is_train_case(test_string: &str) -> bool {
test_string == to_train_case(test_string.clone())
}
/// Converts a `&str` to `Train-Case` `String`
///
/// ```
/// use inflector::cases::traincase::to_train_case;
/// let mock_string: &str = "foo-bar";
/// let expected_string: String = "Foo-Bar".to_string();
/// let asserted_string: String = to_train_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
///
/// ```
/// use inflector::cases::traincase::to_train_case;
/// let mock_string: &str = "FOO_BAR";
/// let expected_string: String = "Foo-Bar".to_string();
/// let asserted_string: String = to_train_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
///
/// ```
/// use inflector::cases::traincase::to_train_case;
/// let mock_string: &str = "foo_bar";
/// let expected_string: String = "Foo-Bar".to_string();
/// let asserted_string: String = to_train_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
///
/// ```
/// use inflector::cases::traincase::to_train_case;
/// let mock_string: &str = "Foo Bar";
/// let expected_string: String = "Foo-Bar".to_string();
/// let asserted_string: String = to_train_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
///
/// ```
/// use inflector::cases::traincase::to_train_case;
/// let mock_string: &str = "Foo bar";
/// let expected_string: String = "Foo-Bar".to_string();
/// let asserted_string: String = to_train_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
///
/// ```
/// use inflector::cases::traincase::to_train_case;
/// let mock_string: &str = "FooBar";
/// let expected_string: String = "Foo-Bar".to_string();
/// let asserted_string: String = to_train_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
///
/// ```
/// use inflector::cases::traincase::to_train_case;
/// let mock_string: &str = "fooBar";
/// let expected_string: String = "Foo-Bar".to_string();
/// let asserted_string: String = to_train_case(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
pub fn to_train_case(non_train_case_string: &str) -> String {
let options = CamelOptions {
new_word: true,
last_char: ' ',
first_word: true,
injectable_char: '-',
has_seperator: true,
inverted: false,
};
to_case_camel_like(non_train_case_string, options)
}
#[cfg(all(feature = "unstable", test))]
mod benchmarks {
extern crate test;
use self::test::Bencher;
#[bench]
fn bench_train(b: &mut Bencher) {
b.iter(|| super::to_train_case("Foo bar"));
}
#[bench]
fn bench_is_train(b: &mut Bencher) {
b.iter(|| super::is_train_case("Foo bar"));
}
#[bench]
fn bench_train_from_snake(b: &mut Bencher) {
b.iter(|| super::to_train_case("test_test_test"));
}
}
#[cfg(test)]
mod tests {
use ::to_train_case;
use ::is_train_case;
#[test]
fn from_camel_case() {
let convertable_string: String = "fooBar".to_owned();
let expected: String = "Foo-Bar".to_owned();
assert_eq!(to_train_case(&convertable_string), expected)
}
#[test]
fn from_pascal_case() {
let convertable_string: String = "FooBar".to_owned();
let expected: String = "Foo-Bar".to_owned();
assert_eq!(to_train_case(&convertable_string), expected)
}
#[test]
fn from_kebab_case() {
let convertable_string: String = "foo-bar".to_owned();
let expected: String = "Foo-Bar".to_owned();
assert_eq!(to_train_case(&convertable_string), expected)
}
#[test]
fn from_sentence_case() {
let convertable_string: String = "Foo bar".to_owned();
let expected: String = "Foo-Bar".to_owned();
assert_eq!(to_train_case(&convertable_string), expected)
}
#[test]
fn from_title_case() {
let convertable_string: String = "Foo Bar".to_owned();
let expected: String = "Foo-Bar".to_owned();
assert_eq!(to_train_case(&convertable_string), expected)
}
#[test]
fn from_train_case() {
let convertable_string: String = "Foo-Bar".to_owned();
let expected: String = "Foo-Bar".to_owned();
assert_eq!(to_train_case(&convertable_string), expected)
}
#[test]
fn from_screaming_snake_case() {
let convertable_string: String = "FOO_BAR".to_owned();
let expected: String = "Foo-Bar".to_owned();
assert_eq!(to_train_case(&convertable_string), expected)
}
#[test]
fn from_snake_case() {
let convertable_string: String = "foo_bar".to_owned();
let expected: String = "Foo-Bar".to_owned();
assert_eq!(to_train_case(&convertable_string), expected)
}
#[test]
fn from_case_with_loads_of_space() {
let convertable_string: String = "foo bar".to_owned();
let expected: String = "Foo-Bar".to_owned();
assert_eq!(to_train_case(&convertable_string), expected)
}
#[test]
fn a_name_with_a_dot() {
let convertable_string: String = "Robert C. Martin".to_owned();
let expected: String = "Robert-C-Martin".to_owned();
assert_eq!(to_train_case(&convertable_string), expected)
}
#[test]
fn random_text_with_bad_chars() {
let convertable_string: String = "Random text with *(bad) chars".to_owned();
let expected: String = "Random-Text-With-Bad-Chars".to_owned();
assert_eq!(to_train_case(&convertable_string), expected)
}
#[test]
fn trailing_bad_chars() {
let convertable_string: String = "trailing bad_chars*(()())".to_owned();
let expected: String = "Trailing-Bad-Chars".to_owned();
assert_eq!(to_train_case(&convertable_string), expected)
}
#[test]
fn leading_bad_chars() {
let convertable_string: String = "-!#$%leading bad chars".to_owned();
let expected: String = "Leading-Bad-Chars".to_owned();
assert_eq!(to_train_case(&convertable_string), expected)
}
#[test]
fn wrapped_in_bad_chars() {
let convertable_string: String = "-!#$%wrapped in bad chars&*^*&(&*^&(<><?>><?><>))".to_owned();
let expected: String = "Wrapped-In-Bad-Chars".to_owned();
assert_eq!(to_train_case(&convertable_string), expected)
}
#[test]
fn has_a_sign() {
let convertable_string: String = "has a + sign".to_owned();
let expected: String = "Has-A-Sign".to_owned();
assert_eq!(to_train_case(&convertable_string), expected)
}
#[test]
fn is_correct_from_camel_case() {
let convertable_string: String = "fooBar".to_owned();
assert_eq!(is_train_case(&convertable_string), false)
}
#[test]
fn is_correct_from_pascal_case() {
let convertable_string: String = "FooBar".to_owned();
assert_eq!(is_train_case(&convertable_string), false)
}
#[test]
fn is_correct_from_kebab_case() {
let convertable_string: String = "foo-bar".to_owned();
assert_eq!(is_train_case(&convertable_string), false)
}
#[test]
fn is_correct_from_sentence_case() {
let convertable_string: String = "Foo bar".to_owned();
assert_eq!(is_train_case(&convertable_string), false)
}
#[test]
fn is_correct_from_title_case() {
let convertable_string: String = "Foo Bar".to_owned();
assert_eq!(is_train_case(&convertable_string), false)
}
#[test]
fn is_correct_from_train_case() {
let convertable_string: String = "Foo-Bar".to_owned();
assert_eq!(is_train_case(&convertable_string), true)
}
#[test]
fn is_correct_from_screaming_snake_case() {
let convertable_string: String = "FOO_BAR".to_owned();
assert_eq!(is_train_case(&convertable_string), false)
}
#[test]
fn is_correct_from_snake_case() {
let convertable_string: String = "foo_bar".to_owned();
assert_eq!(is_train_case(&convertable_string), false)
}
}

332
third_party/rust/Inflector/src/lib.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,332 @@
#![deny(warnings, unused_variables, missing_docs, unsafe_code, unused_extern_crates)]
#![cfg_attr(feature = "unstable", feature(test))]
//! Adds String based inflections for Rust. Snake, kebab, train, camel,
//! sentence, class, and title cases as well as ordinalize,
//! deordinalize, demodulize, deconstantize, and foreign key are supported as
//! both traits and pure functions acting on String types.
//! ```rust
//! use inflector::Inflector;
//! let camel_case_string: String = "some_string".to_camel_case();
//! let is_camel_cased: bool= camel_case_string.is_camel_case();
//! assert!(is_camel_cased == true);
//! ```
#[cfg(feature = "heavyweight")]
extern crate regex;
#[cfg(feature = "heavyweight")]
#[macro_use] extern crate lazy_static;
/// Provides case inflections
/// - Camel case
/// - Class case
/// - Kebab case
/// - Train case
/// - Screaming snake case
/// - Table case
/// - Sentence case
/// - Snake case
/// - Pascal case
pub mod cases;
/// Provides number inflections
/// - Ordinalize
/// - Deordinalize
pub mod numbers;
/// Provides suffix inflections
/// - Foreign key
pub mod suffix;
/// Provides string inflections
/// - Deconstantize
/// - Demodulize
/// - Pluralize
/// - Singularize
#[cfg(feature = "heavyweight")]
pub mod string;
#[cfg(feature = "heavyweight")]
use cases::classcase::to_class_case;
#[cfg(feature = "heavyweight")]
use cases::classcase::is_class_case;
use cases::camelcase::to_camel_case;
use cases::camelcase::is_camel_case;
use cases::pascalcase::to_pascal_case;
use cases::pascalcase::is_pascal_case;
use cases::snakecase::to_snake_case;
use cases::snakecase::is_snake_case;
use cases::screamingsnakecase::to_screaming_snake_case;
use cases::screamingsnakecase::is_screaming_snake_case;
use cases::kebabcase::to_kebab_case;
use cases::kebabcase::is_kebab_case;
use cases::traincase::to_train_case;
use cases::traincase::is_train_case;
use cases::sentencecase::to_sentence_case;
use cases::sentencecase::is_sentence_case;
use cases::titlecase::to_title_case;
use cases::titlecase::is_title_case;
#[cfg(feature = "heavyweight")]
use cases::tablecase::to_table_case;
#[cfg(feature = "heavyweight")]
use cases::tablecase::is_table_case;
use numbers::ordinalize::ordinalize;
use numbers::deordinalize::deordinalize;
use suffix::foreignkey::to_foreign_key;
use suffix::foreignkey::is_foreign_key;
#[cfg(feature = "heavyweight")]
use string::demodulize::demodulize;
#[cfg(feature = "heavyweight")]
use string::deconstantize::deconstantize;
#[cfg(feature = "heavyweight")]
use string::pluralize::to_plural;
#[cfg(feature = "heavyweight")]
use string::singularize::to_singular;
#[allow(missing_docs)]
pub trait Inflector {
fn to_camel_case(&self) -> String;
fn is_camel_case(&self) -> bool;
fn to_pascal_case(&self) -> String;
fn is_pascal_case(&self) -> bool;
fn to_snake_case(&self) -> String;
fn is_snake_case(&self) -> bool;
fn to_screaming_snake_case(&self) -> String;
fn is_screaming_snake_case(&self) -> bool;
fn to_kebab_case(&self) -> String;
fn is_kebab_case(&self) -> bool;
fn to_train_case(&self) -> String;
fn is_train_case(&self) -> bool;
fn to_sentence_case(&self) -> String;
fn is_sentence_case(&self) -> bool;
fn to_title_case(&self) -> String;
fn is_title_case(&self) -> bool;
fn ordinalize(&self) -> String;
fn deordinalize(&self) -> String;
fn to_foreign_key(&self) -> String;
fn is_foreign_key(&self) -> bool;
#[cfg(feature = "heavyweight")]
fn demodulize(&self) -> String;
#[cfg(feature = "heavyweight")]
fn deconstantize(&self) -> String;
#[cfg(feature = "heavyweight")]
fn to_class_case(&self) -> String;
#[cfg(feature = "heavyweight")]
fn is_class_case(&self) -> bool;
#[cfg(feature = "heavyweight")]
fn to_table_case(&self) -> String;
#[cfg(feature = "heavyweight")]
fn is_table_case(&self) -> bool;
#[cfg(feature = "heavyweight")]
fn to_plural(&self) -> String;
#[cfg(feature = "heavyweight")]
fn to_singular(&self) -> String;
}
#[allow(missing_docs)]
pub trait InflectorNumbers {
fn ordinalize(&self) -> String;
}
macro_rules! define_implementations {
( $slf:ident; $($imp_trait:ident => $typ:ident), *) => {
$(
#[inline]
fn $imp_trait(&$slf) -> $typ {
$imp_trait($slf)
}
)*
}
}
macro_rules! define_number_implementations {
( $slf:ident; $($imp_trait:ident => $typ:ident), *) => {
$(
#[inline]
fn $imp_trait(&$slf) -> $typ {
$imp_trait(&$slf.to_string())
}
)*
}
}
macro_rules! define_gated_implementations {
( $slf:ident; $($imp_trait:ident => $typ:ident), *) => {
$(
#[inline]
#[cfg(feature = "heavyweight")]
fn $imp_trait(&$slf) -> $typ {
$imp_trait($slf)
}
)*
}
}
macro_rules! implement_string_for {
( $trt:ident; $($typ:ident), *) => {
$(
impl $trt for $typ {
define_implementations![self;
to_camel_case => String,
is_camel_case => bool,
to_pascal_case => String,
is_pascal_case => bool,
to_screaming_snake_case => String,
is_screaming_snake_case => bool,
to_snake_case => String,
is_snake_case => bool,
to_kebab_case => String,
is_kebab_case => bool,
to_train_case => String,
is_train_case => bool,
to_sentence_case => String,
is_sentence_case => bool,
to_title_case => String,
is_title_case => bool,
to_foreign_key => String,
is_foreign_key => bool,
ordinalize => String,
deordinalize => String
];
define_gated_implementations![self;
to_class_case => String,
is_class_case => bool,
to_table_case => String,
is_table_case => bool,
to_plural => String,
to_singular => String,
demodulize => String,
deconstantize => String
];
}
)*
}
}
macro_rules! implement_number_for {
( $trt:ident; $($typ:ident), *) => {
$(
impl $trt for $typ {
define_number_implementations![self;
ordinalize => String
];
}
)*
}
}
implement_string_for![
Inflector;
String, str
];
implement_number_for![
InflectorNumbers;
i8, i16, i32, i64, u8, u16, u32, u64, isize, usize, f32, f64
];
#[cfg(all(feature = "unstable", test))]
mod benchmarks {
extern crate test;
use self::test::Bencher;
use ::Inflector;
macro_rules! benchmarks {
( $($test_name:ident => $imp_trait:ident => $to_cast:expr), *) => {
$(
#[bench]
fn $test_name(b: &mut Bencher) {
b.iter(|| {
$to_cast.$imp_trait()
});
}
)*
}
}
benchmarks![
benchmark_str_to_camel => to_camel_case => "foo_bar",
benchmark_str_is_camel => is_camel_case => "fooBar",
benchmark_str_to_screaming_snake => to_screaming_snake_case => "fooBar",
benchmark_str_is_screaming_snake => is_screaming_snake_case => "FOO_BAR",
benchmark_str_to_snake => to_snake_case => "fooBar",
benchmark_str_is_snake => is_snake_case => "foo_bar",
benchmark_str_to_kebab => to_kebab_case => "fooBar",
benchmark_str_is_kebab => is_kebab_case => "foo-bar",
benchmark_str_to_train => to_train_case => "fooBar",
benchmark_str_is_train => is_train_case => "Foo-Bar",
benchmark_str_to_sentence => to_sentence_case => "fooBar",
benchmark_str_is_sentence => is_sentence_case => "Foo bar",
benchmark_str_to_title => to_title_case => "fooBar",
benchmark_str_is_title => is_title_case => "Foo Bar",
benchmark_str_ordinalize => ordinalize => "1",
benchmark_str_deordinalize => deordinalize => "1st",
benchmark_str_to_foreign_key => to_foreign_key => "Foo::Bar",
benchmark_str_is_foreign_key => is_foreign_key => "bar_id",
benchmark_string_to_camel => to_camel_case => "foo_bar".to_string(),
benchmark_string_is_camel => is_camel_case => "fooBar".to_string(),
benchmark_string_to_screaming_snake => to_screaming_snake_case => "fooBar".to_string(),
benchmark_string_is_screaming_snake => is_screaming_snake_case => "FOO_BAR".to_string(),
benchmark_string_to_snake => to_snake_case => "fooBar".to_string(),
benchmark_string_is_snake => is_snake_case => "foo_bar".to_string(),
benchmark_string_to_kebab => to_kebab_case => "fooBar".to_string(),
benchmark_string_is_kebab => is_kebab_case => "foo-bar".to_string(),
benchmark_string_to_train => to_train_case => "fooBar".to_string(),
benchmark_string_is_train => is_train_case => "Foo-Bar".to_string(),
benchmark_string_to_sentence => to_sentence_case => "fooBar".to_string(),
benchmark_string_is_sentence => is_sentence_case => "Foo bar".to_string(),
benchmark_string_to_title => to_title_case => "fooBar".to_string(),
benchmark_string_is_title => is_title_case => "Foo Bar".to_string(),
benchmark_string_ordinalize => ordinalize => "1".to_string(),
benchmark_string_deordinalize => deordinalize => "1st".to_string(),
benchmark_string_to_foreign_key => to_foreign_key => "Foo::Bar".to_string(),
benchmark_string_is_foreign_key => is_foreign_key => "bar_id".to_string()
];
#[cfg(feature = "heavyweight")]
benchmarks![
benchmark_str_to_class => to_class_case => "foo",
benchmark_str_is_class => is_class_case => "Foo",
benchmark_str_to_table => to_table_case => "fooBar",
benchmark_str_is_table => is_table_case => "foo_bars",
benchmark_str_pluralize => to_plural => "crate",
benchmark_str_singular => to_singular => "crates",
benchmark_string_to_class => to_class_case => "foo".to_string(),
benchmark_string_is_class => is_class_case => "Foo".to_string(),
benchmark_string_to_table => to_table_case => "fooBar".to_string(),
benchmark_string_is_table => is_table_case => "foo_bars".to_string(),
benchmark_string_pluralize => to_plural => "crate".to_string(),
benchmark_string_singular => to_singular => "crates".to_string(),
benchmark_string_demodulize => demodulize => "Foo::Bar".to_string(),
benchmark_string_deconstantize => deconstantize => "Foo::Bar".to_string(),
benchmark_str_demodulize => demodulize => "Foo::Bar",
benchmark_str_deconstantize => deconstantize => "Foo::Bar"
];
}

117
third_party/rust/Inflector/src/numbers/deordinalize/mod.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,117 @@
/// Deorginalizes a `&str`
///
/// ```
/// use inflector::numbers::deordinalize::deordinalize;
/// let mock_string: &str = "0.1";
/// let expected_string: String = "0.1".to_owned();
/// let asserted_string: String = deordinalize(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::numbers::deordinalize::deordinalize;
/// let mock_string: &str = "-1st";
/// let expected_string: String = "-1".to_owned();
/// let asserted_string: String = deordinalize(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::numbers::deordinalize::deordinalize;
/// let mock_string: &str = "0th";
/// let expected_string: String = "0".to_owned();
/// let asserted_string: String = deordinalize(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::numbers::deordinalize::deordinalize;
/// let mock_string: &str = "1st";
/// let expected_string: String = "1".to_owned();
/// let asserted_string: String = deordinalize(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::numbers::deordinalize::deordinalize;
/// let mock_string: &str = "2nd";
/// let expected_string: String = "2".to_owned();
/// let asserted_string: String = deordinalize(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::numbers::deordinalize::deordinalize;
/// let mock_string: &str = "3rd";
/// let expected_string: String = "3".to_owned();
/// let asserted_string: String = deordinalize(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::numbers::deordinalize::deordinalize;
/// let mock_string: &str = "9th";
/// let expected_string: String = "9".to_owned();
/// let asserted_string: String = deordinalize(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::numbers::deordinalize::deordinalize;
/// let mock_string: &str = "12th";
/// let expected_string: String = "12".to_owned();
/// let asserted_string: String = deordinalize(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::numbers::deordinalize::deordinalize;
/// let mock_string: &str = "12000th";
/// let expected_string: String = "12000".to_owned();
/// let asserted_string: String = deordinalize(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::numbers::deordinalize::deordinalize;
/// let mock_string: &str = "12001th";
/// let expected_string: String = "12001".to_owned();
/// let asserted_string: String = deordinalize(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::numbers::deordinalize::deordinalize;
/// let mock_string: &str = "12002nd";
/// let expected_string: String = "12002".to_owned();
/// let asserted_string: String = deordinalize(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::numbers::deordinalize::deordinalize;
/// let mock_string: &str = "12003rd";
/// let expected_string: String = "12003".to_owned();
/// let asserted_string: String = deordinalize(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::numbers::deordinalize::deordinalize;
/// let mock_string: &str = "12004th";
/// let expected_string: String = "12004".to_owned();
/// let asserted_string: String = deordinalize(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
pub fn deordinalize(non_ordinalized_string: &str) -> String {
if non_ordinalized_string.contains('.') {
non_ordinalized_string.to_owned()
} else {
non_ordinalized_string.trim_end_matches("st")
.trim_end_matches("nd")
.trim_end_matches("rd")
.trim_end_matches("th")
.to_owned()
}
}

9
third_party/rust/Inflector/src/numbers/mod.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,9 @@
#![deny(warnings)]
/// Provides ordinalization of a string.
///
/// Example string "1" becomes "1st"
pub mod ordinalize;
/// Provides deordinalization of a string.
///
/// Example string "1st" becomes "1"
pub mod deordinalize;

147
third_party/rust/Inflector/src/numbers/ordinalize/mod.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,147 @@
/// Orginalizes a `&str`
///
/// ```
/// use inflector::numbers::ordinalize::ordinalize;
/// let mock_string: &str = "a";
/// let expected_string: String = "a".to_owned();
/// let asserted_string: String = ordinalize(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::numbers::ordinalize::ordinalize;
/// let mock_string: &str = "0.1";
/// let expected_string: String = "0.1".to_owned();
/// let asserted_string: String = ordinalize(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::numbers::ordinalize::ordinalize;
/// let mock_string: &str = "-1";
/// let expected_string: String = "-1st".to_owned();
/// let asserted_string: String = ordinalize(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::numbers::ordinalize::ordinalize;
/// let mock_string: &str = "0";
/// let expected_string: String = "0th".to_owned();
/// let asserted_string: String = ordinalize(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::numbers::ordinalize::ordinalize;
/// let mock_string: &str = "1";
/// let expected_string: String = "1st".to_owned();
/// let asserted_string: String = ordinalize(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::numbers::ordinalize::ordinalize;
/// let mock_string: &str = "2";
/// let expected_string: String = "2nd".to_owned();
/// let asserted_string: String = ordinalize(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::numbers::ordinalize::ordinalize;
/// let mock_string: &str = "3";
/// let expected_string: String = "3rd".to_owned();
/// let asserted_string: String = ordinalize(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::numbers::ordinalize::ordinalize;
/// let mock_string: &str = "9";
/// let expected_string: String = "9th".to_owned();
/// let asserted_string: String = ordinalize(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::numbers::ordinalize::ordinalize;
/// let mock_string: &str = "12";
/// let expected_string: String = "12th".to_owned();
/// let asserted_string: String = ordinalize(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::numbers::ordinalize::ordinalize;
/// let mock_string: &str = "12000";
/// let expected_string: String = "12000th".to_owned();
/// let asserted_string: String = ordinalize(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::numbers::ordinalize::ordinalize;
/// let mock_string: &str = "12001";
/// let expected_string: String = "12001st".to_owned();
/// let asserted_string: String = ordinalize(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::numbers::ordinalize::ordinalize;
/// let mock_string: &str = "12002";
/// let expected_string: String = "12002nd".to_owned();
/// let asserted_string: String = ordinalize(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::numbers::ordinalize::ordinalize;
/// let mock_string: &str = "12003";
/// let expected_string: String = "12003rd".to_owned();
/// let asserted_string: String = ordinalize(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::numbers::ordinalize::ordinalize;
/// let mock_string: &str = "12004";
/// let expected_string: String = "12004th".to_owned();
/// let asserted_string: String = ordinalize(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
pub fn ordinalize(non_ordinalized_string: &str) -> String {
let chars: Vec<char> = non_ordinalized_string.clone().chars().collect();
let last_number: char = chars[chars.len() - 1];
if is_ordinalizable(last_number) {
return non_ordinalized_string.to_owned();
}
if chars.len() > 1 {
if second_last_number_is_one(chars) {
return format!("{}{}", non_ordinalized_string, "th");
} else if string_contains_decimal(non_ordinalized_string.to_owned()) {
return non_ordinalized_string.to_owned();
}
}
match last_number {
'1' => format!("{}{}", non_ordinalized_string, "st"),
'2' => format!("{}{}", non_ordinalized_string, "nd"),
'3' => format!("{}{}", non_ordinalized_string, "rd"),
_ => format!("{}{}", non_ordinalized_string, "th"),
}
}
fn is_ordinalizable(last_number: char) -> bool {
!last_number.is_numeric()
}
fn second_last_number_is_one(chars: Vec<char>) -> bool {
let second_last_number: char = chars[chars.len() - 2];
second_last_number == '1'
}
fn string_contains_decimal(non_ordinalized_string: String) -> bool {
non_ordinalized_string.contains('.')
}

225
third_party/rust/Inflector/src/string/constants/mod.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,225 @@
pub const UNACCONTABLE_WORDS: [&'static str; 202] = ["accommodation",
"adulthood",
"advertising",
"advice",
"aggression",
"aid",
"air",
"aircraft",
"alcohol",
"anger",
"applause",
"arithmetic",
"assistance",
"athletics",
"bacon",
"baggage",
"beef",
"biology",
"blood",
"botany",
"bread",
"butter",
"carbon",
"cardboard",
"cash",
"chalk",
"chaos",
"chess",
"crossroads",
"countryside",
"dancing",
"deer",
"dignity",
"dirt",
"dust",
"economics",
"education",
"electricity",
"engineering",
"enjoyment",
"envy",
"equipment",
"ethics",
"evidence",
"evolution",
"fame",
"fiction",
"flour",
"flu",
"food",
"fuel",
"fun",
"furniture",
"gallows",
"garbage",
"garlic",
"genetics",
"gold",
"golf",
"gossip",
"grammar",
"gratitude",
"grief",
"guilt",
"gymnastics",
"happiness",
"hardware",
"harm",
"hate",
"hatred",
"health",
"heat",
"help",
"homework",
"honesty",
"honey",
"hospitality",
"housework",
"humour",
"hunger",
"hydrogen",
"ice",
"importance",
"inflation",
"information",
"innocence",
"iron",
"irony",
"jam",
"jewelry",
"judo",
"karate",
"knowledge",
"lack",
"laughter",
"lava",
"leather",
"leisure",
"lightning",
"linguine",
"linguini",
"linguistics",
"literature",
"litter",
"livestock",
"logic",
"loneliness",
"luck",
"luggage",
"macaroni",
"machinery",
"magic",
"management",
"mankind",
"marble",
"mathematics",
"mayonnaise",
"measles",
"methane",
"milk",
"money",
"mud",
"music",
"mumps",
"nature",
"news",
"nitrogen",
"nonsense",
"nurture",
"nutrition",
"obedience",
"obesity",
"oxygen",
"pasta",
"patience",
"physics",
"poetry",
"pollution",
"poverty",
"pride",
"psychology",
"publicity",
"punctuation",
"quartz",
"racism",
"relaxation",
"reliability",
"research",
"respect",
"revenge",
"rice",
"rubbish",
"rum",
"safety",
"scenery",
"seafood",
"seaside",
"series",
"shame",
"sheep",
"shopping",
"sleep",
"smoke",
"smoking",
"snow",
"soap",
"software",
"soil",
"spaghetti",
"species",
"steam",
"stuff",
"stupidity",
"sunshine",
"symmetry",
"tennis",
"thirst",
"thunder",
"timber",
"traffic",
"transportation",
"trust",
"underwear",
"unemployment",
"unity",
"validity",
"veal",
"vegetation",
"vegetarianism",
"vengeance",
"violence",
"vitality",
"warmth",
"wealth",
"weather",
"welfare",
"wheat",
"wildlife",
"wisdom",
"yoga",
"zinc",
"zoology"];

50
third_party/rust/Inflector/src/string/deconstantize/mod.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,50 @@
#[cfg(feature = "heavyweight")]
use cases::classcase::to_class_case;
#[cfg(feature = "heavyweight")]
/// Deconstantizes a `&str`
///
/// ```
/// use inflector::string::deconstantize::deconstantize;
/// let mock_string: &str = "Bar";
/// let expected_string: String = "".to_owned();
/// let asserted_string: String = deconstantize(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::string::deconstantize::deconstantize;
/// let mock_string: &str = "::Bar";
/// let expected_string: String = "".to_owned();
/// let asserted_string: String = deconstantize(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::string::deconstantize::deconstantize;
/// let mock_string: &str = "Foo::Bar";
/// let expected_string: String = "Foo".to_owned();
/// let asserted_string: String = deconstantize(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::string::deconstantize::deconstantize;
/// let mock_string: &str = "Test::Foo::Bar";
/// let expected_string: String = "Foo".to_owned();
/// let asserted_string: String = deconstantize(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
pub fn deconstantize(non_deconstantized_string: &str) -> String {
if non_deconstantized_string.contains("::") {
let split_string: Vec<&str> = non_deconstantized_string.split("::").collect();
if split_string.len() > 1 {
to_class_case(split_string[split_string.len() - 2])
} else {
"".to_owned()
}
} else {
"".to_owned()
}
}

46
third_party/rust/Inflector/src/string/demodulize/mod.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,46 @@
#[cfg(feature = "heavyweight")]
use cases::classcase::to_class_case;
#[cfg(feature = "heavyweight")]
/// Demodulize a `&str`
///
/// ```
/// use inflector::string::demodulize::demodulize;
/// let mock_string: &str = "Bar";
/// let expected_string: String = "Bar".to_owned();
/// let asserted_string: String = demodulize(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::string::demodulize::demodulize;
/// let mock_string: &str = "::Bar";
/// let expected_string: String = "Bar".to_owned();
/// let asserted_string: String = demodulize(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::string::demodulize::demodulize;
/// let mock_string: &str = "Foo::Bar";
/// let expected_string: String = "Bar".to_owned();
/// let asserted_string: String = demodulize(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::string::demodulize::demodulize;
/// let mock_string: &str = "Test::Foo::Bar";
/// let expected_string: String = "Bar".to_owned();
/// let asserted_string: String = demodulize(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
pub fn demodulize(non_demodulize_string: &str) -> String {
if non_demodulize_string.contains("::") {
let split_string: Vec<&str> = non_demodulize_string.split("::").collect();
to_class_case(split_string[split_string.len() - 1])
} else {
non_demodulize_string.to_owned()
}
}

23
third_party/rust/Inflector/src/string/mod.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,23 @@
#![deny(warnings)]
/// Provides demodulize a string.
///
/// Example string `Foo::Bar` becomes `Bar`
#[cfg(feature = "heavyweight")]
pub mod demodulize;
/// Provides deconstantizea string.
///
/// Example string `Foo::Bar` becomes `Foo`
#[cfg(feature = "heavyweight")]
pub mod deconstantize;
/// Provides conversion to plural strings.
///
/// Example string `FooBar` -> `FooBars`
#[cfg(feature = "heavyweight")]
pub mod pluralize;
/// Provides conversion to singular strings.
///
/// Example string `FooBars` -> `FooBar`
#[cfg(feature = "heavyweight")]
pub mod singularize;
mod constants;

194
third_party/rust/Inflector/src/string/pluralize/mod.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,194 @@
#![deny(warnings)]
use regex::Regex;
use string::constants::UNACCONTABLE_WORDS;
macro_rules! add_rule{
($r:ident, $rule:expr => $replace:expr) => {
$r.push((Regex::new($rule).unwrap(), $replace));
}
}
macro_rules! rules{
($r:ident; $($rule:expr => $replace:expr), *) => {
$(
add_rule!{$r, $rule => $replace}
)*
}
}
lazy_static!{
static ref RULES: Vec<(Regex, &'static str)> = {
let mut r = Vec::with_capacity(24);
rules![r;
r"(\w*)s$" => "s",
r"(\w*([^aeiou]ese))$" => "",
r"(\w*(ax|test))is$" => "es",
r"(\w*(alias|[^aou]us|tlas|gas|ris))$" => "es",
r"(\w*(e[mn]u))s?$" => "s",
r"(\w*([^l]ias|[aeiou]las|[emjzr]as|[iu]am))$" => "",
r"(\w*(alumn|syllab|octop|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat))(?:us|i)$" => "i",
r"(\w*(alumn|alg|vertebr))(?:a|ae)$" => "ae",
r"(\w*(seraph|cherub))(?:im)?$" => "im",
r"(\w*(her|at|gr))o$" => "oes",
r"(\w*(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|automat|quor))(?:a|um)$" => "a",
r"(\w*(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat))(?:a|on)$" => "a",
r"(\w*)sis$" => "ses",
r"(\w*(kni|wi|li))fe$" => "ves",
r"(\w*(ar|l|ea|eo|oa|hoo))f$" => "ves",
r"(\w*([^aeiouy]|qu))y$" => "ies",
r"(\w*([^ch][ieo][ln]))ey$" => "ies",
r"(\w*(x|ch|ss|sh|zz)es)$" => "",
r"(\w*(x|ch|ss|sh|zz))$" => "es",
r"(\w*(matr|cod|mur|sil|vert|ind|append))(?:ix|ex)$" => "ices",
r"(\w*(m|l)(?:ice|ouse))$" => "ice",
r"(\w*(pe)(?:rson|ople))$" => "ople",
r"(\w*(child))(?:ren)?$" => "ren",
r"(\w*eaux)$" => ""
];
r
};
}
macro_rules! special_cases{
($s:ident, $($singular: expr => $plural:expr), *) => {
match &$s[..] {
$(
$singular => {
return $plural.to_owned();
},
)*
_ => ()
}
}
}
/// Converts a `&str` to pluralized `String`
///
/// ```
/// use inflector::string::pluralize::to_plural;
/// let mock_string: &str = "foo_bar";
/// let expected_string: String = "foo_bars".to_owned();
/// let asserted_string: String = to_plural(mock_string);
/// assert_eq!(asserted_string, expected_string);
///
/// ```
/// ```
/// use inflector::string::pluralize::to_plural;
/// let mock_string: &str = "ox";
/// let expected_string: String = "oxen".to_owned();
/// let asserted_string: String = to_plural(mock_string);
/// assert_eq!(asserted_string, expected_string);
///
/// ```
/// ```
/// use inflector::string::pluralize::to_plural;
/// let mock_string: &str = "crate";
/// let expected_string: String = "crates".to_owned();
/// let asserted_string: String = to_plural(mock_string);
/// assert_eq!(asserted_string, expected_string);
///
/// ```
/// ```
/// use inflector::string::pluralize::to_plural;
/// let mock_string: &str = "boxes";
/// let expected_string: String = "boxes".to_owned();
/// let asserted_string: String = to_plural(mock_string);
/// assert_eq!(asserted_string, expected_string);
///
/// ```
/// ```
/// use inflector::string::pluralize::to_plural;
/// let mock_string: &str = "vengeance";
/// let expected_string: String = "vengeance".to_owned();
/// let asserted_string: String = to_plural(mock_string);
/// assert_eq!(asserted_string, expected_string);
///
/// ```
/// ```
/// use inflector::string::pluralize::to_plural;
/// let mock_string: &str = "yoga";
/// let expected_string: String = "yoga".to_owned();
/// let asserted_string: String = to_plural(mock_string);
/// assert_eq!(asserted_string, expected_string);
///
/// ```
/// ```
/// use inflector::string::pluralize::to_plural;
/// let mock_string: &str = "geometry";
/// let expected_string: String = "geometries".to_owned();
/// let asserted_string: String = to_plural(mock_string);
/// assert_eq!(asserted_string, expected_string);
///
/// ```
///
pub fn to_plural(non_plural_string: &str) -> String {
if UNACCONTABLE_WORDS.contains(&non_plural_string.as_ref()) {
non_plural_string.to_owned()
} else {
special_cases![non_plural_string,
"ox" => "oxen",
"man" => "men",
"woman" => "women",
"die" => "dice",
"yes" => "yeses",
"foot" => "feet",
"eave" => "eaves",
"goose" => "geese",
"tooth" => "teeth",
"quiz" => "quizzes"
];
for &(ref rule, replace) in RULES.iter().rev() {
if let Some(c) = rule.captures(&non_plural_string) {
if let Some(c) = c.get(1) {
return format!("{}{}", c.as_str(), replace);
}
}
}
format!("{}s", non_plural_string)
}
}
#[cfg(test)]
mod tests {
macro_rules! as_item {
($i:item) => { $i };
}
macro_rules! make_tests{
($($singular:ident => $plural:ident); *) =>{
$(
as_item! {
#[test]
fn $singular(){
assert_eq!(
stringify!($plural),
super::to_plural(stringify!($singular))
);
}
}
)*
}
}
#[test]
fn boxes() {
assert_eq!("boxes", super::to_plural("box"));
}
make_tests!{
geometry => geometries;
ox => oxen;
woman => women;
test => tests;
axis => axes;
knife => knives;
agendum => agenda;
elf => elves;
zoology => zoology
}
}

189
third_party/rust/Inflector/src/string/singularize/mod.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,189 @@
use regex::Regex;
use string::constants::UNACCONTABLE_WORDS;
macro_rules! special_cases{
($s:ident, $($singular: expr => $plural:expr), *) => {
match &$s[..] {
$(
$singular => {
return $plural.to_owned();
},
)*
_ => ()
}
}
}
/// Converts a `&str` to singularized `String`
///
/// ```
/// use inflector::string::singularize::to_singular;
/// let mock_string: &str = "foo_bars";
/// let expected_string: String = "foo_bar".to_owned();
/// let asserted_string: String = to_singular(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::string::singularize::to_singular;
/// let mock_string: &str = "oxen";
/// let expected_string: String = "ox".to_owned();
/// let asserted_string: String = to_singular(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::string::singularize::to_singular;
/// let mock_string: &str = "crates";
/// let expected_string: String = "crate".to_owned();
/// let asserted_string: String = to_singular(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::string::singularize::to_singular;
/// let mock_string: &str = "oxen";
/// let expected_string: String = "ox".to_owned();
/// let asserted_string: String = to_singular(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::string::singularize::to_singular;
/// let mock_string: &str = "boxes";
/// let expected_string: String = "box".to_owned();
/// let asserted_string: String = to_singular(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::string::singularize::to_singular;
/// let mock_string: &str = "vengeance";
/// let expected_string: String = "vengeance".to_owned();
/// let asserted_string: String = to_singular(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::string::singularize::to_singular;
/// let mock_string: &str = "yoga";
/// let expected_string: String = "yoga".to_owned();
/// let asserted_string: String = to_singular(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
///
pub fn to_singular(non_singular_string: &str) -> String {
if UNACCONTABLE_WORDS.contains(&non_singular_string.as_ref()) {
non_singular_string.to_owned()
} else {
special_cases![non_singular_string,
"oxen" => "ox",
"boxes" => "box",
"men" => "man",
"women" => "woman",
"dice" => "die",
"yeses" => "yes",
"feet" => "foot",
"eaves" => "eave",
"geese" => "goose",
"teeth" => "tooth",
"quizzes" => "quiz"
];
for &(ref rule, replace) in RULES.iter().rev() {
if let Some(captures) = rule.captures(&non_singular_string) {
if let Some(c) = captures.get(1) {
let mut buf = String::new();
captures.expand(&format!("{}{}", c.as_str(), replace), &mut buf);
return buf;
}
}
}
format!("{}", non_singular_string)
}
}
macro_rules! add_rule{
($r:ident, $rule:expr => $replace:expr) => {
$r.push((Regex::new($rule).unwrap(), $replace));
}
}
macro_rules! rules{
($r:ident; $($rule:expr => $replace:expr), *) => {
$(
add_rule!{$r, $rule => $replace}
)*
}
}
lazy_static!{
static ref RULES: Vec<(Regex, &'static str)> = {
let mut r = Vec::with_capacity(27);
rules![r;
r"(\w*)s$" => "",
r"(\w*)(ss)$" => "$2",
r"(n)ews$" => "ews",
r"(\w*)(o)es$" => "",
r"(\w*)([ti])a$" => "um",
r"((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)$" => "sis",
r"(^analy)(sis|ses)$" => "sis",
r"(\w*)([^f])ves$" => "fe",
r"(\w*)(hive)s$" => "",
r"(\w*)(tive)s$" => "",
r"(\w*)([lr])ves$" => "f",
r"(\w*([^aeiouy]|qu))ies$" => "y",
r"(s)eries$" => "eries",
r"(m)ovies$" => "ovie",
r"(\w*)(x|ch|ss|sh)es$" => "$2",
r"(m|l)ice$" => "ouse",
r"(bus)(es)?$" => "",
r"(shoe)s$" => "",
r"(cris|test)(is|es)$" => "is",
r"^(a)x[ie]s$" => "xis",
r"(octop|vir)(us|i)$" => "us",
r"(alias|status)(es)?$" => "",
r"^(ox)en" => "",
r"(vert|ind)ices$" => "ex",
r"(matr)ices$" => "ix",
r"(quiz)zes$" => "",
r"(database)s$" => ""
];
r
};
}
#[test]
fn singularize_ies_suffix() {
assert_eq!("reply", to_singular("replies"));
assert_eq!("lady", to_singular("ladies"));
assert_eq!("soliloquy", to_singular("soliloquies"));
}
#[test]
fn singularize_ss_suffix() {
assert_eq!("glass", to_singular("glass"));
assert_eq!("access", to_singular("access"));
assert_eq!("glass", to_singular("glasses"));
assert_eq!("witch", to_singular("witches"));
assert_eq!("dish", to_singular("dishes"));
}
#[test]
fn singularize_string_if_a_regex_will_match() {
let expected_string: String = "ox".to_owned();
let asserted_string: String = to_singular("oxen");
assert!(expected_string == asserted_string);
}
#[test]
fn singularize_string_returns_none_option_if_no_match() {
let expected_string: String = "bacon".to_owned();
let asserted_string: String = to_singular("bacon");
assert!(expected_string == asserted_string);
}

139
third_party/rust/Inflector/src/suffix/foreignkey/mod.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,139 @@
use cases::snakecase::to_snake_case;
/// Converts a `&str` to a `foreign_key`
///
/// ```
/// use inflector::suffix::foreignkey::to_foreign_key;
/// let mock_string: &str = "foo_bar";
/// let expected_string: String = "foo_bar_id".to_owned();
/// let asserted_string: String = to_foreign_key(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::suffix::foreignkey::to_foreign_key;
/// let mock_string: &str = "Foo bar";
/// let expected_string: String = "foo_bar_id".to_owned();
/// let asserted_string: String = to_foreign_key(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::suffix::foreignkey::to_foreign_key;
/// let mock_string: &str = "Foo Bar";
/// let expected_string: String = "foo_bar_id".to_owned();
/// let asserted_string: String = to_foreign_key(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::suffix::foreignkey::to_foreign_key;
/// let mock_string: &str = "Foo::Bar";
/// let expected_string: String = "bar_id".to_owned();
/// let asserted_string: String = to_foreign_key(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::suffix::foreignkey::to_foreign_key;
/// let mock_string: &str = "Test::Foo::Bar";
/// let expected_string: String = "bar_id".to_owned();
/// let asserted_string: String = to_foreign_key(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::suffix::foreignkey::to_foreign_key;
/// let mock_string: &str = "FooBar";
/// let expected_string: String = "foo_bar_id".to_owned();
/// let asserted_string: String = to_foreign_key(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::suffix::foreignkey::to_foreign_key;
/// let mock_string: &str = "fooBar";
/// let expected_string: String = "foo_bar_id".to_owned();
/// let asserted_string: String = to_foreign_key(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
/// ```
/// use inflector::suffix::foreignkey::to_foreign_key;
/// let mock_string: &str = "fooBar3";
/// let expected_string: String = "foo_bar_3_id".to_owned();
/// let asserted_string: String = to_foreign_key(mock_string);
/// assert!(asserted_string == expected_string);
///
/// ```
pub fn to_foreign_key(non_foreign_key_string: &str) -> String {
if non_foreign_key_string.contains("::") {
let split_string: Vec<&str> = non_foreign_key_string.split("::").collect();
safe_convert(split_string[split_string.len() - 1])
} else {
safe_convert(non_foreign_key_string)
}
}
fn safe_convert(safe_string: &str) -> String {
let snake_cased: String = to_snake_case(safe_string);
if snake_cased.ends_with("_id") {
snake_cased
} else {
format!("{}{}", snake_cased, "_id")
}
}
/// Determines if a `&str` is a `foreign_key`
///
/// ```
/// use inflector::suffix::foreignkey::is_foreign_key;
/// let mock_string: &str = "Foo bar string that is really really long";
/// let asserted_bool: bool = is_foreign_key(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
/// ```
/// use inflector::suffix::foreignkey::is_foreign_key;
/// let mock_string: &str = "foo-bar-string-that-is-really-really-long";
/// let asserted_bool: bool = is_foreign_key(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
/// ```
/// use inflector::suffix::foreignkey::is_foreign_key;
/// let mock_string: &str = "FooBarIsAReallyReallyLongString";
/// let asserted_bool: bool = is_foreign_key(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
/// ```
/// use inflector::suffix::foreignkey::is_foreign_key;
/// let mock_string: &str = "Foo Bar Is A Really Really Long String";
/// let asserted_bool: bool = is_foreign_key(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
/// ```
/// use inflector::suffix::foreignkey::is_foreign_key;
/// let mock_string: &str = "fooBarIsAReallyReallyLongString";
/// let asserted_bool: bool = is_foreign_key(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
/// ```
/// use inflector::suffix::foreignkey::is_foreign_key;
/// let mock_string: &str = "foo_bar_string_that_is_really_really_long";
/// let asserted_bool: bool = is_foreign_key(mock_string);
/// assert!(asserted_bool == false);
///
/// ```
/// ```
/// use inflector::suffix::foreignkey::is_foreign_key;
/// let mock_string: &str = "foo_bar_string_that_is_really_really_long_id";
/// let asserted_bool: bool = is_foreign_key(mock_string);
/// assert!(asserted_bool == true);
///
/// ```
pub fn is_foreign_key(test_string: &str) -> bool {
to_foreign_key(test_string.clone()) == test_string
}

5
third_party/rust/Inflector/src/suffix/mod.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,5 @@
#![deny(warnings)]
/// Provides foreign key conversion for String.
///
/// Example string `foo` becomes `foo_id`
pub mod foreignkey;

162
third_party/rust/Inflector/tests/lib.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,162 @@
#![deny(warnings)]
extern crate inflector;
use inflector::Inflector;
use inflector::InflectorNumbers;
macro_rules! str_tests {
( $($test_name:ident => $imp_trait:ident => $to_cast:expr => $casted:expr), *) => {
$(
#[test]
fn $test_name() {
assert_eq!($to_cast.$imp_trait(), $casted)
}
)*
}
}
macro_rules! string_tests {
( $($test_name:ident => $imp_trait:ident => $to_cast:expr => $casted:expr), *) => {
$(
#[test]
fn $test_name() {
assert_eq!($to_cast.to_string().$imp_trait(), $casted)
}
)*
}
}
macro_rules! number_tests {
( $($test_name:ident => $imp_trait:ident => $typ:ident => $to_cast:expr => $casted:expr), *) => {
$(
#[test]
fn $test_name() {
let to_cast: $typ = $to_cast;
assert_eq!(to_cast.$imp_trait(), $casted)
}
)*
}
}
macro_rules! gated_str_tests {
( $($test_name:ident => $imp_trait:ident => $to_cast:expr => $casted:expr), *) => {
$(
#[test]
#[cfg(feature = "heavyweight")]
fn $test_name() {
assert_eq!($to_cast.$imp_trait(), $casted)
}
)*
}
}
macro_rules! gated_string_tests {
( $($test_name:ident => $imp_trait:ident => $to_cast:expr => $casted:expr), *) => {
$(
#[test]
#[cfg(feature = "heavyweight")]
fn $test_name() {
assert_eq!($to_cast.to_string().$imp_trait(), $casted)
}
)*
}
}
str_tests![
str_to_camel => to_camel_case => "foo_bar" => "fooBar".to_string(),
str_is_camel => is_camel_case => "fooBar" => true,
str_is_not_camel => is_camel_case => "foo_bar" => false,
str_to_screaming_snake => to_screaming_snake_case => "fooBar" => "FOO_BAR".to_string(),
str_is_screaming_snake => is_screaming_snake_case => "FOO_BAR" => true,
str_is_not_screaming_snake => is_screaming_snake_case => "foo_bar" => false,
str_to_snake => to_snake_case => "fooBar" => "foo_bar".to_string(),
str_is_snake => is_snake_case => "foo_bar" => true,
str_is_not_snake => is_snake_case => "fooBar" => false,
str_to_kebab => to_kebab_case => "fooBar" => "foo-bar".to_string(),
str_is_kebab => is_kebab_case => "foo-bar" => true,
str_is_not_kebab => is_kebab_case => "fooBar" => false,
str_to_train => to_train_case => "fooBar" => "Foo-Bar".to_string(),
str_is_train => is_train_case => "Foo-Bar" => true,
str_is_not_train => is_train_case => "FOO-Bar" => false,
str_to_sentence => to_sentence_case => "fooBar" => "Foo bar".to_string(),
str_is_sentence => is_sentence_case => "Foo bar" => true,
str_is_not_sentence => is_sentence_case => "foo_bar" => false,
str_to_title => to_title_case => "fooBar" => "Foo Bar".to_string(),
str_is_title => is_title_case => "Foo Bar" => true,
str_is_not_title => is_title_case => "Foo_Bar" => false,
str_ordinalize => ordinalize => "1" => "1st".to_string(),
str_deordinalize => deordinalize => "1st" => "1".to_string(),
str_to_foreign_key => to_foreign_key => "Foo::Bar" => "bar_id".to_string(),
str_is_foreign_key => is_foreign_key => "bar_id" => true,
str_is_not_foreign_key => is_foreign_key => "bar" => false
];
gated_str_tests![
str_to_class_case => to_class_case => "foo" => "Foo".to_string(),
str_is_class_case => is_class_case => "Foo" => true,
str_is_not_class_case => is_class_case => "foo" => false,
str_to_table => to_table_case => "fooBar" => "foo_bars".to_string(),
str_is_table => is_table_case => "foo_bars" => true,
str_is_not_table => is_table_case => "fooBars" => false,
str_pluralize => to_plural => "crate" => "crates".to_string(),
str_singular => to_singular => "crates" => "crate".to_string(),
str_demodulize => demodulize => "Foo::Bar" => "Bar".to_string(),
str_deconstantize => deconstantize => "Foo::Bar" => "Foo".to_string()
];
string_tests![
string_to_camel => to_camel_case => "foo_bar".to_string() => "fooBar".to_string(),
string_is_camel => is_camel_case => "fooBar".to_string() => true,
string_is_not_camel => is_camel_case => "foo_bar".to_string() => false,
string_to_screaming_snake => to_screaming_snake_case => "fooBar".to_string() => "FOO_BAR".to_string(),
string_is_screaming_snake => is_screaming_snake_case => "FOO_BAR".to_string() => true,
string_is_not_screaming_snake => is_screaming_snake_case => "foo_bar".to_string() => false,
string_to_snake => to_snake_case => "fooBar".to_string() => "foo_bar".to_string(),
string_is_snake => is_snake_case => "foo_bar".to_string() => true,
string_is_not_snake => is_snake_case => "fooBar".to_string() => false,
string_to_kebab => to_kebab_case => "fooBar".to_string() => "foo-bar".to_string(),
string_is_kebab => is_kebab_case => "foo-bar".to_string() => true,
string_is_not_kebab => is_kebab_case => "fooBar".to_string() => false,
string_to_train => to_train_case => "fooBar".to_string() => "Foo-Bar".to_string(),
string_is_train => is_train_case => "Foo-Bar".to_string() => true,
string_is_not_train => is_train_case => "foo-Bar".to_string() => false,
string_to_sentence => to_sentence_case => "fooBar".to_string() => "Foo bar".to_string(),
string_is_sentence => is_sentence_case => "Foo bar".to_string() => true,
string_is_not_sentence => is_sentence_case => "fooBar".to_string() => false,
string_to_title => to_title_case => "fooBar".to_string() => "Foo Bar".to_string(),
string_is_title => is_title_case => "Foo Bar".to_string() => true,
string_is_not_title => is_title_case => "fooBar".to_string() => false,
string_ordinalize => ordinalize => "1".to_string() => "1st".to_string(),
string_deordinalize => deordinalize => "1st".to_string() => "1".to_string(),
string_to_foreign_key => to_foreign_key => "Foo::Bar".to_string() => "bar_id".to_string(),
string_is_foreign_key => is_foreign_key => "bar_id".to_string() => true,
string_is_not_foreign_key => is_foreign_key => "bar".to_string() => false
];
gated_string_tests![
string_to_class_case => to_class_case => "foo".to_string() => "Foo".to_string(),
string_is_class_case => is_class_case => "Foo".to_string() => true,
string_is_not_class_case => is_class_case => "ooBar".to_string() => false,
string_to_table => to_table_case => "fooBar".to_string() => "foo_bars".to_string(),
string_is_table => is_table_case => "foo_bars".to_string() => true,
string_is_not_table => is_table_case => "fooBar".to_string() => false,
string_pluralize => to_plural => "crate".to_string() => "crates".to_string(),
string_singular => to_singular => "crates".to_string() => "crate".to_string(),
string_demodulize => demodulize => "Foo::Bar".to_string() => "Bar".to_string(),
string_deconstantize => deconstantize => "Foo::Bar".to_string() => "Foo".to_string()
];
number_tests![
i8_ordinalize => ordinalize => i8 => 1 => "1st".to_string(),
i16_ordinalize => ordinalize => i16 => 1 => "1st".to_string(),
i32_ordinalize => ordinalize => i32 => 1 => "1st".to_string(),
i64_ordinalize => ordinalize => i64 => 1 => "1st".to_string(),
u8_ordinalize => ordinalize => u8 => 1 => "1st".to_string(),
u16_ordinalize => ordinalize => u16 => 1 => "1st".to_string(),
u32_ordinalize => ordinalize => u32 => 1 => "1st".to_string(),
u64_ordinalize => ordinalize => u64 => 1 => "1st".to_string(),
isize_ordinalize => ordinalize => isize => 1 => "1st".to_string(),
usize_ordinalize => ordinalize => usize => 1 => "1st".to_string(),
f32_ordinalize => ordinalize => f32 => 1.0 => "1st".to_string(),
f64_ordinalize => ordinalize => f64 => 1.0 => "1st".to_string()
];

Просмотреть файл

@ -1 +1 @@
{"files":{"Cargo.toml":"9124a80649d91347830f5e4e91cd35dbaf0d173e8e95f71b3163735f975f6460","README.md":"80b1ac2d22e813da57353131a86e05735201197c4938f8e8bbc0b29b00b1ed24","benches/resolver.rs":"1bfd1d2920e11bd0d9c995abe1365bb2840cd847b6846646d137cedad2cb10ae","examples/README.md":"99a51f7d388d2da3c5291e68de5264feaf642ba9a22f6f882c3b940c1b6429b2","src/args.rs":"44c00a120d7df9f39e410726d51cc542ddf4f68f5cedc492c9367c3759d75b78","src/bundle.rs":"599ae2ef1ca1fab75f39fe459382a1e8702d153614754d4ca812c30de78ef8a7","src/concurrent.rs":"3a760f85d7373af13d8b1fdd2a03bd8aede8c0d08ec61589a8a0866df6a86e76","src/entry.rs":"8be695ed178d072d5471d18fd35d5a711db6e7d6cbcf651a5d9f1ce2ea55804f","src/errors.rs":"165e1a80e1aa2674056a7cd820b4318d87095c8d5709919e92ce7db52b57547f","src/lib.rs":"38138f4d9fb4349c6f170e462094c7ebd6c7c807f6a195004d03add79605dcfe","src/memoizer.rs":"922084f71f02d0532056db9b41cec4c1434001fe60215ee6f6ac8e3fd2518f12","src/message.rs":"dfb53488f82c425f97f99c5544e5410b465b55826423c35467c83e836d6d3464","src/resolver/errors.rs":"57c71d7c4590f44309f67c9ca758fae7ae50bc57563c7b3150ef4763b5a4d1ea","src/resolver/expression.rs":"93f12328241161493371dee6a7d3e4c0baeb7d5db693ad45dec70f11ab766a8f","src/resolver/inline_expression.rs":"e387eb6d6a19ff1df72218868502a2df9f5b6c45852796e6166c4124dbe99c19","src/resolver/mod.rs":"f2566c2d2c3470a816e1d81f94ab790786408379bb894ef26b444fb3a55a7124","src/resolver/pattern.rs":"d2ab5a0e303f2a146efcc89669ee18a66c4a68537d880460224a89bc7022f8d9","src/resolver/scope.rs":"b1ae9c132d575b5d15b9e1b998734ac919576956b62a214a837a128ee00565c6","src/resource.rs":"818f6dfa5835db371f55d6032230d56ebf44761ea3ed058d72dab0d02fb36a15","src/types/mod.rs":"29b13664536f66af1a119773b2785cc51b1aee630ffb640b04c83d57d52239d4","src/types/number.rs":"75383cf77046e234c80b4c353da2643daa882172010b2f4d3a0a36d5ffb6b569","src/types/plural.rs":"f28834e71d6970d5eb48089132f5242433b1e62b90765d85e3c76f805eecc92e"},"package":"a79916560098f0a57215a489e37b7fc83088949eab7f7977dcc329b254d50c17"}
{"files":{"Cargo.toml":"faf6b0a0061a6379af7f95060b77c2e51460d9b2e8f673570c81a67d855bbfa9","LICENSE-APACHE":"5db2b182453ff32ed40f7da63589c9667a3f8bd8b16b1471b152caae56f77e45","LICENSE-MIT":"49c0b000c03731d9e3970dc059ad4ca345d773681f4a612b0024435b663e0220","README.md":"4143ee70148d1e9a14131a0cc9a68c73cc43375bb3173110f516dc0bb2959640","benches/resolver.rs":"084684b22d5ccf86180354381b1be76245b36beb51ab5bbc44d9c94dacc0948f","examples/README.md":"99a51f7d388d2da3c5291e68de5264feaf642ba9a22f6f882c3b940c1b6429b2","src/args.rs":"3e04a53ea22cf86d4b2777942da3cbc183e25673928812884acaaf9a199ed769","src/bundle.rs":"aa59968ce98bba8d4a14b321d38f10938cc89535cb3f8519bce75ef7533c1912","src/concurrent.rs":"3a760f85d7373af13d8b1fdd2a03bd8aede8c0d08ec61589a8a0866df6a86e76","src/entry.rs":"8be695ed178d072d5471d18fd35d5a711db6e7d6cbcf651a5d9f1ce2ea55804f","src/errors.rs":"a924cdfcd3f76b42e162729d9131d7d528e49047cab38bf22cb3aefc8ad1b182","src/lib.rs":"a89ffa82eec432df803c741095563dae60784dedd77132e40c5529eba44a9c90","src/memoizer.rs":"922084f71f02d0532056db9b41cec4c1434001fe60215ee6f6ac8e3fd2518f12","src/message.rs":"dfb53488f82c425f97f99c5544e5410b465b55826423c35467c83e836d6d3464","src/resolver/errors.rs":"beaf41fabbfd11211cb2c3db6ca0ba26bccf75817bed05a92b980393edfb3f9f","src/resolver/expression.rs":"93f12328241161493371dee6a7d3e4c0baeb7d5db693ad45dec70f11ab766a8f","src/resolver/inline_expression.rs":"69052aa5a56bec6d41ae244c015202fae549112b985fff7e4dc79d94218b1af6","src/resolver/mod.rs":"3369d3792e987259ca572547c749930c24602fda48a1ed952f9cc6412a7e16b6","src/resolver/pattern.rs":"772ac9af07343e2cac2da63627b851aa442fe6172554f74879d3fed001f9483a","src/resolver/scope.rs":"8d193e390a356328fcec2b05eb51cf077ac1395c48d987b8dc544d7572b87fa2","src/resource.rs":"bcb5ec46f95ceca948f0d26b681c8569f677d9f9804f6fe5f85236407926b5c7","src/types/mod.rs":"48ab65ba9e9e11fb57fce30020ac69d2ec141c855950bed5bed36f9cd37835b3","src/types/number.rs":"d2073a2c03bcff3a55d9a8b8f206497bc2be11f56c598c448549b64bc2bd5d2d","src/types/plural.rs":"f28834e71d6970d5eb48089132f5242433b1e62b90765d85e3c76f805eecc92e"},"package":"4c0cd40fee9f6eb74dfb38f0fa700a92ac4fe702868b04e52018ead90d415332"}

14
third_party/rust/fluent-bundle/Cargo.toml поставляемый
Просмотреть файл

@ -13,9 +13,9 @@
[package]
edition = "2018"
name = "fluent-bundle"
version = "0.13.1"
version = "0.14.1"
authors = ["Zibi Braniecki <gandalf@mozilla.com>", "Staś Małolepszy <stas@mozilla.com>"]
include = ["src/**/*", "benches/*.rs", "Cargo.toml", "README.md"]
include = ["src/**/*", "benches/*.rs", "Cargo.toml", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
description = "A localization system designed to unleash the entire expressive power of\nnatural language translations.\n"
homepage = "http://www.projectfluent.org"
readme = "README.md"
@ -31,16 +31,16 @@ harness = false
version = "0.13"
[dependencies.fluent-syntax]
version = "0.10"
version = "0.10.1"
[dependencies.intl-memoizer]
version = "0.5"
[dependencies.intl_pluralrules]
version = "7.0"
version = "7.0.1"
[dependencies.rental]
version = "0.5"
[dependencies.ouroboros]
version = "0.7"
[dependencies.smallvec]
version = "1"
@ -51,7 +51,7 @@ version = "0.9"
version = "0.3"
[dev-dependencies.rand]
version = "0.7"
version = "0.8"
[dev-dependencies.serde]
version = "1.0"

201
third_party/rust/fluent-bundle/LICENSE-APACHE поставляемый Normal file
Просмотреть файл

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2017 Mozilla
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

19
third_party/rust/fluent-bundle/LICENSE-MIT поставляемый Normal file
Просмотреть файл

@ -0,0 +1,19 @@
Copyright 2017 Mozilla
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

2
third_party/rust/fluent-bundle/README.md поставляемый
Просмотреть файл

@ -31,7 +31,7 @@ fn main() {
.expect("Could not parse an FTL string.");
let langid_en = langid!("en");
let mut bundle = FluentBundle::new(&[langid_en]);
let mut bundle = FluentBundle::new(vec![langid_en]);
bundle.add_resource(&res)
.expect("Failed to add FTL resources to the bundle.");

Просмотреть файл

@ -74,7 +74,7 @@ fn add_functions<R>(name: &'static str, bundle: &mut FluentBundle<R>) {
fn get_bundle(name: &'static str, source: &str) -> (FluentBundle<FluentResource>, Vec<String>) {
let res = FluentResource::try_new(source.to_owned()).expect("Couldn't parse an FTL source");
let ids = get_ids(&res);
let lids = &[langid!("en")];
let lids = vec![langid!("en")];
let mut bundle = FluentBundle::new(lids);
bundle
.add_resource(res)
@ -89,8 +89,7 @@ fn resolver_bench(c: &mut Criterion) {
let mut group = c.benchmark_group("resolve");
for name in tests {
let source = ftl_strings.get(name)
.expect("Failed to find the source.");
let source = ftl_strings.get(name).expect("Failed to find the source.");
group.bench_with_input(BenchmarkId::from_parameter(name), &source, |b, source| {
let (bundle, ids) = get_bundle(name, source);
let args = get_args(name);
@ -104,7 +103,8 @@ fn resolver_bench(c: &mut Criterion) {
s.clear();
}
for attr in msg.attributes {
let _ = bundle.write_pattern(&mut s, attr.value, args.as_ref(), &mut errors);
let _ =
bundle.write_pattern(&mut s, attr.value, args.as_ref(), &mut errors);
s.clear();
}
assert!(errors.len() == 0, "Resolver errors: {:#?}", errors);
@ -116,8 +116,7 @@ fn resolver_bench(c: &mut Criterion) {
let mut group = c.benchmark_group("resolve_to_str");
for name in tests {
let source = ftl_strings.get(name)
.expect("Failed to find the source.");
let source = ftl_strings.get(name).expect("Failed to find the source.");
group.bench_with_input(BenchmarkId::from_parameter(name), &source, |b, source| {
let (bundle, ids) = get_bundle(name, source);
let args = get_args(name);

1
third_party/rust/fluent-bundle/src/args.rs поставляемый
Просмотреть файл

@ -6,6 +6,7 @@ use crate::types::FluentValue;
/// A map of arguments passed from the code to
/// the localization to be used for message
/// formatting.
#[derive(Debug, Default)]
pub struct FluentArgs<'args>(Vec<(Cow<'args, str>, FluentValue<'args>)>);
impl<'args> FluentArgs<'args> {

56
third_party/rust/fluent-bundle/src/bundle.rs поставляемый
Просмотреть файл

@ -16,12 +16,12 @@ use unic_langid::LanguageIdentifier;
use crate::args::FluentArgs;
use crate::entry::Entry;
use crate::entry::GetEntry;
use crate::errors::FluentError;
use crate::errors::{EntryKind, FluentError};
use crate::memoizer::MemoizerKind;
use crate::message::{FluentAttribute, FluentMessage};
use crate::resolver::{ResolveValue, Scope, WriteValue};
use crate::resource::FluentResource;
use crate::types::FluentValue;
use crate::message::{FluentMessage, FluentAttribute};
/// Base class for a [`FluentBundle`] struct. See its docs for details.
/// It also is implemented for [`concurrent::FluentBundle`].
@ -39,9 +39,11 @@ pub struct FluentBundleBase<R, M> {
}
impl<R, M: MemoizerKind> FluentBundleBase<R, M> {
/// Constructs a FluentBundle. `locales` is the fallback chain of locales
/// to use for formatters like date and time. `locales` does not influence
/// message selection.
/// Constructs a FluentBundle. The first element in `locales` should be the
/// language this bundle represents, and will be used to determine the
/// correct plural rules for this bundle. You can optionally provide extra
/// languages in the list; they will be used as fallback date and time
/// formatters if a formatter for the primary language is unavailable.
///
/// # Examples
///
@ -51,25 +53,19 @@ impl<R, M: MemoizerKind> FluentBundleBase<R, M> {
/// use unic_langid::langid;
///
/// let langid_en = langid!("en-US");
/// let mut bundle: FluentBundle<FluentResource> = FluentBundle::new(&[langid_en]);
/// let mut bundle: FluentBundle<FluentResource> = FluentBundle::new(vec![langid_en]);
/// ```
///
/// # Errors
///
/// This will panic if no formatters can be found for the locales.
pub fn new<'a, L: 'a + Into<LanguageIdentifier> + PartialEq + Clone>(
locales: impl IntoIterator<Item = &'a L>,
) -> Self {
let locales = locales
.into_iter()
.map(|s| s.clone().into())
.collect::<Vec<_>>();
let lang = locales.get(0).cloned().unwrap_or_default();
pub fn new(locales: Vec<LanguageIdentifier>) -> Self {
let first_locale = locales.get(0).cloned().unwrap_or_default();
Self {
locales,
resources: vec![],
entries: HashMap::new(),
intls: M::new(lang),
intls: M::new(first_locale),
use_isolating: true,
transform: None,
formatter: None,
@ -82,7 +78,7 @@ impl<R, M: MemoizerKind> FluentBundleBase<R, M> {
/// existing key in the bundle, the new entry will be ignored and a
/// `FluentError::Overriding` will be added to the result.
///
/// The method can take any type that can be borrowed to FluentResource:
/// The method can take any type that can be borrowed to `FluentResource`:
/// - FluentResource
/// - &FluentResource
/// - Rc<FluentResource>
@ -104,7 +100,7 @@ impl<R, M: MemoizerKind> FluentBundleBase<R, M> {
/// let resource = FluentResource::try_new(ftl_string)
/// .expect("Could not parse an FTL string.");
/// let langid_en = langid!("en-US");
/// let mut bundle = FluentBundle::new(&[langid_en]);
/// let mut bundle = FluentBundle::new(vec![langid_en]);
/// bundle.add_resource(resource)
/// .expect("Failed to add FTL resources to the bundle.");
/// assert_eq!(true, bundle.has_message("hello"));
@ -138,8 +134,10 @@ impl<R, M: MemoizerKind> FluentBundleBase<R, M> {
};
let (entry, kind) = match entry {
ast::Entry::Message(..) => (Entry::Message([res_pos, entry_pos]), "message"),
ast::Entry::Term(..) => (Entry::Term([res_pos, entry_pos]), "term"),
ast::Entry::Message(..) => {
(Entry::Message([res_pos, entry_pos]), EntryKind::Message)
}
ast::Entry::Term(..) => (Entry::Term([res_pos, entry_pos]), EntryKind::Term),
_ => continue,
};
@ -199,7 +197,7 @@ impl<R, M: MemoizerKind> FluentBundleBase<R, M> {
///
/// let langid_en = langid!("en-US");
///
/// let mut bundle = FluentBundle::new(&[langid_en]);
/// let mut bundle = FluentBundle::new(vec![langid_en]);
/// bundle.add_resource(resource)
/// .expect("Failed to add FTL resources to the bundle.");
///
@ -304,7 +302,7 @@ impl<R, M: MemoizerKind> FluentBundleBase<R, M> {
/// let resource = FluentResource::try_new(ftl_string)
/// .expect("Failed to parse an FTL string.");
/// let langid_en = langid!("en-US");
/// let mut bundle = FluentBundle::new(&[langid_en]);
/// let mut bundle = FluentBundle::new(vec![langid_en]);
/// bundle.add_resource(&resource)
/// .expect("Failed to add FTL resources to the bundle.");
/// assert_eq!(true, bundle.has_message("hello"));
@ -330,7 +328,7 @@ impl<R, M: MemoizerKind> FluentBundleBase<R, M> {
/// .expect("Failed to parse an FTL string.");
///
/// let langid_en = langid!("en-US");
/// let mut bundle = FluentBundle::new(&[langid_en]);
/// let mut bundle = FluentBundle::new(vec![langid_en]);
///
/// bundle.add_resource(&resource)
/// .expect("Failed to add FTL resources to the bundle.");
@ -348,8 +346,8 @@ impl<R, M: MemoizerKind> FluentBundleBase<R, M> {
for attr in &message.attributes {
attributes.push(FluentAttribute {
id: &attr.id.name,
value: &attr.value
id: attr.id.name,
value: &attr.value,
});
}
Some(FluentMessage { value, attributes })
@ -368,7 +366,7 @@ impl<R, M: MemoizerKind> FluentBundleBase<R, M> {
/// .expect("Failed to parse an FTL string.");
///
/// let langid_en = langid!("en-US");
/// let mut bundle = FluentBundle::new(&[langid_en]);
/// let mut bundle = FluentBundle::new(vec![langid_en]);
///
/// bundle.add_resource(&resource)
/// .expect("Failed to add FTL resources to the bundle.");
@ -414,7 +412,7 @@ impl<R, M: MemoizerKind> FluentBundleBase<R, M> {
/// .expect("Failed to parse an FTL string.");
///
/// let langid_en = langid!("en-US");
/// let mut bundle = FluentBundle::new(&[langid_en]);
/// let mut bundle = FluentBundle::new(vec![langid_en]);
///
/// bundle.add_resource(&resource)
/// .expect("Failed to add FTL resources to the bundle.");
@ -461,7 +459,7 @@ impl<R, M: MemoizerKind> FluentBundleBase<R, M> {
/// let resource = FluentResource::try_new(ftl_string)
/// .expect("Could not parse an FTL string.");
/// let langid_en = langid!("en-US");
/// let mut bundle = FluentBundle::new(&[langid_en]);
/// let mut bundle = FluentBundle::new(vec![langid_en]);
/// bundle.add_resource(&resource)
/// .expect("Failed to add FTL resources to the bundle.");
///
@ -489,7 +487,7 @@ impl<R, M: MemoizerKind> FluentBundleBase<R, M> {
Ok(())
}
HashEntry::Occupied(_) => Err(FluentError::Overriding {
kind: "function",
kind: EntryKind::Function,
id: id.to_owned(),
}),
}
@ -499,7 +497,7 @@ impl<R, M: MemoizerKind> FluentBundleBase<R, M> {
impl<R, M: MemoizerKind> Default for FluentBundleBase<R, M> {
fn default() -> Self {
let langid = LanguageIdentifier::default();
FluentBundleBase {
Self {
locales: vec![langid.clone()],
resources: vec![],
entries: Default::default(),

36
third_party/rust/fluent-bundle/src/errors.rs поставляемый
Просмотреть файл

@ -1,13 +1,45 @@
use crate::resolver::ResolverError;
use fluent_syntax::parser::ParserError;
use std::error::Error;
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub enum EntryKind {
Message,
Term,
Function,
}
impl std::fmt::Display for EntryKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Message => f.write_str("message"),
Self::Term => f.write_str("term"),
Self::Function => f.write_str("function"),
}
}
}
#[derive(Debug, PartialEq, Clone)]
pub enum FluentError {
Overriding { kind: &'static str, id: String },
Overriding { kind: EntryKind, id: String },
ParserError(ParserError),
ResolverError(ResolverError),
}
impl std::fmt::Display for FluentError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Overriding { kind, id } => {
write!(f, "Attempt to override an existing {}: \"{}\".", kind, id)
}
Self::ParserError(err) => write!(f, "Parser error: {}", err),
Self::ResolverError(err) => write!(f, "Resolver error: {}", err),
}
}
}
impl Error for FluentError {}
impl From<ResolverError> for FluentError {
fn from(error: ResolverError) -> Self {
Self::ResolverError(error)

7
third_party/rust/fluent-bundle/src/lib.rs поставляемый
Просмотреть файл

@ -30,7 +30,7 @@
//! .expect("Failed to parse an FTL string.");
//!
//! let langid_en = langid!("en-US");
//! let mut bundle = FluentBundle::new(&[langid_en]);
//! let mut bundle = FluentBundle::new(vec![langid_en]);
//!
//! bundle
//! .add_resource(res)
@ -79,9 +79,6 @@
//! [`FluentValue`]: ./types/enum.FluentValue.html
//! [`FluentArgs`]: ./struct.FluentArgs.html
#[macro_use]
extern crate rental;
use intl_memoizer::{IntlLangMemoizer, Memoizable};
use unic_langid::LanguageIdentifier;
@ -116,7 +113,7 @@ pub use types::FluentValue;
/// .expect("Could not parse an FTL string.");
///
/// let langid_en = langid!("en-US");
/// let mut bundle = FluentBundle::new(&[langid_en]);
/// let mut bundle = FluentBundle::new(vec![langid_en]);
///
/// bundle.add_resource(&resource)
/// .expect("Failed to add FTL resources to the bundle.");

Просмотреть файл

@ -1,7 +1,96 @@
use fluent_syntax::ast::InlineExpression;
use std::error::Error;
#[derive(Debug, PartialEq, Clone)]
pub enum ReferenceKind {
Function {
id: String,
},
Message {
id: String,
attribute: Option<String>,
},
Term {
id: String,
attribute: Option<String>,
},
Variable {
id: String,
},
}
impl<T> From<&InlineExpression<T>> for ReferenceKind
where
T: ToString,
{
fn from(exp: &InlineExpression<T>) -> Self {
match exp {
InlineExpression::FunctionReference { id, .. } => Self::Function {
id: id.name.to_string(),
},
InlineExpression::MessageReference { id, attribute } => Self::Message {
id: id.name.to_string(),
attribute: attribute.as_ref().map(|i| i.name.to_string()),
},
InlineExpression::TermReference { id, attribute, .. } => Self::Term {
id: id.name.to_string(),
attribute: attribute.as_ref().map(|i| i.name.to_string()),
},
InlineExpression::VariableReference { id, .. } => Self::Variable {
id: id.name.to_string(),
},
_ => unreachable!(),
}
}
}
#[derive(Debug, PartialEq, Clone)]
pub enum ResolverError {
Reference(String),
Reference(ReferenceKind),
NoValue(String),
MissingDefault,
Cyclic,
TooManyPlaceables,
}
impl std::fmt::Display for ResolverError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Reference(exp) => match exp {
ReferenceKind::Function { id } => write!(f, "Unknown function: {}()", id),
ReferenceKind::Message {
id,
attribute: None,
} => write!(f, "Unknown message: {}", id),
ReferenceKind::Message {
id,
attribute: Some(attribute),
} => write!(f, "Unknown attribute: {}.{}", id, attribute),
ReferenceKind::Term {
id,
attribute: None,
} => write!(f, "Unknown term: -{}", id),
ReferenceKind::Term {
id,
attribute: Some(attribute),
} => write!(f, "Unknown attribute: -{}.{}", id, attribute),
ReferenceKind::Variable { id } => write!(f, "Unknown variable: ${}", id),
},
Self::NoValue(id) => write!(f, "No value: {}", id),
Self::MissingDefault => f.write_str("No default"),
Self::Cyclic => f.write_str("Cyclical dependency detected"),
Self::TooManyPlaceables => f.write_str("Too many placeables"),
}
}
}
impl<T> From<&InlineExpression<T>> for ResolverError
where
T: ToString,
{
fn from(exp: &InlineExpression<T>) -> Self {
Self::Reference(exp.into())
}
}
impl Error for ResolverError {}

Просмотреть файл

@ -24,23 +24,34 @@ impl<'p> WriteValue for ast::InlineExpression<&'p str> {
{
match self {
Self::StringLiteral { value } => unescape_unicode(w, value),
Self::MessageReference { id, attribute } => scope
.bundle
.get_entry_message(id.name)
.and_then(|msg| {
Self::MessageReference { id, attribute } => {
if let Some(msg) = scope.bundle.get_entry_message(id.name) {
if let Some(attr) = attribute {
msg.attributes.iter().find_map(|a| {
if a.id.name == attr.name {
Some(scope.track(w, &a.value, self))
} else {
None
}
})
msg.attributes
.iter()
.find_map(|a| {
if a.id.name == attr.name {
Some(scope.track(w, &a.value, self))
} else {
None
}
})
.unwrap_or_else(|| scope.write_ref_error(w, self))
} else {
msg.value.as_ref().map(|value| scope.track(w, value, self))
msg.value
.as_ref()
.map(|value| scope.track(w, value, self))
.unwrap_or_else(|| {
scope.add_error(ResolverError::NoValue(id.name.to_string()));
w.write_char('{')?;
self.write_error(w)?;
w.write_char('}')
})
}
})
.unwrap_or_else(|| scope.write_ref_error(w, self)),
} else {
scope.write_ref_error(w, self)
}
}
Self::NumberLiteral { value } => FluentValue::try_number(*value).write(w, scope),
Self::TermReference {
id,
@ -94,7 +105,7 @@ impl<'p> WriteValue for ast::InlineExpression<&'p str> {
arg.write(w, scope)
} else {
if scope.local_args.is_none() {
scope.add_error(ResolverError::Reference(self.resolve_error()));
scope.add_error(self.into());
}
w.write_char('{')?;
self.write_error(w)?;
@ -153,7 +164,7 @@ impl<'p> ResolveValue for ast::InlineExpression<&'p str> {
arg.clone()
} else {
if scope.local_args.is_none() {
scope.add_error(ResolverError::Reference(self.resolve_error()));
scope.add_error(self.into());
}
FluentValue::Error
}
@ -165,50 +176,4 @@ impl<'p> ResolveValue for ast::InlineExpression<&'p str> {
}
}
}
fn resolve_error(&self) -> String {
match self {
Self::MessageReference {
attribute: None, ..
} => {
let mut error = String::from("Unknown message: ");
self.write_error(&mut error)
.expect("Failed to write to String.");
error
}
Self::MessageReference { .. } => {
let mut error = String::from("Unknown attribute: ");
self.write_error(&mut error)
.expect("Failed to write to String.");
error
}
Self::VariableReference { .. } => {
let mut error = String::from("Unknown variable: ");
self.write_error(&mut error)
.expect("Failed to write to String.");
error
}
Self::TermReference {
attribute: None, ..
} => {
let mut error = String::from("Unknown term: ");
self.write_error(&mut error)
.expect("Failed to write to String.");
error
}
Self::TermReference { .. } => {
let mut error = String::from("Unknown attribute: ");
self.write_error(&mut error)
.expect("Failed to write to String.");
error
}
Self::FunctionReference { .. } => {
let mut error = String::from("Unknown function: ");
self.write_error(&mut error)
.expect("Failed to write to String.");
error
}
_ => unreachable!(),
}
}
}

Просмотреть файл

@ -30,8 +30,6 @@ pub(crate) trait ResolveValue {
) -> FluentValue<'source>
where
R: Borrow<FluentResource>;
fn resolve_error(&self) -> String;
}
pub(crate) trait WriteValue {

Просмотреть файл

@ -48,18 +48,15 @@ impl<'p> WriteValue for ast::Pattern<&'p str> {
let needs_isolation = scope.bundle.use_isolating
&& len > 1
&& match expression {
ast::Expression::InlineExpression(
ast::InlineExpression::MessageReference { .. },
)
| ast::Expression::InlineExpression(
ast::InlineExpression::TermReference { .. },
)
| ast::Expression::InlineExpression(
ast::InlineExpression::StringLiteral { .. },
) => false,
_ => true,
};
&& !matches!(expression, ast::Expression::InlineExpression(
ast::InlineExpression::MessageReference { .. },
)
| ast::Expression::InlineExpression(
ast::InlineExpression::TermReference { .. },
)
| ast::Expression::InlineExpression(
ast::InlineExpression::StringLiteral { .. },
));
if needs_isolation {
w.write_char('\u{2068}')?;
}
@ -105,8 +102,4 @@ impl<'p> ResolveValue for ast::Pattern<&'p str> {
.expect("Failed to write to a string.");
result.into()
}
fn resolve_error(&self) -> String {
unreachable!()
}
}

Просмотреть файл

@ -109,7 +109,7 @@ impl<'scope, 'errors, R, M: MemoizerKind> Scope<'scope, 'errors, R, M> {
where
W: fmt::Write,
{
self.add_error(ResolverError::Reference(exp.resolve_error()));
self.add_error(exp.into());
w.write_char('{')?;
exp.write_error(w)?;
w.write_char('}')

Просмотреть файл

@ -1,32 +1,35 @@
use fluent_syntax::ast;
use fluent_syntax::parser::Parser;
use fluent_syntax::parser::ParserError;
use ouroboros::self_referencing;
rental! {
mod rentals {
use super::*;
#[rental(covariant, debug)]
pub struct FluentResource {
string: String,
ast: ast::Resource<&'string str>,
}
}
#[self_referencing]
#[derive(Debug)]
pub struct InnerFluentResource {
string: String,
#[borrows(string)]
ast: ast::Resource<&'this str>,
}
/// A resource containing a list of localization messages.
#[derive(Debug)]
pub struct FluentResource(rentals::FluentResource);
pub struct FluentResource(InnerFluentResource);
impl FluentResource {
pub fn try_new(source: String) -> Result<Self, (Self, Vec<ParserError>)> {
let mut errors = None;
let res = rentals::FluentResource::new(source, |s| match Parser::new(s).parse() {
Ok(ast) => ast,
Err((ast, err)) => {
errors = Some(err);
ast
}
});
let res = InnerFluentResourceBuilder {
string: source,
ast_builder: |string: &str| match Parser::new(string).parse() {
Ok(ast) => ast,
Err((ast, err)) => {
errors = Some(err);
ast
}
},
}
.build();
if let Some(errors) = errors {
Err((Self(res), errors))
@ -36,6 +39,6 @@ impl FluentResource {
}
pub fn ast(&self) -> &ast::Resource<&str> {
self.0.all().ast
self.0.borrow_ast()
}
}

Просмотреть файл

@ -2,7 +2,7 @@ mod number;
mod plural;
pub use number::*;
use plural::*;
use plural::PluralRules;
use std::any::Any;
use std::borrow::{Borrow, Cow};
@ -37,11 +37,9 @@ pub trait AnyEq: Any + 'static {
impl<T: Any + PartialEq> AnyEq for T {
fn equals(&self, other: &dyn Any) -> bool {
if let Some(that) = other.downcast_ref::<Self>() {
self == that
} else {
false
}
other
.downcast_ref::<Self>()
.map_or(false, |that| self == that)
}
fn as_any(&self) -> &dyn Any {
self

Просмотреть файл

@ -126,7 +126,7 @@ pub struct FluentNumber {
}
impl FluentNumber {
pub fn new(value: f64, options: FluentNumberOptions) -> Self {
pub const fn new(value: f64, options: FluentNumberOptions) -> Self {
Self { value, options }
}

Просмотреть файл

@ -1 +1 @@
{"files":{"Cargo.lock":"86d719f00e87c024063688c9249a5d3b81c5a911b319dbb9c20bcfafc828f33f","Cargo.toml":"d5d89842d3441943922cc9f94bf70ada7ac1822912fa36b9a1b87eaa1abdb75a","README.md":"dcab9c1dfa8dde8d660fc4eadbbc90793180c9d3bc198dd81a2441e8610b89b5","benches/contexts/README.md":"562d317f507caedd62cbe00e6b2bb350cb970168e5ebd5b3c497e68696e21e8b","benches/parser.rs":"50e1fe08dabffeb379fd208ac88260d35852ff6a2a72701b1902b315bc5c18a3","src/ast/helper.rs":"39187bbc97823ba0f3a9baadd76ddc59140bf09cddeb92997dd872e41b305375","src/ast/mod.rs":"86b203d6537a4fe0c761d9180d4663352fe14e55aca5a34c0571e1798693b343","src/bin/parser.rs":"08f4092a9fc8b7346d3935cbf90a663d5ba2ace593f3becf4622bc2e08db43f4","src/bin/update_fixtures.rs":"b4e25f1dbe7b6289d7cdab8114bdd11553787eabf570d3fc04c9ba87da6cee98","src/lib.rs":"ccbc6ff63ef90c280755bf8ef7d056ff3f586708e418e290d3faab0fc4c37889","src/parser/comment.rs":"1ac8500651f812c3187326687cb5f445e5e686d586bc32732ddb0f31560dc71e","src/parser/errors.rs":"343303963847c50109c2f2a9a6f94fd45ee7b0e5c72d26a03f63786e24cf7454","src/parser/expression.rs":"cb2f51b88b5afc639042f7416e8c0c3a4dc0c10c1cd345c2249a24c12a85efea","src/parser/helper.rs":"c30f52bb5ae61775d89bcb253e40b545043c4e6d08259d57678a40cb41db4469","src/parser/mod.rs":"f5b92bf6b22c27e197e876bf4522b579f8083d3d4b6c890b2b42e1e8419041fe","src/parser/pattern.rs":"56b22146f7494e370f7bd69e5f7e39b059599f05d950cfabc9405fcae64d6837","src/parser/slice.rs":"aad45bc35ecc3ff68bcd5b2671fecb134a4535d6ee463092422dfc5cc8b25a1d","src/unicode.rs":"1736a89cb8827a4e49883c0c33f3dd89f37bb90cc92152364578fe2c3a3a1de1"},"package":"9389354f858e38f37d9a249133611a1fcaec469f44773b04ddbd82f4f08d49eb"}
{"files":{"Cargo.lock":"7ef89d17cfb66296e8599334e0b2b7a5c339351156df223ec0de011dc17551cc","Cargo.toml":"35327710f5722106689ab30c0140eae6f75fc4893e72ccc5c8e57cc6643e155a","README.md":"dcab9c1dfa8dde8d660fc4eadbbc90793180c9d3bc198dd81a2441e8610b89b5","benches/contexts/README.md":"562d317f507caedd62cbe00e6b2bb350cb970168e5ebd5b3c497e68696e21e8b","benches/parser.rs":"50e1fe08dabffeb379fd208ac88260d35852ff6a2a72701b1902b315bc5c18a3","src/ast/helper.rs":"39187bbc97823ba0f3a9baadd76ddc59140bf09cddeb92997dd872e41b305375","src/ast/mod.rs":"86b203d6537a4fe0c761d9180d4663352fe14e55aca5a34c0571e1798693b343","src/bin/parser.rs":"08f4092a9fc8b7346d3935cbf90a663d5ba2ace593f3becf4622bc2e08db43f4","src/bin/update_fixtures.rs":"b4e25f1dbe7b6289d7cdab8114bdd11553787eabf570d3fc04c9ba87da6cee98","src/lib.rs":"ccbc6ff63ef90c280755bf8ef7d056ff3f586708e418e290d3faab0fc4c37889","src/parser/comment.rs":"1ac8500651f812c3187326687cb5f445e5e686d586bc32732ddb0f31560dc71e","src/parser/errors.rs":"1e2e90b873d2c92011d883b8ca93a2a0eda2e1c576b3d402e35902e9ffad848e","src/parser/expression.rs":"aa4a37d0f894907b4a61b61fc076e31d327aac66193c9f08586a1d03fd2d803a","src/parser/helper.rs":"71fb35290cba6b5e5b05cbc77aaadd0cc15e1b38984c83f51ac8c4d594d53ae3","src/parser/mod.rs":"02028af70c2d355699a2df2bd5b390d933df81f8d33a6f656cf3f62257202665","src/parser/pattern.rs":"3be83a1123488f7fe2d960c9f6aac72160f3305cfa509a81e1f37df84ca12522","src/parser/slice.rs":"aad45bc35ecc3ff68bcd5b2671fecb134a4535d6ee463092422dfc5cc8b25a1d","src/unicode.rs":"1736a89cb8827a4e49883c0c33f3dd89f37bb90cc92152364578fe2c3a3a1de1"},"package":"edb1016e8c600060e0099218442fff329a204f6316d6ec974d590d3281517a52"}

159
third_party/rust/fluent-syntax/Cargo.lock сгенерированный поставляемый
Просмотреть файл

@ -25,9 +25,9 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]]
name = "bstr"
version = "0.2.13"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31accafdb70df7871592c058eca3985b71104e15ac32f64706022c58867da931"
checksum = "473fc6b38233f9af7baa94fb5852dca389e3d95b8e21c8e3719301462c5d9faf"
dependencies = [
"lazy_static",
"memchr",
@ -62,6 +62,12 @@ version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "2.33.3"
@ -73,6 +79,12 @@ dependencies = [
"unicode-width",
]
[[package]]
name = "const_fn"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd51eab21ab4fd6a3bf889e2d0958c0a6e3a61ad04260325e919e652a2a62826"
[[package]]
name = "criterion"
version = "0.3.3"
@ -111,56 +123,55 @@ dependencies = [
[[package]]
name = "crossbeam-channel"
version = "0.4.4"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b153fe7cbef478c567df0f972e02e6d736db11affe43dfc9c56a9374d1adfb87"
checksum = "dca26ee1f8d361640700bde38b2c37d8c22b3ce2d360e1fc1c74ea4b0aa7d775"
dependencies = [
"cfg-if 1.0.0",
"crossbeam-utils",
"maybe-uninit",
]
[[package]]
name = "crossbeam-deque"
version = "0.7.3"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f02af974daeee82218205558e51ec8768b48cf524bd01d550abe5573a608285"
checksum = "94af6efb46fef72616855b036a624cf27ba656ffc9be1b9a3c931cfc7749a9a9"
dependencies = [
"cfg-if 1.0.0",
"crossbeam-epoch",
"crossbeam-utils",
"maybe-uninit",
]
[[package]]
name = "crossbeam-epoch"
version = "0.8.2"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace"
checksum = "a1aaa739f95311c2c7887a76863f500026092fb1dce0161dab577e559ef3569d"
dependencies = [
"autocfg",
"cfg-if",
"cfg-if 1.0.0",
"const_fn",
"crossbeam-utils",
"lazy_static",
"maybe-uninit",
"memoffset",
"scopeguard",
]
[[package]]
name = "crossbeam-utils"
version = "0.7.2"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8"
checksum = "02d96d1e189ef58269ebe5b97953da3274d83a93af647c2ddd6f9dab28cedb8d"
dependencies = [
"autocfg",
"cfg-if",
"cfg-if 1.0.0",
"lazy_static",
]
[[package]]
name = "csv"
version = "1.1.3"
version = "1.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00affe7f6ab566df61b4be3ce8cf16bc2576bca0963ceb0955e45d514bf9a279"
checksum = "f9d58633299b24b515ac72a3f869f8b91306a3cec616a602843a383acd6f9e97"
dependencies = [
"bstr",
"csv-core",
@ -186,7 +197,7 @@ checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
[[package]]
name = "fluent-syntax"
version = "0.10.0"
version = "0.10.1"
dependencies = [
"criterion",
"glob",
@ -208,9 +219,9 @@ checksum = "d36fab90f82edc3c747f9d438e06cf0a491055896f2a279638bb5beed6c40177"
[[package]]
name = "hermit-abi"
version = "0.1.16"
version = "0.1.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c30f6d0bc6b00693347368a67d41b58f2fb851215ff1da49e90fe2c5c667151"
checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8"
dependencies = [
"libc",
]
@ -226,15 +237,15 @@ dependencies = [
[[package]]
name = "itoa"
version = "0.4.6"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"
checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736"
[[package]]
name = "js-sys"
version = "0.3.45"
version = "0.3.46"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca059e81d9486668f12d455a4ea6daa600bd408134cd17e3d3fb5a32d1f016f8"
checksum = "cf3d7383929f7c9c7c2d0fa596f325832df98c3704f2c60553080f7127a58175"
dependencies = [
"wasm-bindgen",
]
@ -247,9 +258,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.77"
version = "0.2.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2f96b10ec2560088a8e76961b00d47107b3a625fecb76dedb29ee7ccbf98235"
checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb"
[[package]]
name = "log"
@ -257,35 +268,29 @@ version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b"
dependencies = [
"cfg-if",
"cfg-if 0.1.10",
]
[[package]]
name = "maybe-uninit"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00"
[[package]]
name = "memchr"
version = "2.3.3"
version = "2.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400"
checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525"
[[package]]
name = "memoffset"
version = "0.5.6"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "043175f069eda7b85febe4a74abbaeff828d9f8b448515d3151a14a3542811aa"
checksum = "157b4208e3059a8f9e78d559edc658e13df41410cb3ae03979c83130067fdd87"
dependencies = [
"autocfg",
]
[[package]]
name = "num-traits"
version = "0.2.12"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611"
checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"
dependencies = [
"autocfg",
]
@ -302,9 +307,9 @@ dependencies = [
[[package]]
name = "oorandom"
version = "11.1.2"
version = "11.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a170cebd8021a008ea92e4db85a72f80b35df514ec664b296fdcbb654eac0b2c"
checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575"
[[package]]
name = "plotters"
@ -320,27 +325,27 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.21"
version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36e28516df94f3dd551a587da5357459d9b36d945a7c37c3557928c1c2ff2a2c"
checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71"
dependencies = [
"unicode-xid",
]
[[package]]
name = "quote"
version = "1.0.7"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
checksum = "991431c3519a3f36861882da93630ce66b52918dcf1b8e2fd66b397fc96f28df"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rayon"
version = "1.4.0"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cfd016f0c045ad38b5251be2c9c0ab806917f82da4d36b2a327e5166adad9270"
checksum = "8b0d8e0819fadc20c74ea8373106ead0600e3a67ef1fe8da56e39b9ae7275674"
dependencies = [
"autocfg",
"crossbeam-deque",
@ -350,9 +355,9 @@ dependencies = [
[[package]]
name = "rayon-core"
version = "1.8.1"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8c4fec834fb6e6d2dd5eece3c7b432a52f0ba887cf40e595190c4107edc08bf"
checksum = "9ab346ac5921dc62ffa9f89b7a773907511cdfa5490c572ae9be1be33e8afa4a"
dependencies = [
"crossbeam-channel",
"crossbeam-deque",
@ -363,9 +368,9 @@ dependencies = [
[[package]]
name = "regex"
version = "1.3.9"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c3780fcf44b193bc4d09f36d2a3c87b251da4a046c87795a0d35f4f927ad8e6"
checksum = "38cf2c13ed4745de91a5eb834e11c00bcc3709e773173b2ce4c56c9fbde04b9c"
dependencies = [
"regex-syntax",
]
@ -381,9 +386,9 @@ dependencies = [
[[package]]
name = "regex-syntax"
version = "0.6.18"
version = "0.6.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8"
checksum = "3b181ba2dcf07aaccad5448e8ead58db5b742cf85dfe035e2227f137a539a189"
[[package]]
name = "rustc_version"
@ -432,9 +437,9 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
[[package]]
name = "serde"
version = "1.0.116"
version = "1.0.118"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96fe57af81d28386a513cbc6858332abc6117cfdb5999647c6444b8f43a370a5"
checksum = "06c64263859d87aa2eb554587e2d23183398d617427327cf2b3d0ed8c69e4800"
dependencies = [
"serde_derive",
]
@ -451,9 +456,9 @@ dependencies = [
[[package]]
name = "serde_derive"
version = "1.0.116"
version = "1.0.118"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f630a6370fd8e457873b4bd2ffdae75408bc291ba72be773772a4c2a065d9ae8"
checksum = "c84d3526699cd55261af4b941e4e725444df67aa4f9e6a3564f18030d12672df"
dependencies = [
"proc-macro2",
"quote",
@ -462,9 +467,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.57"
version = "1.0.61"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "164eacbdb13512ec2745fb09d51fd5b22b0d65ed294a1dcf7285a360c80a675c"
checksum = "4fceb2595057b6891a4ee808f70054bd2d12f0e97f1cbb78689b59f676df325a"
dependencies = [
"itoa",
"ryu",
@ -473,9 +478,9 @@ dependencies = [
[[package]]
name = "syn"
version = "1.0.41"
version = "1.0.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6690e3e9f692504b941dc6c3b188fd28df054f7fb8469ab40680df52fdcc842b"
checksum = "4211ce9909eb971f111059df92c45640aad50a619cf55cd76476be803c4c68e6"
dependencies = [
"proc-macro2",
"quote",
@ -493,9 +498,9 @@ dependencies = [
[[package]]
name = "tinytemplate"
version = "1.1.0"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d3dc76004a03cec1c5932bca4cdc2e39aaa798e3f82363dd94f9adf6098c12f"
checksum = "a2ada8616fad06a2d0c455adc530de4ef57605a8120cc65da9653e0e9623ca74"
dependencies = [
"serde",
"serde_json",
@ -526,19 +531,19 @@ dependencies = [
[[package]]
name = "wasm-bindgen"
version = "0.2.68"
version = "0.2.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ac64ead5ea5f05873d7c12b545865ca2b8d28adfc50a49b84770a3a97265d42"
checksum = "3cd364751395ca0f68cafb17666eee36b63077fb5ecd972bbcd74c90c4bf736e"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"wasm-bindgen-macro",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.68"
version = "0.2.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f22b422e2a757c35a73774860af8e112bff612ce6cb604224e8e47641a9e4f68"
checksum = "1114f89ab1f4106e5b55e688b828c0ab0ea593a1ea7c094b141b14cbaaec2d62"
dependencies = [
"bumpalo",
"lazy_static",
@ -551,9 +556,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.68"
version = "0.2.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b13312a745c08c469f0b292dd2fcd6411dba5f7160f593da6ef69b64e407038"
checksum = "7a6ac8995ead1f084a8dea1e65f194d0973800c7f571f6edd70adf06ecf77084"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
@ -561,9 +566,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.68"
version = "0.2.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f249f06ef7ee334cc3b8ff031bfc11ec99d00f34d86da7498396dc1e3b1498fe"
checksum = "b5a48c72f299d80557c7c62e37e7225369ecc0c963964059509fbafe917c7549"
dependencies = [
"proc-macro2",
"quote",
@ -574,15 +579,15 @@ dependencies = [
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.68"
version = "0.2.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d649a3145108d7d3fbcde896a468d1bd636791823c9921135218ad89be08307"
checksum = "7e7811dd7f9398f14cc76efd356f98f03aa30419dea46aa810d71e819fc97158"
[[package]]
name = "web-sys"
version = "0.3.45"
version = "0.3.46"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4bf6ef87ad7ae8008e15a355ce696bed26012b7caa21605188cfd8214ab51e2d"
checksum = "222b1ef9334f92a21d3fb53dc3fd80f30836959a90f9274a626d7e06315ba3c3"
dependencies = [
"js-sys",
"wasm-bindgen",

2
third_party/rust/fluent-syntax/Cargo.toml поставляемый
Просмотреть файл

@ -13,7 +13,7 @@
[package]
edition = "2018"
name = "fluent-syntax"
version = "0.10.0"
version = "0.10.1"
authors = ["Zibi Braniecki <gandalf@mozilla.com>", "Staś Małolepszy <stas@mozilla.com>"]
include = ["src/**/*", "benches/*.rs", "Cargo.toml", "README.md"]
description = "Parser/Serializer tools for Fluent Syntax. \n"

Просмотреть файл

@ -1,6 +1,6 @@
use std::fmt::{self, Display, Formatter};
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct ParserError {
pub pos: (usize, usize),
pub slice: Option<(usize, usize)>,
@ -32,7 +32,7 @@ macro_rules! error {
}};
}
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub enum ErrorKind {
Generic,
ExpectedEntry,

Просмотреть файл

@ -71,9 +71,7 @@ where
while let Some(b) = self.source.as_ref().as_bytes().get(self.ptr) {
match b {
b'\\' => match self.source.as_ref().as_bytes().get(self.ptr + 1) {
Some(b'\\') => self.ptr += 2,
Some(b'{') => self.ptr += 2,
Some(b'"') => self.ptr += 2,
Some(b'\\') | Some(b'{') | Some(b'"') => self.ptr += 2,
Some(b'u') => {
self.ptr += 2;
self.skip_unicode_escape_sequence(4)?;
@ -128,9 +126,7 @@ where
let id = self.get_identifier()?;
let arguments = self.get_call_arguments()?;
if arguments.is_some() {
if !id.name.as_ref().bytes().all(|c| {
c.is_ascii_uppercase() || c.is_ascii_digit() || c == b'_' || c == b'-'
}) {
if !Self::is_callee(id.name.as_ref().as_bytes()) {
return error!(ErrorKind::ForbiddenCallee, self.ptr);
}

Просмотреть файл

@ -61,10 +61,7 @@ where
}
pub(super) fn is_identifier_start(&self) -> bool {
match self.source.as_ref().as_bytes().get(self.ptr) {
Some(b) if b.is_ascii_alphabetic() => true,
_ => false,
}
matches!(self.source.as_ref().as_bytes().get(self.ptr), Some(b) if b.is_ascii_alphabetic())
}
pub(super) fn take_byte_if(&mut self, b: u8) -> bool {
@ -93,8 +90,7 @@ where
pub(super) fn skip_blank(&mut self) {
loop {
match self.source.as_ref().as_bytes().get(self.ptr) {
Some(b' ') => self.ptr += 1,
Some(b'\n') => self.ptr += 1,
Some(b' ') | Some(b'\n') => self.ptr += 1,
Some(b'\r')
if self.source.as_ref().as_bytes().get(self.ptr + 1) == Some(&b'\n') =>
{
@ -117,6 +113,11 @@ where
![b'}', b'.', b'[', b'*'].contains(&b)
}
pub(super) fn is_callee(name: &[u8]) -> bool {
name.iter()
.all(|c| c.is_ascii_uppercase() || c.is_ascii_digit() || *c == b'_' || *c == b'-')
}
pub(super) fn expect_byte(&mut self, b: u8) -> Result<()> {
if !self.is_current_byte(b) {
return error!(ErrorKind::ExpectedToken(b as char), self.ptr);
@ -126,10 +127,7 @@ where
}
pub(super) fn is_number_start(&self) -> bool {
match self.source.as_ref().as_bytes().get(self.ptr) {
Some(b) if (b == &b'-') || b.is_ascii_digit() => true,
_ => false,
}
matches!(self.source.as_ref().as_bytes().get(self.ptr), Some(b) if (b == &b'-') || b.is_ascii_digit())
}
pub(super) fn is_eol(&self) -> bool {

Просмотреть файл

@ -174,12 +174,11 @@ where
break;
}
match self.get_attribute() {
Ok(attr) => attributes.push(attr),
Err(_) => {
self.ptr = line_start;
break;
}
if let Ok(attr) = self.get_attribute() {
attributes.push(attr);
} else {
self.ptr = line_start;
break;
}
}
attributes
@ -339,43 +338,41 @@ where
let expr = self.get_inline_expression()?;
match expr {
ast::InlineExpression::MessageReference {
ref id,
attribute: None,
} => {
self.skip_blank();
if self.is_current_byte(b':') {
if argument_names.contains(&id.name) {
return error!(
ErrorKind::DuplicatedNamedArgument(id.name.as_ref().to_owned()),
self.ptr
);
}
self.ptr += 1;
self.skip_blank();
let val = self.get_inline_expression()?;
argument_names.push(id.name.clone());
named.push(ast::NamedArgument {
name: ast::Identifier {
name: id.name.clone(),
},
value: val,
});
} else {
if !argument_names.is_empty() {
return error!(ErrorKind::PositionalArgumentFollowsNamed, self.ptr);
}
positional.push(expr);
if let ast::InlineExpression::MessageReference {
ref id,
attribute: None,
} = expr
{
self.skip_blank();
if self.is_current_byte(b':') {
if argument_names.contains(&id.name) {
return error!(
ErrorKind::DuplicatedNamedArgument(id.name.as_ref().to_owned()),
self.ptr
);
}
}
_ => {
self.ptr += 1;
self.skip_blank();
let val = self.get_inline_expression()?;
argument_names.push(id.name.clone());
named.push(ast::NamedArgument {
name: ast::Identifier {
name: id.name.clone(),
},
value: val,
});
} else {
if !argument_names.is_empty() {
return error!(ErrorKind::PositionalArgumentFollowsNamed, self.ptr);
}
positional.push(expr);
}
} else {
if !argument_names.is_empty() {
return error!(ErrorKind::PositionalArgumentFollowsNamed, self.ptr);
}
positional.push(expr);
}
self.skip_blank();

Просмотреть файл

@ -132,11 +132,10 @@ where
}
PatternElementPlaceholders::TextElement(start, end, indent, role) => {
let start = if role == TextElementPosition::LineStart {
if let Some(common_indent) = common_indent {
start + std::cmp::min(indent, common_indent)
} else {
start + indent
}
common_indent.map_or_else(
|| start + indent,
|common_indent| start + std::cmp::min(indent, common_indent),
)
} else {
start
};

Просмотреть файл

@ -1 +1 @@
{"files":{"Cargo.toml":"0a72309d641decbe9849d17acfc427ccee44dec2c2d13f6bbbaef42cbf90a9bf","README.md":"38ca7cc14db1eb9cce03d8690e9476eaf75e0ed07ae65c68af4573a043c75c34","src/lib.rs":"ce7f9ae6517a4b95764e68c15f208aea81cb69db6ad7985502ff142e3c1c82a7"},"package":"ef9e54ec7b674ae3477d948ae790e90ae24d54fb31c2e7173252978d9b09bdfa"}
{"files":{"Cargo.toml":"6b1f2e50f6591f922f6d3bc96b4085ba25030333dcbcd02d1b05c02185584490","LICENSE-APACHE":"5db2b182453ff32ed40f7da63589c9667a3f8bd8b16b1471b152caae56f77e45","LICENSE-MIT":"49c0b000c03731d9e3970dc059ad4ca345d773681f4a612b0024435b663e0220","README.md":"2d65e0a7ef3bc4033fe0f9aaa8f851e14e892383dcf3bf4ccc5bfcafbf266fe9","src/lib.rs":"ca9f033f6caa7d5acff78fc360e1affd74ac52b95c94cde659ae9eba328f527d"},"package":"e4f3359832f932e4ddbb4c56851623cb50bd08d1ae36e9ec80cfc44f412e1400"}

6
third_party/rust/fluent/Cargo.toml поставляемый
Просмотреть файл

@ -13,9 +13,9 @@
[package]
edition = "2018"
name = "fluent"
version = "0.13.1"
version = "0.14.1"
authors = ["Zibi Braniecki <gandalf@mozilla.com>", "Staś Małolepszy <stas@mozilla.com>"]
include = ["src/**/*", "benches/*.rs", "Cargo.toml", "README.md"]
include = ["src/**/*", "benches/*.rs", "Cargo.toml", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
description = "A localization system designed to unleash the entire expressive power of\nnatural language translations.\n"
homepage = "http://www.projectfluent.org"
readme = "README.md"
@ -24,7 +24,7 @@ categories = ["localization", "internationalization"]
license = "Apache-2.0/MIT"
repository = "https://github.com/projectfluent/fluent-rs"
[dependencies.fluent-bundle]
version = "0.13"
version = "0.14.1"
[dependencies.fluent-pseudo]
version = "0.2"

201
third_party/rust/fluent/LICENSE-APACHE поставляемый Normal file
Просмотреть файл

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2017 Mozilla
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

19
third_party/rust/fluent/LICENSE-MIT поставляемый Normal file
Просмотреть файл

@ -0,0 +1,19 @@
Copyright 2017 Mozilla
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

2
third_party/rust/fluent/README.md поставляемый
Просмотреть файл

@ -31,7 +31,7 @@ fn main() {
.expect("Failed to parse an FTL string.");
let langid_en = langid!("en-US");
let mut bundle = FluentBundle::new(&[langid_en]);
let mut bundle = FluentBundle::new(vec![langid_en]);
bundle.add_resource(&res)
.expect("Failed to add FTL resources to the bundle.");

2
third_party/rust/fluent/src/lib.rs поставляемый
Просмотреть файл

@ -30,7 +30,7 @@
//! .expect("Failed to parse an FTL string.");
//!
//! let langid_en: LanguageIdentifier = "en-US".parse().expect("Parsing failed");
//! let mut bundle = FluentBundle::new(&[langid_en]);
//! let mut bundle = FluentBundle::new(vec![langid_en]);
//!
//! bundle
//! .add_resource(res)

Просмотреть файл

@ -1 +1 @@
{"files":{"Cargo.toml":"fc6b94bccbe543c92858eb40b6538155aa73e85096843bf6b01a38f99c642112","README.md":"4dad9bc033a67101bc318662c055318457f0b91e12fdc0a566495b455ceeb4b8","benches/pluralrules.rs":"9c80009fa94a8dbf31bdba489f320d92a40f482c37149030fbba53cd62b5435f","src/lib.rs":"732bde12e3f83b193bf07fb3528e46decb11d2ce5bb442190df0530b48888013","src/operands.rs":"b58c9f8f0f7ce4622ccc685f08b15ede09591b628deffa3b14abde873d26c44a","src/rules.rs":"7b3f0c12e0722401efbdb54873e8545f943bf4a34cba9f894ead9dc955112aaf"},"package":"6c271cdb1f12a9feb3a017619c3ee681f971f270f6757341d6abe1f9f7a98bc3"}
{"files":{"Cargo.toml":"3b7451d96ed662827dd4163d64d96840fee1c4241c2480b8cdd91ef156ad7896","README.md":"4dad9bc033a67101bc318662c055318457f0b91e12fdc0a566495b455ceeb4b8","benches/pluralrules.rs":"9c80009fa94a8dbf31bdba489f320d92a40f482c37149030fbba53cd62b5435f","src/lib.rs":"a642fa4b7147731449acf39650fc92e764716de8303d9637c3263ae3ae03b899","src/operands.rs":"b58c9f8f0f7ce4622ccc685f08b15ede09591b628deffa3b14abde873d26c44a","src/rules.rs":"7b3f0c12e0722401efbdb54873e8545f943bf4a34cba9f894ead9dc955112aaf"},"package":"b18f988384267d7066cc2be425e6faf352900652c046b6971d2e228d3b1c5ecf"}

Просмотреть файл

@ -13,7 +13,7 @@
[package]
edition = "2018"
name = "intl_pluralrules"
version = "7.0.0"
version = "7.0.1"
authors = ["Kekoa Riggin <kekoariggin@gmail.com>", "Zibi Braniecki <zbraniecki@mozilla.com>"]
include = ["src/**/*", "benches/*.rs", "Cargo.toml", "README.md"]
description = "Unicode Plural Rules categorizer for numeric input."

Просмотреть файл

@ -27,7 +27,7 @@
/// A public AST module for plural rule representations.
pub mod operands;
#[cfg_attr(tarpaulin, skip)]
#[cfg(not(tarpaulin_include))]
mod rules;
use std::convert::TryInto;

1
third_party/rust/ouroboros/.cargo-checksum.json поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
{"files":{"Cargo.toml":"5e757a99e461764a5fadbc8dd3d55570c1d41c6ffeee2b8bdae58db95fcf44c4","src/lib.rs":"60fad6e825c78e83c577ed4134132c46d7d3e613ea764089e9dce57396e9dfa0"},"package":"b0b666c900ea45a357bc7915a4dc8fab7e295f2e756e843aa3c0788d94aa3a29"}

27
third_party/rust/ouroboros/Cargo.toml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,27 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies
#
# If you believe there's an error in this file please file an
# issue against the rust-lang/cargo repository. If you're
# editing this file be aware that the upstream Cargo.toml
# will likely look very different (and much more reasonable)
[package]
edition = "2018"
name = "ouroboros"
version = "0.7.0"
authors = ["Joshua Maros <joshua-maros@github.com>"]
description = "Easy, safe self-referential struct generation."
documentation = "https://docs.rs/ouroboros"
readme = "../README.md"
license = "MIT OR Apache-2.0"
repository = "https://github.com/joshua-maros/ouroboros"
[dependencies.ouroboros_macro]
version = "0.7.0"
[dependencies.stable_deref_trait]
version = "1.2"

249
third_party/rust/ouroboros/src/lib.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,249 @@
//! A crate for creating safe self-referencing structs.
//!
//! See the documentation of [`ouroboros_examples`](https://docs.rs/ouroboros_examples) for
//! sample documentation of structs which have had the macro applied to them.
#![allow(clippy::needless_doctest_main)]
/// This macro is used to turn a regular struct into a self-referencing one. An example:
/// ```rust
/// use ouroboros::self_referencing;
///
/// #[self_referencing]
/// struct MyStruct {
/// int_data: Box<i32>,
/// float_data: Box<f32>,
/// #[borrows(int_data)]
/// int_reference: &'this i32,
/// #[borrows(mut float_data)]
/// float_reference: &'this mut f32,
/// }
///
/// fn main() {
/// let mut my_value = MyStructBuilder {
/// int_data: Box::new(42),
/// float_data: Box::new(3.14),
/// int_reference_builder: |int_data: &i32| int_data,
/// float_reference_builder: |float_data: &mut f32| float_data,
/// }.build();
///
/// // Prints 42
/// println!("{:?}", my_value.borrow_int_data());
/// // Prints 3.14
/// println!("{:?}", my_value.borrow_float_reference());
/// // Sets the value of float_data to 84.0
/// my_value.with_mut(|fields| {
/// **fields.float_reference = (**fields.int_reference as f32) * 2.0;
/// });
///
/// // We can hold on to this reference...
/// let int_ref = *my_value.borrow_int_reference();
/// println!("{:?}", *int_ref);
/// // As long as the struct is still alive.
/// drop(my_value);
/// // This will cause an error!
/// // println!("{:?}", *int_ref);
/// }
/// ```
/// To explain the features and limitations of this crate, some definitions are necessary:
/// # Definitions
/// - **immutably borrowed field**: a field which is immutably borrowed by at least one other field.
/// - **mutably borrowed field**: a field which is mutably borrowed by exactly one other field.
/// - **self-referencing field**: a field which borrows at least one other field.
/// - **head field**: a field which does not borrow any other fields, I.E. not self-referencing.
/// This does not include fields with empty borrows annotations (`#[borrows()]`.)
/// - **tail field**: a field which is not borrowed by any other fields.
///
/// # Usage
/// To make a self-referencing struct, you must write a struct definition and place
/// `#[self_referencing]` on top. For every field that borrows other fields, you must place
/// `#[borrows()]` on top and place inside the parenthesis a list of fields that it borrows. Mut can
/// be prefixed to indicate that a mutable borrow is required. For example,
/// `#[borrows(a, b, mut c)]` indicates that the first two fields need to be borrowed immutably and
/// the third needs to be borrowed mutably. You can also use `#[borrows()]` without any arguments to
/// indicate a field that will eventually borrow from the struct, but does not borrow anything when
/// first created. For example, you could use this on a field like `error: Option<&'this str>`.
///
/// # You must comply with these limitations
/// - Fields must be declared before the first time they are borrowed.
/// - Normal borrowing rules apply, E.G. a field cannot be borrowed mutably twice.
/// - Fields that are borrowed must be of a data type that implement
/// [`StableDeref`](https://docs.rs/stable_deref_trait/1.2.0/stable_deref_trait/trait.StableDeref.html).
/// Normally this just means `Box<T>`.
/// - Fields that use the `'this` lifetime must have a corresponding `#[borrows()]` annotation.
/// The error for this needs some work, currently you will get an error saying that `'this` is
/// undefined at the location it was illegally used in.
///
/// Violating them will result in an error message directly pointing out the violated rule.
///
/// # Flexibility of this crate
/// The example above uses plain references as the self-referencing part of the struct, but you can
/// use anything that is dependent on lifetimes of objects inside the struct. For example, you could
/// do something like this:
/// ```rust
/// use ouroboros::self_referencing;
///
/// pub struct ComplexData<'a, 'b> {
/// aref: &'a i32,
/// bref: &'b mut i32,
/// number: i32,
/// }
///
/// impl<'a, 'b> ComplexData<'a, 'b> {
/// fn new(aref: &'a i32, bref: &'b mut i32, number: i32) -> Self {
/// Self { aref, bref, number }
/// }
///
/// /// Copies the value aref points to into what bref points to.
/// fn transfer(&mut self) {
/// *self.bref = *self.aref;
/// }
///
/// /// Prints the value bref points to.
/// fn print_bref(&self) {
/// println!("{}", *self.bref);
/// }
/// }
///
/// fn main() {
/// #[self_referencing]
/// struct DataStorage {
/// immutable: Box<i32>,
/// mutable: Box<i32>,
/// #[borrows(immutable, mut mutable)]
/// complex_data: ComplexData<'this, 'this>,
/// }
///
/// let mut data_storage = DataStorageBuilder {
/// immutable: Box::new(10),
/// mutable: Box::new(20),
/// complex_data_builder: |i: &i32, m: &mut i32| ComplexData::new(i, m, 12345),
/// }.build();
/// data_storage.with_complex_data_mut(|data| {
/// // Copies the value in immutable into mutable.
/// data.transfer();
/// // Prints 10
/// data.print_bref();
/// });
/// }
/// ```
/// # Using `chain_hack`
/// Unfortunately, as of September 2020, Rust has a
/// [known limitation in its type checker](https://users.rust-lang.org/t/why-does-this-not-compile-box-t-target-t/49027/7?u=aaaaa)
/// which prevents chained references from working (I.E. structs where field C references field B
/// which references field A.) To counteract this problem, you can use
/// `#[self_referencing(chain_hack)]` to allow creating these kinds of structs at the cost of
/// additional restrictions and possible loss of clarity in some error messages. The main limitation
/// is that all fields that are borrowed must be of type `Box<T>`. A nice error message will be
/// generated if you use a different type. There should be no other limitations, but some
/// configurations may produce strange compiler errors. If you find such a configuration, please
/// open an issue on the [Github repository](https://github.com/joshua-maros/ouroboros/issues).
/// You can view a documented example of a struct which uses `chain_hack` [here](https://docs.rs/ouroboros_examples/latest/ouroboros_examples/struct.ChainHack.html).
///
/// # What does the macro generate?
/// The `#[self_referencing]` struct will replace your definition with an unsafe self-referencing
/// struct with a safe public interface. Many functions will be generated depending on your original
/// struct definition. Documentation is generated for all items, so building documentation for
/// your project allows accessing detailed information about available functions. Using
/// `#[self_referencing(no_doc)]` will hide the generated items from documentation if it is becoming
/// too cluttered.
///
/// ### A quick note on visibility
/// The visibility of generated items is dependent on one of two things. If the
/// generated item is related to a specific field of the struct, it uses the visibility of the
/// original field. (The actual field in the struct will be made private since accessing it could cause
/// undefined behavior.) If the generated item is not related to any particular field, it will by
/// default only be visible to the module the struct is declared in. (This includes things like
/// `new()` and `with()`.) You can use `#[self_referencing(pub_extras)]` to make these items have the
/// same visibility as the struct itself.
///
/// # List of generated items
/// ### `MyStruct::new(fields...) -> MyStruct`
/// A basic constructor. It accepts values for each field in the order you declared them in. For
/// **head fields**, you only need to pass in what value it should have and it will be moved in
/// to the output. For **self-referencing fields**, you must provide a function or closure which creates
/// the value based on the values it borrows. A field using the earlier example of
/// `#[borrow(a, b, mut c)]` would require a function typed as
/// `FnOnce(a: &_, b: &_, c: &mut _) -> _`. Fields which have an empty borrows annotation
/// (`#[borrows()]`) should have their value directly passed in. A field using the earlier example
/// of `Option<&'this str>` would require an input of `None`. Do not pass a function. Do not collect
/// 200 dollars.
/// ### `MyStructBuilder`
/// This is the preferred way to create a new instance of your struct. It is similar to using the
/// `MyStruct { a, b, c, d }` syntax instead of `MyStruct::new(a, b, c, d)`. It contains one field
/// for every argument in the actual constructor. **Head fields** have the same name that you
/// originally defined them with. **self-referencing fields** are suffixed with `_builder` since you need
/// to provide a function instead of a value. Fields with an empty borrows annotation are not
/// initialized using builders. Calling `.build()` on an instance of `MyStructBuilder`
/// will convert it to an instance of `MyStruct`.
/// ### `MyStruct::try_new<E>(fields...) -> Result<MyStruct, E>`
/// Similar to the regular `new()` function, except the functions wich create values for all
/// **self-referencing fields** can return `Result<>`s. If any of those are `Err`s, that error will be
/// returned instead of an instance of `MyStruct`. The preferred way to use this function is through
/// `MyStructTryBuilder` and its `try_build()` function.
/// ### `MyStruct::try_new_or_recover<E>(fields...) -> Result<MyStruct, (E, Heads)>`
/// Similar to the `try_new()` function, except that all the **head fields** are returned along side
/// the original error in case of an error. The preferred way to use this function is through
/// `MyStructTryBuilder` and its `try_build_or_recover()` function.
/// ### `MyStruct::with_FIELD<R>(&self, user: FnOnce(field: &FieldType) -> R) -> R`
/// This function is generated for every **tail and immutably-borrowed field** in your struct. It
/// allows safely accessing
/// a reference to that value. The function generates the reference and passes it to `user`. You
/// can do anything you want with the reference, it is constructed to not outlive the struct.
/// ### `MyStruct::borrow_FIELD(&self) -> &FieldType`
/// This function is generated for every **tail and immutably-borrowed field** in your struct. It
/// is equivalent to calling `my_struct.with_FIELD(|field| field)`. Note that certain types of
/// fields would cause this function to generate a compiler error, so it is ommitted. Generally, if
/// your field uses `'this` as a lifetime parameter, the corresponding `borrow_FIELD` function will
/// not be generated. There is no `borrow_FIELD_mut`, unfortunately, as Rust's
/// borrow checker is currently not capable of ensuring that such a method would be used safely.
/// ### `MyStruct::with_FIELD_mut<R>(&mut self, user: FnOnce(field: &mut FieldType) -> R) -> R`
/// This function is generated for every **tail field** in your struct. It is the mutable version
/// of `with_FIELD`.
/// ### `MyStruct::with<R>(&self, user: FnOnce(fields: AllFields) -> R) -> R`
/// Allows borrowing all **tail and immutably-borrowed fields** at once. Functions similarly to
/// `with_FIELD`.
/// ### `MyStruct::with_mut<R>(&self, user: FnOnce(fields: AllFields) -> R) -> R`
/// Allows mutably borrowing all **tail fields** and immutably borrowing all **immutably-borrowed**
/// fields at once. Functions similarly to `with_FIELD_mut`, except that you can borrow multiple
/// fields as mutable at the same time and also have immutable access to any remaining fields.
/// ### `MyStruct::into_heads(self) -> Heads`
/// Drops all self-referencing fields and returns a struct containing all **head fields**.
pub use ouroboros_macro::self_referencing;
#[doc(hidden)]
pub mod macro_help {
use stable_deref_trait::StableDeref;
use std::ops::DerefMut;
/// Converts a reference to an object implementing Deref to a static reference to the data it
/// Derefs to. This is obviously unsafe because the compiler can no longer guarantee that the
/// data outlives the reference. This function is templated to only work for containers that
/// implement StableDeref, E.G. Box and Rc. The intent is that the data that is being pointed
/// to will never move as long as the container itself is not dropped. It is up to the consumer
/// to get rid of the reference before the container is dropped. The + 'static ensures that
/// whatever we are referring to will remain valid indefinitely, that there are no limitations
/// on how long the pointer itself can live.
///
/// # Safety
///
/// The caller must ensure that the returned reference is not used after the originally passed
/// reference would become invalid.
pub unsafe fn stable_deref_and_strip_lifetime<'a, T: StableDeref + 'static>(
data: &'a T,
) -> &'static T::Target {
&*((&**data) as *const _)
}
/// Like stable_deref_and_strip_lifetime, but for mutable references.
///
/// # Safety
///
/// The caller must ensure that the returned reference is not used after the originally passed
/// reference would become invalid.
pub unsafe fn stable_deref_and_strip_lifetime_mut<'a, T: StableDeref + DerefMut + 'static>(
data: &'a mut T,
) -> &'static mut T::Target {
&mut *((&mut **data) as *mut _)
}
}

1
third_party/rust/ouroboros_macro/.cargo-checksum.json поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
{"files":{"Cargo.toml":"0fe2091620d2a21b136a30c206cd2e4cd6440d1ebc0380c2d904efe4daf8c63f","src/lib.rs":"7dd4e3cc1e646541384b0dec167e264d73c35e6264a0d4d5de60e63adf13c3e4"},"package":"dfc618f205c0adc415923c74369d45f5f298462fc473711dfc33056a23f23619"}

36
third_party/rust/ouroboros_macro/Cargo.toml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,36 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies
#
# If you believe there's an error in this file please file an
# issue against the rust-lang/cargo repository. If you're
# editing this file be aware that the upstream Cargo.toml
# will likely look very different (and much more reasonable)
[package]
edition = "2018"
name = "ouroboros_macro"
version = "0.7.0"
authors = ["Joshua Maros <joshua-maros@github.com>"]
description = "Proc macro for ouroboros crate."
documentation = "https://docs.rs/ouroboros_macro"
license = "MIT OR Apache-2.0"
repository = "https://github.com/joshua-maros/ouroboros"
[lib]
proc-macro = true
[dependencies.Inflector]
version = "0.11"
[dependencies.proc-macro2]
version = "1.0"
[dependencies.quote]
version = "1.0"
[dependencies.syn]
version = "1.0"
features = ["full"]

1425
third_party/rust/ouroboros_macro/src/lib.rs поставляемый Normal file

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1 +1 @@
{"files":{"Cargo.toml":"409f95e74eb045b1e188b71514c785feb0b55e69afa3545b72678115b46448fb","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"5e05b024f653a5ce199e77cbbbd42fb5553562ec714b819421ed0c3e552a75d7","README.md":"4a6ab55d5ce8d3ca804db6886b1d926dc12dbc874a526ec5febca61149e2c6c0","src/lib.rs":"868e71a2538bdec347a92bc7e3d16b0f5fa6a2be6a0ade4de37fd373a85626c5"},"package":"15132e0e364248108c5e2c02e3ab539be8d6f5d52a01ca9bbf27ed657316f02b"}
{"files":{"Cargo.toml":"5a8352eba01791ecee28b37cfe1324fa48db52e35023b23a4f07ca84267abfd6","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"5e05b024f653a5ce199e77cbbbd42fb5553562ec714b819421ed0c3e552a75d7","README.md":"750fc2d57412de57566289e567b5674a666cc7a8a054f8c7129b8553f9003de7","src/lib.rs":"c68d43e0ec2727653cc2d37c396c8e60c9ed315b71aab331da8177b129887591"},"package":"a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"}

Просмотреть файл

@ -1,18 +1,27 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies
#
# If you believe there's an error in this file please file an
# issue against the rust-lang/cargo repository. If you're
# editing this file be aware that the upstream Cargo.toml
# will likely look very different (and much more reasonable)
[package]
name = "stable_deref_trait"
version = "1.0.0"
version = "1.2.0"
authors = ["Robert Grosse <n210241048576@gmail.com>"]
license = "MIT/Apache-2.0"
description = "An unsafe marker trait for types like Box and Rc that dereference to a stable address even when moved, and hence can be used with libraries such as owning_ref and rental.\n"
documentation = "https://docs.rs/stable_deref_trait/1.2.0/stable_deref_trait"
readme = "README.md"
categories = ["memory-management", "no-std"]
license = "MIT/Apache-2.0"
repository = "https://github.com/storyyeller/stable_deref_trait"
documentation = "https://docs.rs/stable_deref_trait/1.0.0/stable_deref_trait"
categories = ["no-std"]
description = """
An unsafe marker trait for types like Box and Rc that dereference to a stable address even when moved, and hence can be used with libraries such as owning_ref and rental.
"""
[features]
alloc = []
default = ["std"]
std = []
[dependencies]
std = ["alloc"]

18
third_party/rust/stable_deref_trait/README.md поставляемый
Просмотреть файл

@ -3,3 +3,21 @@ This crate defines an unsafe marker trait, StableDeref, for container types whic
It is intended to be used by crates such as [owning_ref](https://crates.io/crates/owning_ref) and [rental](https://crates.io/crates/rental), as well as library authors who wish to make their code interoperable with such crates. For example, if you write a custom Vec type, you can implement StableDeref, and then users will be able to use your custom Vec type together with owning_ref and rental.
no_std support can be enabled by disabling default features (specifically "std"). In this case, the trait will not be implemented for the std types mentioned above, but you can still use it for your own types.
Enable the "alloc" feature (with default-features disabled) to have this trait be implemented for the above types from the built-in `alloc` crate, specifically
* `alloc::boxed::Box`
* `alloc::vec::Vec`
* `alloc::rc::Rc`
* `alloc::arc::Arc`
* `alloc::string::String`
For example, this crate can be built with alloc support via the following command:
`cargo build --no-default-features --features alloc`
Or added as a `Cargo.toml` dependency as follows:
```
[dependencies.stable_deref_trait]
version = "<version>"
default-features = false
features = [ "alloc" ]
```

Просмотреть файл

@ -19,6 +19,9 @@ no_std support can be enabled by disabling default features (specifically "std")
#[cfg(feature = "std")]
extern crate core;
#[cfg(feature = "alloc")]
extern crate alloc;
use core::ops::Deref;
@ -129,36 +132,50 @@ pub unsafe trait CloneStableDeref: StableDeref + Clone {}
// std types integration
/////////////////////////////////////////////////////////////////////////////
#[cfg(feature = "alloc")]
use alloc::boxed::Box;
#[cfg(feature = "alloc")]
use alloc::rc::Rc;
#[cfg(feature = "alloc")]
use alloc::sync::Arc;
#[cfg(feature = "alloc")]
use alloc::vec::Vec;
#[cfg(feature = "alloc")]
use alloc::string::String;
#[cfg(feature = "std")]
use std::boxed::Box;
use std::ffi::{CString, OsString};
#[cfg(feature = "std")]
use std::rc::Rc;
#[cfg(feature = "std")]
use std::sync::Arc;
use std::path::PathBuf;
#[cfg(feature = "std")]
use std::sync::{MutexGuard, RwLockReadGuard, RwLockWriteGuard};
#[cfg(feature = "std")]
use std::cell::{Ref, RefMut};
#[cfg(feature = "std")]
use core::cell::{Ref, RefMut};
#[cfg(feature = "alloc")]
unsafe impl<T: ?Sized> StableDeref for Box<T> {}
#[cfg(feature = "std")]
#[cfg(feature = "alloc")]
unsafe impl<T> StableDeref for Vec<T> {}
#[cfg(feature = "std")]
#[cfg(feature = "alloc")]
unsafe impl StableDeref for String {}
#[cfg(feature = "std")]
unsafe impl StableDeref for CString {}
#[cfg(feature = "std")]
unsafe impl StableDeref for OsString {}
#[cfg(feature = "std")]
unsafe impl StableDeref for PathBuf {}
#[cfg(feature = "std")]
#[cfg(feature = "alloc")]
unsafe impl<T: ?Sized> StableDeref for Rc<T> {}
#[cfg(feature = "std")]
#[cfg(feature = "alloc")]
unsafe impl<T: ?Sized> CloneStableDeref for Rc<T> {}
#[cfg(feature = "std")]
#[cfg(feature = "alloc")]
unsafe impl<T: ?Sized> StableDeref for Arc<T> {}
#[cfg(feature = "std")]
#[cfg(feature = "alloc")]
unsafe impl<T: ?Sized> CloneStableDeref for Arc<T> {}
#[cfg(feature = "std")]
unsafe impl<'a, T: ?Sized> StableDeref for Ref<'a, T> {}
#[cfg(feature = "std")]
unsafe impl<'a, T: ?Sized> StableDeref for RefMut<'a, T> {}
#[cfg(feature = "std")]
unsafe impl<'a, T: ?Sized> StableDeref for MutexGuard<'a, T> {}

Просмотреть файл

@ -62,7 +62,7 @@ fluent-langneg-ffi = { path = "../../../../intl/locale/rust/fluent-langneg-ffi"
# changing this version.
rusqlite = { version = "0.24.1", features = ["modern_sqlite", "in_gecko"] }
fluent = { version = "0.13.1", features = ["fluent-pseudo"] }
fluent = { version = "0.14.1", features = ["fluent-pseudo"] }
fluent-ffi = { path = "../../../../intl/l10n/rust/fluent-ffi" }
firefox-accounts-bridge = { path = "../../../../services/fxaccounts/rust-bridge/firefox-accounts-bridge", optional=true }
l10nregistry-ffi = { path = "../../../../intl/l10n/rust/l10nregistry-ffi" }