diff options
| author | Michael Howell <michael@notriddle.com> | 2023-11-29 10:54:49 -0700 |
|---|---|---|
| committer | Michael Howell <michael@notriddle.com> | 2023-11-29 11:02:56 -0700 |
| commit | 930cba8061dca5988a58b4e74774489e1b129184 (patch) | |
| tree | 5345a7613db10b3357b54731f67650723f5fd697 /src/librustdoc/html/static/js | |
| parent | 93f17117ed50a972bfabea86762241cd9ac5ccbd (diff) | |
| download | rust-930cba8061dca5988a58b4e74774489e1b129184.tar.gz rust-930cba8061dca5988a58b4e74774489e1b129184.zip | |
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.
Diffstat (limited to 'src/librustdoc/html/static/js')
| -rw-r--r-- | src/librustdoc/html/static/js/search.js | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 37e5276a494..8f68796ad26 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -287,10 +287,6 @@ function initSearch(rawSearchIndex) { } } - function isWhitespace(c) { - return " \t\n\r".indexOf(c) !== -1; - } - function isSpecialStartCharacter(c) { return "<\"".indexOf(c) !== -1; } @@ -408,7 +404,7 @@ function initSearch(rawSearchIndex) { * @return {boolean} */ function isPathSeparator(c) { - return c === ":" || isWhitespace(c); + return c === ":" || c === " "; } /** @@ -425,7 +421,7 @@ function initSearch(rawSearchIndex) { const c = parserState.userQuery[pos - 1]; if (c === lookingFor) { return true; - } else if (!isWhitespace(c)) { + } else if (c !== " ") { break; } pos -= 1; @@ -454,7 +450,7 @@ function initSearch(rawSearchIndex) { function skipWhitespace(parserState) { while (parserState.pos < parserState.userQuery.length) { const c = parserState.userQuery[parserState.pos]; - if (!isWhitespace(c)) { + if (c !== " ") { break; } parserState.pos += 1; @@ -599,7 +595,7 @@ function initSearch(rawSearchIndex) { } else { while (parserState.pos + 1 < parserState.length) { const next_c = parserState.userQuery[parserState.pos + 1]; - if (!isWhitespace(next_c)) { + if (next_c !== " ") { break; } parserState.pos += 1; @@ -953,7 +949,7 @@ function initSearch(rawSearchIndex) { query.literalSearch = false; foundStopChar = true; continue; - } else if (isWhitespace(c)) { + } else if (c === " ") { skipWhitespace(parserState); continue; } @@ -1113,7 +1109,7 @@ function initSearch(rawSearchIndex) { } } } - userQuery = userQuery.trim(); + userQuery = userQuery.trim().replace(/\r|\n|\t/g, " "); const parserState = { length: userQuery.length, pos: 0, |
