Skip to content

Commit 2dd02f3

Browse files
Treehugger RobotGerrit Code Review
authored andcommitted
Merge "Update heck to 0.5.0" into main
2 parents 5ed6cfb + a8c3151 commit 2dd02f3

19 files changed

+99
-113
lines changed

crates/heck/.android-checksum.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"package":null,"files":{".cargo-checksum.json":"50aceee5469518140d55b8b11486d261788aff79aeb43a8d11d0c72ba2cd4adf","Android.bp":"fe170b50140d550a0660daafa2e3938735f77bccbdef31ad0c7a5e8cf36b85c1","CHANGELOG.md":"0d496ccabe5fd92b8073369a841c3f390ffb787d128de05d13e82c459e671d0c","Cargo.toml":"8e414f85412de7f517d2e6988a63a93ec449a38dd6d5c05cc21b0cb385ed8342","LICENSE":"3c7cd2396b5b772507febd2615d3d5a55b80103845037df77c87ba6e64872f2c","LICENSE-APACHE":"3c7cd2396b5b772507febd2615d3d5a55b80103845037df77c87ba6e64872f2c","LICENSE-MIT":"8ff981830ebf3fe518679fabc276f8aade7e253f47946d0d8df0dd30f83d96f5","METADATA":"0157a9355d39040b4d38940d845dd5eaf1a08ac3f14651340ab8dde41c9f0af9","MODULE_LICENSE_APACHE2":"0d6f8afa3940b7f06bebee651376d43bc8b0d5b437337be2696d30377451e93a","README.md":"fead471b7400ee13f5c1b6c9e1ed135c72db8da93de73c6da743c5ecce4174db","TEST_MAPPING":"be0555eea9f9c69d388cb5bf453c2a6f9d1ec093cb2fed6e3046811fd384a107","cargo_embargo.json":"10305b0599b31bd8b0a4501a79d7c278d3492eeedeb7f7e253325199c27363e4","src/kebab.rs":"5399b5b18fbfdb0003d8c891263c9da50f6388c51997d90b78744ced3790dd74","src/lib.rs":"85b7ad88df3f38b74443ca0c5687e72fce8b95f5c9a64a02fb7541c6e8e632ea","src/lower_camel.rs":"7e6f3efb37b37f6b289c51cc5949212619ad501359f534112fb14bc368a5c5e1","src/shouty_kebab.rs":"7fa3b8167fb33e69022ebcf418399eb93ca617d92db88263668f0a02a72be35c","src/shouty_snake.rs":"3478ac0fc9be5d9b2f755f83c692604aabcf73d67d02b1543e36ef98cdf3d76e","src/snake.rs":"ea3fa428e6775385833b0e87411963e605fa7e18a8655110be1e938cae66486f","src/title.rs":"ce29952b0b1d7058cc5d2b922afdcad9bec2da35bd7aa16680efa6213496e40f","src/train.rs":"367c15c236998fe336b216dcdb8aca48b7d0232a6f82906e1be9d942a9785960","src/upper_camel.rs":"a1656b024427a9e70a36fbf07bb4ceaeb14d1e6f18b5089bdfd2adf938bb0f4c"}}
1+
{"package":null,"files":{".cargo-checksum.json":"1302745d76c5f5fee4c59feac4302d338c5f2e897d4f775e6a823659f23a534e","Android.bp":"f3072f0fa671efaf228afd62e11fff440836cbcbc444798dfb3e5c812632a6bf","CHANGELOG.md":"ec7a711d35dfb9ebab67fd25055f12d2c0d0393d63a4efe03673ca511e91a9e1","Cargo.toml":"4ea736e28e34f8f33ad44eba397dbea14fed13ed51fb1027c2141ea62e81bad5","LICENSE":"3c7cd2396b5b772507febd2615d3d5a55b80103845037df77c87ba6e64872f2c","LICENSE-APACHE":"3c7cd2396b5b772507febd2615d3d5a55b80103845037df77c87ba6e64872f2c","LICENSE-MIT":"8ff981830ebf3fe518679fabc276f8aade7e253f47946d0d8df0dd30f83d96f5","METADATA":"ac7ea5052404c3e06fbee974b9ad71d5268b5e70de29cf71481329018d5c95cd","MODULE_LICENSE_APACHE2":"0d6f8afa3940b7f06bebee651376d43bc8b0d5b437337be2696d30377451e93a","README.md":"7874857d8da5c1f393065dca691cb4029e5b9127ea057dd3355a1d2a16ad7f8a","TEST_MAPPING":"be0555eea9f9c69d388cb5bf453c2a6f9d1ec093cb2fed6e3046811fd384a107","cargo_embargo.json":"3c1e1d20399b03bdf55f18d6015a4094345e1520ee0c54e21b2c4c0f8cbb7536","src/kebab.rs":"d5b74f0511cce97ac51641211d7b9956ed7d9b6fbf2ae71b814c6016b9391d42","src/lib.rs":"7be0bc361a2c6fa2b0f929d67d98ec494aa4c7764bcd1cb2f4b467554476868e","src/lower_camel.rs":"77c6ac9eea5c8c81a2999754800b3c200f1b44491a800c7f76d4718e136ebeda","src/shouty_kebab.rs":"b47196c2b0030d7b5be1545bd89152fed56a239e5bf7c5b202c3f467bfaacf02","src/shouty_snake.rs":"0a752565c0c57c98db9d69b0274fd3b1f30ec577f0ede84c2760f820804e5890","src/snake.rs":"9e7e54ba7d9962a9c5775e43bc5405dc325026fd4e0f26b5d744a21165a8370e","src/title.rs":"0813a1959a835242cd48a00213b2c258a57c40d3c7e75768e147a0c754d7b472","src/train.rs":"2e164df47756ee5d9fbdcd3c704f9d78b6d6bb50a84442b634a20bf414b63a5d","src/upper_camel.rs":"47930c79916168a0fdc8dcb2ef4e72c16f479b0daf4135ba9e02f9118a7fa13a"}}

crates/heck/.cargo-checksum.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"files":{"CHANGELOG.md":"be2b711f318b4447b7c0fa067ac1804dff0b01894d2782722646910a6b2c4b10","Cargo.toml":"bef2e967708cafccb70a6de0f2eeed8914f9a58c1fc9094cf0e6bde671768f7b","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"7b63ecd5f1902af1b63729947373683c32745c16a10e8e6292e2e2dcd7e90ae0","README.md":"a53c56a404fa7b97e4a5426798430186e715fcf38480327d42700494cae70f76","src/kebab.rs":"f2a4900541fe36584b0705108f5f1d23501bcb3429fffe04106077baecc6dc5a","src/lib.rs":"6cf5759deb604eb1035061ed52c1f71a629ac3fa6faefecceeb9d3cb9f4a9919","src/lower_camel.rs":"24a3ea7ce7f765b27fb0adec207498569f27045edc56c9089ae05fc428c54d5f","src/shouty_kebab.rs":"4516fbb2295c400869221912257828c90e7c0d43f3bdf4aaefb6d384606f4866","src/shouty_snake.rs":"01b8c1e7ac5e680827e2744e62bf4704fc7ebd0d555c5b040bca5f5fb50e4ffd","src/snake.rs":"fc69443dd1a9248667484d5feb52911a1c6dfed1442b01b5b23e371c5b716a5e","src/title.rs":"0cc0b3014559ab6047ed9e7afb624bbe97014a4498297a4c3b28f3410b75d1dc","src/train.rs":"6d20c7153b2e574653c57d039a5077c707c4f15e5b8be765bd5042a4dabc32d4","src/upper_camel.rs":"9cb094ade94cf6212a4b6e491b0fdad92ad8fbb0d55095c70691f9d66ce25366"},"package":"95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"}
1+
{"files":{"CHANGELOG.md":"972078362c7c30856e5ef46aa52c1c0ec3de40f417544566e225204b4cd4982a","Cargo.toml":"db0e63b72de157a2f5194458b73b6542c3f4e17e33ab34a71d0260bfc035467e","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"7b63ecd5f1902af1b63729947373683c32745c16a10e8e6292e2e2dcd7e90ae0","README.md":"c3c627aa49e64826aaf4914e5a3bd0aa2d1b304464c3e99cb6507190d3620a85","src/kebab.rs":"3075cf72c95404e6b5800494a5d8a3c5f6dd5066593ddb249cefcb376e30b450","src/lib.rs":"bffcc5144da472d2f915696d4654f7608e60861d168d3dd07b5dcb8f14211153","src/lower_camel.rs":"3b1e367db1ae22aa8c49b6800abf5e23e6befadf7cc89a252534f7286676e11f","src/shouty_kebab.rs":"8539eeddd4d78c10a8d0df3e19ad171409e95429debcdc6b7dbefd82d37b6928","src/shouty_snake.rs":"e8b6dcb77de87e2355067d5d47037537b68fa51c2601924a6acfae409c6d9920","src/snake.rs":"e13e8a4373e9388044bd91edff496362a1e7f6bd52f5f6be14a043878035245d","src/title.rs":"a12abc5057b48b8d5922d2a11b6029b230e13ae9a04109a40407d19505c2521b","src/train.rs":"0cbe348135852c12e9c56ab93233ca5c044218bc1b8818b620c3e80cd19973c2","src/upper_camel.rs":"9036542a600fd261b046ac4574622f831335abcf1366665aab56f4045fceb0d5"},"package":"2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"}

crates/heck/Android.bp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,24 @@ rust_test {
1818
host_supported: true,
1919
crate_name: "heck",
2020
cargo_env_compat: true,
21-
cargo_pkg_version: "0.4.1",
21+
cargo_pkg_version: "0.5.0",
2222
crate_root: "src/lib.rs",
2323
test_suites: ["general-tests"],
2424
auto_gen_config: true,
2525
test_options: {
2626
unit_test: true,
2727
},
28-
edition: "2018",
29-
features: [
30-
"unicode",
31-
"unicode-segmentation",
32-
],
33-
rustlibs: ["libunicode_segmentation"],
28+
edition: "2021",
3429
}
3530

3631
rust_library {
3732
name: "libheck",
3833
host_supported: true,
3934
crate_name: "heck",
4035
cargo_env_compat: true,
41-
cargo_pkg_version: "0.4.1",
36+
cargo_pkg_version: "0.5.0",
4237
crate_root: "src/lib.rs",
43-
edition: "2018",
44-
features: [
45-
"unicode",
46-
"unicode-segmentation",
47-
],
48-
rustlibs: ["libunicode_segmentation"],
38+
edition: "2021",
4939
apex_available: [
5040
"//apex_available:platform",
5141
"//apex_available:anyapex",

crates/heck/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# unreleased
2+
3+
# 0.5.0
4+
5+
- Add `no_std` support.
6+
- Remove non-additive `unicode` feature. The library now uses `char::is_alphanumeric`
7+
instead of the `unicode-segmentation` library to determine word boundaries in all cases.
8+
19
# 0.4.1
210

311
Improvements:

crates/heck/Cargo.toml

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,17 @@
1010
# See Cargo.toml.orig for the original contents.
1111

1212
[package]
13-
edition = "2018"
13+
edition = "2021"
14+
rust-version = "1.56"
1415
name = "heck"
15-
version = "0.4.1"
16-
authors = ["Without Boats <[email protected]>"]
16+
version = "0.5.0"
1717
include = [
1818
"src/**/*",
1919
"LICENSE-*",
2020
"README.md",
2121
"CHANGELOG.md",
2222
]
2323
description = "heck is a case conversion library."
24-
homepage = "https://github.com/withoutboats/heck"
25-
documentation = "https://docs.rs/heck"
2624
readme = "README.md"
2725
keywords = [
2826
"string",
@@ -31,13 +29,6 @@ keywords = [
3129
"snake",
3230
"unicode",
3331
]
32+
categories = ["no-std"]
3433
license = "MIT OR Apache-2.0"
3534
repository = "https://github.com/withoutboats/heck"
36-
37-
[dependencies.unicode-segmentation]
38-
version = "1.2.0"
39-
optional = true
40-
41-
[features]
42-
default = []
43-
unicode = ["unicode-segmentation"]

crates/heck/METADATA

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
name: "heck"
22
description: "heck is a case conversion library."
33
third_party {
4-
version: "0.4.1"
4+
version: "0.5.0"
55
license_type: NOTICE
66
last_upgrade_date {
7-
year: 2023
7+
year: 2025
88
month: 2
9-
day: 16
9+
day: 19
1010
}
1111
homepage: "https://crates.io/crates/heck"
1212
identifier {
1313
type: "Archive"
14-
value: "https://static.crates.io/crates/heck/heck-0.4.1.crate"
15-
version: "0.4.1"
14+
value: "https://static.crates.io/crates/heck/heck-0.5.0.crate"
15+
version: "0.5.0"
1616
}
1717
}

crates/heck/README.md

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ consistent, and reasonably well performing.
88

99
## Definition of a word boundary
1010

11-
Word boundaries are defined as the "unicode words" defined in the
12-
`unicode_segmentation` library, as well as within those words in this manner:
11+
Word boundaries are defined by non-alphanumeric characters, as well as
12+
within those words in this manner:
1313

14-
1. All underscore characters are considered word boundaries.
15-
2. If an uppercase character is followed by lowercase letters, a word boundary
16-
is considered to be just prior to that uppercase character.
17-
3. If multiple uppercase characters are consecutive, they are considered to be
18-
within a single word, except that the last will be part of the next word if it
19-
is followed by lowercase characters (see rule 2).
14+
1. If an uppercase character is followed by lowercase letters, a word
15+
boundary is considered to be just prior to that uppercase character.
16+
2. If multiple uppercase characters are consecutive, they are considered to
17+
be within a single word, except that the last will be part of the next word
18+
if it is followed by lowercase characters (see rule 1).
2019

2120
That is, "HelloWorld" is segmented `Hello|World` whereas "XMLHttpRequest" is
2221
segmented `XML|Http|Request`.
@@ -39,19 +38,9 @@ indicators are dropped, except insofar as CamelCase capitalizes the first word.
3938
7. SHOUTY-KEBAB-CASE
4039
8. Train-Case
4140

42-
## Contributing
43-
44-
PRs of additional well-established cases welcome.
45-
46-
This library is a little bit opinionated (dropping punctuation, for example).
47-
If that doesn't fit your use case, I hope there is another crate that does. I
48-
would prefer **not** to receive PRs to make this behavior more configurable.
49-
50-
Bug reports & fixes always welcome. :-)
51-
5241
## MSRV
5342

54-
The minimum supported Rust version for this crate is 1.32.0. This may change in
43+
The minimum supported Rust version for this crate is 1.56.0. This may change in
5544
minor or patch releases, but we probably won't ever require a very recent
5645
version. If you would like to have a stronger guarantee than that, please open
5746
an issue.

crates/heck/cargo_embargo.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
{
22
"tests": true,
3-
"features": [
4-
"unicode"
5-
],
63
"run_cargo": false
74
}

crates/heck/src/kebab.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use std::fmt;
1+
use core::fmt;
2+
3+
use alloc::{borrow::ToOwned, string::ToString};
24

35
use crate::{lowercase, transform};
46

@@ -64,7 +66,10 @@ mod tests {
6466
t!(test6: "SHOUTY_SNAKE_CASE" => "shouty-snake-case");
6567
t!(test7: "snake_case" => "snake-case");
6668
t!(test8: "this-contains_ ALLKinds OfWord_Boundaries" => "this-contains-all-kinds-of-word-boundaries");
67-
#[cfg(feature = "unicode")]
6869
t!(test9: "XΣXΣ baffle" => "xσxς-baffle");
6970
t!(test10: "XMLHttpRequest" => "xml-http-request");
71+
t!(test11: "لِنَذْهَبْ إِلَى السِّيْنَمَا" => "لِنَذْهَبْ-إِلَى-السِّيْنَمَا");
72+
// Japanese and Chinese do not have word separation.
73+
t!(test12: "ファイルを読み込み" => "ファイルを読み込み");
74+
t!(test13: "祝你一天过得愉快" => "祝你一天过得愉快");
7075
}

crates/heck/src/lib.rs

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@
66
//!
77
//! ## Definition of a word boundary
88
//!
9-
//! Word boundaries are defined as the "unicode words" defined in the
10-
//! `unicode_segmentation` library, as well as within those words in this
11-
//! manner:
9+
//! Word boundaries are defined by non-alphanumeric characters, as well as
10+
//! within those words in this manner:
1211
//!
13-
//! 1. All underscore characters are considered word boundaries.
14-
//! 2. If an uppercase character is followed by lowercase letters, a word
12+
//! 1. If an uppercase character is followed by lowercase letters, a word
1513
//! boundary is considered to be just prior to that uppercase character.
16-
//! 3. If multiple uppercase characters are consecutive, they are considered to
14+
//! 2. If multiple uppercase characters are consecutive, they are considered to
1715
//! be within a single word, except that the last will be part of the next word
18-
//! if it is followed by lowercase characters (see rule 2).
16+
//! if it is followed by lowercase characters (see rule 1).
1917
//!
2018
//! That is, "HelloWorld" is segmented `Hello|World` whereas "XMLHttpRequest" is
2119
//! segmented `XML|Http|Request`.
@@ -40,6 +38,9 @@
4038
//! 8. Train-Case
4139
#![deny(missing_docs)]
4240
#![forbid(unsafe_code)]
41+
#![no_std]
42+
43+
extern crate alloc;
4344

4445
mod kebab;
4546
mod lower_camel;
@@ -63,17 +64,7 @@ pub use upper_camel::{
6364
AsUpperCamelCase, AsUpperCamelCase as AsPascalCase, ToPascalCase, ToUpperCamelCase,
6465
};
6566

66-
use std::fmt;
67-
68-
#[cfg(feature = "unicode")]
69-
fn get_iterator(s: &str) -> unicode_segmentation::UnicodeWords {
70-
use unicode_segmentation::UnicodeSegmentation;
71-
s.unicode_words()
72-
}
73-
#[cfg(not(feature = "unicode"))]
74-
fn get_iterator(s: &str) -> impl Iterator<Item = &str> {
75-
s.split(|letter: char| !letter.is_ascii_alphanumeric())
76-
}
67+
use core::fmt;
7768

7869
fn transform<F, G>(
7970
s: &str,
@@ -107,20 +98,12 @@ where
10798

10899
let mut first_word = true;
109100

110-
for word in get_iterator(s) {
101+
for word in s.split(|c: char| !c.is_alphanumeric()) {
111102
let mut char_indices = word.char_indices().peekable();
112103
let mut init = 0;
113104
let mut mode = WordMode::Boundary;
114105

115106
while let Some((i, c)) = char_indices.next() {
116-
// Skip underscore characters
117-
if c == '_' {
118-
if init == i {
119-
init += 1;
120-
}
121-
continue;
122-
}
123-
124107
if let Some(&(next_i, next)) = char_indices.peek() {
125108
// The mode including the current character, assuming the
126109
// current character does not result in a word boundary.
@@ -132,9 +115,9 @@ where
132115
mode
133116
};
134117

135-
// Word boundary after if next is underscore or current is
136-
// not uppercase and next is uppercase
137-
if next == '_' || (next_mode == WordMode::Lowercase && next.is_uppercase()) {
118+
// Word boundary after if current is not uppercase and next
119+
// is uppercase
120+
if next_mode == WordMode::Lowercase && next.is_uppercase() {
138121
if !first_word {
139122
boundary(f)?;
140123
}

0 commit comments

Comments
 (0)