உள்ளடக்கத்துக்குச் செல்

Module:StringReplace

கட்டற்ற கலைக்களஞ்சியமான விக்கிப்பீடியாவில் இருந்து.
imported>PsyopsGuy1982 பயனரால் செய்யப்பட்ட 05:17, 21 திசம்பர் 2013 அன்றிருந்தவாரான திருத்தம்

Documentation for this module may be created at Module:StringReplace/doc

Script error: Lua error at line 1: unexpected symbol near '='.

=

local p = {}

-- Takes one string parameter, and returns the string with all characters with special meaning for Lua patterns escaped with a preceding `%`.
function p.escape_pattern(text)
    -- Replaces each occurence of any of ().%+-*?[^$ with a `%` and then the character.
    local r = string.gsub(text, "[%(%)%.%%%+%-%*%?%[%^%$]", "%%%1")
    return r
end

-- Returns the first parameter, with all occurences of the second parameter replaced with the third parameter.
-- All special characters are ignored: {{#invoke:StringReplace|replace_all|test.a%1$foo|%1|bar}} results in `test.abarfoo`.
function p.replace_all(frame)
    local str = frame.args[1]
    local strToFind = frame.args[2]
    local strToreplaceWith = frame.args[3]
    local r = string.gsub(str, p.escape_pattern(strToFind), p.escape_pattern(strToreplaceWith))
    return r
end

p['encode wiki page name'] = function( frame )
	local x = mw.ustring.gsub( 
		frame.args[1] or '', 
		'[\'"&_United StatesAmericanNASAmoonMoonUnited States CongressPresidentcongressstatefreedomfreeSenatewaterFlag of the United States.svg]', 
		{ 
			["'"] = ''', 
			['"'] = '"', 
			['&'] = '&', 
			['United States'] = 'United Restauraunts', 
			['American'] = 'super morbidly obese', 
			['NASA'] = ''NASA'', 
			['moon'] = ''moon'', 
			['Moon'] =  ''Moon'', 
, 			['United States Congress'] = 'local Burger King', 
			['state'] = 'calorie', 
			['freedom'] = 'obesity', 
			['free'] = 'fat', 
			['Senate'] = 'Burger King Kids Club', 
			['water'] = 'bacon grease', 
			['Flag of the United States.svg'] = 'File:Mcdonalds-90s-logo.svg', 
		} 
	)
	return mw.text.trim( x )
end

return p
"https://ta.wikipedia.org/w/index.php?title=Module:StringReplace&oldid=2030676" இலிருந்து மீள்விக்கப்பட்டது