mirror of https://github.com/koreader/koreader
Merge pull request #1497 from chrox/android_dict
Fix sdcv on Android cannot handle morphological changespull/1502/head
commit
e3ba198009
@ -1 +1 @@
|
|||||||
Subproject commit ae6ea7e96c6695ed23aee84da1065b29e9fed0ea
|
Subproject commit d2c53757a098f3f17fec816bea638adc71e2976f
|
@ -1 +1 @@
|
|||||||
Subproject commit a00e3d1c7f73756a3c3cf45b1828c2b55a903503
|
Subproject commit ddcf09b0f8b60e8e3137b818c973aee3ff76d3f4
|
@ -0,0 +1,36 @@
|
|||||||
|
require("commonrequire")
|
||||||
|
|
||||||
|
local util = require("util")
|
||||||
|
|
||||||
|
describe("util module", function()
|
||||||
|
it("should strip punctuations around word", function()
|
||||||
|
assert.is_equal(util.stripePunctuations("\"hello world\""), "hello world")
|
||||||
|
assert.is_equal(util.stripePunctuations("\"hello world?\""), "hello world")
|
||||||
|
assert.is_equal(util.stripePunctuations("\"hello, world?\""), "hello, world")
|
||||||
|
assert.is_equal(util.stripePunctuations("“你好“"), "你好")
|
||||||
|
assert.is_equal(util.stripePunctuations("“你好?“"), "你好")
|
||||||
|
end)
|
||||||
|
it("should split string with patterns", function()
|
||||||
|
local sentence = "Hello world, welcome to KoReader!"
|
||||||
|
local words = {}
|
||||||
|
for word in util.gsplit(sentence, "%s+", false) do
|
||||||
|
table.insert(words, word)
|
||||||
|
end
|
||||||
|
assert.are_same(words, {"Hello", "world,", "welcome", "to", "KoReader!"})
|
||||||
|
end)
|
||||||
|
it("should split command line arguments with quotation", function()
|
||||||
|
local command = "./sdcv -nj \"words\" \"a lot\" 'more or less' --data-dir=dict"
|
||||||
|
local argv = {}
|
||||||
|
for arg1 in util.gsplit(command, "[\"'].-[\"']", true) do
|
||||||
|
for arg2 in util.gsplit(arg1, "^[^\"'].-%s+", true) do
|
||||||
|
for arg3 in util.gsplit(arg2, "[\"']", false) do
|
||||||
|
local trimed = arg3:gsub("^%s*(.-)%s*$", "%1")
|
||||||
|
if trimed ~= "" then
|
||||||
|
table.insert(argv, trimed)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
assert.are_same(argv, {"./sdcv", "-nj", "words", "a lot", "more or less", "--data-dir=dict"})
|
||||||
|
end)
|
||||||
|
end)
|
Loading…
Reference in New Issue