Skip to content

Commit 2d38367

Browse files
committed
fmt, handle \r\n correctly in bibtex
1 parent 32c629a commit 2d38367

3 files changed

Lines changed: 11 additions & 10 deletions

File tree

crates/engine_bibtex/bibtex/bibtex.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,16 @@ input_ln(peekable_input_t *peekable)
529529
buffer[last] = peekable_getc(peekable);
530530
last++;
531531
}
532+
533+
// For side effects - consume the eoln we saw
534+
int eoln = peekable_getc(peekable);
532535

533-
peekable_getc(peekable);
536+
// Handle \r\n newlines on Windows by trying to consume a \n after a \r, unget if it's not that exact pair
537+
int next = peekable_getc(peekable);
538+
printf("Next Char: %d\n", next);
539+
if (!(eoln == '\r' && next == '\n')) {
540+
peekable_ungetc(peekable, next);
541+
}
534542

535543
while (last > 0) {
536544
if (lex_class[buffer[last - 1]] == 1 /*white_space */ )

tests/bibtex.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ struct TestCase {
2222
}
2323

2424
impl TestCase {
25-
fn new(
26-
stem: &str,
27-
subdir: Option<&str>,
28-
) -> Self {
25+
fn new(stem: &str, subdir: Option<&str>) -> Self {
2926
TestCase {
3027
stem: stem.to_owned(),
3128
subdir: subdir.map(String::from),
@@ -94,9 +91,7 @@ fn single_entry() {
9491

9592
#[test]
9693
fn test_empty_files() {
97-
TestCase::new("empty", Some("empty"))
98-
.test_bbl(false)
99-
.go()
94+
TestCase::new("empty", Some("empty")).test_bbl(false).go()
10095
}
10196

10297
#[test]

tests/util/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,6 @@ impl ExpectedInfo {
166166
}
167167

168168
pub fn test_data(&self, observed: &[u8]) {
169-
println!("Expected:\n{:?}", self.contents);
170-
println!("Observed:\n{observed:?}");
171169
if self.contents == observed {
172170
return;
173171
}

0 commit comments

Comments
 (0)