From 48ab0928587669ff6d5c889df8acdabfd4b29ed0 Mon Sep 17 00:00:00 2001 From: Nomarian Date: Thu, 9 Oct 2025 10:29:15 -0400 Subject: escape_lua_pattern() is now a string pattern/repl --- spellcheck.lua | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) (limited to 'spellcheck.lua') diff --git a/spellcheck.lua b/spellcheck.lua index 84f2ef5..c1ce8bc 100644 --- a/spellcheck.lua +++ b/spellcheck.lua @@ -104,6 +104,11 @@ end -- plugin global list of ignored typos local ignored = {} +-- escapes operators of pattern +local escape_lua_pattern = function (s) + return s:gsub("[*$^().?+%%%[%]-]","%%%0") +end + -- Return an iterator over all not ignored typos and their positions in text. -- The returned iterator is a self contained stateful iterator function closure. -- Which will return the next typo and its start and finish in the text, starting by 1. @@ -111,29 +116,6 @@ local function typo_iter(text, typos, ignored) -- luacheck: ignore ignored local index = 1 local unfiltered_iterator, iter_state = typos:gmatch('(.-)\n') - -- see https://stackoverflow.com/questions/6705872/how-to-escape-a-variable-in-lua - local escape_lua_pattern - do - local matches = { - ['^'] = '%^', - ['$'] = '%$', - ['('] = '%(', - [')'] = '%)', - ['%'] = '%%', - ['.'] = '%.', - ['['] = '%[', - [']'] = '%]', - ['*'] = '%*', - ['+'] = '%+', - ['-'] = '%-', - ['?'] = '%?', - } - - escape_lua_pattern = function(s) - return (s:gsub('.', matches)) - end - end - return function() local typo repeat -- cgit v1.2.3