Module:Convert: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
m (184 revisions imported: infobox) |
(update from sandbox per Template talk:Convert#Module version 24) |
||
Line 759: | Line 759: | ||
result.scale = t.scale * 10 ^ (si.exponent * t.prefixes) |
result.scale = t.scale * 10 ^ (si.exponent * t.prefixes) |
||
return true, setmetatable(result, unit_prefixed_mt) |
return true, setmetatable(result, unit_prefixed_mt) |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
local has_plus = unitcode:find('+', 1, true) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end |
end |
||
end |
end |
||
Line 790: | Line 768: | ||
local err_is_fatal |
local err_is_fatal |
||
local combo = collection() |
local combo = collection() |
||
if |
if unitcode:find('+', 1, true) then |
||
err_is_fatal = true |
err_is_fatal = true |
||
for item in (unitcode .. '+'):gmatch('%s*(.-)%s*%+') do |
for item in (unitcode .. '+'):gmatch('%s*(.-)%s*%+') do |
||
Line 827: | Line 805: | ||
if success or err_is_fatal then |
if success or err_is_fatal then |
||
return success, result |
return success, result |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end |
end |
||
end |
end |
||
Line 1,382: | Line 1,379: | ||
-- Before processing, the input text is cleaned: |
-- Before processing, the input text is cleaned: |
||
-- * Any thousand separators (valid or not) are removed. |
-- * Any thousand separators (valid or not) are removed. |
||
-- * Any sign |
-- * Any sign is replaced with '-' (if negative) or '' (otherwise). |
||
-- '-' (if negative) or '' (otherwise). |
|||
-- That replaces Unicode minus with '-'. |
-- That replaces Unicode minus with '-'. |
||
-- If successful, the returned info table contains named fields: |
-- If successful, the returned info table contains named fields: |
||
Line 1,443: | Line 1,439: | ||
local valstr |
local valstr |
||
for _, prefix in ipairs({ '-', MINUS, '−' }) do |
for _, prefix in ipairs({ '-', MINUS, '−' }) do |
||
-- Including '-' |
-- Including '-' sets isnegative in case input is a fraction like '-2-3/4'. |
||
-- It also sets isnegative in case input is a fraction like '-2-3/4'. |
|||
local plen = #prefix |
local plen = #prefix |
||
if clean:sub(1, plen) == prefix then |
if clean:sub(1, plen) == prefix then |
||
valstr = clean:sub(plen + 1) |
valstr = clean:sub(plen + 1) |
||
if valstr:match('^%s') then -- "- 1" is invalid but "-1 - 1/2" is ok |
|||
return false, { 'cvt_bad_num', text } |
|||
⚫ | |||
break |
break |
||
end |
end |
||
Line 1,785: | Line 1,783: | ||
kv_pairs.sing = nil |
kv_pairs.sing = nil |
||
end |
end |
||
kv_pairs.comma = kv_pairs.comma or config.comma -- for plwiki who want default comma=5 |
|||
for loc_name, loc_value in pairs(kv_pairs) do |
for loc_name, loc_value in pairs(kv_pairs) do |
||
local en_name = text_code.en_option_name[loc_name] |
local en_name = text_code.en_option_name[loc_name] |
||
Line 2,053: | Line 2,052: | ||
-- Testing shows this function is successful for 96% of converts in articles, |
-- Testing shows this function is successful for 96% of converts in articles, |
||
-- and that on average it speeds up converts by 8%. |
-- 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) |
local clean = to_en(strip(parms[1] or ''), parms) |
||
if #clean > 10 or not clean:match('^[0-9.]+$') then |
if parms.opt_ri or parms.opt_spell_in or #clean > 10 or not clean:match('^[0-9.]+$') then |
||
return false, clean |
return false, clean |
||
end |
end |
||
Line 2,532: | Line 2,530: | ||
end |
end |
||
local sortspan |
local sortspan |
||
if sortkey and |
if sortkey and not parms.table_align then |
||
sortspan = parms.opt_sortable_debug and |
sortspan = parms.opt_sortable_debug and |
||
'<span style="border:1px solid |
'<span data-sort-value="' .. sortkey .. '♠"><span style="border:1px solid">' .. sortkey .. '♠</span></span>' or |
||
'<span |
'<span data-sort-value="' .. sortkey .. '♠"></span>' |
||
parms.join_before = sortspan |
parms.join_before = sortspan |
||
end |
end |
||
if parms.table_align then |
if parms.table_align then |
||
local sort |
|||
⚫ | |||
⚫ | |||
if parms.opt_sortable_debug then |
|||
parms.join_before = '<span style="border:1px solid">' .. sortkey .. '</span>' |
|||
end |
|||
else |
|||
sort = '' |
|||
end |
|||
local style = 'style="text-align:' .. parms.table_align .. ';' |
local style = 'style="text-align:' .. parms.table_align .. ';' |
||
⚫ | |||
local joins = {} |
local joins = {} |
||
for i = 1, 2 do |
for i = 1, 2 do |
||
Line 3,154: | Line 3,160: | ||
if (abbr == 'on' or abbr == inout) and not parms.number_word then |
if (abbr == 'on' or abbr == inout) and not parms.number_word then |
||
info.show = info.show .. |
info.show = info.show .. |
||
'<span style="margin-left:0.2em">×<span style="margin-left:0.1em">' .. |
'<span style="margin-left:0.2em">×<span style="margin-left:0.1em">' .. |
||
from_en('10') .. |
from_en('10') .. |
||
'</span></span><s style="display:none">^</s><sup>' .. |
'</span></span><s style="display:none">^</s><sup>' .. |
||
from_en(tostring(engscale.exponent)) .. '</sup>' |
from_en(tostring(engscale.exponent)) .. '</sup>' |
||
elseif number_word then |
elseif number_word then |
||
local number_id |
local number_id |