Modül belgelemesi[oluştur]
--[[ v1.00
     Test the string against the list of countries/continents.
     Return the first word which matches a country/continent name ...
     unless the "match=" parameter specifies a different match.
     If there is no match, then return an empty string ... unless
     the "nomatch" parameter specifies something different
]]

local getArgs = require('Modül:Bağımsız değişkenler').getArgs
local p = {}

-- config
local nomatch = ""
local matchnum = 1

local countryList = {
	'Güney Afrika Cumhuriyeti',
	'Orta Afrika Cumhuriyeti',
	'Afrika',
	'Antarktika',
	'Orta Asya',
	'Güney Asya',
	'Güneydoğu Asya',
	'Asya',
	'Karayipler',
	'Avrasya',
	'Avrupa',
	'Orta Doğu',
	'Orta Amerika',
	'Kuzey Amerika',
	'Güney Amerika',
	'Okyanusya',
	'Amerika',
	'Afganistan',
	'Arnavutluk',
	'Cezayir',
	'Amerikan Samoası',
	'Andorra',
	'Angola',
	'Anguilla',
	'Antigua ve Barbuda',
	'Arjantin',
	'Ermenistan',
	'Aruba',
	'Avustralya',
	'Avusturya İmparatorluğu',
	'Avusturya-Macaristan',
	'Avusturya',
	'Azerbaycan',
	'Bahamalar',
	'Bahreyn',
	'Bangladeş',
	'Barbados',
	'Belarus',
	'Belçika',
	'Belize',
	'Benin',
	'Bermuda',
	'Bhutan',
	'Bolivya',
	'Bosna-Hersek',
	'Botsvana',
	'Brezilya',
	'Brunei',
	'Bulgaristan',
	'Burkina Faso',
	'Burundi',
	'Kamboçya',
	'Kamerun',
	'Kanada',
	'Yeşil Burun Adaları',
	'Cayman Adaları',
	'Çad',
	'Şili',
	"Çin Halk Cumhuriyeti",
	'Çin HC',
	'Çin',
	'Kolombiya',
	'Komorlar',
	'Kongo Cumhuriyeti',
	'Kongo Demokratik Cumhuriyeti',
	'Demokratik Kongo Cumhuriyeti',
	'Kongo DC',
	'Kongo',
	'Cook Adaları',
	'Kosta Rika',
	'Hırvatistan',
	'Küba',
	'Curaçao',
	'Kıbrıs',
	'Çek Cumhuriyeti',
	'Çekya',
	'Danimarka',
	'Cibuti',
	'Dominik Cumhuriyeti',
	'Dominika',
	'Doğu Timor',
	'Ekvador',
	'Mısır',
	'El Salvador',
	'İngiltere',
	'Eritre',
	'Estonya',
	'Esvatini',	
	'Etiyopya',
	'Falkland Adaları',
	'Faroe Adaları',
	'Fiji',
	'Finlandiya',
	'Fransa',
	'Gabon',
	'Gambiya',
	'Gürcistan',
	'Almanya',
	'Gana',
	'Cebelitarık',
	'Büyük Britanya',
	'Britanya',
	'Yunanistan',
	'Grenada',
	'Guam',
	'Guatemala',
	'Papua Yeni Gine',	
	'Ekvator Ginesi',	
	'Gine-Bissau',
	'Gine',
	'Guyana',
	'Haiti',
	'Honduras',
	'Hong Kong',
	'Macaristan',
	'İzlanda',
	'Hindistan',
	'Endonezya',
	'İran',
	'Irak',
	'Kuzey İrlanda',	
	'İrlanda Cumhuriyeti',
	'İrlanda',
	'İsrail',
	'İtalya',
	'Fildişi Sahili',
	'Jamaika',
	'Japonya',
	'Ürdün',
	'Kazakistan',
	'Kenya',
	'Kiribati',
	'Kosova',
	'Kosova Cumhuriyeti',
	'Kuveyt',
	'Kırgızistan',
	'Kırgız Cumhuriyeti',
	"Laos Demokratik Halk Cumhuriyeti",
	'Laos',
	'Letonya',
	'Lübnan',
	'Lesotho',
	'Liberya',
	'Libya',
	'Lihtenştayn',
	'Lithvanya',
	'Lüksemburg',
	'Makao',
	'Makedonya Cumhuriyeti',
	'Kuzey Makedonya',
	'Makedonya',
	'Madagaskar',
	'Malavi',
	'Malezya',
	'Maldivler',
	'Mali',
	'Malta',
	'Marshall Adaları',
	'Moritanya',
	'Mauritius',
	'Meksika',
	'Mikronezya Federal Devletleri',
	'Mikronezya',
	'Moldova',
	'Monako',
	'Moğolistan',
	'Karadağ',
	'Montserrat',
	'Fas',
	'Mozambik',
	'Myanmar',
	'Namibya',
	'Nauru',
	'Nepal',
	'Hollanda',
	'Yeni Kaledonya',
	'Yeni Zelanda',
	'Nikaragua',
	'Nijerya',
	'Nijer',
	'Kuzey Kore',
	"Kore Demokratik Halk Cumhuriyeti",
	'Kore DHC',
	'Norveç',
	'Umman',
	'Osmanlı İmparatorluğu',
	'Osmanlı Devleti',
	'Mısır (eyalet)',	
	'Pakistan',
	'Palau',
	'Filistin Mandası',
	'Fislitin',
	'Filistin toprakları',
	'Panama',
	'Paraguay',
	'Peru',
	'Filipinler',
	'Polonya',
	'Portekiz',
	'Porto Riko',
	'İspanyol Virjin Adaları',
	'Katar',
	'Romanya',
	'Rus İmparatorluğu',
	'Rusya Federasyonu',
	'Rusya',
	'Ruanda',
	'Saint Kitts ve Nevis',
	'Saint Lucia',
	'Saint Vincent ve Grenadinler',
	'Samoa',
	'San Marino',
	'São Tomé ve Príncipe',
	'Sao Tome ve Principe',
	'Suudi Arabistan',
	'İskoçya',
	'Senegal',
	'Sırbistan',
	'Seyşeller',
	'Sierra Leone',
	'Singapur',
	'Slovakya',
	'Slovenya',
	'Solomon Adaları',
	'Somali',
	'Güney Kore',
	'Kore Cumhuriyeti',
	'Güney Sudan',
	'Sudan',
	'İspanya',
	'Sri Lanka',
	'Surinam',
	'Svaziland',
	'İsveç',
	'İsviçre',
	'Suriye',
	'Tahiti',
	'Çin Cumhuriyeti',
	'Tayvan',
	'Tacikistan',
	'Tanzanya',
	'Tayland',
	'Togo',
	'Tonga',
	'Trinidad ve Tobago',
	'Trinidad',
	'Tobago',
	'Tunus',
	'Türkiye',
	'Türkmenistan',
	'Turks ve Caicos Islands',
	'Tuvalu',
	'Uganda',
	'Ukrayna',
	'Birleşik Arap Emirlikleri',
	'BAE',
	'Birleşik Krallık',
	'Amerika Birleşik Devletleri',
	'ABD',
	'Birleşik Devletler',
	'Uruguay',
	'Özbekistan',
	'Vanuatu',
	'Venezuela',
	'Vietnam',
	'Britanya Virjin Adaları',
	'Amerika Birleşik Devletleri Virjin Adaları',
	'ABD Virjin Adaları',
	'Virjin Adaları',
	'Galler',
	'Yemen',
	'Zambiya',
	'Zimbabve',
	'Find country/testcases'
}

-- returns the name of a country that is found in the string
-- ... or an empty string if there is no match
function findcountryinstring(str)

	nMatches = 0
	myMatches ={}
	str=" " .. str:gsub("^%s*(.-)%s*$", "%1") .. " "

		-- check agaist each country
		-- if there is a match, then return that country
		for i, thiscountry in ipairs(countryList) do
			if mw.ustring.find(str, thiscountry) then
				nMatches = nMatches + 1
				myMatches[nMatches] = thiscountry
			end
		end


	if (nMatches == 0) then
		-- none of the title words matches a whole country
		return nomatch
	end
	
	if ((matchnum >= 1) and (matchnum <= nMatches)) then
		return myMatches[matchnum]
	end

	if (matchnum < 0) then
		matchnum = matchnum + 1 -- so that -1 is the last match etc
		if ((matchnum + nMatches) >= 1) then
			return myMatches[matchnum + nMatches]
		end
	end
	
	-- if we get here, we have not found a match at the position specified by "matchnum"
	return nomatch
end

function p.main(frame)
	local args = getArgs(frame)
	return p._main(args)
end

function p._main(args)
	if (args['nomatch'] ~= nil) then
		nomatch = args['nomatch']
	end
	
	-- by default, we return the first match
	-- but the optional "C" paarmeter sets the "matchnum" variable, which
	-- * for a positive matchnum "n", returns the nth match if it exists
	-- * for a positive matchnum "n", returns (if it exists) the nth match
	--   counting backwards from the end.
	--   So "match=-1" returns the last match
	--   and "match=-3" returns the 3rd-last match
	if (args['match'] ~= nil) then
		matchnum = tonumber(args['match'])
		if ((matchnum == nil) or (matchnum == 0)) then
			matchnum = 1
		end
	end
	
	-- by default, we use the current page
	-- but if the "string=" parameters is supplied, we use that
	-- so we try the parameter first
	thispagename = nil
	if ((args['string'] ~= nil) and (args['string'] ~= "")) then
		-- we have a non-empty "string" parameter, so we use it
		thisstring = args['string']
	else
		-- get the page title
		thispage = mw.title.getCurrentTitle()
		thisstring = thispage.text;
	end
	
	-- now check the pagename to try to find a country
	result = findcountryinstring(thisstring)
	if (result == "") then
		return nomatch
	end
	return result
end

return p