1个不稳定版本
使用旧的Rust 2015
0.1.0 | 2017年1月6日 |
---|
#1344 在 Rust模式
191 每月下载量
用于 4 个crate(3个直接使用)
15KB
199 行
string_morph
string_morph是一个注重准确性和性能的Rust库,用于字符串大小写转换。大小写转换既可以作为函数使用,也可以在String类型上作为特质。
示例
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());
基准测试
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)