@@ -178,7 +178,7 @@ public void writePartOfDatabase(Writer writer, BibDatabaseContext bibDatabaseCon
178
178
writePreamble (writer , bibDatabaseContext .getDatabase ().getPreamble ());
179
179
180
180
// Write strings if there are any.
181
- writeStrings (writer , bibDatabaseContext .getDatabase ());
181
+ writeStrings (writer , bibDatabaseContext .getDatabase (), preferences . isReformatFile () );
182
182
183
183
// Write database entries.
184
184
List <BibEntry > sortedEntries = BibDatabaseWriter .getSortedEntries (bibDatabaseContext ,
@@ -198,7 +198,7 @@ public void writePartOfDatabase(Writer writer, BibDatabaseContext bibDatabaseCon
198
198
entryType -> typesToWrite .put (entryType .getName (), entryType ));
199
199
}
200
200
201
- bibtexEntryWriter .write (entry , writer , bibDatabaseContext .getMode ());
201
+ bibtexEntryWriter .write (entry , writer , bibDatabaseContext .getMode (), preferences . isReformatFile () );
202
202
203
203
}
204
204
@@ -324,13 +324,14 @@ private void writePreamble(Writer fw, String preamble) throws IOException {
324
324
}
325
325
}
326
326
327
- private void writeString (Writer fw , BibtexString bs , Map <String , BibtexString > remaining , int maxKeyLength )
327
+ private void writeString (Writer fw , BibtexString bs , Map <String , BibtexString > remaining , int maxKeyLength ,
328
+ Boolean reformatFile )
328
329
throws IOException {
329
330
// First remove this from the "remaining" list so it can't cause problem with circular refs:
330
331
remaining .remove (bs .getName ());
331
332
332
333
//if the string has not been modified, write it back as it was
333
- if (!bs .hasChanged ()) {
334
+ if (!reformatFile && ! bs .hasChanged ()) {
334
335
fw .write (bs .getParsedSerialization ());
335
336
return ;
336
337
}
@@ -351,7 +352,7 @@ private void writeString(Writer fw, BibtexString bs, Map<String, BibtexString> r
351
352
Object referred = remaining .get (foundLabel .substring (1 , foundLabel .length () - 1 ));
352
353
// If the label we found exists as a key in the "remaining" Map, we go on and write it now:
353
354
if (referred != null ) {
354
- writeString (fw , (BibtexString ) referred , remaining , maxKeyLength );
355
+ writeString (fw , (BibtexString ) referred , remaining , maxKeyLength , reformatFile );
355
356
}
356
357
}
357
358
@@ -384,9 +385,10 @@ private void writeString(Writer fw, BibtexString bs, Map<String, BibtexString> r
384
385
*
385
386
* @param fw The Writer to send the output to.
386
387
* @param database The database whose strings we should write.
388
+ * @param reformatFile
387
389
* @throws IOException If anything goes wrong in writing.
388
390
*/
389
- private void writeStrings (Writer fw , BibDatabase database ) throws IOException {
391
+ private void writeStrings (Writer fw , BibDatabase database , Boolean reformatFile ) throws IOException {
390
392
List <BibtexString > strings = database .getStringKeySet ().stream ().map (database ::getString ).collect (
391
393
Collectors .toList ());
392
394
strings .sort (new BibtexStringComparator (true ));
@@ -402,7 +404,7 @@ private void writeStrings(Writer fw, BibDatabase database) throws IOException {
402
404
isFirstStringInType = true ;
403
405
for (BibtexString bs : strings ) {
404
406
if (remaining .containsKey (bs .getName ()) && (bs .getType () == t )) {
405
- writeString (fw , bs , remaining , maxKeyLength );
407
+ writeString (fw , bs , remaining , maxKeyLength , reformatFile );
406
408
isFirstStringInType = false ;
407
409
}
408
410
}
0 commit comments