]>
git.proxmox.com Git - rustc.git/blob - vendor/heck/src/shouty_snake.rs
1 use crate::{transform, uppercase}
;
3 /// This trait defines a shouty snake case conversion.
5 /// In SHOUTY_SNAKE_CASE, word boundaries are indicated by underscores and all
6 /// words are in uppercase.
11 /// use heck::ShoutySnakeCase;
13 /// let sentence = "That world is growing in this minute.";
14 /// assert_eq!(sentence.to_shouty_snake_case(), "THAT_WORLD_IS_GROWING_IN_THIS_MINUTE");
16 pub trait ShoutySnakeCase
: ToOwned
{
17 /// Convert this type to shouty snake case.
18 fn to_shouty_snake_case(&self) -> Self::Owned
;
21 /// Oh heck, ShoutySnekCase is an alias for ShoutySnakeCase. See ShoutySnakeCase
22 /// for more documentation.
23 pub trait ShoutySnekCase
: ToOwned
{
24 /// CONVERT THIS TYPE TO SNEK CASE.
25 #[allow(non_snake_case)]
26 fn TO_SHOUTY_SNEK_CASE(&self) -> Self::Owned
;
29 impl<T
: ?Sized
+ ShoutySnakeCase
> ShoutySnekCase
for T
{
30 fn TO_SHOUTY_SNEK_CASE(&self) -> Self::Owned
{
31 self.to_shouty_snake_case()
35 impl ShoutySnakeCase
for str {
36 fn to_shouty_snake_case(&self) -> Self::Owned
{
37 transform(self, uppercase
, |s
| s
.push('_'
))
43 use super::ShoutySnakeCase
;
46 ($t
:ident
: $s1
:expr
=> $s2
:expr
) => {
49 assert_eq
!($s1
.to_shouty_snake_case(), $s2
)
54 t
!(test1
: "CamelCase" => "CAMEL_CASE");
55 t
!(test2
: "This is Human case." => "THIS_IS_HUMAN_CASE");
56 t
!(test3
: "MixedUP CamelCase, with some Spaces" => "MIXED_UP_CAMEL_CASE_WITH_SOME_SPACES");
57 t
!(test4
: "mixed_up_snake_case with some _spaces" => "MIXED_UP_SNAKE_CASE_WITH_SOME_SPACES");
58 t
!(test5
: "kebab-case" => "KEBAB_CASE");
59 t
!(test6
: "SHOUTY_SNAKE_CASE" => "SHOUTY_SNAKE_CASE");
60 t
!(test7
: "snake_case" => "SNAKE_CASE");
61 t
!(test8
: "this-contains_ ALLKinds OfWord_Boundaries" => "THIS_CONTAINS_ALL_KINDS_OF_WORD_BOUNDARIES");
62 t
!(test9
: "XΣXΣ baffle" => "XΣXΣ_BAFFLE");
63 t
!(test10
: "XMLHttpRequest" => "XML_HTTP_REQUEST");