Skip to content

Commit 874eacb

Browse files
committed
is_ascii_digit
1 parent befc779 commit 874eacb

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

src/util.rs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,10 @@ impl ToSanitizedCase for str {
250250
self.into()
251251
};
252252

253-
match s.chars().next().unwrap_or('\0') {
254-
'0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' => {
255-
Cow::from(format!("_{}", Case::Pascal.to_case(&s)))
256-
}
257-
_ => Case::Pascal.cow_to_case(s),
253+
if s.as_bytes().get(0).unwrap_or(&0).is_ascii_digit() {
254+
Cow::from(format!("_{}", Case::Pascal.to_case(&s)))
255+
} else {
256+
Case::Pascal.cow_to_case(s)
258257
}
259258
}
260259
fn to_sanitized_constant_case(&self) -> Cow<str> {
@@ -264,11 +263,10 @@ impl ToSanitizedCase for str {
264263
self.into()
265264
};
266265

267-
match s.chars().next().unwrap_or('\0') {
268-
'0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' => {
269-
Cow::from(format!("_{}", Case::Constant.to_case(&s)))
270-
}
271-
_ => Case::Constant.cow_to_case(s),
266+
if s.as_bytes().get(0).unwrap_or(&0).is_ascii_digit() {
267+
Cow::from(format!("_{}", Case::Constant.to_case(&s)))
268+
} else {
269+
Case::Constant.cow_to_case(s)
272270
}
273271
}
274272
fn to_sanitized_not_keyword_snake_case(&self) -> Cow<str> {
@@ -279,17 +277,14 @@ impl ToSanitizedCase for str {
279277
} else {
280278
self.into()
281279
};
282-
match s.chars().next().unwrap_or('\0') {
283-
'0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' => {
284-
format!("_{}", Case::Snake.to_case(&s)).into()
285-
}
286-
_ => {
287-
let s = Case::Snake.cow_to_case(s);
288-
if INTERNALS.contains(&s.as_ref()) {
289-
s + "_"
290-
} else {
291-
s
292-
}
280+
if s.as_bytes().get(0).unwrap_or(&0).is_ascii_digit() {
281+
format!("_{}", Case::Snake.to_case(&s)).into()
282+
} else {
283+
let s = Case::Snake.cow_to_case(s);
284+
if INTERNALS.contains(&s.as_ref()) {
285+
s + "_"
286+
} else {
287+
s
293288
}
294289
}
295290
}

0 commit comments

Comments
 (0)