Module:Citation/CS1/Utilities: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
No edit summary |
No edit summary |
||
Line 147: | Line 147: | ||
end |
end |
||
return value, selected; -- return newly selected alias, or previously selected alias |
return value, selected; -- return newly selected alias, or previously selected alias |
||
end |
|||
--[[--------------------------< S E L E C T _ O N E >---------------------------------------------------------- |
|||
Chooses one matching parameter from a list of parameters to consider. The list of parameters to consider is just |
|||
names. For parameters that may be enumerated, the position of the numerator in the parameter name is identified |
|||
by the '#' so |author-last1= and |author1-last= are represented as 'author-last#' and 'author#-last'. |
|||
Because enumerated parameter |<param>1= is an alias of |<param>= we must test for both possibilities. |
|||
Generates an error if more than one match is present. |
|||
]] |
|||
local function select_one( args, aliases_list, error_condition, index ) |
|||
local value = nil; -- the value assigned to the selected parameter |
|||
local selected = ''; -- the name of the parameter we have chosen |
|||
local error_list = {}; |
|||
if index ~= nil then index = tostring(index); end |
|||
for _, alias in ipairs( aliases_list ) do -- for each alias in the aliases list |
|||
if alias:match ('#') then -- if this alias can be enumerated |
|||
if '1' == index then -- when index is 1 test for enumerated and non-enumerated aliases |
|||
value, selected = is_alias_used (args, alias, index, false, value, selected, error_list); -- first test for non-enumerated alias |
|||
end |
|||
value, selected = is_alias_used (args, alias, index, true, value, selected, error_list); -- test for enumerated alias |
|||
else |
|||
value, selected = is_alias_used (args, alias, index, false, value, selected, error_list); --test for non-enumerated alias |
|||
end |
|||
end |
|||
if #error_list > 0 and 'none' ~= error_condition then -- for cases where this code is used outside of extract_names() |
|||
local error_str = ""; |
|||
for _, k in ipairs( error_list ) do |
|||
if error_str ~= "" then error_str = error_str .. cfg.messages['parameter-separator'] end |
|||
error_str = error_str .. wrap_style ('parameter', k); |
|||
end |
|||
if #error_list > 1 then |
|||
error_str = error_str .. cfg.messages['parameter-final-separator']; |
|||
else |
|||
error_str = error_str .. cfg.messages['parameter-pair-separator']; |
|||
end |
|||
error_str = error_str .. wrap_style ('parameter', selected); |
|||
table.insert( z.message_tail, { set_error( error_condition, {error_str}, true ) } ); |
|||
end |
|||
return value, selected; |
|||
end |
end |
||
Line 256: | Line 206: | ||
return substitute( cfg.presentation[key], {str} ); |
return substitute( cfg.presentation[key], {str} ); |
||
end |
end |
||
--[[--------------------------< S E L E C T _ O N E >---------------------------------------------------------- |
|||
Chooses one matching parameter from a list of parameters to consider. The list of parameters to consider is just |
|||
names. For parameters that may be enumerated, the position of the numerator in the parameter name is identified |
|||
by the '#' so |author-last1= and |author1-last= are represented as 'author-last#' and 'author#-last'. |
|||
Because enumerated parameter |<param>1= is an alias of |<param>= we must test for both possibilities. |
|||
Generates an error if more than one match is present. |
|||
]] |
|||
local function select_one( args, aliases_list, error_condition, index ) |
|||
local value = nil; -- the value assigned to the selected parameter |
|||
local selected = ''; -- the name of the parameter we have chosen |
|||
local error_list = {}; |
|||
if index ~= nil then index = tostring(index); end |
|||
for _, alias in ipairs( aliases_list ) do -- for each alias in the aliases list |
|||
if alias:match ('#') then -- if this alias can be enumerated |
|||
if '1' == index then -- when index is 1 test for enumerated and non-enumerated aliases |
|||
value, selected = is_alias_used (args, alias, index, false, value, selected, error_list); -- first test for non-enumerated alias |
|||
end |
|||
value, selected = is_alias_used (args, alias, index, true, value, selected, error_list); -- test for enumerated alias |
|||
else |
|||
value, selected = is_alias_used (args, alias, index, false, value, selected, error_list); --test for non-enumerated alias |
|||
end |
|||
end |
|||
if #error_list > 0 and 'none' ~= error_condition then -- for cases where this code is used outside of extract_names() |
|||
local error_str = ""; |
|||
for _, k in ipairs( error_list ) do |
|||
if error_str ~= "" then error_str = error_str .. cfg.messages['parameter-separator'] end |
|||
error_str = error_str .. wrap_style ('parameter', k); |
|||
end |
|||
if #error_list > 1 then |
|||
error_str = error_str .. cfg.messages['parameter-final-separator']; |
|||
else |
|||
error_str = error_str .. cfg.messages['parameter-pair-separator']; |
|||
end |
|||
error_str = error_str .. wrap_style ('parameter', selected); |
|||
table.insert( z.message_tail, { set_error( error_condition, {error_str}, true ) } ); |
|||
end |
|||
return value, selected; |
|||
end |
|||