+-- (Internal function)
+-- Initialize given parameter and coerce string into table when the parameter
+-- already exists.
+-- @param tbl Table where parameter should be created
+-- @param key Parameter name
+-- @return Always nil
+local function __initval( tbl, key )
+ if tbl[key] == nil then
+ tbl[key] = ""
+ elseif type(tbl[key]) == "string" then
+ tbl[key] = { tbl[key], "" }
+ else
+ table.insert( tbl[key], "" )
+ end
+end
+
+-- (Internal function)
+-- Append given data to given parameter, either by extending the string value
+-- or by appending it to the last string in the parameter's value table.
+-- @param tbl Table containing the previously initialized parameter value
+-- @param key Parameter name
+-- @param chunk String containing the data to append
+-- @return Always nil
+-- @see __initval
+local function __appendval( tbl, key, chunk )
+ if type(tbl[key]) == "table" then
+ tbl[key][#tbl[key]] = tbl[key][#tbl[key]] .. chunk
+ else
+ tbl[key] = tbl[key] .. chunk
+ end
+end
+
+-- (Internal function)
+-- Finish the value of given parameter, either by transforming the string value
+-- or - in the case of multi value parameters - the last element in the
+-- associated values table.
+-- @param tbl Table containing the previously initialized parameter value
+-- @param key Parameter name
+-- @param handler Function which transforms the parameter value
+-- @return Always nil
+-- @see __initval
+-- @see __appendval
+local function __finishval( tbl, key, handler )
+ if handler then
+ if type(tbl[key]) == "table" then
+ tbl[key][#tbl[key]] = handler( tbl[key][#tbl[key]] )
+ else
+ tbl[key] = handler( tbl[key] )
+ end
+ end
+end
+