Fix hyphenation words with unicode character in texboxwidget (#2356)

pull/2362/head
robert00s 8 years ago committed by Qingping Hou
parent 64bc5cd63c
commit fc5ba9b862

@ -138,7 +138,7 @@ end
-- Test whether a string could be separated by a char for multi-line rendering
function util.isSplitable(c)
return #c > 1 or c == " " or string.match(c, "%p") ~= nil
return c == " " or string.match(c, "%p") ~= nil
end
return util

@ -76,4 +76,34 @@ describe("util module", function()
local words = util.splitToWords("BBC纪录片")
assert.are_same(words, {"BBC", "", "", ""})
end)
it("should split text to line - unicode", function()
local text = "Pójdźże, chmurność glück schließen Štěstí neštěstí. Uñas gavilán"
local word = ""
local table_of_words = {}
local c
local table_chars = util.splitToChars(text)
for i = 1, #table_chars do
c = table_chars[i]
word = word .. c
if util.isSplitable(c) then
table.insert(table_of_words, word)
word = ""
end
if i == #table_chars then table.insert(table_of_words, word) end
end
assert.are_same(table_of_words, {
"Pójdźże,",
" ",
"chmurność ",
"glück ",
"schließen ",
"Štěstí ",
"neštěstí.",
" ",
"Uñas ",
"gavilán",
})
end)
end)

Loading…
Cancel
Save