@@ -2,6 +2,7 @@ use std::borrow::Cow;
2
2
3
3
use crate :: svd:: { Access , Device , DimElement , Field , RegisterInfo , RegisterProperties } ;
4
4
use html_escape:: encode_text_minimal;
5
+ use inflections:: Inflect ;
5
6
use proc_macro2:: { Ident , Span , TokenStream } ;
6
7
use quote:: quote;
7
8
use std:: collections:: HashSet ;
@@ -69,45 +70,43 @@ pub enum Case {
69
70
70
71
impl Case {
71
72
pub fn to_case < ' a > ( & self , s : & ' a str ) -> Cow < ' a , str > {
72
- use convert_case:: { Case as CCase , Casing } ;
73
73
match self {
74
74
Self :: Constant => {
75
- if s. is_case ( CCase :: UpperSnake ) {
75
+ if s. is_constant_case ( ) {
76
76
s. into ( )
77
77
} else {
78
- s. to_case ( CCase :: UpperSnake ) . into ( )
78
+ s. to_constant_case ( ) . into ( )
79
79
}
80
80
}
81
81
Self :: Pascal => {
82
- if s. is_case ( CCase :: Pascal ) {
82
+ if s. is_pascal_case ( ) {
83
83
s. into ( )
84
84
} else {
85
- s. to_case ( CCase :: Pascal ) . into ( )
85
+ s. to_pascal_case ( ) . into ( )
86
86
}
87
87
}
88
88
Self :: Snake => {
89
- if s. is_case ( CCase :: Snake ) {
89
+ if s. is_snake_case ( ) {
90
90
s. into ( )
91
91
} else {
92
- s. to_case ( CCase :: Snake ) . into ( )
92
+ s. to_snake_case ( ) . into ( )
93
93
}
94
94
}
95
95
}
96
96
}
97
97
pub fn cow_to_case < ' a > ( & self , cow : Cow < ' a , str > ) -> Cow < ' a , str > {
98
- use convert_case:: { Case as CCase , Casing } ;
99
98
match self {
100
99
Self :: Constant => match cow {
101
- Cow :: Borrowed ( s) if s. is_case ( CCase :: UpperSnake ) => cow,
102
- _ => cow. to_case ( CCase :: UpperSnake ) . into ( ) ,
100
+ Cow :: Borrowed ( s) if s. is_constant_case ( ) => cow,
101
+ _ => cow. to_constant_case ( ) . into ( ) ,
103
102
} ,
104
103
Self :: Pascal => match cow {
105
- Cow :: Borrowed ( s) if s. is_case ( CCase :: Pascal ) => cow,
106
- _ => cow. to_case ( CCase :: Pascal ) . into ( ) ,
104
+ Cow :: Borrowed ( s) if s. is_pascal_case ( ) => cow,
105
+ _ => cow. to_pascal_case ( ) . into ( ) ,
107
106
} ,
108
107
Self :: Snake => match cow {
109
- Cow :: Borrowed ( s) if s. is_case ( CCase :: Snake ) => cow,
110
- _ => cow. to_case ( CCase :: Snake ) . into ( ) ,
108
+ Cow :: Borrowed ( s) if s. is_snake_case ( ) => cow,
109
+ _ => cow. to_snake_case ( ) . into ( ) ,
111
110
} ,
112
111
}
113
112
}
0 commit comments