Module:Ordnance Survey coordinates/sandbox: Difference between revisions

Content deleted Content added
sync sandbox
use unicode functions
Line 39:
local function northeast(lett,num,shift)
-- split into northings and eastings
local le=stringmw.ustring.len(num)
if le%2 == 1 then
return "Malformed numerical part of NGR"
end
local pr=le/2
local n = stringmw.ustring.sub(num,pr+1)
local e = stringmw.ustring.sub(num,1,pr)
-- Hack to move to center of square: append a 5 to northings and eastings
if shift ~= nil and shift > 0 then
Line 53:
end
-- end hack
if stringmw.ustring.len(n) == 0 then
n = 0
end
if stringmw.ustring.len(e) == 0 then
e = 0
end
pr = math.pow(10.0,(5.0-pr))
local T1 = stringmw.ustring.byte(stringmw.ustring.sub(lett,1,1))-65
if T1>8 then
T1 = T1-1
end
local T2 = nil
if stringmw.ustring.len(lett)>1 then
T2 = stringmw.ustring.byte(stringmw.ustring.sub(lett,2))-65
if T2>8 then
T2 = T2-1
Line 272:
local function NGR2LL(ngr)
-- returns a country,error,lat,long list
ngr = stringmw.ustring.gsub(stringmw.ustring.upper(ngr),"[^%d%u]","")
local lett = stringmw.ustring.gsub(ngr,"[^%u]","")
local num = stringmw.ustring.gsub(ngr,"[^%d]","")
if stringmw.ustring.len(lett) == 1 then
return Irish2LL(lett,num)
end
if stringmw.ustring.len(lett) == 2 then
return GB2LL(lett,num)
end
Line 290:
end
local t = {}
for chunk in stringmw.ustring.gmatch(s,"([^"..sep.."]+)") do
table.insert(t,chunk)
end
Line 297:
 
local function trim(s)
s = stringmw.ustring.gsub(s,"^%s+","")
s = stringmw.ustring.gsub(s,"%s+$","")
return s
end
 
local function alldigits(s)
return stringmw.ustring.find(s,"%D") == nil
end
 
Line 320:
local args = getArgs(frame,{parentFirst=true,parentOnly=false,frameOnly=false})
local input = args[1]
if input == nil or stringmw.ustring.len(input)==0 then
return warning(nil)
end
Line 332:
local pagename = mw.uri.encode( current_page.prefixedText, 'WIKI' );
if #args >= 2 and alldigits(args[2]) then
if stringmw.ustring.sub(args[1],1,1) == 'i' then
local firstArg = stringmw.ustring.sub(args[1],2)
if alldigits(firstArg) then
LL = {IrishEN2LL(firstArg,args[2])}
restargs = 3
if linktitle == nil or stringmw.ustring.len(linktitle) == 0 then
linktitle=args[1]..'_'..args[2]
end
Line 344:
LL = {GBEN2LL(args[1],args[2])}
restargs = 3
if linktitle == nil or stringmw.ustring.len(linktitle) == 0 then
linktitle=args[1]..'_'..args[2]
end
Line 351:
LL = {NGR2LL(args[1])}
restargs = 2
if linktitle == nil or stringmw.ustring.len(linktitle) == 0 then
linktitle=args[1]
end
Line 377:
url = url..'_'..args[i]
end
if stringmw.ustring.find(input,"region") == nil then
url = url..'_region:'..LL[1]
end