strip punctuations around word before searching

This should fix #1337.
This commit is contained in:
chrox
2015-02-01 17:40:34 +08:00
parent 3f691bab93
commit 07586cea71
3 changed files with 13 additions and 3 deletions

View File

@@ -59,9 +59,7 @@ end
function ReaderDictionary:stardictLookup(word, box)
DEBUG("lookup word:", word, box)
if word then
-- strip ASCII punctuation characters around selected word
-- and strip any generic punctuation (U+2000 - U+206F) in the word
word = word:gsub("\226[\128-\131][\128-\191]",''):gsub("^%p+",''):gsub("%p+$",'')
word = require("util").stripePunctuations(word)
DEBUG("stripped word:", word)
-- escape quotes and other funny characters in word
local std_out = io.popen("./sdcv --utf8-input --utf8-output -nj "..("%q"):format(word), "r")

View File

@@ -29,6 +29,7 @@ function ReaderSearch:addToMainMenu(tab_item_table)
end
function ReaderSearch:onShowSearchDialog(text)
text = require("util").stripePunctuations(text)
local do_search = function(search_func, text, param)
return function()
local res = search_func(self, text, param)

11
frontend/util.lua Normal file
View File

@@ -0,0 +1,11 @@
local util = {}
function util.stripePunctuations(word)
if not word then return end
-- strip ASCII punctuation characters around word
-- and strip any generic punctuation (U+2000 - U+206F) in the word
return word:gsub("\226[\128-\131][\128-\191]",''):gsub("^%p+",''):gsub("%p+$",'')
end
return util