Module:Ordnance Survey coordinates/sandbox: Difference between revisions

Content deleted Content added
protect against empty strings
better error handling
Line 264:
local n=n*pr+100000.0*(4.0-math.floor(T1/5.0))
return IrishEN2LL(e,n)
end
 
local function empty(s)
return s == nil or s == ''
end
 
Line 269 ⟶ 273:
-- returns a country,error,lat,long list
ngr = mw.ustring.gsub(mw.ustring.upper(ngr),"[^%d%u]","")
local first, last, lett, num = mw.ustring.gsubfind(ngr,"[^(%u]","+)(%d+)$")
localif numfirst == nil or empty(lett) or empty(num) or mw.ustring.gsublen(ngr,"[^%d]",""lett) > 2 then
return nil,"Malformed NGR",0.0,0.0
end
if mw.ustring.len(lett) == 1 then
return Irish2LL(lett,num)
end
ifreturn mw.ustring.lenGB2LL(lett, num) == 2 then
return GB2LL(lett,num)
end
return nil,"Malformed NGR",0.0,0.0
end
 
Line 309 ⟶ 312:
end
return html
end
 
local function empty(s)
return s == nil or s == ''
end