drone_macros_core/
unkeywordize.rs1use lazy_static::lazy_static;
2use regex::Regex;
3
4lazy_static! {
5 static ref KEYWORDS: Regex = Regex::new(
6 r"(?x)
7 ^ ( as | break | const | continue | crate | else | enum | extern | false | fn | for | if
8 | impl | in | let | loop | match | mod | move | mut | pub | ref | return | Self | self |
9 static | struct | super | trait | true | type | unsafe | use | where | while | abstract
10 | alignof | become | box | do | final | macro | offsetof | override | priv | proc | pure
11 | sizeof | typeof | unsized | virtual | yield ) $
12 "
13 )
14 .unwrap();
15}
16
17pub fn unkeywordize<T: AsRef<str>>(ident: T) -> String {
20 let mut ident = ident.as_ref().to_string();
21 if KEYWORDS.is_match(ident.as_ref()) {
22 ident.push('_');
23 }
24 ident
25}