Module:String2: Difference between revisions

Content deleted Content added
catch nil parameter when passed and gracefully return an empty string rather than an error message
no globals
Line 1:
-- Version 2021-01-30
 
local p = {}
 
Line 83 ⟶ 85:
if sep == "" then sep = ", " end
local pattern = ".*" .. sep .. "(.*)"
local a, b, last = s:find(pattern)
if a then
return last
Line 200 ⟶ 202:
if plain:sub(1, 1) == "f" then plain = false else plain = true end
-- get the page content and look for 'text' - return position or nomatch
local content = titleobj:getContent()
return mw.ustring.find(content, text, 1, plain) or nomatch -- returns multiple values
end
Line 230 ⟶ 232:
p._getBoolean = p._GetParameters.getBoolean
 
--[[
Strip
 
Line 243 ⟶ 245:
plain: A flag indicating that the chars should be understood as plain text. defaults to true.
 
Leading and trailing whitespace is also automatically stripped from the string.
]]
function p.strip( frame )
Line 250 ⟶ 252:
local chars = new_args['chars'] or '' or 'characters';
source_str = mw.text.trim(source_str);
if source_str == '' or chars == '' then
return source_str;
end