Anonymous user
Module:Convert: Difference between revisions
an output combination unit can be user-defined, consisting of unit codes separated by "+" or " " (space)
(new style: 4-column tabs) |
(an output combination unit can be user-defined, consisting of unit codes separated by "+" or " " (space)) |
||
Line 590:
end
end
-- Accept user-defined
-- If '+' is used, each unit code can include a space, and any error is fatal.
-- If ' ' is used and if each space-separated word is a unit code, it is a combo,
-- but errors are not fatal so the unit code can be looked up as an extra unit.
local err_is_fatal
local combo = collection()
if unitcode:find('+', 1, true) then
for item in string.gmatch(unitcode .. '+', '%s*(.-)%s*%+') do▼
err_is_fatal = true
if item ~= '' then▼
▲ if item ~= '' then
combo:add(item)
end▼
end
elseif unitcode:find('%s') then
for item in unitcode:gmatch('%S+') do
combo:add(item)
end
end
if combo.n > 1 then
local function lookup_combo()
if what == 'no_combination' or what == 'only_multiple' then
return false, { 'cvt_bad_unit', unitcode }
▲ end
local result = { combination = {} }▼
local
for i, v in ipairs(combo) do
local success, t = lookup(v, opt_sp_us, 'no_combination', utable, fails, depth)
if
result.utype = t.utype
▲ else
else
return false, mismatch
end
end
cvt[i] = t
end
end
local success, result = lookup_combo()
if success or err_is_fatal then
end
▲ return true, result
end
if not extra_units then
Line 627 ⟶ 644:
-- A unit in one data table might refer to a unit in the other table, so
-- switch between them, relying on fails or depth to terminate loops.
fails[unitcode] = true
local other = (utable == all_units) and extra_units or all_units
|