Allow for simple conditions in name scheme.

I.e., only output a comma between last and first name if there is
a first name.
This commit is contained in:
Juergen Spitzmueller 2017-03-19 11:45:42 +01:00
parent 08500c1a7c
commit 9f4df64f23
2 changed files with 12 additions and 3 deletions

View File

@ -32,9 +32,9 @@ CiteFormat default
# Macros # Macros
# #
# Scheme of the first author in the bibliography # Scheme of the first author in the bibliography
!firstnameform %surname%, %prename% !firstnameform %surname%{%prename%[[, %prename%]]}
# Scheme of other authors in the bibliography # Scheme of other authors in the bibliography
!othernameform %surname%, %prename% !othernameform %surname%{%prename%[[, %prename%]]}
# Scheme of the first name in later parts (such as book editor) # Scheme of the first name in later parts (such as book editor)
!firstbynameform %prename% %surname% !firstbynameform %prename% %surname%
# Scheme of other authors in later parts (such as book editor) # Scheme of other authors in later parts (such as book editor)

View File

@ -151,7 +151,16 @@ docstring constructName(docstring const & name, string const scheme)
// to a given scheme // to a given scheme
docstring const prename = nameParts(name).first; docstring const prename = nameParts(name).first;
docstring const surname = nameParts(name).second; docstring const surname = nameParts(name).second;
docstring result = from_ascii(scheme); string res = scheme;
static regex const reg1("(.*)(\\{%prename%\\[\\[)([^\\]]+)(\\]\\]\\})(.*)");
smatch sub;
if (regex_match(scheme, sub, reg1)) {
res = sub.str(1);
if (!prename.empty())
res += sub.str(3);
res += sub.str(5);
}
docstring result = from_ascii(res);
result = subst(result, from_ascii("%prename%"), prename); result = subst(result, from_ascii("%prename%"), prename);
result = subst(result, from_ascii("%surname%"), surname); result = subst(result, from_ascii("%surname%"), surname);
return result; return result;