pub enum Pattern {
Lowercase,
Uppercase,
Capital,
Sentence,
Camel,
Alternating,
Toggle,
PseudoRandom,
}
Expand description
A pattern is how a set of words is mutated before joining with a delimeter.
The Random
and PseudoRandom
patterns are used for their respective cases
and are only available in the “random” feature.
Variants§
Lowercase
Lowercase patterns make all words lowercase.
use convert_case::Pattern;
assert_eq!(
vec!["case", "conversion", "library"],
Pattern::Lowercase.mutate(&["Case", "CONVERSION", "library"])
);
Uppercase
Uppercase patterns make all words uppercase.
use convert_case::Pattern;
assert_eq!(
vec!["CASE", "CONVERSION", "LIBRARY"],
Pattern::Uppercase.mutate(&["Case", "CONVERSION", "library"])
);
Capital
Capital patterns makes the first letter of each word uppercase and the remaining letters of each word lowercase.
use convert_case::Pattern;
assert_eq!(
vec!["Case", "Conversion", "Library"],
Pattern::Capital.mutate(&["Case", "CONVERSION", "library"])
);
Sentence
Capital patterns make the first word capitalized and the remaining lowercase.
use convert_case::Pattern;
assert_eq!(
vec!["Case", "conversion", "library"],
Pattern::Sentence.mutate(&["Case", "CONVERSION", "library"])
);
Camel
Camel patterns make the first word lowercase and the remaining capitalized.
use convert_case::Pattern;
assert_eq!(
vec!["case", "Conversion", "Library"],
Pattern::Camel.mutate(&["Case", "CONVERSION", "library"])
);
Alternating
Alternating patterns make each letter of each word alternate between lowercase and uppercase. They alternate across words, which means the last letter of one word and the first letter of the next will not be the same letter casing.
use convert_case::Pattern;
assert_eq!(
vec!["cAsE", "cOnVeRsIoN", "lIbRaRy"],
Pattern::Alternating.mutate(&["Case", "CONVERSION", "library"])
);
assert_eq!(
vec!["aNoThEr", "ExAmPlE"],
Pattern::Alternating.mutate(&["Another", "Example"]),
);
Toggle
Toggle patterns have the first letter of each word uppercase and the remaining letters of each word uppercase.
use convert_case::Pattern;
assert_eq!(
vec!["cASE", "cONVERSION", "lIBRARY"],
Pattern::Toggle.mutate(&["Case", "CONVERSION", "library"])
);
PseudoRandom
PseudoRandom patterns are random-like patterns. Instead of randomizing
each letter individually, it mutates each pair of characters
as either (Lowercase, Uppercase) or (Uppercase, Lowercase). This generates
more “random looking” words. A consequence of this algorithm for randomization
is that there will never be three consecutive letters that are all lowercase
or all uppercase. This uses the rand
crate and is only available with the “random”
feature. This example will not pass the assertion due to randomness, but it used as an
example of what output is possible.
use convert_case::Pattern;
assert_eq!(
vec!["cAsE", "cONveRSioN", "lIBrAry"],
Pattern::Random.mutate(&["Case", "CONVERSION", "library"]),
);