Add includesSorted function, use for faster searches of sorted arrays.

This commit is contained in:
David Anson 2019-03-28 22:06:42 -07:00
parent d7c0d195d7
commit 9b9532e163
8 changed files with 86 additions and 50 deletions

View file

@ -3,13 +3,14 @@
"use strict";
const shared = require("./shared");
const { addErrorContext, forEachInlineChild } = shared;
module.exports = {
"names": [ "MD037", "no-space-in-emphasis" ],
"description": "Spaces inside emphasis markers",
"tags": [ "whitespace", "emphasis" ],
"function": function MD037(params, onError) {
shared.forEachInlineChild(params, "text", function forToken(token) {
forEachInlineChild(params, "text", (token) => {
let left = true;
let match = /(?:^|\s)(\*\*?|__?)\s.*[^\\]\1/.exec(token.content);
if (!match) {
@ -19,11 +20,11 @@ module.exports = {
if (match) {
const fullText = match[0];
const line = params.lines[token.lineNumber - 1];
if (line.indexOf(fullText) !== -1) {
if (line.includes(fullText)) {
const text = fullText.trim();
const column = line.indexOf(text) + 1;
const length = text.length;
shared.addErrorContext(onError, token.lineNumber,
addErrorContext(onError, token.lineNumber,
text, left, !left, [ column, length ]);
}
}