יחידה:מירכאות

מתוך ויקיפדיה, האנציקלופדיה החופשית

הקוד ביחידה זו משמש לתבניות הבאות:


local p = {}

function p.removeQuotes_internal(str)
    local len = #str
    -- Check if the string starts and ends with a single quotation mark
    if len >= 2 and str:sub(1, 1) == "'" and str:sub(-1) == "'" then
        -- Check if there are two/three/five consecutive single quotation marks
        if (str:sub(2, 2) == "'" and str:sub(3, 3) ~= "'" and len >= 3) or
           (str:sub(2, 2) == "'" and str:sub(3, 3) == "'" and str:sub(4, 4) ~= "'" and len >= 4) or
           (str:sub(2, 2) == "'" and str:sub(3, 3) == "'" and str:sub(4, 4) == "'" and str:sub(5, 5) ~= "'" and len >= 5) then
            -- Return the original string without changes
            return str
        else
            -- Remove the first and last character (single quotation marks) from the string
            return str:sub(2, -2)
        end
    else
        -- No quotation marks, return the original string
        return str
    end
end

function p.removeQuotes( frame )
     str = frame.args.string
     return p.removeQuotes_internal(str)
end

return p