@@ -33,8 +33,7 @@ pub use types::*;
33
33
use std:: collections:: { BTreeMap , HashMap } ;
34
34
use std:: error:: Error ;
35
35
use std:: fmt;
36
- use std:: fmt:: { Display , Formatter , Write as _} ;
37
- use std:: io:: { self , Write } ;
36
+ use std:: fmt:: { Display , Formatter , Write } ;
38
37
39
38
use mechanics:: { AuthorMode , PagesChapterMode } ;
40
39
@@ -196,41 +195,45 @@ impl Bibliography {
196
195
self . entries . iter_mut ( )
197
196
}
198
197
198
+ /// Write the entry into a writer in the BibLaTeX format.
199
+ pub fn write_biblatex ( & self , mut sink : impl Write ) -> fmt:: Result {
200
+ let mut first = true ;
201
+ for entry in & self . entries {
202
+ if !first {
203
+ write ! ( sink, "\n " ) ?;
204
+ }
205
+ writeln ! ( sink, "{}" , entry. to_biblatex_string( ) ) ?;
206
+ first = false ;
207
+ }
208
+ Ok ( ( ) )
209
+ }
210
+
199
211
/// Serialize this bibliography into a BibLaTeX string.
200
212
pub fn to_biblatex_string ( & self ) -> String {
201
213
let mut biblatex = String :: new ( ) ;
202
- for entry in & self . entries {
203
- biblatex. push_str ( & entry. to_biblatex_string ( ) ) ;
204
- biblatex. push ( '\n' ) ;
205
- }
214
+ self . write_biblatex ( & mut biblatex) . unwrap ( ) ;
206
215
biblatex
207
216
}
208
217
209
- /// Write the entry into a writer in the BibLaTeX format.
210
- pub fn write_biblatex ( & self , mut sink : impl Write ) -> io:: Result < ( ) > {
218
+ /// Write the entry into a writer in the BibTeX format.
219
+ pub fn write_bibtex ( & self , mut sink : impl Write ) -> fmt:: Result {
220
+ let mut first = true ;
211
221
for entry in & self . entries {
212
- writeln ! ( sink, "{}" , entry. to_biblatex_string( ) ) ?;
222
+ if !first {
223
+ write ! ( sink, "\n " ) ?;
224
+ }
225
+ writeln ! ( sink, "{}" , entry. to_bibtex_string( ) ) ?;
226
+ first = false ;
213
227
}
214
228
Ok ( ( ) )
215
229
}
216
230
217
231
/// Serialize this bibliography into a BibTeX string.
218
232
pub fn to_bibtex_string ( & self ) -> String {
219
233
let mut bibtex = String :: new ( ) ;
220
- for entry in & self . entries {
221
- bibtex. push_str ( & entry. to_bibtex_string ( ) ) ;
222
- bibtex. push ( '\n' ) ;
223
- }
234
+ self . write_bibtex ( & mut bibtex) . unwrap ( ) ;
224
235
bibtex
225
236
}
226
-
227
- /// Write the entry into a writer in the BibTeX format.
228
- pub fn write_bibtex ( & self , mut sink : impl Write ) -> io:: Result < ( ) > {
229
- for entry in & self . entries {
230
- writeln ! ( sink, "{}" , entry. to_bibtex_string( ) ) ?;
231
- }
232
- Ok ( ( ) )
233
- }
234
237
}
235
238
236
239
impl IntoIterator for Bibliography {
0 commit comments