use of org.jabref.model.entry.AuthorList in project jabref by JabRef.
the class NameFormatter method format.
public String format(String toFormat, String inParameters) {
AuthorList al = AuthorList.parse(toFormat);
String parameters;
if ((inParameters == null) || inParameters.isEmpty()) {
parameters = "*:*:\"{ff}{vv}{ll}{,jj} \"";
} else {
parameters = inParameters;
}
String[] cases = parameters.split("@@");
for (String aCase : cases) {
String[] formatString = aCase.split("@");
if (formatString.length < 3) {
// Error
return toFormat;
}
if ("*".equals(formatString[0])) {
return format(toFormat, al, formatString);
} else {
if (al.getNumberOfAuthors() <= Integer.parseInt(formatString[0])) {
return format(toFormat, al, formatString);
}
}
}
return toFormat;
}
use of org.jabref.model.entry.AuthorList in project jabref by JabRef.
the class OOBibStyle method createAuthorList.
private String createAuthorList(String author, int maxAuthors, String andString, String yearSep) {
Objects.requireNonNull(author);
// The String to represent authors that are not mentioned, e.g. " et al."
String etAlString = getStringCitProperty(ET_AL_STRING);
// The String to add between author names except the last two, e.g. ", ".
String authorSep = getStringCitProperty(AUTHOR_SEPARATOR);
// The String to put after the second to last author in case of three or more authors
String oxfordComma = getStringCitProperty(OXFORD_COMMA);
StringBuilder sb = new StringBuilder();
AuthorList al = AuthorList.parse(author);
if (!al.isEmpty()) {
sb.append(getAuthorLastName(al, 0));
}
if ((al.getNumberOfAuthors() > 1) && ((al.getNumberOfAuthors() <= maxAuthors) || (maxAuthors < 0))) {
int j = 1;
while (j < (al.getNumberOfAuthors() - 1)) {
sb.append(authorSep);
sb.append(getAuthorLastName(al, j));
j++;
}
if (al.getNumberOfAuthors() > 2) {
sb.append(oxfordComma);
}
sb.append(andString);
sb.append(getAuthorLastName(al, al.getNumberOfAuthors() - 1));
} else if (al.getNumberOfAuthors() > maxAuthors) {
sb.append(etAlString);
}
sb.append(yearSep);
return sb.toString();
}
use of org.jabref.model.entry.AuthorList in project jabref by JabRef.
the class OOBibStyle method getAuthorLastName.
/**
* Look up the nth author and return the proper last name for citation markers.
*
* @param al The author list.
* @param number The number of the author to return.
* @return The author name, or an empty String if inapplicable.
*/
private String getAuthorLastName(AuthorList al, int number) {
StringBuilder sb = new StringBuilder();
if (al.getNumberOfAuthors() > number) {
Author a = al.getAuthor(number);
a.getVon().filter(von -> !von.isEmpty()).ifPresent(von -> sb.append(von).append(' '));
sb.append(a.getLast().orElse(""));
}
return sb.toString();
}
use of org.jabref.model.entry.AuthorList in project jabref by JabRef.
the class BibtexNameFormatterTest method testFormatName.
@Test
public void testFormatName() {
{
AuthorList al = AuthorList.parse("Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin");
Assert.assertEquals("de~laVall{\\'e}e~PoussinCharles Louis Xavier~Joseph", BibtexNameFormatter.formatName(al.getAuthor(0), "{vv}{ll}{jj}{ff}", Assert::fail));
}
{
AuthorList al = AuthorList.parse("Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin");
Assert.assertEquals("de~la Vall{\\'e}e~Poussin, C.~L. X.~J.", BibtexNameFormatter.formatName(al.getAuthor(0), "{vv~}{ll}{, jj}{, f.}", Assert::fail));
}
{
AuthorList al = AuthorList.parse("Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin");
Assert.assertEquals("de~la Vall{\\'e}e~Poussin, C.~L. X.~J?", BibtexNameFormatter.formatName(al.getAuthor(0), "{vv~}{ll}{, jj}{, f}?", Assert::fail));
}
AuthorList al = AuthorList.parse("Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin");
Assert.assertEquals("dlVP", BibtexNameFormatter.formatName(al.getAuthor(0), "{v{}}{l{}}", Assert::fail));
assertNameFormatA("Meyer, J?", "Jonathan Meyer and Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin");
assertNameFormatB("J.~Meyer", "Jonathan Meyer and Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin");
assertNameFormatC("Jonathan Meyer", "Jonathan Meyer and Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin");
assertNameFormatA("Masterly, {\\'{E}}?", "{\\'{E}}douard Masterly");
assertNameFormatB("{\\'{E}}.~Masterly", "{\\'{E}}douard Masterly");
assertNameFormatC("{\\'{E}}douard Masterly", "{\\'{E}}douard Masterly");
assertNameFormatA("{\\\"{U}}nderwood, U?", "Ulrich {\\\"{U}}nderwood and Ned {\\~N}et and Paul {\\={P}}ot");
assertNameFormatB("U.~{\\\"{U}}nderwood", "Ulrich {\\\"{U}}nderwood and Ned {\\~N}et and Paul {\\={P}}ot");
assertNameFormatC("Ulrich {\\\"{U}}nderwood", "Ulrich {\\\"{U}}nderwood and Ned {\\~N}et and Paul {\\={P}}ot");
assertNameFormatA("Victor, P.~{\\'E}?", "Paul {\\'E}mile Victor and and de la Cierva y Codorn{\\’\\i}u, Juan");
assertNameFormatB("P.~{\\'E}. Victor", "Paul {\\'E}mile Victor and and de la Cierva y Codorn{\\’\\i}u, Juan");
assertNameFormatC("Paul~{\\'E}mile Victor", "Paul {\\'E}mile Victor and and de la Cierva y Codorn{\\’\\i}u, Juan");
}
Aggregations