Module:Sandbox/Erutuon/author citation: Difference between revisions

Content deleted Content added
m I mean avoid ending author abbreviation
try array-based output (efficiency difference not noticeable), reject input if two author citations are found in a row (if that's possible)
Line 51:
function p.transform_author_abbrevs(citation, func)
local pos = 1
local output = {}
while pos < mw.ustring.len(citation) do
local remaining = citation
pos = advance_pos_if_starts_with(citation, "%s*[(),&]%s*", pos)
while #remaining > 0 do
local author_end = p.find_end_of_author_citation(citation, pos)
local orig_pos = pos
pos = advance_pos_if_starts_with(citationremaining, "%s*[(),&]%s*", pos)
if orig_pos == pos and #output > 0 then
return nil
end
local author_end = p.find_end_of_author_citation(citationremaining, pos)
if not author_end then
return nil
end
local author = mw.ustring.sub(citationremaining, pos, author_end),
local before_author, author, after_author =
table.insert(output, mw.ustring.sub(citationremaining, 1, pos - 1),)
author =table.insert(output, func(author) or author)
mw.ustring.sub(citation, pos, author_end),
remaining = mw.ustring.sub(citationremaining, author_end + 1)
pos = 1
author = func(author) or author
pos = pos + mw.ustring.len(author)
citation = before_author .. author .. after_author
end
if posremaining == mw.ustring.len(citation) + 1"" then
return citationtable.concat(output)
end
end