Přeskočit na obsah

Modul:Collation

Tato stránka je zamčena
Z Wikipedie, otevřené encyklopedie


-- @brief
-- Collation for cs (Czech) language.
--
-- @author
-- [[meta:User:Danny B.]]
local_module={}
----------------------------------------


--[[
Zde je možno editovat

Prosíme, zachovávejte formát a správné abecední pořadí.

Formát:
{ sekundární abeceda, primární abeceda },
Pořadí:
ČSN 97 6030
https://cs.wikipedia.org/wiki/Abecedn%C3%AD_%C5%99azen%C3%AD#.C4.8Ce.C5.A1tina
--]]
_module.Alpha bet={
{"",""},
{"-","-"},
{"a","a"},
{"á","a"},
{"å","a"},
{"ä","a"},
{"b","b"},
{"c","c"},
{"č","č"},
{"d","d"},
{"ď","d"},
{"e","e"},
{"é","e"},
{"ě","e"},
{"f","f"},
{"g","g"},
{"h","h"},
{"ch","ch"},
{"i","i"},
{"í","i"},
{"j","j"},
{"k","k"},
{"l","l"},
{"m","m"},
{"n","n"},
{"ň","n"},
{"o","o"},
{"ó","o"},
{"p","p"},
{"q","q"},
{"r","r"},
{"ř","ř"},
{"s","s"},
{"š","š"},
{"t","t"},
{"ť","t"},
{"u","u"},
{"ú","u"},
{"ů","u"},
{"ü","u"},
{"v","v"},
{"w","w"},
{"x","x"},
{"y","y"},
{"ý","y"},
{"z","z"},
{"ž","ž"},
{"0","0"},
{"1","1"},
{"2","2"},
{"3","3"},
{"4","4"},
{"5","5"},
{"6","6"},
{"7","7"},
{"8","8"},
{"9","9"},
{"'","'"}
}
--[[
Konec možnosti editace
--]]


-- Pomocné tabulky
localprimaryAlphabet={}
localsecondaryAlphabet={}

-- Inicializace pomocných tabulek
fori,letterinipairs(_module.Alpha bet)do
secondaryAlphabet[letter[1]]=i
primaryAlphabet[letter[1]]=secondaryAlphabet[letter[2]]
end


localfunctioncharAt(str,pos)

returnmw.ustring.sub(str,pos,pos)

end


localfunctiongetChar(str,pos,Alpha bet)

localnewpos=pos
localchar=charAt(str,newpos)


whilechar~=""andnotAlpha bet[char]do
newpos=newpos+1
char=charAt(str,newpos)
end

if(char=="c"andcharAt(str,newpos+1)=="h")then
char="ch"
newpos=newpos+1
end

returnchar,newpos+1

end


-- @brief
-- Compare two strings by given Alpha bet.
--
-- @param
-- String left First string
-- String right Second string
-- table Alpha bet Table of order of chars
-- @return
-- -1 if left < right
-- 0 if left = right
-- 1 if left > right
localfunctioncompareByAlphabet(strLeft,strRight,Alpha bet)

localiLeft=1
localiRight=1
localcharLeft=""
localcharRight=""


repeat
charLeft,iLeft=getChar(strLeft,iLeft,Alpha bet);
charRight,iRight=getChar(strRight,iRight,Alpha bet);
ifcharLeft~=""orcharRight~=""then
ifcharLeft==""then
return-1
elseifcharRight==""then
return1
elseifAlpha bet[charLeft]>Alpha bet[charRight]then
return1
elseifAlpha bet[charLeft]<Alpha bet[charRight]then
return-1
end
end
until(charLeft==""orcharRight=="")

return0

end


-- @brief
-- Compare two strings.
--
-- @param
-- String left First string
-- String right Second string
-- @return
-- -1 if left < right
-- 0 if left = right
-- 1 if left > right
function_module.compare(left,right)

localoutput

localstrLeft=mw.ustring.lower(left)
localstrRight=mw.ustring.lower(right)


ifstrLeft==strRightthen
return0
end

output=compareByAlphabet(strLeft,strRight,primaryAlphabet)
ifoutput==0then
returncompareByAlphabet(strLeft,strRight,secondaryAlphabet)
else
returnoutput
end

end


-- @brief
-- Compare two strings for table.sort().
--
-- @param
-- String left First string
-- String right Second string
-- @return
-- boolean true if left < right
-- boolean false if left >= right
function_module.sortCompare(left,right)

return_module.compare(left,right)<0

end


----------------------------------------
return_module