MCPcopy Create free account
hub / github.com/microsoft/SandDance / scanStringLiteral

Function scanStringLiteral

docs/app/js/sanddance-app.js:143807–143872  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

143805 };
143806} // 7.8.4 String Literals
143807function scanStringLiteral() {
143808 var str = "", quote, start, ch, code, octal = false;
143809 quote = source[index];
143810 assert(quote === "'" || quote === '"', "String literal must starts with a quote");
143811 start = index;
143812 ++index;
143813 while(index < length){
143814 ch = source[index++];
143815 if (ch === quote) {
143816 quote = "";
143817 break;
143818 } else if (ch === "\\") {
143819 ch = source[index++];
143820 if (!ch || !isLineTerminator(ch.charCodeAt(0))) switch(ch){
143821 case "u":
143822 case "x":
143823 if (source[index] === "{") {
143824 ++index;
143825 str += scanUnicodeCodePointEscape();
143826 } else str += scanHexEscape(ch);
143827 break;
143828 case "n":
143829 str += "\n";
143830 break;
143831 case "r":
143832 str += "\r";
143833 break;
143834 case "t":
143835 str += " ";
143836 break;
143837 case "b":
143838 str += "\b";
143839 break;
143840 case "f":
143841 str += "\f";
143842 break;
143843 case "v":
143844 str += "\v";
143845 break;
143846 default:
143847 if (isOctalDigit(ch)) {
143848 code = "01234567".indexOf(ch); // \0 is not octal escape sequence
143849 if (code !== 0) octal = true;
143850 if (index < length && isOctalDigit(source[index])) {
143851 octal = true;
143852 code = code * 8 + "01234567".indexOf(source[index++]); // 3 digits are only allowed when string starts
143853 // with 0, 1, 2, 3
143854 if ("0123".indexOf(ch) >= 0 && index < length && isOctalDigit(source[index])) code = code * 8 + "01234567".indexOf(source[index++]);
143855 }
143856 str += String.fromCharCode(code);
143857 } else str += ch;
143858 break;
143859 }
143860 else if (ch === "\r" && source[index] === "\n") ++index;
143861 } else if (isLineTerminator(ch.charCodeAt(0))) break;
143862 else str += ch;
143863 }
143864 if (quote !== "") throwError({}, MessageUnexpectedToken, ILLEGAL);

Callers 1

advanceFunction · 0.70

Calls 6

assertFunction · 0.70
isLineTerminatorFunction · 0.70
scanHexEscapeFunction · 0.70
isOctalDigitFunction · 0.70
throwErrorFunction · 0.70

Tested by

no test coverage detected