#snake-case #string #camel #inflect

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

#1344 in Rust patterns

Download history 31/week @ 2023-11-20 21/week @ 2023-11-27 23/week @ 2023-12-04 23/week @ 2023-12-11 36/week @ 2023-12-18 15/week @ 2023-12-25 18/week @ 2024-01-01 29/week @ 2024-01-08 24/week @ 2024-01-15 23/week @ 2024-01-22 43/week @ 2024-01-29 24/week @ 2024-02-05 44/week @ 2024-02-12 45/week @ 2024-02-19 50/week @ 2024-02-26 47/week @ 2024-03-04

191 downloads per month
Used in 4 crates (3 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