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)