Module:OfcFunctions

From OurFoodChain
Revision as of 22:44, 8 August 2019 by U3606214 (talk | contribs)

Documentation for this module may be created at Module:OfcFunctions/doc

local p = {}

-- string parsing functions

function p.test() 
    return "hello, world!"
end

function p.trim(input) 
    input = string.gsub(input, "^%s+", "")
    input = string.gsub(input, "%s+$", "")
    return input
end

function p.split(input, delimiter)
    
    if delimiter == nil then
        delimiter = " "
    end

    local pattern = string.format("([^%s]+)", delimiter)
    local result = {}

    for substr in input:gmatch(pattern) do
        result[#result + 1] = substr
    end

    return result

end

-- category functions

function p.splitToCategoryTags(input, delimiter) 

    local arr = p.split(input, delimiter);
    local result = "";

    for i = 1, #arr do
        result = result .. string.format("[Category:%s]\n", p.trim(arr[i]))
    end

    return result;
    
end

return p