1 unstable release
Uses old Rust 2015
0.1.0 | Jan 6, 2017 |
---|
#1669 in Text processing
2,665 downloads per month
Used in 10 crates
(4 directly)
15KB
199 lines
string_morph
string_morph is a Rust library of string case transformations with an emphasis on accuracy and performance. The case conversions are available as functions as well as traits on String types.
Examples
use string_morph::Morph;
// Camel case
assert_eq!("loremIpsumDolor", string_morph::to_camel_case("lorem_ipsum_dolor"));
assert_eq!("loremIpsumDolor", "lorem_ipsum_dolor".to_camel_case());
// Pascal case
assert_eq!("LoremIpsumDolor", string_morph::to_pascal_case("lorem_ipsum_dolor"));
assert_eq!("LoremIpsumDolor", "lorem_ipsum_dolor".to_pascal_case());
// Kebab case
assert_eq!("lorem-ipsum-dolor", string_morph::to_kebab_case("lorem_ipsum_dolor"));
assert_eq!("lorem-ipsum-dolor", "lorem_ipsum_dolor".to_kebab_case());
// Sentence case
assert_eq!("Lorem ipsum dolor", string_morph::to_sentence_case("lorem_ipsum_dolor"));
assert_eq!("Lorem ipsum dolor", "lorem_ipsum_dolor".to_sentence_case());
// Snake case
assert_eq!("lorem_ipsum_dolor", string_morph::to_snake_case("Lorem ipsum dolor"));
assert_eq!("lorem_ipsum_dolor", "Lorem ipsum dolor".to_snake_case());
// Upper snake case
assert_eq!("LOREM_IPSUM_DOLOR", string_morph::to_snake_caps_case("Lorem ipsum dolor"));
assert_eq!("LOREM_IPSUM_DOLOR", "Lorem ipsum dolor".to_snake_caps_case());
// Title case
assert_eq!("Lorem Ipsum Dolor", string_morph::to_title_case("lorem-ipsum-dolor"));
assert_eq!("Lorem Ipsum Dolor", "lorem-ipsum-dolor".to_title_case());
// Upper first
assert_eq!("Test", string_morph::to_upper_first("test"));
assert_eq!("Test", "test".to_upper_first());
Benchmarks
running 8 tests
test bench_camel ... bench: 538 ns/iter (+/- 28)
test bench_dashed ... bench: 517 ns/iter (+/- 38)
test bench_first_case ... bench: 68 ns/iter (+/- 1)
test bench_human ... bench: 578 ns/iter (+/- 11)
test bench_pascal ... bench: 611 ns/iter (+/- 22)
test bench_snake_caps ... bench: 529 ns/iter (+/- 23)
test bench_snake_case ... bench: 510 ns/iter (+/- 52)
test bench_title ... bench: 566 ns/iter (+/- 58)