Module:StringHelper: Difference between revisions
From Guild of Archivists
(add line iterator) |
m (1 revision imported) |
Latest revision as of 07:26, 30 October 2015
Documentation for this module may be created at Module:StringHelper/doc
local p = {}
-- copy mw.ustring methods
for k, v in pairs( mw.ustring ) do p[k] = v end
-- true if string 's' starts with string 'prefix'
function p.startswith( s, prefix )
return p.sub( s, 1, p.len( prefix ) ) == prefix
end
-- true if string 's' ends with string 'suffix'
function p.endswith( s, suffix )
return suffix == '' or p.sub( s, 0 - p.len( suffix ) ) == suffix
end
-- strip characters 'chars' from beginning and end of string 's'
function p.strip( s, chars )
s = p.gsub( s, '^[' .. chars .. ']*', '' )
s = p.gsub( s, '[' .. chars .. ']*$', '' )
return s
end
-- line iterator
function p.lines( s )
return p.gmatch( s, "[^\r\n]+" )
end
return p