Module:String2: Difference between revisions
From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
Content added Content deleted
(allow split to use negative indices) |
(function one2a) |
||
Line 134: | Line 134: | ||
txt = txt:gsub("%d[%d%.]*", v2p) -- store just the string |
txt = txt:gsub("%d[%d%.]*", v2p) -- store just the string |
||
return txt |
return txt |
||
end |
|||
-- one2a scans through a string, passed as either the first unnamed parameter or |txt= |
|||
-- it converts each occurrence of 'one ' into either 'a ' or 'an ' and returns the resultant string. |
|||
p.one2a = function(frame) |
|||
local args = frame.args |
|||
if not(args[1] or args.txt) then args = frame:getParent().args end |
|||
local txt = mw.text.trim(args[1] or args.txt or "") |
|||
if txt == "" then return nil end |
|||
return txt:gsub(" one ", " a "):gsub("One ", "A "):gsub("a ([aeiou])", "an %1"):gsub("A ([aeiou])", "An %1") |
|||
end |
end |
||