localp={}
-- compares arguments [1] and [2]
-- returns -1, 0, 1
-- ci=1 case-insensitive comparison
-- versions=1 splits on whitespace and compares tokens alphabetically,
-- except when tokens are all digits/periods,
-- in which case it splits the token on the period and compares the numbers numerically.
functionp.base(...)
p.current_frame=mw.getCurrentFrame()
localargs={...}
ifargs[1]==p.current_framethen
args=require('Module:ProcessArgs').merge(true)
else
args=args[1]
end
ifargs[1]==nilorargs[2]==nilthen
return0
end
locala=args[1]..''
localb=args[2]..''
ifargs.ci~=nilandargs.ci~=falsethen
a=a:lower()
b=b:lower()
end
ifargs.versions~=nilandargs.versions~=falsethen
locala_tokens={}
localb_tokens={}
fortinstring.gmatch(a,"%S+")dotable.insert(a_tokens,t)end
fortinstring.gmatch(b,"%S+")dotable.insert(b_tokens,t)end
fori,a_tokeninpairs(a_tokens)do
ifb_tokens[i]==nilthenreturn1end
localb_token=b_tokens[i]
locala_token_is_ver=(string.find(a_token,"^[%d%.]+$")~=nil)
localb_token_is_ver=(string.find(b_token,"^[%d%.]+$")~=nil)
ifa_token_is_verandb_token_is_verthen
locala_nums={}
localb_nums={}
fortinstring.gmatch(a_token,"%d+")dotable.insert(a_nums,t)end
fortinstring.gmatch(b_token,"%d+")dotable.insert(b_nums,t)end
forj,a_numinpairs(a_nums)do
ifb_nums[j]==nilthenreturn1end
localb_num=b_nums[j]
iftonumber(a_num)<tonumber(b_num)thenreturn-1end
iftonumber(a_num)>tonumber(b_num)thenreturn1end
end
if#a_nums<#b_numsthenreturn-1end
else
ifa_token<b_tokenthenreturn-1end
ifa_token>b_tokenthenreturn1end
end
end
if#a_tokens<#b_tokensthenreturn-1end
return0
end
ifa<bthenreturn-1end
ifa>bthenreturn1end
ifa==bthenreturn0end
end
returnp