Crate ncase

source ·
Expand description

ncase [ɪn’keɪs] is a library to enforce case styles.

§Usage

Use the free functions for one-off case conversions. They automatically split the input string into words as described in Words::from

assert_eq!(ncase::camel("camel case"), "camelCase");
assert_eq!(ncase::snake("snake case"), "snake_case");

Use Words if you need to convert one string into many case styles

use ncase::Words;

let s = "Lorem ipsum dolor sit amet";
let w = Words::from(s);

assert_eq!(w.kebab(), "lorem-ipsum-dolor-sit-amet");
assert_eq!(w.title(), "Lorem Ipsum Dolor Sit Amet");

Or if you want to use the separator regex (requires the regex feature)

use ncase::Words;
use regex::Regex;

let s = "Lorem, ipsum (dolor _sit)_ amet";
let sep = Regex::new(r"[\pP\s]+").unwrap();
let w = Words::with_separator(s, &sep);

assert_eq!(w.lower(), "lorem ipsum dolor sit amet");
assert_eq!(w.upper(), "LOREM IPSUM DOLOR SIT AMET");

§Features

regex : Enables Words::with_separator in the library and -F <separator> in the binary. Adds the regex crate as a dependency.

rand : Enables rANdOm cASe support. Adds the rand crate as a dependency.

Structs§

  • Sequence of words of some original string.

Functions§