diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-12-08 15:13:22 -0500 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-12-08 16:01:29 -0500 |
commit | bb334acab65ae194d749ac2da5bd1ba6b02413ec (patch) | |
tree | d99415d12c50d28c2f06bb9eeae72bfdca42bbcc /ext | |
parent | 8ca44d722c6db79f6f3a1892558c7c24f98abd5e (diff) |
Use substring instead of slice
Diffstat (limited to 'ext')
-rw-r--r-- | ext/bg/js/api.js | 8 | ||||
-rw-r--r-- | ext/bg/js/search-query-parser.js | 7 | ||||
-rw-r--r-- | ext/mixed/js/japanese.js | 9 |
3 files changed, 12 insertions, 12 deletions
diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js index b489b8d2..c43a6dd7 100644 --- a/ext/bg/js/api.js +++ b/ext/bg/js/api.js @@ -87,7 +87,7 @@ async function apiTextParse(text, optionsContext) { while (text.length > 0) { const term = []; const [definitions, sourceLength] = await translator.findTermsInternal( - text.slice(0, options.scanning.length), + text.substring(0, options.scanning.length), dictEnabledSet(options), options.scanning.alphanumeric, {} @@ -95,16 +95,16 @@ async function apiTextParse(text, optionsContext) { if (definitions.length > 0) { dictTermsSort(definitions); const {expression, reading} = definitions[0]; - const source = text.slice(0, sourceLength); + const source = text.substring(0, sourceLength); for (const {text, furigana} of jpDistributeFuriganaInflected(expression, reading, source)) { const reading = jpConvertReading(text, furigana, options.parsing.readingMode); term.push({text, reading}); } - text = text.slice(source.length); + text = text.substring(source.length); } else { const reading = jpConvertReading(text[0], null, options.parsing.readingMode); term.push({text: text[0], reading}); - text = text.slice(1); + text = text.substring(1); } results.push(term); } diff --git a/ext/bg/js/search-query-parser.js b/ext/bg/js/search-query-parser.js index 1c583bf1..1632b561 100644 --- a/ext/bg/js/search-query-parser.js +++ b/ext/bg/js/search-query-parser.js @@ -148,10 +148,9 @@ class QueryParser { async setPreview(text) { const previewTerms = []; - while (text.length > 0) { - const tempText = text.slice(0, 2); - previewTerms.push([{text: Array.from(tempText)}]); - text = text.slice(2); + for (let i = 0, ii = text.length; i < ii; i += 2) { + const tempText = text.substring(i, i + 2); + previewTerms.push([{text: tempText.split('')}]); } this.queryParser.innerHTML = await apiTemplateRender('query-parser.html', { terms: previewTerms, diff --git a/ext/mixed/js/japanese.js b/ext/mixed/js/japanese.js index 8b841b2e..ea1c0065 100644 --- a/ext/mixed/js/japanese.js +++ b/ext/mixed/js/japanese.js @@ -160,16 +160,17 @@ function jpDistributeFuriganaInflected(expression, reading, source) { } const offset = source.length - stemLength; - const stemExpression = source.slice(0, source.length - offset); - const stemReading = reading.slice( - 0, offset === 0 ? reading.length : reading.length - expression.length + stemLength + const stemExpression = source.substring(0, source.length - offset); + const stemReading = reading.substring( + 0, + offset === 0 ? reading.length : reading.length - expression.length + stemLength ); for (const segment of jpDistributeFurigana(stemExpression, stemReading)) { output.push(segment); } if (stemLength !== source.length) { - output.push({text: source.slice(stemLength)}); + output.push({text: source.substring(stemLength)}); } return output; |