"ഘടകം:String" എന്ന താളിന്റെ പതിപ്പുകൾ തമ്മിലുള്ള വ്യത്യാസം

en>Ranjithsiji
No edit summary
(ചെ.) ഒരു പതിപ്പ് ഇറക്കുമതി ചെയ്തു
 
(3 ഉപയോക്താക്കൾ ചെയ്ത ഇടയ്ക്കുള്ള 4 നാൾപ്പതിപ്പുകൾ പ്രദർശിപ്പിക്കുന്നില്ല)
വരി 407: വരി 407:
if plain then
if plain then
pattern = str._escapePattern( pattern )
pattern = str._escapePattern( pattern )
replace = mw.ustring.gsub( replace, "%%", "%%%%" ) --Only need to escape replacement sequences.
replace = string.gsub( replace, "%%", "%%%%" ) --Only need to escape replacement sequences.
end
end


വരി 512: വരി 512:
end
end


-- findpagetext returns the position of a piece of text in a page
-- First positional parameter or |text is the search text
-- Optional parameter |title is the page title, defaults to current page
-- Optional parameter |plain is either true for plain search (default) or false for Lua pattern search
-- Optional parameter |nomatch is the return value when no match is found; default is nil
function str._findpagetext(args)
-- process parameters
local nomatch = args.nomatch or ""
if nomatch == "" then nomatch = nil end
--
local text = mw.text.trim(args[1] or args.text or "")
if text == "" then return nil end
--
local title = args.title or ""
local titleobj
if title == "" then
titleobj = mw.title.getCurrentTitle()
else
titleobj = mw.title.new(title)
end
--
local plain = args.plain or ""
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 and titleobj:getContent()
return content and mw.ustring.find(content, text, 1, plain) or nomatch
end
function str.findpagetext(frame)
local args = frame.args
local pargs = frame:getParent().args
for k, v in pairs(pargs) do
args[k] = v
end
if not (args[1] or args.text) then return nil end
-- just the first value
return (str._findpagetext(args))
end
--[[
--[[
Helper function that populates the argument list given that user may need to use a mix of
Helper function that populates the argument list given that user may need to use a mix of
വരി 583: വരി 620:
]]
]]
function str._escapePattern( pattern_str )
function str._escapePattern( pattern_str )
return mw.ustring.gsub( pattern_str, "([%(%)%.%%%+%-%*%?%[%^%$%]])", "%%%1" )
return ( string.gsub( pattern_str, "[%(%)%.%%%+%-%*%?%[%^%$%]]", "%%%0" ) )
end
 
--[[
Split
 
This function Splits a string based on a separator, returns nth substring based on count.
 
Usage:
{{#invoke:StringFunc|split|source_string|separator|count}}
 
Parameters:
source:    The string to return a subset of
separator: The string to split on
count:    The nth substring based on the separator to return
]]
function str.split( frame )
local new_args = _getParameters( frame.args, {'source', 'separator', 'count'} )
local source_str = new_args['source'] or ''
local separator = (new_args['separator'] or ''):gsub('"', '')
local separator_len = mw.ustring.len(separator)
if source_str == '' or separator == '' then
return source_str;
end
local ret_count = tonumber( new_args['count'] ) or 1
if ret_count < 1 then
return ""
end
local start = 1
local iter = mw.ustring.find(source_str, separator, start, true)
if iter == nil then
if ret_count == 1 then
return source_str
else
return ""
end
else
iter = iter - 1
end
if ret_count == 1 then
return mw.ustring.sub( source_str, start, iter)
end
    for i=2, ret_count do
    start = iter+separator_len + 1
    iter = mw.ustring.find(source_str, separator, start, true)
    if iter == nil then
    if ret_count == i then
    return mw.ustring.sub(source_str, start, mw.ustring.len(source_str))
    else
    return ""
    end
    else
    iter = iter - 1
    end
    end
    return mw.ustring.sub( source_str,start,iter)
end
 
function str.isNumber( frame )
local new_args = _getParameters( frame.args, {'source'} )
local source_str = new_args['source'] or ''
if source_str == '' then
  return "false"
end
if tonumber(source_str) == nil and tonumber(string.gsub(source_str, ",", ".", 1) .. '') == nil then
return "false"
end
return "true"
end
end


return str
return str
"https://schoolwiki.in/ഘടകം:String" എന്ന താളിൽനിന്ന് ശേഖരിച്ചത്