Skip to content
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We added ability to jump to an entry in the command line using `-j CITATIONKEY`. [koppor#540](https://github.com/koppor/jabref/issues/540)
- We added a new boolean to the style files for Openoffice/Libreoffice integration to switch between ZERO_WIDTH_SPACE (default) and no space. [#10843](https://github.com/JabRef/jabref/pull/10843)
- We added the possibility to redownload files that had been present but are no longer in the specified location. [#10848](https://github.com/JabRef/jabref/issues/10848)
- We added the citation key pattern `[camelN]`. Equivalent to the first N words of the `[camel]` pattern.

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,9 @@ 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 (pattern.matches("camel[\\d]+")) {
int num = Integer.parseInt(pattern.substring(5));
return getCamelizedTitle_N(entry.getResolvedFieldOrAlias(StandardField.TITLE, database).orElse(""), num);
} else if ("camel".equals(pattern)) {
return getCamelizedTitle(entry.getResolvedFieldOrAlias(StandardField.TITLE, database).orElse(""));
} else if ("shortyear".equals(pattern)) {
Expand Down Expand Up @@ -662,6 +665,36 @@ 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 N words.
*/
public static String getCamelizedTitle_N(String title, int number) {
return keepLettersAndDigitsOnly(camelizeTitle_N(title, number));
}

private static String camelizeTitle_N(String title, int number) {
StringBuilder stringBuilder = new StringBuilder();
String formattedTitle = formatTitle(title);

try (Scanner titleScanner = new Scanner(formattedTitle)) {
while (titleScanner.hasNext()) {
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);
}
}

String camelString = stringBuilder.toString();

return getSomeWords(number, camelString);
}

/**
* Capitalises the significant words of the "title" field in the given BibTeX entry
*/
Expand Down Expand Up @@ -704,7 +737,11 @@ public static String removeSmallWords(String title) {
private static String getTitleWordsWithSpaces(int number, String title) {
String formattedTitle = formatTitle(title);

try (Scanner titleScanner = new Scanner(formattedTitle)) {
return getSomeWords(number, formattedTitle);
}

private static String getSomeWords(int number, String string) {
try (Scanner titleScanner = new Scanner(string)) {
return titleScanner.tokens()
.limit(number)
.collect(Collectors.joining(" "));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,19 @@ void expandBracketsDoesNotTruncateWithoutAnArgumentToTruncateModifier() {
BracketedPattern.expandBrackets("[fulltitle:truncate]", ';', dbentry, database));
}

/**
* Test the [camelN] title marker.
*/
@Test
void expandBracketsCamelNTitle() {
assertEquals("Open",
BracketedPattern.expandBrackets("[camel1]", ';', dbentry, database));
assertEquals("OpenSourceSoftwareAnd",
BracketedPattern.expandBrackets("[camel4]", ';', dbentry, database));
assertEquals("OpenSourceSoftwareAndThePrivateCollectiveInnovationModelIssues",
BracketedPattern.expandBrackets("[camel10]", ';', dbentry, database));
}

@Test
void expandBracketsWithAuthorStartingWithBrackets() {
// Issue https://github.com/JabRef/jabref/issues/3920
Expand Down