File tree 1 file changed +9
-59
lines changed
Sources/_OpenAPIGeneratorCore/Extensions 1 file changed +9
-59
lines changed Original file line number Diff line number Diff line change @@ -67,8 +67,6 @@ fileprivate extension String {
67
67
}
68
68
69
69
// Only allow [a-zA-Z][a-zA-Z0-9_]*
70
- // This is bad, is there something like percent encoding functionality but for general "allowed chars only"?
71
-
72
70
let firstCharSet : CharacterSet = . letters
73
71
let numbers : CharacterSet = . decimalDigits
74
72
let otherCharSet : CharacterSet = . alphanumerics. union ( . init( charactersIn: " _ " ) )
@@ -83,7 +81,15 @@ fileprivate extension String {
83
81
sanitizedScalars. append ( " _ " )
84
82
outScalar = scalar
85
83
} else {
86
- outScalar = " _ "
84
+ var hexString = String ( scalar. value, radix: 16 , uppercase: true )
85
+ if let firstChar = hexString. unicodeScalars. first,
86
+ !firstCharSet. contains ( firstChar) {
87
+ hexString = " _ \( hexString) "
88
+ }
89
+ for char in hexString. unicodeScalars {
90
+ sanitizedScalars. append ( char)
91
+ }
92
+ continue
87
93
}
88
94
sanitizedScalars. append ( outScalar)
89
95
}
@@ -153,62 +159,6 @@ fileprivate extension String {
153
159
" true " ,
154
160
" try " ,
155
161
" throws " ,
156
- " __FILE__ " ,
157
- " __LINE__ " ,
158
- " __COLUMN__ " ,
159
- " __FUNCTION__ " ,
160
- " __DSO_HANDLE__ " ,
161
- " _ " ,
162
- " ( " ,
163
- " ) " ,
164
- " { " ,
165
- " } " ,
166
- " [ " ,
167
- " ] " ,
168
- " < " ,
169
- " > " ,
170
- " . " ,
171
- " . " ,
172
- " , " ,
173
- " ... " ,
174
- " : " ,
175
- " ; " ,
176
- " = " ,
177
- " @ " ,
178
- " # " ,
179
- " & " ,
180
- " -> " ,
181
- " ` " ,
182
- " \\ " ,
183
- " ! " ,
184
- " ? " ,
185
- " ? " ,
186
- " \" " ,
187
- " \' " ,
188
- " \" \" \" " ,
189
- " #keyPath " ,
190
- " #line " ,
191
- " #selector " ,
192
- " #file " ,
193
- " #fileID " ,
194
- " #filePath " ,
195
- " #column " ,
196
- " #function " ,
197
- " #dsohandle " ,
198
- " #assert " ,
199
- " #sourceLocation " ,
200
- " #warning " ,
201
- " #error " ,
202
- " #if " ,
203
- " #else " ,
204
- " #elseif " ,
205
- " #endif " ,
206
- " #available " ,
207
- " #unavailable " ,
208
- " #fileLiteral " ,
209
- " #imageLiteral " ,
210
- " #colorLiteral " ,
211
- " ) " ,
212
162
" yield " ,
213
163
" String " ,
214
164
" Error " ,
You can’t perform that action at this time.
0 commit comments