File tree Expand file tree Collapse file tree 12 files changed +28
-1
lines changed Expand file tree Collapse file tree 12 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -91,6 +91,14 @@ class Namer {
91
91
std::string keyword_prefix;
92
92
// Suffix used to escape keywords. It is usually "_".
93
93
std::string keyword_suffix;
94
+ // The casing used for keywords when escaping. For most languages, keywords
95
+ // are case sensitive. PHP is an instance where some keywords are case
96
+ // insensitive.
97
+ enum KeywordsCasing {
98
+ CASE_SENSITIVE,
99
+ CASE_INSENSITIVE,
100
+ };
101
+ KeywordsCasing keywords_casing;
94
102
95
103
// Files.
96
104
@@ -205,7 +213,14 @@ class Namer {
205
213
}
206
214
207
215
virtual std::string EscapeKeyword (const std::string &name) const {
208
- if (keywords_.find (name) == keywords_.end ()) {
216
+ std::string cased_name (name);
217
+
218
+ if (config_.keywords_casing == Config::KeywordsCasing::CASE_INSENSITIVE) {
219
+ for (auto chr = cased_name.begin (); chr != cased_name.end (); chr++) {
220
+ *chr = CharToLower (*chr);
221
+ }
222
+ }
223
+ if (keywords_.find (cased_name) == keywords_.end ()) {
209
224
return name;
210
225
} else {
211
226
return config_.keyword_prefix + name + config_.keyword_suffix ;
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ static const Namer::Config kConfig = {
26
26
/* object_suffix=*/ " T" ,
27
27
/* keyword_prefix=*/ " " ,
28
28
/* keyword_suffix=*/ " _" ,
29
+ /* keywords_casing=*/ Namer::Config::KeywordsCasing::CASE_SENSITIVE,
29
30
/* filenames=*/ Case::kKeep ,
30
31
/* directories=*/ Case::kKeep ,
31
32
/* output_path=*/ " " ,
@@ -49,6 +50,7 @@ static const Namer::Config kStubConfig = {
49
50
/* object_suffix=*/ " T" ,
50
51
/* keyword_prefix=*/ " " ,
51
52
/* keyword_suffix=*/ " _" ,
53
+ /* keywords_casing=*/ Namer::Config::KeywordsCasing::CASE_SENSITIVE,
52
54
/* filenames=*/ Case::kKeep ,
53
55
/* directories=*/ Case::kKeep ,
54
56
/* output_path=*/ " " ,
Original file line number Diff line number Diff line change @@ -61,6 +61,7 @@ Namer::Config LuaDefaultConfig() {
61
61
/* object_suffix=*/ " " ,
62
62
/* keyword_prefix=*/ " " ,
63
63
/* keyword_suffix=*/ " _" ,
64
+ /* keywords_casing=*/ Namer::Config::KeywordsCasing::CASE_SENSITIVE,
64
65
/* filenames=*/ Case::kKeep ,
65
66
/* directories=*/ Case::kKeep ,
66
67
/* output_path=*/ " " ,
Original file line number Diff line number Diff line change @@ -70,6 +70,7 @@ Namer::Config NimDefaultConfig() {
70
70
/* object_suffix=*/ " T" ,
71
71
/* keyword_prefix=*/ " " ,
72
72
/* keyword_suffix=*/ " _" ,
73
+ /* keywords_casing=*/ Namer::Config::KeywordsCasing::CASE_SENSITIVE,
73
74
/* filenames=*/ Case::kKeep ,
74
75
/* directories=*/ Case::kKeep ,
75
76
/* output_path=*/ " " ,
Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ static Namer::Config DartDefaultConfig() {
48
48
/* object_suffix=*/ " T" ,
49
49
/* keyword_prefix=*/ " $" ,
50
50
/* keyword_suffix=*/ " " ,
51
+ /* keywords_casing=*/ Namer::Config::KeywordsCasing::CASE_SENSITIVE,
51
52
/* filenames=*/ Case::kKeep ,
52
53
/* directories=*/ Case::kKeep ,
53
54
/* output_path=*/ " " ,
Original file line number Diff line number Diff line change @@ -75,6 +75,7 @@ static Namer::Config GoDefaultConfig() {
75
75
/* object_suffix=*/ " T" ,
76
76
/* keyword_prefix=*/ " " ,
77
77
/* keyword_suffix=*/ " _" ,
78
+ /* keywords_casing=*/ Namer::Config::KeywordsCasing::CASE_SENSITIVE,
78
79
/* filenames=*/ Case::kKeep ,
79
80
/* directories=*/ Case::kKeep ,
80
81
/* output_path=*/ " " ,
Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ static Namer::Config JavaDefaultConfig() {
46
46
/* object_suffix=*/ " T" ,
47
47
/* keyword_prefix=*/ " " ,
48
48
/* keyword_suffix=*/ " _" ,
49
+ /* keywords_casing=*/ Namer::Config::KeywordsCasing::CASE_SENSITIVE,
49
50
/* filenames=*/ Case::kKeep ,
50
51
/* directories=*/ Case::kKeep ,
51
52
/* output_path=*/ " " ,
Original file line number Diff line number Diff line change @@ -64,6 +64,7 @@ static Namer::Config KotlinDefaultConfig() {
64
64
/* object_suffix=*/ " T" ,
65
65
/* keyword_prefix=*/ " " ,
66
66
/* keyword_suffix=*/ " _" ,
67
+ /* keywords_casing=*/ Namer::Config::KeywordsCasing::CASE_SENSITIVE,
67
68
/* filenames=*/ Case::kKeep ,
68
69
/* directories=*/ Case::kKeep ,
69
70
/* output_path=*/ " " ,
Original file line number Diff line number Diff line change @@ -62,6 +62,7 @@ static Namer::Config KotlinDefaultConfig() {
62
62
/* object_suffix=*/ " T" ,
63
63
/* keyword_prefix=*/ " " ,
64
64
/* keyword_suffix=*/ " E" ,
65
+ /* keywords_casing=*/ Namer::Config::KeywordsCasing::CASE_SENSITIVE,
65
66
/* filenames=*/ Case::kUpperCamel ,
66
67
/* directories=*/ Case::kLowerCamel ,
67
68
/* output_path=*/ " " ,
Original file line number Diff line number Diff line change @@ -49,6 +49,7 @@ static Namer::Config RustDefaultConfig() {
49
49
/* object_suffix=*/ " T" ,
50
50
/* keyword_prefix=*/ " " ,
51
51
/* keyword_suffix=*/ " _" ,
52
+ /* keywords_casing=*/ Namer::Config::KeywordsCasing::CASE_SENSITIVE,
52
53
/* filenames=*/ Case::kSnake ,
53
54
/* directories=*/ Case::kSnake ,
54
55
/* output_path=*/ " " ,
Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ static Namer::Config SwiftDefaultConfig() {
47
47
/* object_suffix=*/ " T" ,
48
48
/* keyword_prefix=*/ " " ,
49
49
/* keyword_suffix=*/ " _" ,
50
+ /* keywords_casing=*/ Namer::Config::KeywordsCasing::CASE_SENSITIVE,
50
51
/* filenames=*/ Case::kKeep ,
51
52
/* directories=*/ Case::kKeep ,
52
53
/* output_path=*/ " " ,
Original file line number Diff line number Diff line change @@ -67,6 +67,7 @@ Namer::Config TypeScriptDefaultConfig() {
67
67
/* object_suffix=*/ " T" ,
68
68
/* keyword_prefix=*/ " " ,
69
69
/* keyword_suffix=*/ " _" ,
70
+ /* keywords_casing=*/ Namer::Config::KeywordsCasing::CASE_SENSITIVE,
70
71
/* filenames=*/ Case::kDasher ,
71
72
/* directories=*/ Case::kDasher ,
72
73
/* output_path=*/ " " ,
You can’t perform that action at this time.
0 commit comments