#string #inflect #camel #snake #case

string_morph

string_morph is a 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.

1 unstable release

Uses old Rust 2015

0.1.0 Jan 6, 2017

#11 in #snake

Download history 18/week @ 2022-06-06 15/week @ 2022-06-13 23/week @ 2022-06-20 14/week @ 2022-06-27 14/week @ 2022-07-04 16/week @ 2022-07-11 16/week @ 2022-07-18 15/week @ 2022-07-25 24/week @ 2022-08-01 44/week @ 2022-08-08 20/week @ 2022-08-15 24/week @ 2022-08-22 19/week @ 2022-08-29 33/week @ 2022-09-05 32/week @ 2022-09-12 47/week @ 2022-09-19

131 downloads per month
Used in 3 crates (2 directly)

MIT license

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)

No runtime deps