Content deleted Content added
better; |
fix |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 12:
end
p.ucfirst = function (frame
local s = frame.args[1];
if not s or '' == s or s:match ('^%s+$') then -- when <s> is nil, empty, or only whitespace
Line 87:
p.title = function (frame
-- http://grammar.yourdictionary.com/capitalization/rules-for-capitalization-in-titles.html
-- recommended by The U.S. Government Printing Office Style Manual:
Line 379:
function p.startswith(frame)
return (frame.args[1]:sub(1, frame.args[2]:len()) == frame.args[2]) and 'yes' or ''
end
-- Implements [[Template:Isnumeric]]
function p.isnumeric(frame)
local s = frame.args[1] or frame:getParent().args[1]
local boolean = (frame.args.boolean or frame:getParent().args.boolean) == 'true'
if type(s) == 'string' and mw.getContentLanguage():parseFormattedNumber( s ) then
return boolean and 1 or s
end
return boolean and 0 or ''
end
-- Checks if a value in a group of numbers is not an interger.
-- Allows usage of an |empty= parameter to allow empty values to be skipped.
function p.isInteger(frame)
local values = frame.args or frame:getParent().args
local allow_empty = frame.args.empty or frame:getParent().args.empty
for _, value in ipairs(values) do
-- Trim spaces
value = value and value:gsub("^%s*(.-)%s*$", "%1")
if value == "" or value == nil then
if not allow_empty then
return false -- Empty values are not allowed
end
else
value = tonumber(value)
if not (type(value) == "number" and value == math.floor(value)) then
return false
end
end
end
return true
end
-- Returns an error found in a string.
function p.getError(frame)
local text = frame.args[1] or frame:getParent().args[1]
local error_message = text:match('(<strong class="error">.-</strong>)')
return error_message or nil
end
|