Skip to content

Commit 56f45e5

Browse files
New work
1 parent 20124a0 commit 56f45e5

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

src/classifier.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,13 @@ impl<'a> CsvClassifier<'a> {
8484

8585
let mut temp = [0u8; 16];
8686
temp[..slice.len()].copy_from_slice(slice);
87-
87+
88+
let last = self.data[self.data.len() - 1];
89+
90+
if last != 0x0A && last != 0x0D {
91+
temp[slice.len()] = 0x0A;
92+
}
93+
8894
(u8x16::from_slice_unchecked(&temp), false)
8995
}
9096
}
@@ -115,11 +121,11 @@ mod tests {
115121
QUOTATION_CLASS,
116122
0,
117123
QUOTATION_CLASS,
124+
WHITESPACE_CLASS, // we always add a \n at the end
118125
0,
119126
0,
120127
0,
121128
0,
122-
0
123129
]
124130
);
125131
}

src/reader.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,14 @@ impl CsvReader {
8080
if first_whitespace < first_comma {
8181
rows.push(Row::from(current_row.clone()));
8282
current_row.clear();
83-
break;
8483
}
8584

8685
bitset_cursor += bits_traveled + 1;
8786
valid_commas <<= bits_traveled + 1;
8887
valid_whitespace <<= bits_traveled + 1;
8988
}
9089
}
91-
90+
9291
Ok(rows)
9392
}
9493
}
@@ -152,7 +151,7 @@ mod tests {
152151

153152
#[test]
154153
fn read_basic() -> Result<()> {
155-
let data = b"aaa,bbb,ccc\n";
154+
let data = b"aaa,bbb,ccc";
156155

157156
check_line(
158157
data,
@@ -168,7 +167,7 @@ mod tests {
168167

169168
#[test]
170169
fn read_basic2() -> Result<()> {
171-
let data = b"aaa,\"bbb\",ccc\n";
170+
let data = b"aaa,\"bbb\",ccc";
172171

173172
check_line(
174173
data,
@@ -184,7 +183,7 @@ mod tests {
184183

185184
#[test]
186185
fn read_nested() -> Result<()> {
187-
let data = b"\"aaa,howdy\",\"b\"\"bb\",\"ccc\"\n";
186+
let data = b"\"aaa,howdy\",\"b\"\"bb\",\"ccc\"";
188187

189188
check_line(
190189
data,
@@ -198,18 +197,9 @@ mod tests {
198197
Ok(())
199198
}
200199

201-
// #[test]
202-
// fn read_nested2() -> Result<()> {
203-
// let data = b"aaa,\"b\"\"\"\n";
204-
//
205-
// check_line(data, vec![vec!["aaa".to_string(), "\"b\"\"\"".to_string()]])?;
206-
//
207-
// Ok(())
208-
// }
209-
210200
#[test]
211201
fn read_newline_field() -> Result<()> {
212-
let data = b"\"aaa,ho\nwdy\",\"b\"\"bb\",\"ccc\"\n";
202+
let data = b"\"aaa,ho\nwdy\",\"b\"\"bb\",\"ccc\"";
213203

214204
check_line(
215205
data,
@@ -225,7 +215,7 @@ mod tests {
225215

226216
#[test]
227217
fn read_crlf_field() -> Result<()> {
228-
let data = b"\"aaa,ho\r\nwdy\",\"b\"\"bb\",\"ccc\"\n";
218+
let data = b"\"aaa,ho\r\nwdy\",\"b\"\"bb\",\"ccc\"";
229219

230220
check_line(
231221
data,
@@ -241,8 +231,8 @@ mod tests {
241231

242232
#[test]
243233
fn read_taxi_zone_lookup_header() -> Result<()> {
244-
let data = b"\"LocationID\",\"Borough\",\"Zone\",\"service_zone\"\r\n";
245-
234+
let data = b"\"LocationID\",\"Borough\",\"Zone\",\"service_zone\"\n";
235+
246236
check_line(
247237
data,
248238
vec![vec![
@@ -252,7 +242,7 @@ mod tests {
252242
r#""service_zone""#.to_string(),
253243
]],
254244
)?;
255-
245+
256246
Ok(())
257247
}
258248

0 commit comments

Comments
 (0)