MCPcopy Create free account
hub / github.com/DFHack/dfhack / read_string

Function read_string

depends/lua/src/llex.c:369–429  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

367
368
369static void read_string (LexState *ls, int del, SemInfo *seminfo) {
370 save_and_next(ls); /* keep delimiter (for error messages) */
371 while (ls->current != del) {
372 switch (ls->current) {
373 case EOZ:
374 lexerror(ls, "unfinished string", TK_EOS);
375 break; /* to avoid warnings */
376 case '\n':
377 case '\r':
378 lexerror(ls, "unfinished string", TK_STRING);
379 break; /* to avoid warnings */
380 case '\\': { /* escape sequences */
381 int c; /* final character to be saved */
382 save_and_next(ls); /* keep '\\' for error messages */
383 switch (ls->current) {
384 case 'a': c = '\a'; goto read_save;
385 case 'b': c = '\b'; goto read_save;
386 case 'f': c = '\f'; goto read_save;
387 case 'n': c = '\n'; goto read_save;
388 case 'r': c = '\r'; goto read_save;
389 case 't': c = '\t'; goto read_save;
390 case 'v': c = '\v'; goto read_save;
391 case 'x': c = readhexaesc(ls); goto read_save;
392 case 'u': utf8esc(ls); goto no_save;
393 case '\n': case '\r':
394 inclinenumber(ls); c = '\n'; goto only_save;
395 case '\\': case '\"': case '\'':
396 c = ls->current; goto read_save;
397 case EOZ: goto no_save; /* will raise an error next loop */
398 case 'z': { /* zap following span of spaces */
399 luaZ_buffremove(ls->buff, 1); /* remove '\\' */
400 next(ls); /* skip the 'z' */
401 while (lisspace(ls->current)) {
402 if (currIsNewline(ls)) inclinenumber(ls);
403 else next(ls);
404 }
405 goto no_save;
406 }
407 default: {
408 esccheck(ls, lisdigit(ls->current), "invalid escape sequence");
409 c = readdecesc(ls); /* digital escape '\ddd' */
410 goto only_save;
411 }
412 }
413 read_save:
414 next(ls);
415 /* go through */
416 only_save:
417 luaZ_buffremove(ls->buff, 1); /* remove '\\' */
418 save(ls, c);
419 /* go through */
420 no_save: break;
421 }
422 default:
423 save_and_next(ls);
424 }
425 }
426 save_and_next(ls); /* skip delimiter */

Callers 1

llexFunction · 0.85

Calls 8

lexerrorFunction · 0.85
readhexaescFunction · 0.85
utf8escFunction · 0.85
inclinenumberFunction · 0.85
esccheckFunction · 0.85
readdecescFunction · 0.85
saveFunction · 0.85
luaX_newstringFunction · 0.85

Tested by

no test coverage detected