@@ -8,79 +8,63 @@ use cases::snakecase::to_snake_case;
8
8
///
9
9
/// #Examples
10
10
/// ```
11
- /// use inflector::cases::camelcase::to_camel_case;
12
- ///
13
- /// // camelize_fooBar_as_fooBar() {
11
+ /// use inflector::cases::camelcase::to_camel_case;
14
12
/// let mock_string: String = "fooBar".to_string();
15
13
/// let expected_string: String = "fooBar".to_string();
16
14
/// let asserted_string: String = to_camel_case(mock_string);
17
15
/// assert!(asserted_string == expected_string);
18
16
///
19
17
/// ```
20
18
/// ```
21
- /// use inflector::cases::camelcase::to_camel_case;
22
- ///
23
- /// // camelize_FOO_BAR_as_fooBar() {
19
+ /// use inflector::cases::camelcase::to_camel_case;
24
20
/// let mock_string: String = "FOO_BAR".to_string();
25
21
/// let expected_string: String = "fooBar".to_string();
26
22
/// let asserted_string: String = to_camel_case(mock_string);
27
23
/// assert!(asserted_string == expected_string);
28
24
///
29
25
/// ```
30
26
/// ```
31
- /// use inflector::cases::camelcase::to_camel_case;
32
- ///
33
- /// // camelize_Foo_Bar_as_fooBar() {
27
+ /// use inflector::cases::camelcase::to_camel_case;
34
28
/// let mock_string: String = "Foo Bar".to_string();
35
29
/// let expected_string: String = "fooBar".to_string();
36
30
/// let asserted_string: String = to_camel_case(mock_string);
37
31
/// assert!(asserted_string == expected_string);
38
32
///
39
33
/// ```
40
34
/// ```
41
- /// use inflector::cases::camelcase::to_camel_case;
42
- ///
43
- /// // camelize_foo_bar_as_fooBar() {
35
+ /// use inflector::cases::camelcase::to_camel_case;
44
36
/// let mock_string: String = "foo_bar".to_string();
45
37
/// let expected_string: String = "fooBar".to_string();
46
38
/// let asserted_string: String = to_camel_case(mock_string);
47
39
/// assert!(asserted_string == expected_string);
48
40
///
49
41
/// ```
50
42
/// ```
51
- /// use inflector::cases::camelcase::to_camel_case;
52
- ///
53
- /// // camelize_Foo_space_bar_as_fooBar() {
43
+ /// use inflector::cases::camelcase::to_camel_case;
54
44
/// let mock_string: String = "Foo bar".to_string();
55
45
/// let expected_string: String = "fooBar".to_string();
56
46
/// let asserted_string: String = to_camel_case(mock_string);
57
47
/// assert!(asserted_string == expected_string);
58
48
///
59
49
/// ```
60
50
/// ```
61
- /// use inflector::cases::camelcase::to_camel_case;
62
- ///
63
- /// // camelize_foo_dash_bar_as_fooBar() {
51
+ /// use inflector::cases::camelcase::to_camel_case;
64
52
/// let mock_string: String = "foo-bar".to_string();
65
53
/// let expected_string: String = "fooBar".to_string();
66
54
/// let asserted_string: String = to_camel_case(mock_string);
67
55
/// assert!(asserted_string == expected_string);
68
56
///
69
57
/// ```
70
58
/// ```
71
- /// use inflector::cases::camelcase::to_camel_case;
72
- ///
73
- /// // camelize_FooBar_as_fooBar() {
59
+ /// use inflector::cases::camelcase::to_camel_case;
74
60
/// let mock_string: String = "FooBar".to_string();
75
61
/// let expected_string: String = "fooBar".to_string();
76
62
/// let asserted_string: String = to_camel_case(mock_string);
77
63
/// assert!(asserted_string == expected_string);
78
64
///
79
65
/// ```
80
66
/// ```
81
- /// use inflector::cases::camelcase::to_camel_case;
82
- ///
83
- /// // camelize_FooBar3_as_fooBar3() {
67
+ /// use inflector::cases::camelcase::to_camel_case;
84
68
/// let mock_string: String = "FooBar3".to_string();
85
69
/// let expected_string: String = "fooBar3".to_string();
86
70
/// let asserted_string: String = to_camel_case(mock_string);
@@ -91,132 +75,110 @@ pub fn to_camel_case(non_camelized_string: String) -> String {
91
75
to_camel_from_snake ( to_snake_case ( non_camelized_string) )
92
76
}
93
77
94
- fn to_camel_from_snake ( non_camelized_string : String ) -> String {
95
- let mut result: String = "" . to_string ( ) ;
96
- let mut new_word: bool = false ;
78
+ fn to_camel_from_snake ( non_camelized_string : String ) -> String {
79
+ let mut result: String = "" . to_string ( ) ;
80
+ let mut new_word: bool = false ;
97
81
98
- for character in non_camelized_string. chars ( ) {
99
- if character. to_string ( ) == "_" {
100
- new_word = true ;
101
- } else if new_word {
102
- result = format ! ( "{}{}" , result, character. to_ascii_uppercase( ) ) ;
103
- new_word = false ;
104
- } else {
105
- result = format ! ( "{}{}" , result, character. to_ascii_lowercase( ) ) ;
106
- }
82
+ for character in non_camelized_string. chars ( ) {
83
+ if character. to_string ( ) == "_" {
84
+ new_word = true ;
85
+ } else if new_word {
86
+ result = format ! ( "{}{}" , result, character. to_ascii_uppercase( ) ) ;
87
+ new_word = false ;
88
+ } else {
89
+ result = format ! ( "{}{}" , result, character. to_ascii_lowercase( ) ) ;
107
90
}
108
- result
109
91
}
92
+ result
93
+ }
110
94
111
95
/// Determines if a `String` is camelCase bool``
112
96
///
113
97
/// #Examples
114
98
/// ```
115
- /// use inflector::cases::camelcase::is_camel_case;
116
- ///
117
- /// // returns_falsey_value_for_is_camel_case_when_start_cased() {
99
+ /// use inflector::cases::camelcase::is_camel_case;
118
100
/// let mock_string: String = "Foo".to_string();
119
101
/// let asserted_bool: bool = is_camel_case(mock_string);
120
102
/// assert!(asserted_bool == false);
121
103
///
122
104
///
123
105
/// ```
124
106
/// ```
125
- /// use inflector::cases::camelcase::is_camel_case;
126
- ///
127
- ///
128
- /// // returns_falsey_value_for_is_camel_case_when_lower_case() {
107
+ /// use inflector::cases::camelcase::is_camel_case;
129
108
/// let mock_string: String = "foo".to_string();
130
109
/// let asserted_bool: bool = is_camel_case(mock_string);
131
110
/// assert!(asserted_bool == false);
132
111
///
133
112
///
134
113
/// ```
135
114
/// ```
136
- /// use inflector::cases::camelcase::is_camel_case;
137
- ///
138
- /// // returns_falsey_value_for_is_camel_case_when_kebab() {
115
+ /// use inflector::cases::camelcase::is_camel_case;
139
116
/// let mock_string: String = "foo-bar-string-that-is-really-really-long".to_string();
140
117
/// let asserted_bool: bool = is_camel_case(mock_string);
141
118
/// assert!(asserted_bool == false);
142
119
///
143
120
///
144
121
/// ```
145
122
/// ```
146
- /// use inflector::cases::camelcase::is_camel_case;
147
- ///
148
- /// // returns_falsey_value_for_is_camel_case_when_class() {
123
+ /// use inflector::cases::camelcase::is_camel_case;
149
124
/// let mock_string: String = "FooBarIsAReallyReallyLongString".to_string();
150
125
/// let asserted_bool: bool = is_camel_case(mock_string);
151
126
/// assert!(asserted_bool == false);
152
127
///
153
128
///
154
129
/// ```
155
130
/// ```
156
- /// use inflector::cases::camelcase::is_camel_case;
157
- ///
158
- /// // returns_truthy_value_for_is_camel_case_when_camel_with_number() {
131
+ /// use inflector::cases::camelcase::is_camel_case;
159
132
/// let mock_string: String = "fooBarIsAReallyReally3LongString".to_string();
160
133
/// let asserted_bool: bool = is_camel_case(mock_string);
161
134
/// assert!(asserted_bool == true);
162
135
///
163
136
///
164
137
/// ```
165
138
/// ```
166
- /// use inflector::cases::camelcase::is_camel_case;
167
- ///
168
- /// // returns_truthy_value_for_is_camel_case_when_camel() {
139
+ /// use inflector::cases::camelcase::is_camel_case;
169
140
/// let mock_string: String = "fooBarIsAReallyReallyLongString".to_string();
170
141
/// let asserted_bool: bool = is_camel_case(mock_string);
171
142
/// assert!(asserted_bool == true);
172
143
///
173
144
///
174
145
/// ```
175
146
/// ```
176
- /// use inflector::cases::camelcase::is_camel_case;
177
- ///
178
- /// // returns_falsey_value_for_is_camel_case_when_screaming_snake() {
147
+ /// use inflector::cases::camelcase::is_camel_case;
179
148
/// let mock_string: String = "FOO_BAR_STRING_THAT_IS_REALLY_REALLY_LONG".to_string();
180
149
/// let asserted_bool: bool = is_camel_case(mock_string);
181
150
/// assert!(asserted_bool == false);
182
151
///
183
152
///
184
153
/// ```
185
154
/// ```
186
- /// use inflector::cases::camelcase::is_camel_case;
187
- ///
188
- /// // returns_falsey_value_for_is_camel_case_when_snake() {
155
+ /// use inflector::cases::camelcase::is_camel_case;
189
156
/// let mock_string: String = "foo_bar_string_that_is_really_really_long".to_string();
190
157
/// let asserted_bool: bool = is_camel_case(mock_string);
191
158
/// assert!(asserted_bool == false);
192
159
///
193
160
///
194
161
/// ```
195
162
/// ```
196
- /// use inflector::cases::camelcase::is_camel_case;
197
- ///
198
- /// // returns_falsey_value_for_is_camel_case_when_sentence() {
163
+ /// use inflector::cases::camelcase::is_camel_case;
199
164
/// let mock_string: String = "Foo bar string that is really really long".to_string();
200
165
/// let asserted_bool: bool = is_camel_case(mock_string);
201
166
/// assert!(asserted_bool == false);
202
167
///
203
168
///
204
169
/// ```
205
170
/// ```
206
- /// use inflector::cases::camelcase::is_camel_case;
207
- ///
208
- /// // returns_falsey_value_for_is_camel_case_when_title() {
171
+ /// use inflector::cases::camelcase::is_camel_case;
209
172
/// let mock_string: String = "Foo Bar Is A Really Really Long String".to_string();
210
173
/// let asserted_bool: bool = is_camel_case(mock_string);
211
174
/// assert!(asserted_bool == false);
212
175
/// ```
213
- pub fn is_camel_case ( test_string : String ) -> bool {
176
+ pub fn is_camel_case ( test_string : String ) -> bool {
214
177
let camel_matcher = Regex :: new ( r"(^|[A-Z])([^-|^_|^ ]*[a-z0-9]+[A-Z][a-z0-9]+)" ) . unwrap ( ) ;
215
178
let kebab_snake_matcher = Regex :: new ( r"[-|_| ]" ) . unwrap ( ) ;
216
- if camel_matcher. is_match ( test_string. as_ref ( ) )
217
- && !kebab_snake_matcher. is_match ( test_string. as_ref ( ) )
218
- && !is_class_case ( test_string) {
219
- return true ;
220
- }
179
+ if camel_matcher. is_match ( test_string. as_ref ( ) ) &&
180
+ !kebab_snake_matcher. is_match ( test_string. as_ref ( ) ) && !is_class_case ( test_string) {
181
+ return true ;
182
+ }
221
183
false
222
184
}
0 commit comments