cvs: php3 /functions file.c

From: Date: Thu, 14 Dec 2000 14:41:53 +0000
Subject: cvs: php3 /functions file.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-3152@lists.php.net to get a copy of this message
hholzgra Thu Dec 14 06:41:53 2000 EDT Modified files: /php3/functions file.c Log: fgetcsv() will now work correct with empty fields in tab delimited files # fix for bug #8258 Index: php3/functions/file.c diff -u php3/functions/file.c:1.233 php3/functions/file.c:1.234 --- php3/functions/file.c:1.233 Wed Sep 27 09:15:07 2000 +++ php3/functions/file.c Thu Dec 14 06:41:52 2000 @@ -26,7 +26,7 @@ | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | +----------------------------------------------------------------------+ */ -/* $Id: file.c,v 1.233 2000/09/27 16:15:07 sas Exp $ */ +/* $Id: file.c,v 1.234 2000/12/14 14:41:52 hholzgra Exp $ */ #include "php.h" #include <stdio.h> @@ -1489,7 +1489,7 @@ /* }}} */ -/* {{{ proto array fgetcsv(int fp, int length) +/* {{{ proto array fgetcsv(int fp, int length [, string delimiter]) Get line from file pointer and parse for CSV fields */ void php3_fgetcsv(INTERNAL_FUNCTION_PARAMETERS) { char *temp, *tptr, *bptr; @@ -1562,7 +1562,7 @@ lineEnd = emalloc(sizeof(char) * (len + 1)); bptr = buf; tptr = buf + strlen(buf) -1; - while ( isspace(*tptr) && (tptr > bptr) ) tptr--; + while ( isspace(*tptr) && (*tptr!=delimiter) && (tptr > bptr) ) tptr--; tptr++; strcpy(lineEnd, tptr); @@ -1588,7 +1588,7 @@ do { /* 1. Strip any leading space */ - while(isspace(*bptr)) bptr++; + while(isspace(*bptr) && (*bptr!=delimiter)) bptr++; /* 2. Read field, leaving bptr pointing at start of next field */ if (*bptr == '"') { /* 2A. handle quote delimited field */ @@ -1622,7 +1622,7 @@ } bptr = buf; tptr = buf + strlen(buf) -1; - while ( isspace(*tptr) && (tptr > bptr) ) tptr--; + while ( isspace(*tptr) && (*tptr!=delimiter) && (tptr > bptr) ) tptr--; tptr++; strcpy(lineEnd, tptr); *tptr++ = ' '; *tptr = 0; @@ -1637,7 +1637,7 @@ *tptr=0; /* terminate temporary string */ if (strlen(temp)) { tptr--; - while (isspace(*tptr)) *tptr-- = 0; /* strip any trailing spaces */ + while (isspace(*tptr) && (*tptr!=delimiter)) *tptr-- = 0; /* strip any trailing spaces */ } if (*bptr == delimiter) bptr++;

« previous php.cvs (#3152) next »