Signs: back Slugify lib, drop utf8lib
parent
4306bb5bb0
commit
c520af1138
|
@ -15,6 +15,7 @@ read_globals = {
|
|||
"minetest",
|
||||
"dump",
|
||||
"vector",
|
||||
"utf8",
|
||||
"VoxelManip", "VoxelArea",
|
||||
"PseudoRandom", "PcgRandom",
|
||||
"ItemStack",
|
||||
|
@ -39,8 +40,7 @@ exclude_files = {
|
|||
"files/bluestone/mesecons/internal.lua",
|
||||
"files/deprecated/init.lua",
|
||||
"files/mobs/mobs_redo/api.lua",
|
||||
"files/utf8lib/slugify.lua",
|
||||
"files/utf8lib/utf8data.lua",
|
||||
"files/signs/slugify.lua",
|
||||
"files/workbench/init.lua",
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
utf8lib?
|
|
@ -11,9 +11,10 @@ end
|
|||
local vadd = vector.add
|
||||
local floor, pi = math.floor, math.pi
|
||||
local find = string.find
|
||||
local b = "blank.png"
|
||||
|
||||
-- Cyrillic transliteration library
|
||||
local slugify = utf8lib and utf8lib.slugify or function(s) return s end
|
||||
local slugify = dofile(minetest.get_modpath("signs") .. "/slugify.lua")
|
||||
|
||||
local sign_positions = {
|
||||
[0] = {{x = 0, y = 0.18, z = -0.07}, pi},
|
||||
|
@ -67,7 +68,7 @@ local wrap_chars = {
|
|||
|
||||
local function generate_sign_texture(str)
|
||||
if not str or str == "" then
|
||||
return "blank.png"
|
||||
return b
|
||||
end
|
||||
|
||||
local row = 0
|
||||
|
@ -155,8 +156,8 @@ minetest.register_entity("signs:sign_text", {
|
|||
|
||||
-- remove entity for missing sign
|
||||
local node_name = minetest.get_node(pos).name
|
||||
if not node_name == "signs:sign" and
|
||||
not node_name == "signs:wall_sign" then
|
||||
if node_name ~= "signs:sign" and
|
||||
node_name ~= "signs:wall_sign" then
|
||||
ent:remove()
|
||||
return
|
||||
end
|
||||
|
@ -172,13 +173,13 @@ minetest.register_entity("signs:sign_text", {
|
|||
if meta_text and meta_text ~= "" then
|
||||
texture = generate_sign_texture(meta_text)
|
||||
else
|
||||
texture = "blank.png"
|
||||
texture = b
|
||||
end
|
||||
meta:set_string("sign_texture", texture)
|
||||
end
|
||||
|
||||
ent:set_properties({
|
||||
textures = {texture, "blank.png"}
|
||||
textures = {texture, b}
|
||||
})
|
||||
end
|
||||
})
|
||||
|
@ -310,7 +311,9 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
p2 = p2 - 2
|
||||
sign_pos = wall_sign_positions
|
||||
end
|
||||
if not p2 or p2 > 3 or p2 < 0 then return end
|
||||
if not p2 or p2 > 3 or p2 < 0 then
|
||||
return
|
||||
end
|
||||
|
||||
local sign
|
||||
for _, obj in pairs(minetest.get_objects_inside_radius(pos, 0.5)) do
|
||||
|
@ -326,6 +329,9 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
else
|
||||
sign:set_pos(vadd(pos, sign_pos[p2][1]))
|
||||
end
|
||||
if not sign then
|
||||
return
|
||||
end
|
||||
|
||||
-- Serialization longer values may cause a crash
|
||||
-- because we are serializing the texture too
|
||||
|
@ -333,7 +339,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
|
||||
local texture = generate_sign_texture(text)
|
||||
sign:set_properties({
|
||||
textures = {texture, "blank.png"}
|
||||
textures = {texture, b}
|
||||
})
|
||||
sign:set_yaw(sign_pos[p2][2])
|
||||
|
||||
|
|
|
@ -69,10 +69,12 @@ local charmap = {
|
|||
["č"] = "c", ["ž"] = "z"
|
||||
}
|
||||
|
||||
function utf8lib.slugify(str)
|
||||
local function slugify(str)
|
||||
for k, _ in pairs(charmap) do
|
||||
str = str:gsub(tostring(k), charmap[k])
|
||||
end
|
||||
|
||||
return str
|
||||
end
|
||||
|
||||
return slugify
|
|
@ -1,209 +0,0 @@
|
|||
--[[
|
||||
$Id: utf8.lua 179 2009-04-03 18:10:03Z pasta $
|
||||
|
||||
Provides UTF-8 aware string functions implemented in pure lua:
|
||||
* string.len(s)
|
||||
* string.upper(s)
|
||||
* string.lower(s)
|
||||
|
||||
All functions behave as their non UTF-8 aware counterparts with the exception
|
||||
that UTF-8 characters are used instead of bytes for all units.
|
||||
|
||||
Copyright (c) 2006-2007, Kyle Smith
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the author nor the names of its contributors may be
|
||||
used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Based on: https://github.com/Planimeter/grid-sdk/blob/master/public/utf8.lua
|
||||
https://github.com/Stepets/utf8.lua
|
||||
Changed by: MultiCraft Development Team (2019)
|
||||
Note: Now used very minimal version, with the support of only lower and upper.
|
||||
Only latin and russian letters are supported.
|
||||
Support for additional characters will be added as the game localizes.
|
||||
]]
|
||||
|
||||
utf8lib = {}
|
||||
|
||||
local path = minetest.get_modpath("utf8lib")
|
||||
dofile(path .. "/utf8data.lua")
|
||||
dofile(path .. "/slugify.lua")
|
||||
|
||||
-- returns the number of bytes used by the UTF-8 character at byte i in s
|
||||
-- also doubles as a UTF-8 character validator
|
||||
local function utf8charbytes(s, i)
|
||||
-- argument defaults
|
||||
i = i or 1
|
||||
|
||||
-- argument checking
|
||||
if type(s) ~= "string" then
|
||||
error("bad argument #1 to 'utf8charbytes' (string expected, got " .. type(s) .. ")")
|
||||
end
|
||||
if type(i) ~= "number" then
|
||||
error("bad argument #2 to 'utf8charbytes' (number expected, got " .. type(i) .. ")")
|
||||
end
|
||||
|
||||
local c = s:byte(i)
|
||||
|
||||
-- determine bytes needed for character, based on RFC 3629
|
||||
-- validate byte 1
|
||||
if c > 0 and c <= 127 then
|
||||
-- UTF8-1
|
||||
return 1
|
||||
elseif c >= 194 and c <= 223 then
|
||||
-- UTF8-2
|
||||
local c2 = s:byte(i + 1)
|
||||
|
||||
if not c2 then
|
||||
error("UTF-8 string terminated early")
|
||||
end
|
||||
|
||||
-- validate byte 2
|
||||
if c2 < 128 or c2 > 191 then
|
||||
error("Invalid UTF-8 character")
|
||||
end
|
||||
|
||||
return 2
|
||||
elseif c >= 224 and c <= 239 then
|
||||
-- UTF8-3
|
||||
local c2 = s:byte(i + 1)
|
||||
local c3 = s:byte(i + 2)
|
||||
|
||||
if not c2 or not c3 then
|
||||
error("UTF-8 string terminated early")
|
||||
end
|
||||
|
||||
-- validate byte 2
|
||||
if c == 224 and (c2 < 160 or c2 > 191) then
|
||||
error("Invalid UTF-8 character")
|
||||
elseif c == 237 and (c2 < 128 or c2 > 159) then
|
||||
error("Invalid UTF-8 character")
|
||||
elseif c2 < 128 or c2 > 191 then
|
||||
error("Invalid UTF-8 character")
|
||||
end
|
||||
|
||||
-- validate byte 3
|
||||
if c3 < 128 or c3 > 191 then
|
||||
error("Invalid UTF-8 character")
|
||||
end
|
||||
|
||||
return 3
|
||||
elseif c >= 240 and c <= 244 then
|
||||
-- UTF8-4
|
||||
local c2 = s:byte(i + 1)
|
||||
local c3 = s:byte(i + 2)
|
||||
local c4 = s:byte(i + 3)
|
||||
|
||||
if not c2 or not c3 or not c4 then
|
||||
error("UTF-8 string terminated early")
|
||||
end
|
||||
|
||||
-- validate byte 2
|
||||
if c == 240 and (c2 < 144 or c2 > 191) then
|
||||
error("Invalid UTF-8 character")
|
||||
elseif c == 244 and (c2 < 128 or c2 > 143) then
|
||||
error("Invalid UTF-8 character")
|
||||
elseif c2 < 128 or c2 > 191 then
|
||||
error("Invalid UTF-8 character")
|
||||
end
|
||||
|
||||
-- validate byte 3
|
||||
if c3 < 128 or c3 > 191 then
|
||||
error("Invalid UTF-8 character")
|
||||
end
|
||||
|
||||
-- validate byte 4
|
||||
if c4 < 128 or c4 > 191 then
|
||||
error("Invalid UTF-8 character")
|
||||
end
|
||||
|
||||
return 4
|
||||
else
|
||||
error("Invalid UTF-8 character")
|
||||
end
|
||||
end
|
||||
|
||||
--
|
||||
-- Implement String Library with UTF-8 support
|
||||
--
|
||||
|
||||
utf8lib.string = {}
|
||||
|
||||
-- returns the number of characters in a UTF-8 string
|
||||
local function utf8len(s)
|
||||
-- argument checking
|
||||
if type(s) ~= "string" then
|
||||
error("bad argument #1 to 'utf8len' (string expected, got " .. type(s) .. ")")
|
||||
end
|
||||
|
||||
local pos = 1
|
||||
local bytes = string.len(s)
|
||||
local len = 0
|
||||
|
||||
while pos <= bytes do
|
||||
len = len + 1
|
||||
pos = pos + utf8charbytes(s, pos)
|
||||
end
|
||||
|
||||
return len
|
||||
end
|
||||
|
||||
-- replace UTF-8 characters based on a mapping table
|
||||
local function utf8replace(s, mapping)
|
||||
-- argument checking
|
||||
if type(s) ~= "string" then
|
||||
error("bad argument #1 to 'utf8replace' (string expected, got " .. type(s) .. ")")
|
||||
end
|
||||
if type(mapping) ~= "table" then
|
||||
error("bad argument #2 to 'utf8replace' (table expected, got " .. type(mapping) .. ")")
|
||||
end
|
||||
|
||||
local pos = 1
|
||||
local bytes = string.len(s)
|
||||
local charbytes
|
||||
local newstr = ""
|
||||
|
||||
while pos <= bytes do
|
||||
charbytes = utf8charbytes(s, pos)
|
||||
local c = s:sub(pos, pos + charbytes - 1)
|
||||
newstr = newstr .. (mapping[c] or c)
|
||||
pos = pos + charbytes
|
||||
end
|
||||
|
||||
return newstr
|
||||
end
|
||||
|
||||
-- identical to string.len with UTF-8 support
|
||||
function utf8lib.string.len(s)
|
||||
return utf8len(s)
|
||||
end
|
||||
|
||||
-- identical to string.upper with UTF-8 support
|
||||
function utf8lib.string.upper(s)
|
||||
return string.upper(utf8replace(s, utf8lib.utf8_lc_uc))
|
||||
end
|
||||
|
||||
-- identical to string.lower with UTF-8 support
|
||||
function utf8lib.string.lower(s)
|
||||
return string.lower(utf8replace(s, utf8lib.utf8_uc_lc))
|
||||
end
|
|
@ -1,7 +0,0 @@
|
|||
utf8lib.utf8_uc_lc = {
|
||||
["А"]="а",["Б"]="б",["В"]="в",["Г"]="г",["Д"]="д",["Е"]="е",["Ё"]="ё",["Ж"]="ж",["З"]="з",["И"]="и",["Й"]="й",["К"]="к",["Л"]="л",["М"]="м",["Н"]="н",["О"]="о",["П"]="п",["Р"]="р",["С"]="с",["Т"]="т",["У"]="у",["Ф"]="ф",["Х"]="х",["Ц"]="ц",["Ч"]="ч",["Ш"]="ш",["Щ"]="щ",["Ъ"]="ъ",["Ы"]="ы",["Ь"]="ь",["Э"]="э",["Ю"]="ю",["Я"]="я"
|
||||
}
|
||||
|
||||
utf8lib.utf8_lc_uc = {
|
||||
["а"]="А",["б"]="Б",["в"]="В",["г"]="Г",["д"]="Д",["е"]="Е",["ё"]="Ё",["ж"]="Ж",["з"]="З",["и"]="И",["й"]="Й",["к"]="К",["л"]="Л",["м"]="М",["н"]="Н",["о"]="О",["п"]="П",["р"]="Р",["с"]="С",["т"]="Т",["у"]="У",["ф"]="Ф",["х"]="Х",["ц"]="Ц",["ч"]="Ч",["ш"]="Ш",["щ"]="Щ",["ъ"]="Ъ",["ы"]="Ы",["ь"]="Ь",["э"]="Э",["ю"]="Ю",["я"]="Я"
|
||||
}
|
Loading…
Reference in New Issue