diff options
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | Android.bp | 28 | ||||
-rw-r--r-- | Cargo.toml | 3 | ||||
-rw-r--r-- | Cargo.toml.orig | 3 | ||||
-rw-r--r-- | METADATA | 10 | ||||
-rw-r--r-- | README.md | 15 | ||||
-rw-r--r-- | TEST_MAPPING | 23 | ||||
-rw-r--r-- | cargo2android.json | 5 | ||||
-rw-r--r-- | no_step_on_snek.png | bin | 0 -> 43512 bytes | |||
-rw-r--r-- | src/camel.rs | 2 | ||||
-rw-r--r-- | src/kebab.rs | 2 | ||||
-rw-r--r-- | src/lib.rs | 66 | ||||
-rw-r--r-- | src/mixed.rs | 17 | ||||
-rw-r--r-- | src/shouty_kebab.rs | 2 | ||||
-rw-r--r-- | src/shouty_snake.rs | 7 | ||||
-rw-r--r-- | src/snake.rs | 2 | ||||
-rw-r--r-- | src/title.rs | 2 |
17 files changed, 70 insertions, 119 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 43f6c71..d8c857d 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,5 +1,5 @@ { "git": { - "sha1": "d2f9cda3a00a62ae1e0eeeea8f0a081c7598b8c5" + "sha1": "1c13e81591e356f13fb97a12d9775876a40c1a02" } } @@ -1,5 +1,4 @@ -// This file is generated by cargo2android.py --config cargo2android.json. -// Do not modify this file as changes will be overridden on upgrade. +// This file is generated by cargo2android.py --run --device --tests --dependencies. package { default_applicable_licenses: ["external_rust_crates_heck_license"], @@ -37,33 +36,38 @@ license { ], } -rust_test { - name: "heck_test_src_lib", - host_supported: true, +rust_defaults { + name: "heck_defaults", crate_name: "heck", - cargo_env_compat: true, - cargo_pkg_version: "0.3.3", srcs: ["src/lib.rs"], test_suites: ["general-tests"], auto_gen_config: true, - test_options: { - unit_test: true, - }, edition: "2018", rustlibs: [ "libunicode_segmentation", ], } +rust_test_host { + name: "heck_host_test_src_lib", + defaults: ["heck_defaults"], +} + +rust_test { + name: "heck_device_test_src_lib", + defaults: ["heck_defaults"], +} + rust_library { name: "libheck", host_supported: true, crate_name: "heck", - cargo_env_compat: true, - cargo_pkg_version: "0.3.3", srcs: ["src/lib.rs"], edition: "2018", rustlibs: [ "libunicode_segmentation", ], } + +// dependent_library ["feature_list"] +// unicode-segmentation-1.7.1 @@ -13,9 +13,8 @@ [package] edition = "2018" name = "heck" -version = "0.3.3" +version = "0.3.2" authors = ["Without Boats <woboats@gmail.com>"] -include = ["src/**/*", "LICENSE-*", "README.md", "CHANGELOG.md"] description = "heck is a case conversion library." homepage = "https://github.com/withoutboats/heck" documentation = "https://docs.rs/heck" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 80acd39..13025c2 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,7 +1,7 @@ [package] authors = ["Without Boats <woboats@gmail.com>"] name = "heck" -version = "0.3.3" +version = "0.3.2" edition = "2018" license = "MIT OR Apache-2.0" description = "heck is a case conversion library." @@ -10,7 +10,6 @@ repository = "https://github.com/withoutboats/heck" documentation = "https://docs.rs/heck" keywords = ["string", "case", "camel", "snake", "unicode"] readme = "README.md" -include = ["src/**/*", "LICENSE-*", "README.md", "CHANGELOG.md"] [dependencies] unicode-segmentation = "1.2.0" @@ -7,13 +7,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/heck/heck-0.3.3.crate" + value: "https://static.crates.io/crates/heck/heck-0.3.2.crate" } - version: "0.3.3" + version: "0.3.2" license_type: NOTICE last_upgrade_date { - year: 2021 - month: 6 - day: 21 + year: 2020 + month: 12 + day: 22 } } @@ -1,6 +1,6 @@ # **heck** is a case conversion library -!["I specifically requested the opposite of this."](./no_step_on_snek.png) +!["I specifically requested the opposite of this."](https://github.com/withoutboats/heck/blob/master/no_step_on_snek.png) This library exists to provide case conversion between common cases like CamelCase and snake_case. It is intended to be unicode aware, internally @@ -28,7 +28,7 @@ underscores) are folded into one. ("hello__world" in snake case is therefore "hello_world", not the exact same string). Leading or trailing word boundary indicators are dropped, except insofar as CamelCase capitalizes the first word. -## Cases contained in this library: +### Cases contained in this library: 1. CamelCase 2. snake_case @@ -38,7 +38,7 @@ indicators are dropped, except insofar as CamelCase capitalizes the first word. 6. Title Case 7. SHOUTY-KEBAB-CASE -## Contributing +### Contributing PRs of additional well-established cases welcome. @@ -48,14 +48,7 @@ would prefer **not** to receive PRs to make this behavior more configurable. Bug reports & fixes always welcome. :-) -## MSRV - -The minimum supported Rust version for this crate is 1.32.0. This may change in -minor or patch releases, but we probably won't ever require a very recent -version. If you would like to have a stronger guarantee than that, please open -an issue. - -## License +### License heck is distributed under the terms of both the MIT license and the Apache License (Version 2.0). diff --git a/TEST_MAPPING b/TEST_MAPPING index e5f5c4c..60b40b7 100644 --- a/TEST_MAPPING +++ b/TEST_MAPPING @@ -1,27 +1,8 @@ -// Generated by update_crate_tests.py for tests that depend on this crate. +// Generated by cargo2android.py for tests in Android.bp { - "imports": [ - { - "path": "external/rust/crates/argh" - }, - { - "path": "external/rust/crates/base64" - } - ], "presubmit": [ { - "name": "authfs_device_test_src_lib" - }, - { - "name": "heck_test_src_lib" - } - ], - "presubmit-rust": [ - { - "name": "authfs_device_test_src_lib" - }, - { - "name": "heck_test_src_lib" + "name": "heck_device_test_src_lib" } ] } diff --git a/cargo2android.json b/cargo2android.json deleted file mode 100644 index d36fb44..0000000 --- a/cargo2android.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "device": true, - "run": true, - "tests": true -}
\ No newline at end of file diff --git a/no_step_on_snek.png b/no_step_on_snek.png Binary files differnew file mode 100644 index 0000000..8aff445 --- /dev/null +++ b/no_step_on_snek.png diff --git a/src/camel.rs b/src/camel.rs index 6949435..fa31f0c 100644 --- a/src/camel.rs +++ b/src/camel.rs @@ -34,7 +34,7 @@ mod tests { fn $t() { assert_eq!($s1.to_camel_case(), $s2) } - }; + } } t!(test1: "CamelCase" => "CamelCase"); diff --git a/src/kebab.rs b/src/kebab.rs index 75e5978..94ac322 100644 --- a/src/kebab.rs +++ b/src/kebab.rs @@ -33,7 +33,7 @@ mod tests { fn $t() { assert_eq!($s1.to_kebab_case(), $s2) } - }; + } } t!(test1: "CamelCase" => "camel-case"); @@ -7,15 +7,14 @@ //! ## Definition of a word boundary //! //! Word boundaries are defined as the "unicode words" defined in the -//! `unicode_segmentation` library, as well as within those words in this -//! manner: +//! `unicode_segmentation` library, as well as within those words in this manner: //! //! 1. All underscore characters are considered word boundaries. -//! 2. If an uppercase character is followed by lowercase letters, a word -//! boundary is considered to be just prior to that uppercase character. -//! 3. If multiple uppercase characters are consecutive, they are considered to -//! be within a single word, except that the last will be part of the next word -//! if it is followed by lowercase characters (see rule 2). +//! 2. If an uppercase character is followed by lowercase letters, a word boundary +//! is considered to be just prior to that uppercase character. +//! 3. If multiple uppercase characters are consecutive, they are considered to be +//! within a single word, except that the last will be part of the next word if it +//! is followed by lowercase characters (see rule 2). //! //! That is, "HelloWorld" is segmented `Hello|World` whereas "XMLHttpRequest" is //! segmented `XML|Http|Request`. @@ -25,8 +24,7 @@ //! being converted to. Multiple adjacent word boundaries (such as a series of //! underscores) are folded into one. ("hello__world" in snake case is therefore //! "hello_world", not the exact same string). Leading or trailing word boundary -//! indicators are dropped, except insofar as CamelCase capitalizes the first -//! word. +//! indicators are dropped, except insofar as CamelCase capitalizes the first word. //! //! ### Cases contained in this library: //! @@ -60,21 +58,18 @@ use unicode_segmentation::UnicodeSegmentation; fn transform<F, G>(s: &str, with_word: F, boundary: G) -> String where F: Fn(&str, &mut String), - G: Fn(&mut String), + G: Fn(&mut String) { - /// Tracks the current 'mode' of the transformation algorithm as it scans - /// the input string. + + /// Tracks the current 'mode' of the transformation algorithm as it scans the input string. /// - /// The mode is a tri-state which tracks the case of the last cased - /// character of the current word. If there is no cased character - /// (either lowercase or uppercase) since the previous word boundary, - /// than the mode is `Boundary`. If the last cased character is lowercase, - /// then the mode is `Lowercase`. Othertherwise, the mode is - /// `Uppercase`. + /// The mode is a tri-state which tracks the case of the last cased character of the current + /// word. If there is no cased character (either lowercase or uppercase) since the previous + /// word boundary, than the mode is `Boundary`. If the last cased character is lowercase, then + /// the mode is `Lowercase`. Othertherwise, the mode is `Uppercase`. #[derive(Clone, Copy, PartialEq)] enum WordMode { - /// There have been no lowercase or uppercase characters in the current - /// word. + /// There have been no lowercase or uppercase characters in the current word. Boundary, /// The previous cased character in the current word is lowercase. Lowercase, @@ -93,15 +88,14 @@ where while let Some((i, c)) = char_indices.next() { // Skip underscore characters if c == '_' { - if init == i { - init += 1; - } - continue; + if init == i { init += 1; } + continue } if let Some(&(next_i, next)) = char_indices.peek() { - // The mode including the current character, assuming the - // current character does not result in a word boundary. + + // The mode including the current character, assuming the current character does + // not result in a word boundary. let next_mode = if c.is_lowercase() { WordMode::Lowercase } else if c.is_uppercase() { @@ -113,9 +107,7 @@ where // Word boundary after if next is underscore or current is // not uppercase and next is uppercase if next == '_' || (next_mode == WordMode::Lowercase && next.is_uppercase()) { - if !first_word { - boundary(&mut out); - } + if !first_word { boundary(&mut out); } with_word(&word[init..next_i], &mut out); first_word = false; init = next_i; @@ -124,11 +116,8 @@ where // Otherwise if current and previous are uppercase and next // is lowercase, word boundary before } else if mode == WordMode::Uppercase && c.is_uppercase() && next.is_lowercase() { - if !first_word { - boundary(&mut out); - } else { - first_word = false; - } + if !first_word { boundary(&mut out); } + else { first_word = false; } with_word(&word[init..i], &mut out); init = i; mode = WordMode::Boundary; @@ -139,11 +128,8 @@ where } } else { // Collect trailing characters as a word - if !first_word { - boundary(&mut out); - } else { - first_word = false; - } + if !first_word { boundary(&mut out); } + else { first_word = false; } with_word(&word[init..], &mut out); break; } @@ -164,7 +150,7 @@ fn lowercase(s: &str, out: &mut String) { } } -fn uppercase(s: &str, out: &mut String) { +fn uppercase(s: &str, out: &mut String ) { for c in s.chars() { out.extend(c.to_uppercase()) } diff --git a/src/mixed.rs b/src/mixed.rs index 71089f2..cca3262 100644 --- a/src/mixed.rs +++ b/src/mixed.rs @@ -20,17 +20,10 @@ 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) } + }, |_| {}) } } @@ -44,7 +37,7 @@ mod tests { fn $t() { assert_eq!($s1.to_mixed_case(), $s2) } - }; + } } t!(test1: "CamelCase" => "camelCase"); diff --git a/src/shouty_kebab.rs b/src/shouty_kebab.rs index 0225471..0e0c7e7 100644 --- a/src/shouty_kebab.rs +++ b/src/shouty_kebab.rs @@ -34,7 +34,7 @@ mod tests { fn $t() { assert_eq!($s1.to_shouty_kebab_case(), $s2) } - }; + } } t!(test1: "CamelCase" => "CAMEL-CASE"); diff --git a/src/shouty_snake.rs b/src/shouty_snake.rs index 8f4289a..43be539 100644 --- a/src/shouty_snake.rs +++ b/src/shouty_snake.rs @@ -18,8 +18,8 @@ pub trait ShoutySnakeCase: ToOwned { fn to_shouty_snake_case(&self) -> Self::Owned; } -/// Oh heck, ShoutySnekCase is an alias for ShoutySnakeCase. See ShoutySnakeCase -/// for more documentation. +/// Oh heck, ShoutySnekCase is an alias for ShoutySnakeCase. See ShoutySnakeCase for +/// more documentation. pub trait ShoutySnekCase: ToOwned { /// CONVERT THIS TYPE TO SNEK CASE. #[allow(non_snake_case)] @@ -32,6 +32,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('_')) @@ -48,7 +49,7 @@ mod tests { fn $t() { assert_eq!($s1.to_shouty_snake_case(), $s2) } - }; + } } t!(test1: "CamelCase" => "CAMEL_CASE"); diff --git a/src/snake.rs b/src/snake.rs index c1ad376..13329fe 100644 --- a/src/snake.rs +++ b/src/snake.rs @@ -46,7 +46,7 @@ mod tests { fn $t() { assert_eq!($s1.to_snake_case(), $s2) } - }; + } } t!(test1: "CamelCase" => "camel_case"); diff --git a/src/title.rs b/src/title.rs index 015a9fa..3723f1f 100644 --- a/src/title.rs +++ b/src/title.rs @@ -34,7 +34,7 @@ mod tests { fn $t() { assert_eq!($s1.to_title_case(), $s2) } - }; + } } t!(test1: "CamelCase" => "Camel Case"); |