-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Fix: bibkey generated does not handle diacritics #4713
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0313b4e
Clean key in BracketedPattern after author value is retrieved
chel-seyy 7d8de04
Shift cleaning of authString to authN only
chel-seyy fa73ea0
Extract authN method
chel-seyy 03fc076
Filter unwanted characters before removing whitespaces
chel-seyy a0219f3
Update test cases
chel-seyy 89a398b
Remove -s from key
chel-seyy e3e6961
Remove the dashes from test case
chel-seyy f414a96
Rename method to removeUnwantedCharacters
chel-seyy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,6 +92,10 @@ public String expand(BibEntry bibentry, Character keywordDelimiter, BibDatabase | |
return expandBrackets(this.pattern, keywordDelimiter, bibentry, database); | ||
} | ||
|
||
public static String expandBrackets(String pattern, Character keywordDelimiter, BibEntry entry, BibDatabase database) { | ||
return expandBrackets(pattern, keywordDelimiter, entry, database, false); | ||
} | ||
|
||
/** | ||
* Expands a pattern | ||
* | ||
|
@@ -101,7 +105,7 @@ public String expand(BibEntry bibentry, Character keywordDelimiter, BibDatabase | |
* @param database The database for field resolving. May be null. | ||
* @return The expanded pattern. Not null. | ||
*/ | ||
public static String expandBrackets(String pattern, Character keywordDelimiter, BibEntry entry, BibDatabase database) { | ||
public static String expandBrackets(String pattern, Character keywordDelimiter, BibEntry entry, BibDatabase database, boolean isEnforceLegalKey) { | ||
Objects.requireNonNull(pattern); | ||
Objects.requireNonNull(entry); | ||
StringBuilder sb = new StringBuilder(); | ||
|
@@ -122,10 +126,10 @@ public static String expandBrackets(String pattern, Character keywordDelimiter, | |
// check whether there is a modifier on the end such as | ||
// ":lower": | ||
if (fieldParts.size() <= 1) { | ||
sb.append(getFieldValue(entry, token, keywordDelimiter, database)); | ||
sb.append(getFieldValue(entry, token, keywordDelimiter, database, isEnforceLegalKey)); | ||
} else { | ||
// apply modifiers: | ||
String fieldValue = getFieldValue(entry, fieldParts.get(0), keywordDelimiter, database); | ||
String fieldValue = getFieldValue(entry, fieldParts.get(0), keywordDelimiter, database, isEnforceLegalKey); | ||
sb.append(applyModifiers(fieldValue, fieldParts, 1)); | ||
} | ||
// Fetch and discard the closing ']' | ||
|
@@ -156,7 +160,7 @@ public static String expandBrackets(String pattern, Character keywordDelimiter, | |
* | ||
* @return String containing the evaluation result. Empty string if the pattern cannot be resolved. | ||
*/ | ||
public static String getFieldValue(BibEntry entry, String value, Character keywordDelimiter, BibDatabase database) { | ||
public static String getFieldValue(BibEntry entry, String value, Character keywordDelimiter, BibDatabase database, boolean isEnforceLegalKey) { | ||
|
||
String val = value; | ||
try { | ||
|
@@ -224,15 +228,8 @@ else if ("authorLast".equals(val)) { | |
return authNofMth(authString, Integer.parseInt(nums[0]), | ||
Integer.parseInt(nums[1])); | ||
} else if (val.matches("auth\\d+")) { | ||
// authN. First N chars of the first author's last | ||
// name. | ||
|
||
String fa = firstAuthor(authString); | ||
int num = Integer.parseInt(val.substring(4)); | ||
if (num > fa.length()) { | ||
num = fa.length(); | ||
} | ||
return fa.substring(0, num); | ||
return authN(authString, num, isEnforceLegalKey); | ||
} else if (val.matches("authors\\d+")) { | ||
return nAuthors(authString, Integer.parseInt(val.substring(7))); | ||
} else { | ||
|
@@ -840,6 +837,18 @@ public static String authNofMth(String authorField, int n, int m) { | |
} | ||
} | ||
|
||
/** | ||
* First N chars of the first author's last name. | ||
*/ | ||
public static String authN(String authString, int num, boolean isEnforceLegalKey) { | ||
authString = BibtexKeyGenerator.removeUnwantedCharacters(authString, isEnforceLegalKey); | ||
String fa = firstAuthor(authString); | ||
if (num > fa.length()) { | ||
num = fa.length(); | ||
} | ||
return fa.substring(0, num); | ||
} | ||
|
||
/** | ||
* authshort format: | ||
* added by Kolja Brix, [email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chelseyong Do you, by chance, remember why you introduced
-
here? We have issues with that. See #6295 for details.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is due to a suggestion made in the issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your reply. I Think, there was some misunderstanding at #4709 (comment)
We will fix it at #6300