#camel-case #snake-case #pascal-case #case #kebab-case #string #snake

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

#1669 in Text processing

Download history 170/week @ 2024-07-21 181/week @ 2024-07-28 303/week @ 2024-08-04 289/week @ 2024-08-11 221/week @ 2024-08-18 424/week @ 2024-08-25 338/week @ 2024-09-01 328/week @ 2024-09-08 321/week @ 2024-09-15 636/week @ 2024-09-22 651/week @ 2024-09-29 667/week @ 2024-10-06 484/week @ 2024-10-13 927/week @ 2024-10-20 615/week @ 2024-10-27 622/week @ 2024-11-03

2,665 downloads per month
Used in 10 crates (4 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