Module:Convert: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
(update from sandbox per Template talk:Convert#Module version 20) |
(update from sandbox per Template talk:Convert#Module version 23) |
||
Line 1,613: | Line 1,613: | ||
-- p2 is text to insert before the output unit |
-- p2 is text to insert before the output unit |
||
-- p1 or p2 may be nil to mean "no preunit" |
-- p1 or p2 may be nil to mean "no preunit" |
||
-- Using '+ |
-- Using '+' gives output like "5+ feet" (no space before, but space after). |
||
local function withspace(text, |
local function withspace(text, wantboth) |
||
-- |
-- Return text with space before and, if wantboth, after. |
||
-- However, no space is |
-- However, no space is added if there is a space 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). |
|||
⚫ | |||
local char = text:sub(1, 1) |
|||
⚫ | |||
return text -- an html entity can be used to specify the exact display |
|||
end |
end |
||
if |
if not (char == ' ' or char == '-' or char == '+') then |
||
text = ' ' .. text |
|||
⚫ | |||
current = text:sub(-6, -1) |
|||
end |
end |
||
if |
if wantboth then |
||
char = text:sub(-1, -1) |
|||
if not (char == ' ' or char == '-' or text:sub(-6, -1) == ' ') then |
|||
⚫ | |||
⚫ | |||
end |
end |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end |
end |
||
local PLUS = '+ ' |
|||
preunit1 = preunit1 or '' |
preunit1 = preunit1 or '' |
||
local trim1 = strip(preunit1) |
local trim1 = strip(preunit1) |
||
Line 1,641: | Line 1,642: | ||
return nil |
return nil |
||
end |
end |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end |
end |
||
preunit1 = withspace(preunit1) |
|||
preunit2 = preunit2 or '' |
preunit2 = preunit2 or '' |
||
local trim2 = strip(preunit2) |
local trim2 = strip(preunit2) |
||
if trim1 == ' |
if trim1 == '+' then |
||
⚫ | |||
⚫ | |||
return PLUS, PLUS |
|||
⚫ | |||
end |
|||
⚫ | |||
preunit1 = |
preunit1 = PLUS |
||
end |
end |
||
if trim2 == ' |
if trim2 == '' then |
||
if trim1 == '' then |
|||
return nil, nil |
|||
elseif trim2 == '' then |
|||
end |
|||
preunit2 = preunit1 |
preunit2 = preunit1 |
||
elseif trim2 |
elseif trim2 == '+' then |
||
preunit2 = |
preunit2 = PLUS |
||
elseif trim2 == ' ' then -- trick to make preunit2 empty |
|||
preunit2 = nil |
|||
⚫ | |||
preunit2 = withspace(preunit2) |
|||
end |
end |
||
return preunit1, preunit2 |
return preunit1, preunit2 |
||
Line 2,241: | Line 2,251: | ||
else |
else |
||
parms.precision = precision |
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 |
end |
||
return true, in_unit_table |
return true, in_unit_table |
||
Line 3,197: | Line 3,214: | ||
return preunit .. id1 |
return preunit .. id1 |
||
end |
end |
||
if parms.opt_also_symbol and not composite then |
if parms.opt_also_symbol and not composite and not parms.opt_flip then |
||
local join1 = parms.joins[1] |
local join1 = parms.joins[1] |
||
if join1 == ' (' or join1 == ' [' then |
if join1 == ' (' or join1 == ' [' then |