MCPcopy Create free account
hub / github.com/davidkingzyb/SCAST / readString

Function readString

lib/filbert.js:971–1049  ·  view source on GitHub ↗
(quote)

Source from the content-addressed store, hash-verified

969 // Read a string value, interpreting backslash-escapes.
970
971 function readString(quote) {
972 tokPos++;
973 var ch = input.charCodeAt(tokPos);
974 var tripleQuoted = false;
975 if (ch === quote && input.charCodeAt(tokPos+1) === quote) {
976 tripleQuoted = true;
977 tokPos += 2;
978 }
979 var out = "";
980 for (;;) {
981 if (tokPos >= inputLen) raise(tokStart, "Unterminated string constant");
982 var ch = input.charCodeAt(tokPos);
983 if (ch === quote) {
984 if (tripleQuoted) {
985 if (input.charCodeAt(tokPos+1) === quote &&
986 input.charCodeAt(tokPos+2) === quote) {
987 tokPos += 3;
988 return finishToken(_string, out);
989 }
990 } else {
991 ++tokPos;
992 return finishToken(_string, out);
993 }
994 }
995 if (ch === 92) { // '\'
996 ch = input.charCodeAt(++tokPos);
997 var octal = /^[0-7]+/.exec(input.slice(tokPos, tokPos + 3));
998 if (octal) octal = octal[0];
999 while (octal && parseInt(octal, 8) > 255) octal = octal.slice(0, -1);
1000 if (octal === "0") octal = null;
1001 ++tokPos;
1002 if (octal) {
1003 if (strict) raise(tokPos - 2, "Octal literal in strict mode");
1004 out += String.fromCharCode(parseInt(octal, 8));
1005 tokPos += octal.length - 1;
1006 } else {
1007 switch (ch) {
1008 case 110: out += "\n"; break; // 'n' -> '\n'
1009 case 114: out += "\r"; break; // 'r' -> '\r'
1010 case 120: out += String.fromCharCode(readHexChar(2)); break; // 'x'
1011 case 117: out += String.fromCharCode(readHexChar(4)); break; // 'u'
1012 case 85: // 'U'
1013 ch = readHexChar(8);
1014 if (ch < 0xFFFF && (ch < 0xD800 || 0xDBFF < ch)) out += String.fromCharCode(ch); // If it's UTF-16
1015 else { // If we need UCS-2
1016 ch -= 0x10000;
1017 out += String.fromCharCode((ch>>10)+0xd800)+String.fromCharCode((ch%0x400)+0xdc00);
1018 }
1019 break;
1020 case 116: out += "\t"; break; // 't' -> '\t'
1021 case 98: out += "\b"; break; // 'b' -> '\b'
1022 case 118: out += "\u000b"; break; // 'v' -> '\u000b'
1023 case 102: out += "\f"; break; // 'f' -> '\f'
1024 case 48: out += "\0"; break; // 0 -> '\0'
1025 case 13: if (input.charCodeAt(tokPos) === 10) ++tokPos; // '\r\n'
1026 case 10: // ' \n'
1027 if (options.locations) { tokLineStart = tokPos; ++tokCurLine; }
1028 break;

Callers 1

getTokenFromCodeFunction · 0.85

Calls 5

raiseFunction · 0.85
finishTokenFunction · 0.85
readHexCharFunction · 0.85
isNewlineFunction · 0.85
execMethod · 0.45

Tested by

no test coverage detected