felipe Sun Nov 2 18:24:35 2008 UTC Added files: (Branch: PHP_5_3) /php-src/ext/standard/tests/strings str_getcsv_001.phpt
Modified files: /php-src/ext/standard basic_functions.c file.c php_string.h string.c Log: - MFH: Added str_getcsv() http://cvs.php.net/viewvc.cgi/php-src/ext/standard/basic_functions.c?r1=1.725.2.31.2.64.2.66&r2=1.725.2.31.2.64.2.67&diff_format=u Index: php-src/ext/standard/basic_functions.c diff -u php-src/ext/standard/basic_functions.c:1.725.2.31.2.64.2.66 php-src/ext/standard/basic_functions.c:1.725.2.31.2.64.2.67 --- php-src/ext/standard/basic_functions.c:1.725.2.31.2.64.2.66 Fri Oct 24 14:35:38 2008 +++ php-src/ext/standard/basic_functions.c Sun Nov 2 18:24:34 2008 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: basic_functions.c,v 1.725.2.31.2.64.2.66 2008/10/24 14:35:38 felipe Exp $ */ +/* $Id: basic_functions.c,v 1.725.2.31.2.64.2.67 2008/11/02 18:24:34 felipe Exp $ */ #include "php.h" #include "php_streams.h" @@ -2344,6 +2344,13 @@ ZEND_ARG_INFO(1, result) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_str_getcsv, 0, 0, 1) + ZEND_ARG_INFO(0, string) + ZEND_ARG_INFO(0, delimiter) + ZEND_ARG_INFO(0, enclosure) + ZEND_ARG_INFO(0, escape) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO(arginfo_str_repeat, 0) ZEND_ARG_INFO(0, input) ZEND_ARG_INFO(0, mult) @@ -2745,6 +2752,7 @@ PHP_FE(chr, arginfo_chr) PHP_FE(ord, arginfo_ord) PHP_FE(parse_str, arginfo_parse_str) + PHP_FE(str_getcsv, arginfo_str_getcsv) PHP_FE(str_pad, arginfo_str_pad) PHP_FALIAS(chop, rtrim, arginfo_rtrim) PHP_FALIAS(strchr, strstr, arginfo_strstr) http://cvs.php.net/viewvc.cgi/php-src/ext/standard/file.c?r1=1.409.2.6.2.28.2.23&r2=1.409.2.6.2.28.2.24&diff_format=u Index: php-src/ext/standard/file.c diff -u php-src/ext/standard/file.c:1.409.2.6.2.28.2.23 php-src/ext/standard/file.c:1.409.2.6.2.28.2.24 --- php-src/ext/standard/file.c:1.409.2.6.2.28.2.23 Tue Oct 21 22:08:37 2008 +++ php-src/ext/standard/file.c Sun Nov 2 18:24:34 2008 @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: file.c,v 1.409.2.6.2.28.2.23 2008/10/21 22:08:37 lbarnaud Exp $ */ +/* $Id: file.c,v 1.409.2.6.2.28.2.24 2008/11/02 18:24:34 felipe Exp $ */ /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ @@ -2180,7 +2180,9 @@ memcpy(tptr, line_end, line_end_len); tptr += line_end_len; - if ((new_buf = php_stream_get_line(stream, NULL, 0, &new_len)) == NULL) { + if (stream == NULL) { + goto quit_loop_2; + } else if ((new_buf = php_stream_get_line(stream, NULL, 0, &new_len)) == NULL) { /* we've got an unterminated enclosure, * assign all the data from the start of * the enclosure to end of data to the @@ -2341,7 +2343,9 @@ out: efree(temp); - efree(buf); + if (stream) { + efree(buf); + } } /* }}} */ http://cvs.php.net/viewvc.cgi/php-src/ext/standard/php_string.h?r1=1.87.2.2.2.3.2.2&r2=1.87.2.2.2.3.2.3&diff_format=u Index: php-src/ext/standard/php_string.h diff -u php-src/ext/standard/php_string.h:1.87.2.2.2.3.2.2 php-src/ext/standard/php_string.h:1.87.2.2.2.3.2.3 --- php-src/ext/standard/php_string.h:1.87.2.2.2.3.2.2 Sat Jan 19 19:27:21 2008 +++ php-src/ext/standard/php_string.h Sun Nov 2 18:24:34 2008 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_string.h,v 1.87.2.2.2.3.2.2 2008/01/19 19:27:21 davidc Exp $ */ +/* $Id: php_string.h,v 1.87.2.2.2.3.2.3 2008/11/02 18:24:34 felipe Exp $ */ /* Synced with php 3.0 revision 1.43 1999-06-16 [ssb] */ @@ -76,6 +76,7 @@ PHP_FUNCTION(stristr); PHP_FUNCTION(chunk_split); PHP_FUNCTION(parse_str); +PHP_FUNCTION(str_getcsv); PHP_FUNCTION(bin2hex); PHP_FUNCTION(similar_text); PHP_FUNCTION(strip_tags); http://cvs.php.net/viewvc.cgi/php-src/ext/standard/string.c?r1=1.445.2.14.2.69.2.36&r2=1.445.2.14.2.69.2.37&diff_format=u Index: php-src/ext/standard/string.c diff -u php-src/ext/standard/string.c:1.445.2.14.2.69.2.36 php-src/ext/standard/string.c:1.445.2.14.2.69.2.37 --- php-src/ext/standard/string.c:1.445.2.14.2.69.2.36 Tue Oct 21 22:08:37 2008 +++ php-src/ext/standard/string.c Sun Nov 2 18:24:34 2008 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: string.c,v 1.445.2.14.2.69.2.36 2008/10/21 22:08:37 lbarnaud Exp $ */ +/* $Id: string.c,v 1.445.2.14.2.69.2.37 2008/11/02 18:24:34 felipe Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -50,6 +50,9 @@ #include "TSRM.h" #endif +/* For str_getcsv() support */ +#include "ext/standard/file.h" + #define STR_PAD_LEFT 0 #define STR_PAD_RIGHT 1 #define STR_PAD_BOTH 2 @@ -4456,6 +4459,27 @@ } /* }}} */ +/* {{{ proto array str_getcsv(string input[, string delimiter[, string enclosure[, string escape]]]) +Parse a CSV string into an array */ +PHP_FUNCTION(str_getcsv) +{ + char *str, delim = ',', enc = '"', esc = '\\'; + char *delim_str = NULL, *enc_str = NULL, *esc_str = NULL; + int str_len = 0, delim_len = 0, enc_len = 0, esc_len = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|sss", &str, &str_len, &delim_str, &delim_len, + &enc_str, &enc_len, &esc_str, &esc_len) == FAILURE) { + return; + } + + delim = delim_len ? delim_str[0] : delim; + enc = enc_len ? enc_str[0] : enc; + esc = esc_len ? esc_str[0] : esc; + + php_fgetcsv(NULL, delim, enc, esc, str_len, str, return_value TSRMLS_CC); +} +/* }}} */ + /* {{{ proto string str_repeat(string input, int mult) Returns the input string repeat mult times */ PHP_FUNCTION(str_repeat) http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/str_getcsv_001.phpt?view=markup&rev=1.1 Index: php-src/ext/standard/tests/strings/str_getcsv_001.phpt +++ php-src/ext/standard/tests/strings/str_getcsv_001.phpt --TEST-- str_getcsv(): Testing using various arguments --FILE-- <?php // unicode input[, unicode delimiter[, unicode enclosure[, unicode escape]]] var_dump(str_getcsv('"f", "o", ""')); print "-----\n"; var_dump(str_getcsv('foo||bar', '|')); print "-----\n"; var_dump(str_getcsv('foo|bar', '|')); print "-----\n"; var_dump(str_getcsv('|foo|-|bar|', '-', '|')); print "-----\n"; var_dump(str_getcsv('|f.|.|bar|.|-|-.|', '.', '|', '-')); print "-----\n"; var_dump(str_getcsv('.foo..bar.', '.', '.', '.')); print "-----\n"; var_dump(str_getcsv('.foo. .bar.', ' ', '.', '.')); print "-----\n"; var_dump(str_getcsv((binary)'1foo1 1bar111', (binary)' ', (binary)'1 ', (binary) '\ ')); print "-----\n"; var_dump(str_getcsv('.foo . . bar .', ' ', '.', '')); print "-----\n"; var_dump(str_getcsv('" "" "', ' ')); print "-----\n"; var_dump(str_getcsv(NULL)); print "-----\n"; var_dump(str_getcsv('')); print "-----\n"; ?> --EXPECT-- array(3) { [0]=> unicode(1) "f" [1]=> unicode(1) "o" [2]=> unicode(0) "" } ----- array(3) { [0]=> unicode(3) "foo" [1]=> unicode(0) "" [2]=> unicode(3) "bar" } ----- array(2) { [0]=> unicode(3) "foo" [1]=> unicode(3) "bar" } ----- array(2) { [0]=> unicode(3) "foo" [1]=> unicode(3) "bar" } ----- array(3) { [0]=> unicode(2) "f." [1]=> unicode(3) "bar" [2]=> unicode(4) "-|-." } ----- array(1) { [0]=> unicode(7) "foo.bar" } ----- array(2) { [0]=> unicode(3) "foo" [1]=> unicode(3) "bar" } ----- array(2) { [0]=> string(3) "foo" [1]=> string(4) "bar1" } ----- array(2) { [0]=> unicode(5) "foo " [1]=> unicode(7) " bar " } ----- array(1) { [0]=> unicode(3) " " " } ----- array(1) { [0]=> unicode(0) "" } ----- array(1) { [0]=> unicode(0) "" } ----- -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php