8 releases
new 0.3.2 | Feb 14, 2025 |
---|---|
0.3.1 | Feb 14, 2025 |
0.2.2 | Mar 22, 2024 |
0.2.1 | Nov 26, 2023 |
0.1.0 | Jul 22, 2022 |
#761 in Text processing
197 downloads per month
18KB
310 lines
ncase [ɪn'keɪs] — enforce a case style
Why?
So that I can
% for f in *.pdf; do
mv "$f" "$(ncase -s `basename "$f" .pdf`).pdf"
done
Binary
Install
% cargo install ncase
Usage
Enforce a case style on a string and write it to the standard output
% ncase --pascal this is a test string
ThisIsATestString
By default, enforce tOGGLE cASE
[^1]
% ncase this is a test string
tHIS iS a tEST sTRING
[^1]: rANdOm cASe
if built with the rand
feature.
Library
Install
Add the dependency to Cargo.toml
% cargo add ncase@0.3
Usage
See on docs.rs.
lib.rs
:
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 just as
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 a separator regex (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
dependency.
rand
: Enables rANdOm cASe
support. Adds the rand
dependency.
Dependencies
~2–8MB
~42K SLoC