@@ -42,7 +42,7 @@ typedef struct {
42
42
const char * point ;
43
43
44
44
Jimp_Token token ;
45
- const char * token_start ;
45
+ const char * token_start ; // TODO: `token_start` is primarily used for diagnostics location. Rename it accordingly.
46
46
47
47
char * string ;
48
48
size_t string_count ;
@@ -188,12 +188,45 @@ static bool jimp__get_token(Jimp *jimp)
188
188
while (jimp -> point < jimp -> end ) {
189
189
// TODO: support all the JSON escape sequences defined in the spec
190
190
// Yes, including those dumb suroggate pairs. Spec is spec.
191
- if (* jimp -> point == '"' ) {
191
+ switch (* jimp -> point ) {
192
+ case '\\' : {
193
+ jimp -> point ++ ;
194
+ if (jimp -> point >= jimp -> end ) {
195
+ jimp -> token_start = jimp -> point ;
196
+ jimp_diagf (jimp , "ERROR: unfinished escape sequence\n" );
197
+ return false;
198
+ }
199
+ switch (* jimp -> point ) {
200
+ case 'r' :
201
+ jimp -> point ++ ;
202
+ jimp__append_to_string (jimp , '\r' );
203
+ break ;
204
+ case 'n' :
205
+ jimp -> point ++ ;
206
+ jimp__append_to_string (jimp , '\n' );
207
+ break ;
208
+ case 't' :
209
+ jimp -> point ++ ;
210
+ jimp__append_to_string (jimp , '\t' );
211
+ break ;
212
+ case '\\' :
213
+ jimp -> point ++ ;
214
+ jimp__append_to_string (jimp , '\\' );
215
+ break ;
216
+ default :
217
+ jimp -> token_start = jimp -> point ;
218
+ jimp_diagf (jimp , "ERROR: invalid escape sequence\n" );
219
+ return false;
220
+ }
221
+ break ;
222
+ }
223
+ case '"' : {
192
224
jimp -> point ++ ;
193
225
jimp__append_to_string (jimp , '\0' );
194
226
jimp -> token = JIMP_STRING ;
195
227
return true;
196
- } else {
228
+ }
229
+ default :
197
230
char x = * jimp -> point ++ ;
198
231
jimp__append_to_string (jimp , x );
199
232
}
0 commit comments