diff options
| author | Nomarian <nomarian@outlook.com> | 2025-10-09 10:29:15 -0400 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-10-12 21:00:36 +0200 |
| commit | 48ab0928587669ff6d5c889df8acdabfd4b29ed0 (patch) | |
| tree | cfe00a3b88e01ef0200ee0b077db8ec8a4f7e621 | |
| parent | 6c1842f86d34d0e9afdea3e445c36091b5bf8246 (diff) | |
| download | vis-spellcheck-48ab0928587669ff6d5c889df8acdabfd4b29ed0.tar.gz vis-spellcheck-48ab0928587669ff6d5c889df8acdabfd4b29ed0.zip | |
escape_lua_pattern() is now a string pattern/repl
| -rw-r--r-- | spellcheck.lua | 28 |
1 files changed, 5 insertions, 23 deletions
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 |
