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

Function scanRegExpBody

jsonpath.js:1053–1098  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1051 }
1052
1053 function scanRegExpBody() {
1054 var ch, str, classMarker, terminated, body;
1055
1056 ch = source[index];
1057 assert(ch === '/', 'Regular expression literal must start with a slash');
1058 str = source[index++];
1059
1060 classMarker = false;
1061 terminated = false;
1062 while (index < length) {
1063 ch = source[index++];
1064 str += ch;
1065 if (ch === '\\') {
1066 ch = source[index++];
1067 // ECMA-262 7.8.5
1068 if (isLineTerminator(ch.charCodeAt(0))) {
1069 throwError({}, Messages.UnterminatedRegExp);
1070 }
1071 str += ch;
1072 } else if (isLineTerminator(ch.charCodeAt(0))) {
1073 throwError({}, Messages.UnterminatedRegExp);
1074 } else if (classMarker) {
1075 if (ch === ']') {
1076 classMarker = false;
1077 }
1078 } else {
1079 if (ch === '/') {
1080 terminated = true;
1081 break;
1082 } else if (ch === '[') {
1083 classMarker = true;
1084 }
1085 }
1086 }
1087
1088 if (!terminated) {
1089 throwError({}, Messages.UnterminatedRegExp);
1090 }
1091
1092 // Exclude leading and trailing slash.
1093 body = str.substr(1, str.length - 2);
1094 return {
1095 value: body,
1096 literal: str
1097 };
1098 }
1099
1100 function scanRegExpFlags() {
1101 var ch, str, flags, restore;

Callers 1

scanRegExpFunction · 0.85

Calls 3

assertFunction · 0.85
isLineTerminatorFunction · 0.85
throwErrorFunction · 0.85

Tested by

no test coverage detected