cvs: php4(php_4_0_4) /ext/standard file.c /ext/standard/tests/general_functions 004.data 004.phpt

From: Date: Thu, 14 Dec 2000 14:34:52 +0000
Subject: cvs: php4(php_4_0_4) /ext/standard file.c /ext/standard/tests/general_functions 004.data 004.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-3151@lists.php.net to get a copy of this message
hholzgra Thu Dec 14 06:34:52 2000 EDT Branch: php_4_0_4 Added files: /php4/ext/standard/tests/general_functions 004.data 004.phpt Modified files: /php4/ext/standard file.c Log: fgetcsv() will now work correct with empty fields in tab delimited files # fix for bug #8258 and regression test Index: php4/ext/standard/file.c diff -u php4/ext/standard/file.c:1.125.2.1 php4/ext/standard/file.c:1.125.2.2 --- php4/ext/standard/file.c:1.125.2.1 Thu Dec 7 11:15:02 2000 +++ php4/ext/standard/file.c Thu Dec 14 06:34:51 2000 @@ -20,7 +20,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: file.c,v 1.125.2.1 2000/12/07 19:15:02 sas Exp $ */ +/* $Id: file.c,v 1.125.2.2 2000/12/14 14:34:51 hholzgra Exp $ */ /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ @@ -1741,7 +1741,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 */ PHP_FUNCTION(fgetcsv) { @@ -1813,7 +1813,7 @@ lineEnd = emalloc(sizeof(char) * (len + 1)); bptr = buf; tptr = buf + strlen(buf) -1; - while ( isspace((int)*tptr) && (tptr > bptr) ) tptr--; + while ( isspace((int)*tptr) && (*tptr!=delimiter) && (tptr > bptr) ) tptr--; tptr++; strcpy(lineEnd, tptr); @@ -1839,7 +1839,7 @@ do { /* 1. Strip any leading space */ - while(isspace((int)*bptr)) bptr++; + while(isspace((int)*bptr) && (*bptr!=delimiter)) bptr++; /* 2. Read field, leaving bptr pointing at start of next field */ if (*bptr == '"') { /* 2A. handle quote delimited field */ @@ -1874,7 +1874,7 @@ } bptr = buf; tptr = buf + strlen(buf) -1; - while ( isspace((int)*tptr) && (tptr > bptr) ) tptr--; + while ( isspace((int)*tptr) && (*tptr!=delimiter) && (tptr > bptr) ) tptr--; tptr++; strcpy(lineEnd, tptr); *tptr++ = ' '; *tptr = 0; @@ -1889,7 +1889,7 @@ *tptr=0; /* terminate temporary string */ if (strlen(temp)) { tptr--; - while (isspace((int)*tptr)) *tptr-- = 0; /* strip any trailing spaces */ + while (isspace((int)*tptr) && (*tptr!=delimiter)) *tptr-- = 0; /* strip any trailing spaces */ } if (*bptr == delimiter) bptr++; } Index: php4/ext/standard/tests/general_functions/004.data +++ php4/ext/standard/tests/general_functions/004.data name value comment true 1 boolean true false 0 boolean false empty nothing Index: php4/ext/standard/tests/general_functions/004.phpt +++ php4/ext/standard/tests/general_functions/004.phpt --TEST-- fgetcsv() with tab delimited fields (BUG #8258) --POST-- --GET-- --FILE-- <?php $fp=fopen("004.data","r"); while($a=fgetcsv($fp,100,"\t")) { echo join(",",$a)."\n"; } fclose($fp); ?> --EXPECT-- name,value,comment true,1,boolean true false,0,boolean false empty,,nothing

« previous php.cvs (#3151) next »