@@ -92,6 +92,10 @@ public String expand(BibEntry bibentry, Character keywordDelimiter, BibDatabase
9292 return expandBrackets (this .pattern , keywordDelimiter , bibentry , database );
9393 }
9494
95+ public static String expandBrackets (String pattern , Character keywordDelimiter , BibEntry entry , BibDatabase database ) {
96+ return expandBrackets (pattern , keywordDelimiter , entry , database , false );
97+ }
98+
9599 /**
96100 * Expands a pattern
97101 *
@@ -101,7 +105,7 @@ public String expand(BibEntry bibentry, Character keywordDelimiter, BibDatabase
101105 * @param database The database for field resolving. May be null.
102106 * @return The expanded pattern. Not null.
103107 */
104- public static String expandBrackets (String pattern , Character keywordDelimiter , BibEntry entry , BibDatabase database ) {
108+ public static String expandBrackets (String pattern , Character keywordDelimiter , BibEntry entry , BibDatabase database , boolean isEnforceLegalKey ) {
105109 Objects .requireNonNull (pattern );
106110 Objects .requireNonNull (entry );
107111 StringBuilder sb = new StringBuilder ();
@@ -122,10 +126,10 @@ public static String expandBrackets(String pattern, Character keywordDelimiter,
122126 // check whether there is a modifier on the end such as
123127 // ":lower":
124128 if (fieldParts .size () <= 1 ) {
125- sb .append (getFieldValue (entry , token , keywordDelimiter , database ));
129+ sb .append (getFieldValue (entry , token , keywordDelimiter , database , isEnforceLegalKey ));
126130 } else {
127131 // apply modifiers:
128- String fieldValue = getFieldValue (entry , fieldParts .get (0 ), keywordDelimiter , database );
132+ String fieldValue = getFieldValue (entry , fieldParts .get (0 ), keywordDelimiter , database , isEnforceLegalKey );
129133 sb .append (applyModifiers (fieldValue , fieldParts , 1 ));
130134 }
131135 // Fetch and discard the closing ']'
@@ -156,7 +160,7 @@ public static String expandBrackets(String pattern, Character keywordDelimiter,
156160 *
157161 * @return String containing the evaluation result. Empty string if the pattern cannot be resolved.
158162 */
159- public static String getFieldValue (BibEntry entry , String value , Character keywordDelimiter , BibDatabase database ) {
163+ public static String getFieldValue (BibEntry entry , String value , Character keywordDelimiter , BibDatabase database , boolean isEnforceLegalKey ) {
160164
161165 String val = value ;
162166 try {
@@ -224,15 +228,8 @@ else if ("authorLast".equals(val)) {
224228 return authNofMth (authString , Integer .parseInt (nums [0 ]),
225229 Integer .parseInt (nums [1 ]));
226230 } else if (val .matches ("auth\\ d+" )) {
227- // authN. First N chars of the first author's last
228- // name.
229-
230- String fa = firstAuthor (authString );
231231 int num = Integer .parseInt (val .substring (4 ));
232- if (num > fa .length ()) {
233- num = fa .length ();
234- }
235- return fa .substring (0 , num );
232+ return authN (authString , num , isEnforceLegalKey );
236233 } else if (val .matches ("authors\\ d+" )) {
237234 return nAuthors (authString , Integer .parseInt (val .substring (7 )));
238235 } else {
@@ -840,6 +837,18 @@ public static String authNofMth(String authorField, int n, int m) {
840837 }
841838 }
842839
840+ /**
841+ * First N chars of the first author's last name.
842+ */
843+ public static String authN (String authString , int num , boolean isEnforceLegalKey ) {
844+ authString = BibtexKeyGenerator .removeUnwantedCharacters (authString , isEnforceLegalKey );
845+ String fa = firstAuthor (authString );
846+ if (num > fa .length ()) {
847+ num = fa .length ();
848+ }
849+ return fa .substring (0 , num );
850+ }
851+
843852 /**
844853 * authshort format:
845854 * added by Kolja Brix, [email protected]
0 commit comments