aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-05-11 05:06:29 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-05-11 05:06:29 +0000
commit16ef4df5f324af5f9f0f283c36539d26ca9abf11 (patch)
tree23224284f98ea749c0273ccbb1f1777193b70beb
parent25a2eb17bef2f1f95e8ccddc503aa4ae5dc6d9f8 (diff)
parente5c8d7ae5166aafde18d2a1d186ffefda2a3abeb (diff)
downloadheck-android13-mainline-scheduling-release.tar.gz
Snap for 8570526 from e5c8d7ae5166aafde18d2a1d186ffefda2a3abeb to mainline-scheduling-releaseaml_sch_331113000aml_sch_331111000android13-mainline-scheduling-release
Change-Id: I543f508da66b0d005992cd71c0b4703b00c6d1ca
-rw-r--r--.cargo_vcs_info.json2
-rw-r--r--Android.bp28
-rw-r--r--Cargo.toml3
-rw-r--r--Cargo.toml.orig3
-rw-r--r--METADATA10
-rw-r--r--README.md15
-rw-r--r--TEST_MAPPING23
-rw-r--r--cargo2android.json5
-rw-r--r--no_step_on_snek.pngbin43512 -> 0 bytes
-rw-r--r--src/camel.rs2
-rw-r--r--src/kebab.rs2
-rw-r--r--src/lib.rs66
-rw-r--r--src/mixed.rs17
-rw-r--r--src/shouty_kebab.rs2
-rw-r--r--src/shouty_snake.rs7
-rw-r--r--src/snake.rs2
-rw-r--r--src/title.rs2
17 files changed, 119 insertions, 70 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index d8c857d..43f6c71 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,5 +1,5 @@
{
"git": {
- "sha1": "1c13e81591e356f13fb97a12d9775876a40c1a02"
+ "sha1": "d2f9cda3a00a62ae1e0eeeea8f0a081c7598b8c5"
}
}
diff --git a/Android.bp b/Android.bp
index 4aab8db..0d8524e 100644
--- a/Android.bp
+++ b/Android.bp
@@ -1,4 +1,5 @@
-// This file is generated by cargo2android.py --run --device --tests --dependencies.
+// This file is generated by cargo2android.py --config cargo2android.json.
+// Do not modify this file as changes will be overridden on upgrade.
package {
default_applicable_licenses: ["external_rust_crates_heck_license"],
@@ -36,38 +37,33 @@ license {
],
}
-rust_defaults {
- name: "heck_defaults",
+rust_test {
+ name: "heck_test_src_lib",
+ host_supported: true,
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
diff --git a/Cargo.toml b/Cargo.toml
index aadaa08..fc9c28d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,8 +13,9 @@
[package]
edition = "2018"
name = "heck"
-version = "0.3.2"
+version = "0.3.3"
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 13025c2..80acd39 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.2"
+version = "0.3.3"
edition = "2018"
license = "MIT OR Apache-2.0"
description = "heck is a case conversion library."
@@ -10,6 +10,7 @@ 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"
diff --git a/METADATA b/METADATA
index 4a392db..dd9970c 100644
--- a/METADATA
+++ b/METADATA
@@ -7,13 +7,13 @@ third_party {
}
url {
type: ARCHIVE
- value: "https://static.crates.io/crates/heck/heck-0.3.2.crate"
+ value: "https://static.crates.io/crates/heck/heck-0.3.3.crate"
}
- version: "0.3.2"
+ version: "0.3.3"
license_type: NOTICE
last_upgrade_date {
- year: 2020
- month: 12
- day: 22
+ year: 2021
+ month: 6
+ day: 21
}
}
diff --git a/README.md b/README.md
index 5563875..33f2a5d 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# **heck** is a case conversion library
-!["I specifically requested the opposite of this."](https://github.com/withoutboats/heck/blob/master/no_step_on_snek.png)
+!["I specifically requested the opposite of this."](./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,7 +48,14 @@ would prefer **not** to receive PRs to make this behavior more configurable.
Bug reports & fixes always welcome. :-)
-### License
+## 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
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 60b40b7..e5f5c4c 100644
--- a/TEST_MAPPING
+++ b/TEST_MAPPING
@@ -1,8 +1,27 @@
-// Generated by cargo2android.py for tests in Android.bp
+// Generated by update_crate_tests.py for tests that depend on this crate.
{
+ "imports": [
+ {
+ "path": "external/rust/crates/argh"
+ },
+ {
+ "path": "external/rust/crates/base64"
+ }
+ ],
"presubmit": [
{
- "name": "heck_device_test_src_lib"
+ "name": "authfs_device_test_src_lib"
+ },
+ {
+ "name": "heck_test_src_lib"
+ }
+ ],
+ "presubmit-rust": [
+ {
+ "name": "authfs_device_test_src_lib"
+ },
+ {
+ "name": "heck_test_src_lib"
}
]
}
diff --git a/cargo2android.json b/cargo2android.json
new file mode 100644
index 0000000..d36fb44
--- /dev/null
+++ b/cargo2android.json
@@ -0,0 +1,5 @@
+{
+ "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
deleted file mode 100644
index 8aff445..0000000
--- a/no_step_on_snek.png
+++ /dev/null
Binary files differ
diff --git a/src/camel.rs b/src/camel.rs
index fa31f0c..6949435 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 94ac322..75e5978 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");
diff --git a/src/lib.rs b/src/lib.rs
index 9540587..00a9fbe 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -7,14 +7,15 @@
//! ## 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`.
@@ -24,7 +25,8 @@
//! 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:
//!
@@ -58,18 +60,21 @@ 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,
@@ -88,14 +93,15 @@ 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() {
@@ -107,7 +113,9 @@ 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;
@@ -116,8 +124,11 @@ 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;
@@ -128,8 +139,11 @@ 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;
}
@@ -150,7 +164,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 cca3262..71089f2 100644
--- a/src/mixed.rs
+++ b/src/mixed.rs
@@ -20,10 +20,17 @@ 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)
+ }
+ },
+ |_| {},
+ )
}
}
@@ -37,7 +44,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 0e0c7e7..0225471 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 43be539..8f4289a 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,7 +32,6 @@ 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('_'))
@@ -49,7 +48,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 13329fe..c1ad376 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 3723f1f..015a9fa 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");