Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds the ability to specify [camelN] as a title-related field marker for citation key generation #10772

Merged
merged 12 commits into from
Feb 19, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,8 @@ public static String getFieldValue(BibEntry entry, String pattern, Character key
} else if ("veryshorttitle".equals(pattern)) {
return getTitleWords(1,
removeSmallWords(entry.getResolvedFieldOrAlias(StandardField.TITLE, database).orElse("")));
} else if ("shortcamel".equals(pattern)) {
return getCamelizedTitleShort(entry.getResolvedFieldOrAlias(StandardField.TITLE, database).orElse(""));
} else if ("camel".equals(pattern)) {
return getCamelizedTitle(entry.getResolvedFieldOrAlias(StandardField.TITLE, database).orElse(""));
} else if ("shortyear".equals(pattern)) {
Expand Down Expand Up @@ -662,6 +664,37 @@ private static String camelizeTitle(String title) {
return stringBuilder.toString();
}

/**
* Capitalises and concatenates the words out of the "title" field in the given BibTeX entry, to a maximum of 7 words.
*/
public static String getCamelizedTitleShort(String title) {
return keepLettersAndDigitsOnly(camelizeTitleShort(title));
}

public static String camelizeTitleShort(String title) {
StringBuilder stringBuilder = new StringBuilder();
String formattedTitle = formatTitle(title);
int count = 0;
try (Scanner titleScanner = new Scanner(formattedTitle)) {
while (titleScanner.hasNext()) {
if (count >= 7) {break}
Siedlerchr marked this conversation as resolved.
Show resolved Hide resolved

String word = titleScanner.next();

// Camelize the word
word = word.substring(0, 1).toUpperCase(Locale.ROOT) + word.substring(1);

if (stringBuilder.length() > 0) {
stringBuilder.append(' ');
}
stringBuilder.append(word);
count += 1;
}
}

return stringBuilder.toString();
}

/**
* Capitalises the significant words of the "title" field in the given BibTeX entry
*/
Expand Down
Loading