Skip to content

Commit

Permalink
Make unicode support optional (off by default)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eli Flanagan authored Dec 9, 2021
1 parent e78e258 commit c501fc9
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 4 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ jobs:
toolchain: 1.32
default: true
profile: minimal
- name: Build
- name: Build default
uses: actions-rs/cargo@v1
with:
command: build
- name: Build with unicode segmentation on
uses: actions-rs/cargo@v1
with:
args: --features unicode
command: build
# Use stable for other jobs
- uses: actions-rs/toolchain@v1
with:
Expand Down
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ keywords = ["string", "case", "camel", "snake", "unicode"]
readme = "README.md"
include = ["src/**/*", "LICENSE-*", "README.md", "CHANGELOG.md"]

[features]
default = []
unicode = ["unicode-segmentation"]

[dependencies]
unicode-segmentation = "1.2.0"
unicode-segmentation = { version = "1.2.0", optional = true }
1 change: 1 addition & 0 deletions src/kebab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ mod tests {
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");
#[cfg(feature = "unicode")]
t!(test9: "XΣXΣ baffle" => "xσxς-baffle");
t!(test10: "XMLHttpRequest" => "xml-http-request");
}
12 changes: 10 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,15 @@ pub use upper_camel::{

use std::fmt;

use unicode_segmentation::UnicodeSegmentation;
#[cfg(feature = "unicode")]
fn get_iterator(s: &str) -> unicode_segmentation::UnicodeWords {
use unicode_segmentation::UnicodeSegmentation;
s.unicode_words()
}
#[cfg(not(feature = "unicode"))]
fn get_iterator(s: &str) -> impl Iterator<Item = &str> {
s.split(|letter: char| !letter.is_ascii_alphanumeric())
}

fn transform<F, G>(
s: &str,
Expand Down Expand Up @@ -96,7 +104,7 @@ where

let mut first_word = true;

for word in s.unicode_words() {
for word in get_iterator(s) {
let mut char_indices = word.char_indices().peekable();
let mut init = 0;
let mut mode = WordMode::Boundary;
Expand Down
1 change: 1 addition & 0 deletions src/lower_camel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ mod tests {
t!(test6: "SHOUTY_SNAKE_CASE" => "shoutySnakeCase");
t!(test7: "snake_case" => "snakeCase");
t!(test8: "this-contains_ ALLKinds OfWord_Boundaries" => "thisContainsAllKindsOfWordBoundaries");
#[cfg(feature = "unicode")]
t!(test9: "XΣXΣ baffle" => "xσxςBaffle");
t!(test10: "XMLHttpRequest" => "xmlHttpRequest");
// TODO unicode tests
Expand Down
1 change: 1 addition & 0 deletions src/shouty_kebab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ mod tests {
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");
#[cfg(feature = "unicode")]
t!(test9: "XΣXΣ baffle" => "XΣXΣ-BAFFLE");
t!(test10: "XMLHttpRequest" => "XML-HTTP-REQUEST");
t!(test11: "SHOUTY-KEBAB-CASE" => "SHOUTY-KEBAB-CASE");
Expand Down
1 change: 1 addition & 0 deletions src/shouty_snake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ mod tests {
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");
#[cfg(feature = "unicode")]
t!(test9: "XΣXΣ baffle" => "XΣXΣ_BAFFLE");
t!(test10: "XMLHttpRequest" => "XML_HTTP_REQUEST");
}
1 change: 1 addition & 0 deletions src/snake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ mod tests {
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");
#[cfg(feature = "unicode")]
t!(test9: "XΣXΣ baffle" => "xσxς_baffle");
t!(test10: "XMLHttpRequest" => "xml_http_request");
t!(test11: "FIELD_NAME11" => "field_name11");
Expand Down
1 change: 1 addition & 0 deletions src/title.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ mod tests {
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");
#[cfg(feature = "unicode")]
t!(test9: "XΣXΣ baffle" => "Xσxς Baffle");
t!(test10: "XMLHttpRequest" => "Xml Http Request");
}
1 change: 1 addition & 0 deletions src/upper_camel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ mod tests {
t!(test6: "SHOUTY_SNAKE_CASE" => "ShoutySnakeCase");
t!(test7: "snake_case" => "SnakeCase");
t!(test8: "this-contains_ ALLKinds OfWord_Boundaries" => "ThisContainsAllKindsOfWordBoundaries");
#[cfg(feature = "unicode")]
t!(test9: "XΣXΣ baffle" => "XσxςBaffle");
t!(test10: "XMLHttpRequest" => "XmlHttpRequest");
}

0 comments on commit c501fc9

Please sign in to comment.