MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / read_string

Function read_string

lib/lua/src/llex.c:382–442  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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