MCPcopy Create free account
hub / github.com/dchester/jsonpath / scanStringLiteral

Function scanStringLiteral

jsonpath.js:933–1041  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

931 // 7.8.4 String Literals
932
933 function scanStringLiteral() {
934 var str = '', quote, start, ch, code, unescaped, restore, octal = false, startLineNumber, startLineStart;
935 startLineNumber = lineNumber;
936 startLineStart = lineStart;
937
938 quote = source[index];
939 assert((quote === '\'' || quote === '"'),
940 'String literal must starts with a quote');
941
942 start = index;
943 ++index;
944
945 while (index < length) {
946 ch = source[index++];
947
948 if (ch === quote) {
949 quote = '';
950 break;
951 } else if (ch === '\\') {
952 ch = source[index++];
953 if (!ch || !isLineTerminator(ch.charCodeAt(0))) {
954 switch (ch) {
955 case 'u':
956 case 'x':
957 restore = index;
958 unescaped = scanHexEscape(ch);
959 if (unescaped) {
960 str += unescaped;
961 } else {
962 index = restore;
963 str += ch;
964 }
965 break;
966 case 'n':
967 str += '\n';
968 break;
969 case 'r':
970 str += '\r';
971 break;
972 case 't':
973 str += '\t';
974 break;
975 case 'b':
976 str += '\b';
977 break;
978 case 'f':
979 str += '\f';
980 break;
981 case 'v':
982 str += '\x0B';
983 break;
984
985 default:
986 if (isOctalDigit(ch)) {
987 code = '01234567'.indexOf(ch);
988
989 // \0 is not octal escape sequence
990 if (code !== 0) {

Callers 1

advanceFunction · 0.85

Calls 5

assertFunction · 0.85
isLineTerminatorFunction · 0.85
scanHexEscapeFunction · 0.85
isOctalDigitFunction · 0.85
throwErrorFunction · 0.85

Tested by

no test coverage detected