1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | |
5 | /// Taken from `https://en.cppreference.com/w/cpp/keyword` |
6 | /// Some experimental keywords were filtered out and the resulting list was |
7 | /// sorted using a rust program. |
8 | const RESERVED_KEYWORDS: &[&str] = &[ |
9 | "alignas" , |
10 | "alignof" , |
11 | "auto" , |
12 | "bool" , |
13 | "break" , |
14 | "case" , |
15 | "catch" , |
16 | "char" , |
17 | "char16_t" , |
18 | "char32_t" , |
19 | "char8_t" , |
20 | "class" , |
21 | "const" , |
22 | "const_cast" , |
23 | "consteval" , |
24 | "constexpr" , |
25 | "continue" , |
26 | "decltype" , |
27 | "default" , |
28 | "delete" , |
29 | "do" , |
30 | "double" , |
31 | "dynamic_cast" , |
32 | "else" , |
33 | "enum" , |
34 | "explicit" , |
35 | "export" , |
36 | "extern" , |
37 | "false" , |
38 | "float" , |
39 | "for" , |
40 | "friend" , |
41 | "goto" , |
42 | "if" , |
43 | "inline" , |
44 | "int" , |
45 | "long" , |
46 | "mutable" , |
47 | "namespace" , |
48 | "new" , |
49 | "noexcept" , |
50 | "nullptr" , |
51 | "operator" , |
52 | "private" , |
53 | "protected" , |
54 | "public" , |
55 | "register" , |
56 | "reinterpret_cast" , |
57 | "return" , |
58 | "short" , |
59 | "signed" , |
60 | "sizeof" , |
61 | "static" , |
62 | "static_assert" , |
63 | "static_cast" , |
64 | "struct" , |
65 | "switch" , |
66 | "template" , |
67 | "this" , |
68 | "thread_local" , |
69 | "throw" , |
70 | "true" , |
71 | "try" , |
72 | "typedef" , |
73 | "typename" , |
74 | "union" , |
75 | "unsigned" , |
76 | "using" , |
77 | "virtual" , |
78 | "void" , |
79 | "volatile" , |
80 | "wchar_t" , |
81 | "while" , |
82 | ]; |
83 | |
84 | pub fn escape(rust_identifier: &mut String) { |
85 | if RESERVED_KEYWORDS |
86 | .binary_search(&rust_identifier.as_ref()) |
87 | .is_ok() |
88 | { |
89 | rust_identifier.push(ch:'_' ); |
90 | } |
91 | } |
92 | |