Skip to content

Commit 6b28be1

Browse files
committed
Don't write out NULLs for the subtable column
1 parent 8612178 commit 6b28be1

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/main.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,16 @@ fn main() -> std::io::Result<()> {
215215
}
216216
else if path.len() > table.path.len() {
217217
for i in 0..table.columns.len() {
218-
if path == table.columns[i].path {
218+
if path == table.columns[i].path { // This start tag matches one of the defined columns
219+
220+
// Handle 'subtable' case (the 'cols' entry has 'cols' of its own)
219221
if table.columns[i].subtable.is_some() {
220222
tables.push(table);
221223
table = &table.columns[i].subtable.as_ref().unwrap();
222224
break;
223225
}
226+
227+
// Handle the 'attr' case where the content is read from an attribute of this tag
224228
if let Some(request) = table.columns[i].attr {
225229
for res in e.attributes() {
226230
if let Ok(attr) = res {
@@ -241,6 +245,8 @@ fn main() -> std::io::Result<()> {
241245
eprintln!("Column {} requested attribute {} not found", table.columns[i].name, request);
242246
}
243247
}
248+
249+
// Set the appropriate convert flag for the following data in case the 'conv' option is present
244250
match table.columns[i].convert {
245251
None => (),
246252
Some("xml-to-text") => xmltotext = true,
@@ -291,11 +297,16 @@ fn main() -> std::io::Result<()> {
291297
},
292298
Ok(Event::End(_)) => {
293299
if path == table.path {
300+
301+
// End tag of a subtable; write the first column value of the parent table as the first column of the subtable
294302
if !tables.is_empty() {
295303
table.write(&tables.last().unwrap().columns[0].value.borrow());
296304
table.write("\t");
297305
}
306+
307+
// Now write out the other column values
298308
for i in 0..table.columns.len() {
309+
if table.columns[i].subtable.is_some() { continue; }
299310
if i > 0 { table.write("\t"); }
300311
if table.columns[i].value.borrow().is_empty() { table.write("\\N"); }
301312
else {

0 commit comments

Comments
 (0)