diff options
Diffstat (limited to 'script/files.lua')
-rw-r--r-- | script/files.lua | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/script/files.lua b/script/files.lua index b84295bf..df49b183 100644 --- a/script/files.lua +++ b/script/files.lua @@ -278,13 +278,17 @@ function m.getWords(uri) end local mark = {} for word in text:gmatch '([%a_][%w_]+)' do - if #word >= 3 and not mark[word] then - mark[word] = true - local head = word:sub(1, 2) - if not words[head] then - words[head] = {} + if #word >= 3 then + if not mark[word] then + mark[word] = true + local head = word:sub(1, 2) + if not words[head] then + words[head] = {} + end + words[head][word] = true end - words[head][#words[head]+1] = word + else + words[word] = true end end return words @@ -303,6 +307,30 @@ function m.getWordsOfHead(uri, head) return words[head] end +---@param uri uri +---@param word string +---@return boolean +function m.hasWord(uri, word) + uri = getUriKey(uri) + local file = m.fileMap[uri] + if not file then + return false + end + local words = m.getWords(uri) + if not words then + return false + end + if #word <= 2 then + return words[word] == true + end + local head = word:sub(1, 2) + local headWords = words[head] + if not headWords then + return false + end + return headWords[word] == true +end + --- 获取文件版本 function m.getVersion(uri) uri = getUriKey(uri) |