Expand description
This library provides some functions that convert string cases between
camelCase, COBOL-CASE, kebab-case, MACRO_CASE, PascalCase, snake_case and
Train-Case.
And this library also provides a trait Caser
which makes strings enable
to convert their cases by their own methods.
Basically, these functions targets the upper and lower cases of only ASCII alphabets for capitalization, and all characters except ASCII alphabets and ASCII numbers are eliminated as word separators.
To limit characters using as separators, the functions named like
*_with_sep
are provided, and to keep specified characters, the functions
named like *_with_keep
are provided.
In this crate, the default behavior of the conversion functions is to insert
a separator after a sequence of numbers and symbols, but not before them.
(For example, snake_case("abc123def") ==> "abc123_def"
)
However, for cases where you want to insert a separator before the sequence
as well, the functions names like *_with_nums_as_word
are provided.
(For example, snake_case_with_nums_as_word("abc123def") ==> "abc_123_def"
)
§Install
In Cargo.toml
, write this crate as a dependency.
[dependencies]
stringcase = "0.3.0"
§Usage
The function contained in this crate are executed as follows:
use stringcase::camel_case;
fn main() {
let input = "foo-bar-baz";
let camel = camel_case(input);
assert_eq!(camel, "fooBarBaz");
}
And by bringing Caser
with use
declaration, it will be able to execute
methods of strings, String
or &str
, to convert their cases.
use stringcase::Caser;
fn main() {
let input = "foo-bar-baz";
let camel = input.to_camel_case();
assert_eq!(camel, "fooBarBaz");
}
Traits§
- Caser
Caser
is the trait to attach methods for converting strings&str
andString
to various cases.
Functions§
- camel_
case - Converts a string to camel case.
- camel_
case_ with_ keep - Converts a string to camel case using characters other than the specified characters as separators.
- camel_
case_ with_ sep - Converts a string to camel case using the specified characters as separators.
- cobol_
case - Converts a string to cobol case.
- cobol_
case_ with_ keep - Converts a string to cobol case using characters other than the specified characters as separators.
- cobol_
case_ with_ nums_ as_ word - Converts a string to cobol case.
- cobol_
case_ with_ sep - Converts a string to cobol case using the specified characters as separators.
- kebab_
case - Converts a string to kebab case.
- kebab_
case_ with_ keep - Converts a string to kebab case using characters other than the specified characters as separators.
- kebab_
case_ with_ nums_ as_ word - Converts a string to kebab case.
- kebab_
case_ with_ sep - Converts a string to kebab case using the specified characters as separators.
- macro_
case - Converts a string to macro case.
- macro_
case_ with_ keep - Converts a string to macro case using characters other than the specified characters as separators.
- macro_
case_ with_ nums_ as_ word - Converts a string to macro case.
- macro_
case_ with_ sep - Converts a string to macro case using the specified characters as separators.
- pascal_
case - Converts a string to pascal case.
- pascal_
case_ with_ keep - Converts a string to pascal case using characters other than the specified characters as separators.
- pascal_
case_ with_ sep - Converts a string to pascal case using the specified characters as separators.
- snake_
case - Converts a string to snake case.
- snake_
case_ with_ keep - Converts a string to snake case using characters other than the specified characters as separators.
- snake_
case_ with_ nums_ as_ word - Converts a string to snake case.
- snake_
case_ with_ sep - Converts a string to snake case using the specified characters as separators.
- train_
case - Converts a string to train case.
- train_
case_ with_ keep - Converts a string to train case using characters other than the specified characters as separators.
- train_
case_ with_ nums_ as_ word - Converts a string to train case.
- train_
case_ with_ sep - Converts a string to train case using the specified characters as separators.