+ res.prename = renormalize(prename);
+ res.prefix = renormalize(parseSurname(surname).first);
+ res.surname = renormalize(parseSurname(surname).second);
+ return res;
+}
+
+
+docstring constructName(docstring const & name, string const scheme)
+{
+ // re-constructs a name from name parts according
+ // to a given scheme
+ docstring const prename = nameParts(name).prename;
+ docstring const surname = nameParts(name).surname;
+ docstring const prefix = nameParts(name).prefix;
+ docstring const suffix = nameParts(name).suffix;
+ string res = scheme;
+ static regex const reg1("(.*)(\\{%prename%\\[\\[)([^\\]]+)(\\]\\]\\})(.*)");
+ static regex const reg2("(.*)(\\{%suffix%\\[\\[)([^\\]]+)(\\]\\]\\})(.*)");
+ static regex const reg3("(.*)(\\{%prefix%\\[\\[)([^\\]]+)(\\]\\]\\})(.*)");
+ smatch sub;
+ // Changing the first parameter of regex_match() may corrupt the
+ // second one. In this case we use the temporary string tmp.
+ if (regex_match(scheme, sub, reg1)) {
+ res = sub.str(1);
+ if (!prename.empty())
+ res += sub.str(3);
+ res += sub.str(5);
+ }
+ if (regex_match(res, sub, reg2)) {
+ string tmp = sub.str(1);
+ if (!suffix.empty())
+ tmp += sub.str(3);
+ res = tmp + sub.str(5);
+ }
+ if (regex_match(res, sub, reg3)) {
+ string tmp = sub.str(1);
+ if (!prefix.empty())
+ tmp += sub.str(3);
+ res = tmp + sub.str(5);
+ }
+ docstring result = from_ascii(res);
+ result = subst(result, from_ascii("%prename%"), prename);
+ result = subst(result, from_ascii("%surname%"), surname);
+ result = subst(result, from_ascii("%prefix%"), prefix);
+ result = subst(result, from_ascii("%suffix%"), suffix);
+ return result;
+}
+
+
+vector<docstring> const getAuthors(docstring const & author)
+{
+ // We check for goupings (via {...}) and only consider " and "
+ // outside groups as author separator. This is to account
+ // for cases such as {{Barnes and Noble, Inc.}}, which
+ // need to be treated as one single family name.
+ // We use temporary placeholders in order to differentiate the
+ // diverse " and " cases.
+
+ // First, we temporarily replace all ampersands. It is rather unusual
+ // in author names, but can happen (consider cases such as "C \& A Corp.").
+ docstring iname = subst(author, from_ascii("&"), from_ascii("$$amp!"));
+ // Then, we temporarily make all " and " strings to ampersands in order
+ // to handle them later on a per-char level.
+ iname = subst(iname, from_ascii(" and "), from_ascii(" & "));
+ // Now we traverse through the string and replace the "&" by the proper
+ // output in- and outside groups
+ docstring name;
+ int gl = 0;
+ docstring::const_iterator p = iname.begin();
+ while (p != iname.end()) {
+ // count grouping level
+ if (*p == '{')
+ ++gl;
+ else if (*p == '}')
+ --gl;
+ // generate string with probable placeholders
+ if (*p == '&') {
+ if (gl > 0)
+ // Inside groups, we output "and"
+ name += from_ascii("and");
+ else
+ // Outside groups, we output a separator
+ name += from_ascii("$$namesep!");
+ }
+ else
+ name += *p;
+ ++p;
+ }
+
+ // re-insert the literal ampersands
+ name = subst(name, from_ascii("$$amp!"), from_ascii("&"));
+
+ // Now construct the actual vector
+ return getVectorFromString(name, from_ascii(" $$namesep! "));
+}
+
+
+bool multipleAuthors(docstring const author)
+{
+ return getAuthors(author).size() > 1;