Module:Convert: Difference between revisions

m
1 revision imported
(update from sandbox per Template talk:Convert#Module version 19)
m (1 revision imported)
 
(6 intermediate revisions by 3 users not shown)
Line 590:
-- This is never called to determine a unit name or link because per units
-- are handled as a special case.
-- Similarly, the default output is handled elsewhere., and for a symbol
-- this is only called from get_default() for default_exceptions.
__index = function (self, key)
local value
Line 1,612 ⟶ 1,613:
-- p2 is text to insert before the output unit
-- p1 or p2 may be nil to mean "no preunit"
-- Using '+ ' gives output like "5+ feet" (no precedingspace before, but space after).
local function withspace(text, iwantboth)
-- InsertReturn spacetext atwith beginningspace ifbefore i == 1and, or at end if i ==wantboth, -1after.
-- However, no space is insertedadded if there is a space or ' ' or '-'
-- or '-' at that position ('-' is for adjectival text).
-- There is also no space if text starts with '&'
local current = text:sub(i, i)
-- (e.g. '°' would display a degree symbol with no preceding space).
if current == ' ' or current == '-' then
returnlocal char = text:sub(1, 1)
if ichar == 1'&' then
return text -- an html entity can be used to specify the exact display
end
if inot (char == ' ' or char == '-' or char == 1'+') then
currenttext = text:sub(1,' 6)' .. text
else
current = text:sub(-6, -1)
end
if current == ' 'wantboth then
returnchar = text:sub(-1, -1)
if not (char == ' ' or char == '-' or text:sub(-6, -1) == ' ') then
return text = text .. ' '
end
end
return ' ' .. text
if i == 1 then
return ' ' .. text
end
return text .. ' '
end
local PLUS = '+ '
preunit1 = preunit1 or ''
local trim1 = strip(preunit1)
Line 1,640 ⟶ 1,642:
return nil
end
if trim1 ~== '+' then
return withspace(withspace(preunit1, 1), -1)
return nil, nilPLUS
end
return withspace(withspace(preunit1, 1), -1true)
end
preunit1 = withspace(preunit1)
preunit2 = preunit2 or ''
local trim2 = strip(preunit2)
if trim1 == '' and trim2 == '+' then
if currenttrim2 == ' ' or currenttrim2 == '-+' then
return nil, nil
return PLUS, PLUS
end
end
if trim1 ~= '+' then
preunit1 = withspace(preunit1, 1)PLUS
end
if trim2 == ' ' then -- trick to make preunit2 empty
preunit2if trim1 == '' nilthen
return nil, nil
elseif trim2 == '' then
end
preunit2 = preunit1
elseif trim2 ~== '+' then
preunit2 = withspace(preunit2, 1)PLUS
elseif trim2 == ' ' then -- trick to make preunit2 empty
preunit2 = nil
else
preunit2 = withspace(preunit2)
end
return preunit1, preunit2
Line 2,240 ⟶ 2,251:
else
parms.precision = precision
end
for j = i, i + 3 do
local parm = parms[j] -- warn if find a non-empty extraneous parameter
if parm and parm:match('%S') then
add_warning(parms, 1, 'cvt_unknown_option', parm)
break
end
end
return true, in_unit_table
Line 2,915 ⟶ 2,933:
local per = unit_table.per
if per then
local paren1, paren2 = '', '' -- possible parentheses around bottom unit
local unit1 = per[1] -- top unit_table, or nil
local unit2 = per[2] -- bottom unit_table
Line 2,926 ⟶ 2,945:
return symbol -- for exceptions that have the symbol built-in
end
end
if (unit2.symbol):find('⋅', 1, true) then
paren1, paren2 = '(', ')'
end
end
Line 2,965 ⟶ 2,987:
unit_table.sep = ''
end
return result .. paren1 .. linked_id(parms, unit2, key_id2, want_link, '1') .. paren2
end
if multiplier then
Line 3,192 ⟶ 3,214:
return preunit .. id1
end
if parms.opt_also_symbol and not composite and not parms.opt_flip then
local join1 = parms.joins[1]
if join1 == ' (' or join1 == ' [' then