rustdoc-search: replace TAB/NL/LF with SP first
This way, most of the parsing code doesn't need to be designed to handle it, since they should always be treated exactly the same anyhow.
This commit is contained in:
parent
93f17117ed
commit
930cba8061
4 changed files with 28 additions and 23 deletions
|
@ -287,10 +287,6 @@ function initSearch(rawSearchIndex) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function isWhitespace(c) {
|
|
||||||
return " \t\n\r".indexOf(c) !== -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
function isSpecialStartCharacter(c) {
|
function isSpecialStartCharacter(c) {
|
||||||
return "<\"".indexOf(c) !== -1;
|
return "<\"".indexOf(c) !== -1;
|
||||||
}
|
}
|
||||||
|
@ -408,7 +404,7 @@ function initSearch(rawSearchIndex) {
|
||||||
* @return {boolean}
|
* @return {boolean}
|
||||||
*/
|
*/
|
||||||
function isPathSeparator(c) {
|
function isPathSeparator(c) {
|
||||||
return c === ":" || isWhitespace(c);
|
return c === ":" || c === " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -425,7 +421,7 @@ function initSearch(rawSearchIndex) {
|
||||||
const c = parserState.userQuery[pos - 1];
|
const c = parserState.userQuery[pos - 1];
|
||||||
if (c === lookingFor) {
|
if (c === lookingFor) {
|
||||||
return true;
|
return true;
|
||||||
} else if (!isWhitespace(c)) {
|
} else if (c !== " ") {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pos -= 1;
|
pos -= 1;
|
||||||
|
@ -454,7 +450,7 @@ function initSearch(rawSearchIndex) {
|
||||||
function skipWhitespace(parserState) {
|
function skipWhitespace(parserState) {
|
||||||
while (parserState.pos < parserState.userQuery.length) {
|
while (parserState.pos < parserState.userQuery.length) {
|
||||||
const c = parserState.userQuery[parserState.pos];
|
const c = parserState.userQuery[parserState.pos];
|
||||||
if (!isWhitespace(c)) {
|
if (c !== " ") {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
parserState.pos += 1;
|
parserState.pos += 1;
|
||||||
|
@ -599,7 +595,7 @@ function initSearch(rawSearchIndex) {
|
||||||
} else {
|
} else {
|
||||||
while (parserState.pos + 1 < parserState.length) {
|
while (parserState.pos + 1 < parserState.length) {
|
||||||
const next_c = parserState.userQuery[parserState.pos + 1];
|
const next_c = parserState.userQuery[parserState.pos + 1];
|
||||||
if (!isWhitespace(next_c)) {
|
if (next_c !== " ") {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
parserState.pos += 1;
|
parserState.pos += 1;
|
||||||
|
@ -953,7 +949,7 @@ function initSearch(rawSearchIndex) {
|
||||||
query.literalSearch = false;
|
query.literalSearch = false;
|
||||||
foundStopChar = true;
|
foundStopChar = true;
|
||||||
continue;
|
continue;
|
||||||
} else if (isWhitespace(c)) {
|
} else if (c === " ") {
|
||||||
skipWhitespace(parserState);
|
skipWhitespace(parserState);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1113,7 +1109,7 @@ function initSearch(rawSearchIndex) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
userQuery = userQuery.trim();
|
userQuery = userQuery.trim().replace(/\r|\n|\t/g, " ");
|
||||||
const parserState = {
|
const parserState = {
|
||||||
length: userQuery.length,
|
length: userQuery.length,
|
||||||
pos: 0,
|
pos: 0,
|
||||||
|
|
|
@ -161,6 +161,15 @@ const PARSED = [
|
||||||
userQuery: "a:: ::b",
|
userQuery: "a:: ::b",
|
||||||
error: "Unexpected `:: ::`",
|
error: "Unexpected `:: ::`",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
query: "a::\t::b",
|
||||||
|
elems: [],
|
||||||
|
foundElems: 0,
|
||||||
|
original: "a:: ::b",
|
||||||
|
returned: [],
|
||||||
|
userQuery: "a:: ::b",
|
||||||
|
error: "Unexpected `:: ::`",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
query: "a::b::",
|
query: "a::b::",
|
||||||
elems: [],
|
elems: [],
|
||||||
|
|
|
@ -5,7 +5,7 @@ const PARSED = [
|
||||||
query: 'aaaaaa b',
|
query: 'aaaaaa b',
|
||||||
elems: [
|
elems: [
|
||||||
{
|
{
|
||||||
name: 'aaaaaa\tb',
|
name: 'aaaaaa b',
|
||||||
fullPath: ['aaaaaa', 'b'],
|
fullPath: ['aaaaaa', 'b'],
|
||||||
pathWithoutLast: ['aaaaaa'],
|
pathWithoutLast: ['aaaaaa'],
|
||||||
pathLast: 'b',
|
pathLast: 'b',
|
||||||
|
@ -14,9 +14,9 @@ const PARSED = [
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
foundElems: 1,
|
foundElems: 1,
|
||||||
original: "aaaaaa b",
|
original: "aaaaaa b",
|
||||||
returned: [],
|
returned: [],
|
||||||
userQuery: "aaaaaa b",
|
userQuery: "aaaaaa b",
|
||||||
error: null,
|
error: null,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -40,9 +40,9 @@ const PARSED = [
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
foundElems: 2,
|
foundElems: 2,
|
||||||
original: "aaaaaa, b",
|
original: "aaaaaa, b",
|
||||||
returned: [],
|
returned: [],
|
||||||
userQuery: "aaaaaa, b",
|
userQuery: "aaaaaa, b",
|
||||||
error: null,
|
error: null,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -93,7 +93,7 @@ const PARSED = [
|
||||||
query: 'a\tb',
|
query: 'a\tb',
|
||||||
elems: [
|
elems: [
|
||||||
{
|
{
|
||||||
name: 'a\tb',
|
name: 'a b',
|
||||||
fullPath: ['a', 'b'],
|
fullPath: ['a', 'b'],
|
||||||
pathWithoutLast: ['a'],
|
pathWithoutLast: ['a'],
|
||||||
pathLast: 'b',
|
pathLast: 'b',
|
||||||
|
@ -102,9 +102,9 @@ const PARSED = [
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
foundElems: 1,
|
foundElems: 1,
|
||||||
original: "a\tb",
|
original: "a b",
|
||||||
returned: [],
|
returned: [],
|
||||||
userQuery: "a\tb",
|
userQuery: "a b",
|
||||||
error: null,
|
error: null,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -176,7 +176,7 @@ const PARSED = [
|
||||||
pathLast: 'a',
|
pathLast: 'a',
|
||||||
generics: [
|
generics: [
|
||||||
{
|
{
|
||||||
name: 'b\tc',
|
name: 'b c',
|
||||||
fullPath: ['b', 'c'],
|
fullPath: ['b', 'c'],
|
||||||
pathWithoutLast: ['b'],
|
pathWithoutLast: ['b'],
|
||||||
pathLast: 'c',
|
pathLast: 'c',
|
||||||
|
@ -187,9 +187,9 @@ const PARSED = [
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
foundElems: 1,
|
foundElems: 1,
|
||||||
original: "a<b\tc>",
|
original: "a<b c>",
|
||||||
returned: [],
|
returned: [],
|
||||||
userQuery: "a<b\tc>",
|
userQuery: "a<b c>",
|
||||||
error: null,
|
error: null,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
|
@ -92,9 +92,9 @@ const PARSED = [
|
||||||
query: 'mod\t:',
|
query: 'mod\t:',
|
||||||
elems: [],
|
elems: [],
|
||||||
foundElems: 0,
|
foundElems: 0,
|
||||||
original: 'mod\t:',
|
original: 'mod :',
|
||||||
returned: [],
|
returned: [],
|
||||||
userQuery: 'mod\t:',
|
userQuery: 'mod :',
|
||||||
error: "Unexpected `:` (expected path after type filter `mod:`)",
|
error: "Unexpected `:` (expected path after type filter `mod:`)",
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue