-- dead code, remove from /sandbox
local tX100DEV =
{
['H1'] = 'Physical hazards',
['H2'] = 'Health hazards',
['H3'] = 'Environmental hazards',
['P1'] = 'General precautionary statements',
['P2'] = 'Prevention precautionary statements',
['P3'] = 'Response precautionary statements',
['P4'] = 'Storage precautionary statements',
['P5'] = 'Disposal precautionary statements'
}
--------------------------------------------------------------------------------
-- test2DEV current range
--------------------------------------------------------------------------------
function r.test2DEV(frame)
local tArgs = getArgs(frame)
local min, max, ccRange
ccRange = tArgs['range']
min = string.match(ccRange, '^([PH][%d%+A-Za-z]*)-') or 'Nil'
max = string.match(ccRange, '-([PH][%d%+A-Za-z]*)$') or 'Nil'
return 'test2: ' .. ccRange .. ' MIN:' .. min .. ' MAX:' .. max
end
--------------------------------------------------------------------------------
-- listRangeDEV
--
-- listtypes: all + tablerow x col + pipedlist
-- range = H330-H399 min-max (inclde 401-330-402 !)
-- range = single only [AND/OR]
-- range = all
-- range = min-max
-- has ellipses (=wordtype)
-- X100 group headers H123, P12345
--------------------------------------------------------------------------------
function r.listRangeDEV(frame) -- DEV
local tArgs = getArgs(frame)
local tL = {}
local t2 = {} -- from listAll orig: wellordered
-- PARAMS setid, Rmin, Rmax, Rform
prepareArgsAndCodes(tArgs)
---- setid?; later more
tArgs.Range = 'H300-H350'
-- -- range = todo ellipses, X100, multi/single H/P/all
local range = {}
range.range, range.min, range.max = getRangeMinMax(tArgs.Range)
-- -- DEV: range parameter
if isDebug then
return range.range .. ' |min=' .. range.min .. ' max=' .. range.max
else
return '' -- DEV only
end
-- SOURCE table tGHSdata (H/P GHSdata table)
local tGHSdata
tGHSdata = GHSdata['GHSphrases']
if tArgName.setid == '' then -- ?
-- no setid; -- when when setid=X?
errorSetidOrCode('ERR901', listRangeDEV)
return 'ERR901 List range: setid missing: ' .. tArgName.setid .. ' ' .. showTailMsgsCats()
end
-- ORDERED RANGE: t2 { i, code }; pairs not ipairs -- (from listAll 28-11 7:00)
local t2 = {}
for s, v in pairs(tGHSdata) do
table.insert(t2, s)
end
t2 = tTools.compressSparseArray(t2)
table.sort(t2) -- required
-- STRUCT TABLE t3 (ordered, has data on code number)
-- suffix 1=from 1st table (GHSdata); 2=from t2 (ordered);
local t3 = {}
local numC, countC, phrase1
local hasEllipses = ''
local multiC -- C2, C3, C4
local trip
local withPhrase = true
for i2, c2 in pairs(t2) do -- value=phrase: ignored for now,
countC = 0
multiC = {}
local iterator = mw.ustring.gmatch(c2, '%d%d%d') -- todo not [HP] ???
for codeN in iterator do
countC = countC + 1
if countC == 1 then
numC = getNumberFromC(codeN)
else -- other codes (not num)
table.insert(multiC, countC - 1, codeN)
end
end
if withPhrase then
phrase1 = tGHSdata[c2]
hasEllipses = string.match(phrase1, '%.%.%.') or false
end
trip = {c2, numC, table.concat(multiC, ', '), countC, i2, tostring(yesno(hasEllipses, true)), phrase1}
table.insert(t3, trip)
if i2 > 20 then
break
end
end
t3 = tTools.compressSparseArray(t3)
-- LIST t33
local t33 = {}
for i3, tV in ipairs(t3) do
table.insert(t33, table.concat(unpack(t3, i3), '; '))
end
return 't33:' .. tTools.size(t3) .. ' \n ' .. table.concat(t33, ' \n ')
end
--------------------------------------------------------------------------------
-- H300-H340 into min, max
--------------------------------------------------------------------------------
local function getRangeMinMax(ccRange)
local c
c = mw.text.decode(ccRange)
c = mw.ustring.gsub(c, '[%−%–]', '-') -- minus, ndash
c = mw.ustring.gsub(c, '[^%d%+A-Za-z%-]', '') -- hyphen: extra for Range definition
c = mw.ustring.gsub(c, '^(%d)', tArgName.setid .. '%1')
ccRange = mw.ustring.gsub(c, '%+(%d)', '+' .. tArgName.setid .. '%1')
local min, max
min = string.match(ccRange, '^([PH][%d%+A-Za-z]*)-') or ''
max = string.match(ccRange, '-([PH][%d%+A-Za-z]*)$') or ''
return ccRange, min, max
end
return x