MCPcopy
hub / github.com/lengstrom/falcon / getArgumentForRegex

Function getArgumentForRegex

extension/js/queryparser.js:32–89  ·  view source on GitHub ↗
(text, regex)

Source from the content-addressed store, hash-verified

30}
31
32function getArgumentForRegex(text, regex) {
33 var textLen = text.length;
34 var quoteMap = new Array(textLen);
35 var currQuote = false;
36 var i = 0;
37 while (i < textLen) {
38 var ch = text[i];
39 if (currQuote === false) {
40 if (ch.match(QUOTEREGEX) != null) {
41 currQuote = ch;
42 }
43 } else {
44 if (ch === currQuote) {
45 currQuote = false;
46 }
47 }
48
49 quoteMap[i] = currQuote === false ? 0 : 1;
50 i += 1;
51 }
52
53 var res = text.match(regex);
54 var offset = 0;
55 var pos;
56 if (res != null) {
57 pos = res.index;
58 } else {
59 pos = 0;
60 }
61
62 while (res !== null && quoteMap[pos] === 1) {
63 offset += res.index + res.length;
64 res = text.substring(offset+1,text.length).match(regex);
65 pos = res.index + 1 + offset
66 }
67
68 if (res === null) return [false, false];
69 if (offset > 0) res.index += offset + 1;
70
71 var i = res.index + res[0].length;
72 while (text[i] === ' ') {i += 1};
73 if (i >= textLen) {
74 return [false, false];
75 }
76
77 if (text[i].match(QUOTEREGEX)) {
78 var [matched, text] = extractTextBtwChars(i, text);
79 } else {
80 var [matched, text] = extractTextBtwChars(i-1, text);
81 }
82
83 if (text === false) {
84 return [false, false];
85 }
86
87 text = text.substring(0, res.index) + " " + text.substring(res.index + res[0].length, text.length);
88 return [matched, text];
89}

Callers 2

parseDateFunction · 0.85
parseNegativeFunction · 0.85

Calls 1

extractTextBtwCharsFunction · 0.85

Tested by

no test coverage detected