mirror of
https://github.com/cave-story-randomizer/cave-story-randomizer
synced 2024-11-14 02:42:46 +00:00
Properly truncate utf-8 text
Simply slicing byte-wise produces illegal sequences -- throw away any leftover illegal sequences as well.
This commit is contained in:
parent
cedd865e24
commit
1018d1c46c
|
@ -12,6 +12,8 @@ local music = Luigi(require 'ui.music')
|
||||||
local style = require 'ui.style'
|
local style = require 'ui.style'
|
||||||
local theme = require 'lib.luigi.theme.dark'
|
local theme = require 'lib.luigi.theme.dark'
|
||||||
|
|
||||||
|
local utf8 = require("utf8")
|
||||||
|
|
||||||
layout:setStyle(style)
|
layout:setStyle(style)
|
||||||
settings:setStyle(style)
|
settings:setStyle(style)
|
||||||
sequence:setStyle(style)
|
sequence:setStyle(style)
|
||||||
|
@ -295,7 +297,12 @@ end)
|
||||||
|
|
||||||
settings.customseed:onChange(function()
|
settings.customseed:onChange(function()
|
||||||
if #settings.customseed.value > 20 then
|
if #settings.customseed.value > 20 then
|
||||||
settings.customseed.value = settings.customseed.value:sub(1, 20)
|
local str = settings.customseed.value:sub(1, 20)
|
||||||
|
local length, invalidPos = utf8.len(str)
|
||||||
|
if not length then -- produced invalid sequence, need to adjust
|
||||||
|
str = str:sub(1, invalidPos - 1)
|
||||||
|
end
|
||||||
|
settings.customseed.value = str
|
||||||
end
|
end
|
||||||
settings.seedcount.text = ("%s/20"):format(#settings.customseed.value)
|
settings.seedcount.text = ("%s/20"):format(#settings.customseed.value)
|
||||||
end)
|
end)
|
||||||
|
@ -344,4 +351,4 @@ function C:setStatus(text)
|
||||||
layout.status.text = text
|
layout.status.text = text
|
||||||
end
|
end
|
||||||
|
|
||||||
return C
|
return C
|
||||||
|
|
Loading…
Reference in a new issue