From fc5ba9b8626a4084b2ba83ef0f2ba3e60fb5e604 Mon Sep 17 00:00:00 2001 From: robert00s Date: Sat, 19 Nov 2016 21:26:53 +0100 Subject: [PATCH] Fix hyphenation words with unicode character in texboxwidget (#2356) --- frontend/util.lua | 2 +- spec/unit/util_spec.lua | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/frontend/util.lua b/frontend/util.lua index b8c73ba2f..c9ebae5e0 100644 --- a/frontend/util.lua +++ b/frontend/util.lua @@ -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 diff --git a/spec/unit/util_spec.lua b/spec/unit/util_spec.lua index de1918a5a..7a57fc87f 100644 --- a/spec/unit/util_spec.lua +++ b/spec/unit/util_spec.lua @@ -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)