947
edits
(update from sandbox per Template talk:Convert#Module version 24) |
m (1 revision imported) |
||
Line 759:
result.scale = t.scale * 10 ^ (si.exponent * t.prefixes)
return true, setmetatable(result, unit_prefixed_mt)
end▼
end▼
end▼
-- Accept any unit with an engineering notation prefix like "e6cuft"▼
-- (million cubic feet), but not chained prefixes like "e3e6cuft",▼
-- and not if the unit is a combination or multiple,▼
-- and not if the unit has an offset or is a built-in.▼
-- Only en digits are accepted.▼
local has_plus = unitcode:find('+', 1, true)
local engscale = text_code.eng_scales[exponent]▼
local success, result = lookup(parms, baseunit, 'no_combination', utable, fails, depth)▼
if success and not (result.offset or result.builtin or result.engscale) then▼
result.unitcode = unitcode -- 'e6cuft' not 'cuft'▼
result.defkey = unitcode -- key to lookup default exception▼
result.engscale = engscale▼
result.scale = result.scale * 10 ^ tonumber(exponent)▼
return true, result▼
end▼
end
end
Line 768 ⟶ 790:
local err_is_fatal
local combo = collection()
if
err_is_fatal = true
for item in (unitcode .. '+'):gmatch('%s*(.-)%s*%+') do
Line 805 ⟶ 827:
if success or err_is_fatal then
return success, result
▲ end
▲ end
▲ -- Accept any unit with an engineering notation prefix like "e6cuft"
▲ -- (million cubic feet), but not chained prefixes like "e3e6cuft",
▲ -- and not if the unit is a combination or multiple,
▲ -- and not if the unit has an offset or is a built-in.
▲ -- Only en digits are accepted.
▲ local exponent, baseunit = unitcode:match('^e(%d+)(.*)')
▲ if exponent then
▲ local engscale = text_code.eng_scales[exponent]
▲ if engscale then
▲ local success, result = lookup(parms, baseunit, 'no_combination', utable, fails, depth)
▲ if success and not (result.offset or result.builtin or result.engscale) then
▲ result.unitcode = unitcode -- 'e6cuft' not 'cuft'
▲ result.defkey = unitcode -- key to lookup default exception
▲ result.engscale = engscale
▲ result.scale = result.scale * 10 ^ tonumber(exponent)
▲ return true, result
▲ end
end
end
Line 1,379 ⟶ 1,382:
-- Before processing, the input text is cleaned:
-- * Any thousand separators (valid or not) are removed.
-- * Any sign
-- '-' (if negative) or '' (otherwise).
-- That replaces Unicode minus with '-'.
-- If successful, the returned info table contains named fields:
Line 1,439 ⟶ 1,443:
local valstr
for _, prefix in ipairs({ '-', MINUS, '−' }) do
-- Including '-'
-- It also sets isnegative in case input is a fraction like '-2-3/4'.
local plen = #prefix
if clean:sub(1, plen) == prefix then
valstr = clean:sub(plen + 1)
▲ end
break
end
Line 1,783 ⟶ 1,785:
kv_pairs.sing = nil
end
for loc_name, loc_value in pairs(kv_pairs) do
local en_name = text_code.en_option_name[loc_name]
Line 2,052 ⟶ 2,053:
-- Testing shows this function is successful for 96% of converts in articles,
-- and that on average it speeds up converts by 8%.
if parms.opt_ri or parms.opt_spell_in then return end
local clean = to_en(strip(parms[1] or ''), parms)
if
return false, clean
end
Line 2,530 ⟶ 2,532:
end
local sortspan
if sortkey and (parms.opt_sortable_debug or not parms.table_align) then
sortspan = parms.opt_sortable_debug and
'
'<span
parms.join_before = sortspan
end
if parms.table_align then
▲ if sortkey then
sort = ' data-sort-value="' .. sortkey .. '"'▼
local style = 'style="text-align:' .. parms.table_align .. ';'
local joins = {}
for i = 1, 2 do
Line 3,160 ⟶ 3,154:
if (abbr == 'on' or abbr == inout) and not parms.number_word then
info.show = info.show ..
elseif number_word then
local number_id
|