Module:Remove accessory suffix

From Final Fantasy XIV Online Wiki
Jump to navigation Jump to search

This module removes the following suffixes from an input string (case insensitive): of fending, of slaying ,of aiming, of casting, of healing and returns the stripped string.

Usage: {{#invoke:Remove accessory suffix|strip|<input string>}}.


local p = {}

function p.strip(frame)
    local input = frame.args[1] or ""
    return p._strip(input)
end

function p._strip(input)
    if not input or input == "" then
        return ""
    end
    
    -- Define patterns to remove (case insensitive)
    local patterns = {
        "of fending",
        "of slaying",
        "of aiming",
        "of casting",
        "of healing"
    }
    
    local result = input
    
    -- Remove each pattern (case insensitive)
    for _, pattern in ipairs(patterns) do
        -- Escape special pattern characters and make case insensitive
        local escaped = pattern:gsub("([%^%$%(%)%%%.%[%]%*%+%-%?])", "%%%1")
        result = result:gsub(escaped, "", 1) -- Remove first occurrence
        
        -- Also try case insensitive version
        local lower = result:lower()
        local patternLower = pattern:lower()
        local pos = lower:find(patternLower, 1, true)
        if pos then
            result = result:sub(1, pos - 1) .. result:sub(pos + #pattern)
        end
    end
    
    -- Trim whitespace from result
    result = result:gsub("^%s+", ""):gsub("%s+$", "")
    
    return result
end

return p