Unicode support for length checking in /nick
This commit is contained in:
parent
fefadc562f
commit
6fdd906d2c
@ -34,7 +34,7 @@ function nick:action(msg)
|
|||||||
else
|
else
|
||||||
output = target.name .. ' currently has no nickname.'
|
output = target.name .. ' currently has no nickname.'
|
||||||
end
|
end
|
||||||
elseif string.len(input) > 32 then
|
elseif utilities.utf8_len(input) > 32 then
|
||||||
output = 'The character limit for nicknames is 32.'
|
output = 'The character limit for nicknames is 32.'
|
||||||
elseif input == '--' or input == utilities.char.em_dash then
|
elseif input == '--' or input == utilities.char.em_dash then
|
||||||
self.database.users[target.id_str].nickname = nil
|
self.database.users[target.id_str].nickname = nil
|
||||||
|
@ -39,6 +39,18 @@ function utilities.input(s)
|
|||||||
return s:sub(s:find(' ')+1)
|
return s:sub(s:find(' ')+1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Calculates the length of the given string as UTF-8 characters
|
||||||
|
function utilities.utf8_len(s)
|
||||||
|
local chars = 0
|
||||||
|
for i = 1, string.len(s) do
|
||||||
|
local b = string.byte(s, i)
|
||||||
|
if b < 128 or b >= 192 then
|
||||||
|
chars = chars + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return chars
|
||||||
|
end
|
||||||
|
|
||||||
-- I swear, I copied this from PIL, not yago! :)
|
-- I swear, I copied this from PIL, not yago! :)
|
||||||
function utilities.trim(str) -- Trims whitespace from a string.
|
function utilities.trim(str) -- Trims whitespace from a string.
|
||||||
local s = str:gsub('^%s*(.-)%s*$', '%1')
|
local s = str:gsub('^%s*(.-)%s*$', '%1')
|
||||||
|
Reference in New Issue
Block a user