--[[
desc: STRING, a lib that encapsulate string function.
author: Musoucrow
since: 2018-8-13
alter: 2018-12-31
]]--
local _UTF8 = require("utf8")
local _CONFIG = require("config")
---@class Lib.STRING
local _STRING = {
colorMap = {
w = {255, 255, 255, 255}, --white
W = {255, 255, 230, 255},
B = {0, 0, 0, 0}, --black
r = {255, 100, 100, 255}, --red
R = {255, 0, 0, 255},
g = {180, 255, 180, 255}, --green
b = {200, 255, 255, 255}, --blue
y = {255, 255, 180, 255}, --yellow
o = {255, 200, 55, 255}, --orange
p = {255, 150, 255, 255}, --pink
P = {255, 50, 255, 255}, --purple
G = {192, 192, 192, 255}, --grey
D = {233, 218, 195, 255} --dialog
}
}
---@param map table
---@return string
function _STRING.GetVersion(map)
if (map == nil) then
return ""
elseif (type(map) == "string") then
return map
end
return map[_CONFIG.setting.language]
end
---@param content string
---@return table | string
function _STRING.Colorize(content)
if (type(content) == "table" or not string.find(content, "|")) then
return content
end
local list = _STRING.Split(content, "|")
local ret = {}
for n=1, #list do
if (#list[n] > 1) then
local color = n == 1 and _STRING.colorMap.w or _STRING.colorMap[string.sub(list[n], 1, 1)]
local text = n == 1 and list[n] or string.sub(list[n], 2)
table.insert(ret, color)
table.insert(ret, text)
end
end
return ret
end
最新发布