Module:Convert/wikidata: Difference between revisions

Content deleted Content added
Line 277:
end
 
local function input_from_text(tdata, parms, text, insert2)
-- Given string should be of form "<value><space><unit>". or
-- "<value1><space>ft<space><value2><space>in" for a special case (feet and inches).
-- Return value,true ucodeif (twovalues/units strings)were extracted and inserted, or return nothing.
text = text:gsub('&nbsp;', ' '):gsub(' %s+', ' ')
local pos = text:find(' ', 1, true)
if pos then
Line 286 ⟶ 287:
local value = text:sub(1, pos - 1)
local uid = text:sub(pos + 1)
if uid:sub(1, 3) == 'ft ' and uid:sub(-3) == ' in' then
local ucode = make_unit(tdata.wikidata_units, parms, uid)
-- Special case for enwiki to allow {{convert|input=5 ft 10+1/2 in}}
return value, ucode or uid
insert2(uid:sub(4, -4), 'in')
insert2(value, 'ft')
else
local ucode = insert2(value, make_unit(tdata.wikidata_units, parms, uid) or uid)
end
return true
end
end
Line 310 ⟶ 317:
return false, pid and { 'cvt_no_output' } or { 'cvt_bad_input', text }
end
local function insertinsert2(first, second)
table.insert(parms, index, second)
table.insert(parms, index, first)
Line 331 ⟶ 338:
local item = ucode
for i = result.n, 1, -1 do
insertinsert2(result[i][1], item)
item = sep
end
return true
else
local amount, ucode =if input_from_text(tdata, parms, text, insert2) then
if amount and ucode then
insert(amount, ucode)
return true
end