Fix global declarations check (#1101)

* Fix getSubstringCount not properly checking word boundaries

* Remove unused global declarations
This commit is contained in:
toasted-nutbread 2020-12-12 14:47:17 -05:00 committed by GitHub
parent fe16793779
commit 92cfd31c0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 7 additions and 10 deletions

View File

@ -22,6 +22,10 @@ const assert = require('assert');
const {getAllFiles} = require('../util'); const {getAllFiles} = require('../util');
function escapeRegExp(string) {
return string.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&');
}
function countOccurences(string, pattern) { function countOccurences(string, pattern) {
return (string.match(pattern) || []).length; return (string.match(pattern) || []).length;
} }
@ -38,13 +42,12 @@ function getNewline(string) {
} }
function getSubstringCount(string, substring) { function getSubstringCount(string, substring) {
let start = 0;
let count = 0; let count = 0;
const pattern = new RegExp(`\\b${escapeRegExp(substring)}\\b`, 'g');
while (true) { while (true) {
const pos = string.indexOf(substring, start); const match = pattern.exec(string);
if (pos < 0) { break; } if (match === null) { break; }
++count; ++count;
start = pos + substring.length;
} }
return count; return count;
} }

View File

@ -17,7 +17,6 @@
/* global /* global
* AnkiNoteBuilder * AnkiNoteBuilder
* Modal
* TemplateRendererProxy * TemplateRendererProxy
* api * api
*/ */

View File

@ -17,7 +17,6 @@
/* global /* global
* DictionaryController * DictionaryController
* Modal
* OptionsUtil * OptionsUtil
* api * api
*/ */

View File

@ -17,7 +17,6 @@
/* global /* global
* DictionaryDatabase * DictionaryDatabase
* Modal
* ObjectPropertyAccessor * ObjectPropertyAccessor
* api * api
*/ */

View File

@ -18,7 +18,6 @@
/* global /* global
* DictionaryDatabase * DictionaryDatabase
* DictionaryImporter * DictionaryImporter
* Modal
* ObjectPropertyAccessor * ObjectPropertyAccessor
* api * api
*/ */

View File

@ -17,7 +17,6 @@
/* global /* global
* Frontend * Frontend
* Popup
* TextSourceRange * TextSourceRange
* api * api
* wanakana * wanakana

View File

@ -16,7 +16,6 @@
*/ */
/* global /* global
* Modal
* ProfileConditionsUI * ProfileConditionsUI
* api * api
*/ */