diff options
author | Florian Fischer <florian.fl.fischer@fau.de> | 2020-08-27 15:42:01 +0200 |
---|---|---|
committer | Florian Fischer <florian.fl.fischer@fau.de> | 2020-08-27 15:42:01 +0200 |
commit | 819f67b78f2bc64f39fc0a48613908c36c674621 (patch) | |
tree | 0fb053a4c238bae54467c6c1f8bf6497aad175cc /spellcheck.lua | |
parent | c0eef2f85a44e4bbaac1af27f428dfd22ebd06ab (diff) | |
download | vis-spellcheck-819f67b78f2bc64f39fc0a48613908c36c674621.tar.gz |
special case typos at the beginning of text as well
Diffstat (limited to 'spellcheck.lua')
-rw-r--r-- | spellcheck.lua | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/spellcheck.lua b/spellcheck.lua index 89d2bd7..0627d4d 100644 --- a/spellcheck.lua +++ b/spellcheck.lua @@ -79,7 +79,7 @@ local ignored = {} -- The returned iterator is a self contained statefull iterator function closure. -- Which will return the next typo and its start and finish in the text, starting by 1. local function typo_iter(text, typos, ignored) - local index = 0 + local index = 1 local unfiltered_iterator, iter_state = typos:gmatch("(.-)\n") return function(foo, bar) repeat @@ -91,17 +91,30 @@ local function typo_iter(text, typos, ignored) -- ("stuff stuf", "broken ok", ...) -- we match typos only when they are enclosed in non-letter characters. local start, finish = text:find("[%A]" .. typo .. "[%A]", index) - -- the typo was not found by our pattern this means it must be the last word in the text + -- typo was not found by our pattern this means it must be either + -- the first or last word in the text if not start then - start, finish = text:find("[%A]" .. typo .. "$", index) - if not start then - vis:info(string.format("typo %s not found after %d this must be a bug please report", typo, index)) + -- check start of text + if index == 1 then + start = index + finish = #typo + -- must be the end of text + else + start = #text - #typo + 1 + finish = start + #typo - 1 + end + + if text:sub(start, finish) ~= typo then + vis:info(string.format("typo %s not where expected after %d at %d %d found: %s", + typo, index, start, finish, text:sub(start, finish))) end + else + start = start + 1 -- ignore leading non letter char + finish = finish - 1 -- ignore trailing non letter char end index = finish - -- ignore the first and last non letter character - return typo, start + 1, finish - 1 + return typo, start, finish end end end |