a little more work

This commit is contained in:
John Cupitt 2020-02-10 20:31:45 +00:00
parent 2d14554e44
commit 51d0e8b79c

View File

@ -110,7 +110,7 @@ vips_foreign_load_csv_get_flags( VipsForeignLoad *load )
/* Skip to the start of the next block of non-whitespace. /* Skip to the start of the next block of non-whitespace.
* *
* FIXME ... we should have something to stop \n appearing in whitespace * FIXME ... we should have something to stop \n appearing in whitemap
*/ */
static int static int
vips_foreign_load_csv_skip_white( VipsForeignLoadCsv *csv ) vips_foreign_load_csv_skip_white( VipsForeignLoadCsv *csv )
@ -129,10 +129,10 @@ vips_foreign_load_csv_skip_white( VipsForeignLoadCsv *csv )
} }
/* We have just seen " (open quotes). Skip to just after the matching close /* We have just seen " (open quotes). Skip to just after the matching close
* quotes. * quotes.
* *
* If there is no matching close quotes before the end of the line, don't * If there is no matching close quotes before the end of the line, don't
* skip to the next line. * skip to the next line.
*/ */
static int static int
vips_foreign_load_csv_skip_quoted( VipsForeignLoadCsv *csv ) vips_foreign_load_csv_skip_quoted( VipsForeignLoadCsv *csv )
@ -142,7 +142,7 @@ vips_foreign_load_csv_skip_quoted( VipsForeignLoadCsv *csv )
do { do {
ch = VIPS_SBUF_GETC( csv->sbuf ); ch = VIPS_SBUF_GETC( csv->sbuf );
/* Ignore \" in strings. /* Ignore \" (actually \anything) in strings.
*/ */
if( ch == '\\' ) if( ch == '\\' )
ch = VIPS_SBUF_GETC( csv->sbuf ); ch = VIPS_SBUF_GETC( csv->sbuf );
@ -157,8 +157,8 @@ vips_foreign_load_csv_skip_quoted( VipsForeignLoadCsv *csv )
return( ch ); return( ch );
} }
/* Fetch the next item, as a string. The string is valid until the next call /* Fetch the next item (not whitespace, separator or \n), as a string. The
* to fetch item. * returned string is valid until the next call to fetch item. NULL for EOF.
*/ */
static const char * static const char *
vips_foreign_load_csv_fetch_item( VipsForeignLoadCsv *csv ) vips_foreign_load_csv_fetch_item( VipsForeignLoadCsv *csv )
@ -167,8 +167,10 @@ vips_foreign_load_csv_fetch_item( VipsForeignLoadCsv *csv )
int space_remaining; int space_remaining;
int ch; int ch;
/* -1 so there's space for the \0 terminator.
*/
space_remaining = MAX_ITEM_SIZE - 1;
write_point = 0; write_point = 0;
space_remaining = MAX_ITEM_SIZE;
while( (ch = VIPS_SBUF_GETC( csv->sbuf )) != -1 && while( (ch = VIPS_SBUF_GETC( csv->sbuf )) != -1 &&
ch != '\n' && ch != '\n' &&
@ -188,18 +190,20 @@ vips_foreign_load_csv_fetch_item( VipsForeignLoadCsv *csv )
return( NULL ); return( NULL );
/* If we filled the item buffer without seeing the end of the item, /* If we filled the item buffer without seeing the end of the item,
* keep going. * read up to the item end.
*/ */
if( space_remaining == 0 && while( ch != -1 &&
ch != '\n' && ch != '\n' &&
!csv->whitemap[ch] && !csv->whitemap[ch] &&
!csv->sepmap[ch] ) { !csv->sepmap[ch] )
while( (ch = VIPS_SBUF_GETC( sbuf )) != -1 && ch = VIPS_SBUF_GETC( csv->sbuf );
ch != '\n' &&
!csv->whitemap[ch] && /* We've (probably) read the end of item character. Push it bakc.
!csv->sepmap[ch] ) */
; if( ch == '\n' ||
} csv->whitemap[ch] ||
csv->sepmap[ch] )
VIPS_SBUF_UNGETC( csv->sbuf );
return( csv->item ); return( csv->item );
} }