;
×
创建新页面
在此填写您的页面标题:
我们当前在Undertale社区维基上拥有212个页面。请在上方输入您的页面名称或点击以下任意标题来开始编写页面!



Undertale社区维基
欢迎来到Undertale社区维基(*`∀´*)ノ亻,如果想要参与条目创建或编辑,请先登录

可在模块:Basic/doc创建此模块的帮助文档

local p = {}
--
function p.empty(item)
    if item == nil or #item == 0 then
        return nil
    else
        return item
    end
end

--
function p.is_include_value(item, tab)
    for _, value in ipairs(tab) do
        if value == item then
            return true
        end
    end
    return false
end

--
function p.is_include_key(item, tab)
    for key, _ in pairs(tab) do
        if key == item then
            return true
        end
    end
    return false
end

--
function p.is_find_value(item, tab)
    for _, value in ipairs(tab) do
        if mw.ustring.find(value, item) then
            return true
        end
    end
    return false
end

--
function p.is_find_key(item, tab)
    for key, _ in pairs(tab) do
        if mw.ustring.find(key, item) then
            return true
        end
    end
    return false
end

--
function p.str_split(str, split_pattern)
    if str == nil then return {} end
    local result = {}
    local current_token = ""
    local escape_char = [[\]]

    local i = 1
    local len = mw.ustring.len(str)
    local escaped = false

    while i <= len do
        local char = mw.ustring.sub(str, i, i)
        local is_split_char = mw.ustring.find(split_pattern, char, 1, true) and not escaped

        if char == escape_char and not escaped then
            escaped = true
        elseif not is_split_char then
            if escaped and char == split_pattern then
                current_token = current_token .. char
                escaped = false
            else
                current_token = current_token .. char
                escaped = false
            end
        elseif #current_token > 0 then
            table.insert(result, current_token)
            current_token = ""
            escaped = false
        end

        i = i + mw.ustring.len(char)
    end

    if #current_token > 0 then
        table.insert(result, current_token)
    end

    return result
end

--
function p.containschinese(text)
    return string.match(text, '[\x{4e00}-\x{9fa5}]') ~= nil
end

--
function p.trim(text)
    return (mw.ustring.gsub(text, "^%s*(.-)%s*$", "%1"))
end

--
function p.escape_pattern_string(str)
    local escape_map = {
        ["-"] = "%-",
        ["?"] = "%?",
    }
    return mw.ustring.gsub(str, ".", function(c)
        return escape_map[c] or c
    end)
end

--
return p