diff options
author | Haibo Huang <hhb@google.com> | 2021-01-12 00:32:18 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-01-12 00:32:18 +0000 |
commit | bdfe9f014f24c7f062a6a0e7235885d488e4f30d (patch) | |
tree | aeaf1c535c28d84c77e7a08bb06ee9064206009b | |
parent | 3b526a6eb611177e784cbdf2bf1a63ed11cbccf6 (diff) | |
parent | 44e117ee6d37afccf78b0de9856866eed8f1f8f5 (diff) | |
download | heck-bdfe9f014f24c7f062a6a0e7235885d488e4f30d.tar.gz |
Upgrade rust/crates/heck to 0.3.2 am: 79ec7f1ff9 am: fa0b8afa5a am: 44e117ee6d
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/heck/+/1535581
MUST ONLY BE SUBMITTED BY AUTOMERGER
Change-Id: I1f438f702a8d7d9515d0368bfde5aa61a89e3ee7
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | Android.bp | 6 | ||||
-rw-r--r-- | Cargo.toml | 5 | ||||
-rw-r--r-- | Cargo.toml.orig | 3 | ||||
-rw-r--r-- | METADATA | 8 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | TEST_MAPPING | 4 | ||||
-rw-r--r-- | src/camel.rs | 14 | ||||
-rw-r--r-- | src/kebab.rs | 14 | ||||
-rw-r--r-- | src/lib.rs | 4 | ||||
-rw-r--r-- | src/mixed.rs | 18 | ||||
-rw-r--r-- | src/shouty_kebab.rs | 51 | ||||
-rw-r--r-- | src/shouty_snake.rs | 14 | ||||
-rw-r--r-- | src/snake.rs | 16 | ||||
-rw-r--r-- | src/title.rs | 14 |
15 files changed, 107 insertions, 68 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 14b06ff..d8c857d 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,5 +1,5 @@ { "git": { - "sha1": "093d56fbf001e1506e56dbfa38631d99b1066df1" + "sha1": "1c13e81591e356f13fb97a12d9775876a40c1a02" } } @@ -6,7 +6,7 @@ rust_defaults { srcs: ["src/lib.rs"], test_suites: ["general-tests"], auto_gen_config: true, - edition: "2015", + edition: "2018", rustlibs: [ "libunicode_segmentation", ], @@ -27,11 +27,11 @@ rust_library { host_supported: true, crate_name: "heck", srcs: ["src/lib.rs"], - edition: "2015", + edition: "2018", rustlibs: [ "libunicode_segmentation", ], } // dependent_library ["feature_list"] -// unicode-segmentation-1.6.0 +// unicode-segmentation-1.7.1 @@ -3,7 +3,7 @@ # 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 +# 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 @@ -11,8 +11,9 @@ # will likely look very different (and much more reasonable) [package] +edition = "2018" name = "heck" -version = "0.3.1" +version = "0.3.2" authors = ["Without Boats <woboats@gmail.com>"] description = "heck is a case conversion library." homepage = "https://github.com/withoutboats/heck" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 93b64e8..13025c2 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,7 +1,8 @@ [package] authors = ["Without Boats <woboats@gmail.com>"] name = "heck" -version = "0.3.1" +version = "0.3.2" +edition = "2018" license = "MIT OR Apache-2.0" description = "heck is a case conversion library." homepage = "https://github.com/withoutboats/heck" @@ -7,13 +7,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/heck/heck-0.3.1.crate" + value: "https://static.crates.io/crates/heck/heck-0.3.2.crate" } - version: "0.3.1" + version: "0.3.2" license_type: NOTICE last_upgrade_date { year: 2020 - month: 5 - day: 6 + month: 12 + day: 22 } } @@ -36,7 +36,7 @@ indicators are dropped, except insofar as CamelCase capitalizes the first word. 4. SHOUTY_SNAKE_CASE 5. mixedCase 6. Title Case - +7. SHOUTY-KEBAB-CASE ### Contributing diff --git a/TEST_MAPPING b/TEST_MAPPING index b7cdaa3..10744a3 100644 --- a/TEST_MAPPING +++ b/TEST_MAPPING @@ -7,10 +7,6 @@ }, { "name": "heck_device_test_src_lib" - }, - { - "host": true, - "name": "structopt-derive_host_test_src_lib" } ] } diff --git a/src/camel.rs b/src/camel.rs index 74bd741..fa31f0c 100644 --- a/src/camel.rs +++ b/src/camel.rs @@ -1,3 +1,5 @@ +use crate::{capitalize, transform}; + /// This trait defines a camel case conversion. /// /// In CamelCase, word boundaries are indicated by capital letters, including @@ -6,14 +8,10 @@ /// ## Example: /// /// ```rust -/// extern crate heck; -/// fn main() { -/// -/// use heck::CamelCase; +/// use heck::CamelCase; /// -/// let sentence = "We are not in the least afraid of ruins."; -/// assert_eq!(sentence.to_camel_case(), "WeAreNotInTheLeastAfraidOfRuins"); -/// } +/// let sentence = "We are not in the least afraid of ruins."; +/// assert_eq!(sentence.to_camel_case(), "WeAreNotInTheLeastAfraidOfRuins"); /// ``` pub trait CamelCase: ToOwned { /// Convert this type to camel case. @@ -22,7 +20,7 @@ pub trait CamelCase: ToOwned { impl CamelCase for str { fn to_camel_case(&self) -> String { - ::transform(self, ::capitalize, |_| {}) + transform(self, capitalize, |_| {}) } } diff --git a/src/kebab.rs b/src/kebab.rs index f81ba92..94ac322 100644 --- a/src/kebab.rs +++ b/src/kebab.rs @@ -1,3 +1,5 @@ +use crate::{lowercase, transform}; + /// This trait defines a kebab case conversion. /// /// In kebab-case, word boundaries are indicated by hyphens. @@ -5,14 +7,10 @@ /// ## Example: /// /// ```rust -/// extern crate heck; -/// fn main() { -/// -/// use heck::KebabCase; +/// use heck::KebabCase; /// -/// let sentence = "We are going to inherit the earth."; -/// assert_eq!(sentence.to_kebab_case(), "we-are-going-to-inherit-the-earth"); -/// } +/// let sentence = "We are going to inherit the earth."; +/// assert_eq!(sentence.to_kebab_case(), "we-are-going-to-inherit-the-earth"); /// ``` pub trait KebabCase: ToOwned { /// Convert this type to kebab case. @@ -21,7 +19,7 @@ pub trait KebabCase: ToOwned { impl KebabCase for str { fn to_kebab_case(&self) -> Self::Owned { - ::transform(self, ::lowercase, |s| s.push('-')) + transform(self, lowercase, |s| s.push('-')) } } @@ -34,12 +34,13 @@ //! 4. SHOUTY_SNAKE_CASE //! 5. mixedCase //! 6. Title Case +//! 7. SHOUTY-KEBAB-CASE #![deny(missing_docs)] -extern crate unicode_segmentation; mod camel; mod kebab; mod mixed; +mod shouty_kebab; mod shouty_snake; mod snake; mod title; @@ -47,6 +48,7 @@ mod title; pub use camel::CamelCase; pub use kebab::KebabCase; pub use mixed::MixedCase; +pub use shouty_kebab::ShoutyKebabCase; pub use shouty_snake::{ShoutySnakeCase, ShoutySnekCase}; pub use snake::{SnakeCase, SnekCase}; pub use title::TitleCase; diff --git a/src/mixed.rs b/src/mixed.rs index 7736684..cca3262 100644 --- a/src/mixed.rs +++ b/src/mixed.rs @@ -1,3 +1,5 @@ +use crate::{capitalize, lowercase, transform}; + /// This trait defines a mixed case conversion. /// /// In mixedCase, word boundaries are indicated by capital letters, excepting @@ -6,14 +8,10 @@ /// ## Example: /// /// ```rust -/// extern crate heck; -/// fn main() { -/// -/// use heck::MixedCase; +/// use heck::MixedCase; /// -/// let sentence = "It is we who built these palaces and cities."; -/// assert_eq!(sentence.to_mixed_case(), "itIsWeWhoBuiltThesePalacesAndCities"); -/// } +/// let sentence = "It is we who built these palaces and cities."; +/// assert_eq!(sentence.to_mixed_case(), "itIsWeWhoBuiltThesePalacesAndCities"); /// ``` pub trait MixedCase: ToOwned { /// Convert this type to mixed case. @@ -22,9 +20,9 @@ pub trait MixedCase: ToOwned { impl MixedCase for str { fn to_mixed_case(&self) -> String { - ::transform(self, |s, out| { - if out.is_empty() { ::lowercase(s, out); } - else { ::capitalize(s, out) } + transform(self, |s, out| { + if out.is_empty() { lowercase(s, out); } + else { capitalize(s, out) } }, |_| {}) } } diff --git a/src/shouty_kebab.rs b/src/shouty_kebab.rs new file mode 100644 index 0000000..0e0c7e7 --- /dev/null +++ b/src/shouty_kebab.rs @@ -0,0 +1,51 @@ +use crate::{transform, uppercase}; + +/// This trait defines a shouty kebab case conversion. +/// +/// In SHOUTY-KEBAB-CASE, word boundaries are indicated by hyphens and all +/// words are in uppercase. +/// +/// ## Example: +/// +/// ```rust +/// use heck::ShoutyKebabCase; +/// +/// let sentence = "We are going to inherit the earth."; +/// assert_eq!(sentence.to_shouty_kebab_case(), "WE-ARE-GOING-TO-INHERIT-THE-EARTH"); +/// ``` +pub trait ShoutyKebabCase: ToOwned { + /// Convert this type to shouty kebab case. + fn to_shouty_kebab_case(&self) -> Self::Owned; +} + +impl ShoutyKebabCase for str { + fn to_shouty_kebab_case(&self) -> Self::Owned { + transform(self, uppercase, |s| s.push('-')) + } +} + +#[cfg(test)] +mod tests { + use super::ShoutyKebabCase; + + macro_rules! t { + ($t:ident : $s1:expr => $s2:expr) => { + #[test] + fn $t() { + assert_eq!($s1.to_shouty_kebab_case(), $s2) + } + } + } + + t!(test1: "CamelCase" => "CAMEL-CASE"); + t!(test2: "This is Human case." => "THIS-IS-HUMAN-CASE"); + t!(test3: "MixedUP CamelCase, with some Spaces" => "MIXED-UP-CAMEL-CASE-WITH-SOME-SPACES"); + t!(test4: "mixed_up_ snake_case with some _spaces" => "MIXED-UP-SNAKE-CASE-WITH-SOME-SPACES"); + t!(test5: "kebab-case" => "KEBAB-CASE"); + t!(test6: "SHOUTY_SNAKE_CASE" => "SHOUTY-SNAKE-CASE"); + t!(test7: "snake_case" => "SNAKE-CASE"); + t!(test8: "this-contains_ ALLKinds OfWord_Boundaries" => "THIS-CONTAINS-ALL-KINDS-OF-WORD-BOUNDARIES"); + t!(test9: "XΣXΣ baffle" => "XΣXΣ-BAFFLE"); + t!(test10: "XMLHttpRequest" => "XML-HTTP-REQUEST"); + t!(test11: "SHOUTY-KEBAB-CASE" => "SHOUTY-KEBAB-CASE"); +} diff --git a/src/shouty_snake.rs b/src/shouty_snake.rs index 0f846c3..43be539 100644 --- a/src/shouty_snake.rs +++ b/src/shouty_snake.rs @@ -1,3 +1,5 @@ +use crate::{transform, uppercase}; + /// This trait defines a shouty snake case conversion. /// /// In SHOUTY_SNAKE_CASE, word boundaries are indicated by underscores and all @@ -6,14 +8,10 @@ /// ## Example: /// /// ```rust -/// extern crate heck; -/// fn main() { +/// use heck::ShoutySnakeCase; /// -/// use heck::ShoutySnakeCase; -/// -/// let sentence = "That world is growing in this minute."; -/// assert_eq!(sentence.to_shouty_snake_case(), "THAT_WORLD_IS_GROWING_IN_THIS_MINUTE"); -/// } +/// let sentence = "That world is growing in this minute."; +/// assert_eq!(sentence.to_shouty_snake_case(), "THAT_WORLD_IS_GROWING_IN_THIS_MINUTE"); /// ``` pub trait ShoutySnakeCase: ToOwned { /// Convert this type to shouty snake case. @@ -37,7 +35,7 @@ impl<T: ?Sized + ShoutySnakeCase> ShoutySnekCase for T { impl ShoutySnakeCase for str { fn to_shouty_snake_case(&self) -> Self::Owned { - ::transform(self, ::uppercase, |s| s.push('_')) + transform(self, uppercase, |s| s.push('_')) } } diff --git a/src/snake.rs b/src/snake.rs index 86c3756..13329fe 100644 --- a/src/snake.rs +++ b/src/snake.rs @@ -1,18 +1,16 @@ -/// This trait defines a camel case conversion. +use crate::{lowercase, transform}; + +/// This trait defines a snake case conversion. /// /// In snake_case, word boundaries are indicated by underscores. /// /// ## Example: /// /// ```rust -/// extern crate heck; -/// fn main() { -/// -/// use heck::SnakeCase; +/// use heck::SnakeCase; /// -/// let sentence = "We carry a new world here, in our hearts."; -/// assert_eq!(sentence.to_snake_case(), "we_carry_a_new_world_here_in_our_hearts"); -/// } +/// let sentence = "We carry a new world here, in our hearts."; +/// assert_eq!(sentence.to_snake_case(), "we_carry_a_new_world_here_in_our_hearts"); /// ``` pub trait SnakeCase: ToOwned { /// Convert this type to snake case. @@ -34,7 +32,7 @@ impl<T: ?Sized + SnakeCase> SnekCase for T { impl SnakeCase for str { fn to_snake_case(&self) -> String { - ::transform(self, ::lowercase, |s| s.push('_')) + transform(self, lowercase, |s| s.push('_')) } } diff --git a/src/title.rs b/src/title.rs index cb48302..3723f1f 100644 --- a/src/title.rs +++ b/src/title.rs @@ -1,3 +1,5 @@ +use crate::{capitalize, transform}; + /// This trait defines a title case conversion. /// /// In Title Case, word boundaries are indicated by spaces, and every word is @@ -6,14 +8,10 @@ /// ## Example: /// /// ```rust -/// extern crate heck; -/// fn main() { -/// -/// use heck::TitleCase; +/// use heck::TitleCase; /// -/// let sentence = "We have always lived in slums and holes in the wall."; -/// assert_eq!(sentence.to_title_case(), "We Have Always Lived In Slums And Holes In The Wall"); -/// } +/// let sentence = "We have always lived in slums and holes in the wall."; +/// assert_eq!(sentence.to_title_case(), "We Have Always Lived In Slums And Holes In The Wall"); /// ``` pub trait TitleCase: ToOwned { /// Convert this type to title case. @@ -22,7 +20,7 @@ pub trait TitleCase: ToOwned { impl TitleCase for str { fn to_title_case(&self) -> String { - ::transform(self, ::capitalize, |s| s.push(' ')) + transform(self, capitalize, |s| s.push(' ')) } } |