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

Content deleted Content added
repair
transform_author_abbrevs
Line 20:
-- [[d:Property:P428#P1793]]
-- ('t )?(d')?(de )?(la )?(van (der )?)?(Ma?c)?(De)?(Di)?\p{Lu}?C?['\p{Ll}]*([-'. ]*(van )?(y )?(d[ae][nr]?[- ])?(Ma?c)?[\p{Lu}bht]?C?['\p{Ll}]*)*\.? ?f?\.?
function p.is_author_citationfind_end_of_author_citation(str, i, j)
local pos = i or 1
pos = advance_by_prefixes(str, {
Line 35:
pos = advance_pos_if_starts_with(str, "%.? ?f?%.?", pos)
returnif pos ==and (not j or mw.ustring.len(str)pos +<= 1j) then
return pos
end
end
 
-- Does not attempt to validate form of author citation. Returns successfully if
-- the citation is composed of valid author citations separated by
-- single commas, parentheses, or ampersands with optional whitespace around
-- them.
function p.transform_author_abbrevs(citation, func)
local pos = 1
while i < mw.ustring.len(citation) do
pos = advance_pos_if_starts_with(citation, "%s*[(),&]%s*", pos)
local author_end = find_end_of_author_citation(str, pos)
if not author_end then
return nil
end
local before_author, author, after_author =
mw.ustring.sub(citation, 1, pos - 1),
mw.ustring.sub(citation, pos, author_end),
mw.ustring.sub(citation, author_end + 1)
author = func(author) or author
pos = pos + mw.ustring.len(author)
citation = before_author .. author .. after_author
end
if pos == mw.ustring.len(citation) + 1 then
return citation
end
end