]>
git.proxmox.com Git - rustc.git/blob - vendor/heck/src/kebab.rs
f81ba928830f3f119b6a48e77769f37904560831
1 /// This trait defines a kebab case conversion.
3 /// In kebab-case, word boundaries are indicated by hyphens.
11 /// use heck::KebabCase;
13 /// let sentence = "We are going to inherit the earth.";
14 /// assert_eq!(sentence.to_kebab_case(), "we-are-going-to-inherit-the-earth");
17 pub trait KebabCase
: ToOwned
{
18 /// Convert this type to kebab case.
19 fn to_kebab_case(&self) -> Self::Owned
;
22 impl KebabCase
for str {
23 fn to_kebab_case(&self) -> Self::Owned
{
24 ::transform(self, ::lowercase
, |s
| s
.push('
-'
))
33 ($t
:ident
: $s1
:expr
=> $s2
:expr
) => {
36 assert_eq
!($s1
.to_kebab_case(), $s2
)
41 t
!(test1
: "CamelCase" => "camel-case");
42 t
!(test2
: "This is Human case." => "this-is-human-case");
43 t
!(test3
: "MixedUP CamelCase, with some Spaces" => "mixed-up-camel-case-with-some-spaces");
44 t
!(test4
: "mixed_up_ snake_case with some _spaces" => "mixed-up-snake-case-with-some-spaces");
45 t
!(test5
: "kebab-case" => "kebab-case");
46 t
!(test6
: "SHOUTY_SNAKE_CASE" => "shouty-snake-case");
47 t
!(test7
: "snake_case" => "snake-case");
48 t
!(test8
: "this-contains_ ALLKinds OfWord_Boundaries" => "this-contains-all-kinds-of-word-boundaries");
49 t
!(test9
: "XΣXΣ baffle" => "xσxς-baffle");
50 t
!(test10
: "XMLHttpRequest" => "xml-http-request");