Kontent qismiga oʻtish

Modul:Convert character width

Vikipediya, ochiq ensiklopediya

Bu modul uchun Modul:Convert character width/doc nomli hujjat sahifasini yaratishingiz mumkin

local data = mw.loadData( 'Module:Convert character width/data' )

local p = {}

local function getFull( s )
    return data[ s ] or s
end

local function getHalf( s )
    for half, full in pairs( data ) do
        if s == full then
            return half
        end
    end
    return s
end

function p.full( frame )
    local s = type( frame ) == 'table' and frame.args and frame.args[ 1 ] or frame
    s = type( s ) == 'number' and tostring( s ) or s
    if type( s ) ~= 'string' then return end
    return ( mw.ustring.gsub( s, '.', getFull ) )
end

function p.half( frame )
    local s = type( frame ) == 'table' and frame.args and frame.args[ 1 ] or frame
    s = type( s ) == 'number' and tostring( s ) or s
    if type( s ) ~= 'string' then return end
    return ( mw.ustring.gsub( s, '.', getHalf ) )
end

return p