pollita         Tue Dec  5 04:52:44 2006 UTC

  Modified files:              
    /php-src    NEWS 
    /php-src/ext/standard       basic_functions.c file.c php_string.h 
                                string.c 
  Log:
  Add str_getcsv() and fix a couple cases in recent fgetcsv() reimplementation
  
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2132&r2=1.2133&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2132 php-src/NEWS:1.2133
--- php-src/NEWS:1.2132 Wed Nov 15 17:16:25 2006
+++ php-src/NEWS        Tue Dec  5 04:52:44 2006
@@ -64,6 +64,7 @@
   . "context" and "binary_pipes" params in "other_options" arg. (Sara)
   . stream_resolve_include_path(). (Sara)
 - Added shm_has_var() function. (Mike)
+- Added str_getcsv() function. (Sara)
 
 - Fixed bug #39504 (xmlwriter_write_dtd_entity() creates Attlist tag, 
   not enity). (Hannes Magnusson)
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/basic_functions.c?r1=1.828&r2=1.829&diff_format=u
Index: php-src/ext/standard/basic_functions.c
diff -u php-src/ext/standard/basic_functions.c:1.828 
php-src/ext/standard/basic_functions.c:1.829
--- php-src/ext/standard/basic_functions.c:1.828        Tue Dec  5 02:54:07 2006
+++ php-src/ext/standard/basic_functions.c      Tue Dec  5 04:52:44 2006
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: basic_functions.c,v 1.828 2006/12/05 02:54:07 stas Exp $ */
+/* $Id: basic_functions.c,v 1.829 2006/12/05 04:52:44 pollita Exp $ */
 
 #include "php.h"
 #include "php_streams.h"
@@ -2752,6 +2752,14 @@
 ZEND_END_ARG_INFO()
 
 static
+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()
+
+static
 ZEND_BEGIN_ARG_INFO(arginfo_str_repeat, 0)
        ZEND_ARG_INFO(0, input)
        ZEND_ARG_INFO(0, mult)
@@ -3230,6 +3238,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.470&r2=1.471&diff_format=u
Index: php-src/ext/standard/file.c
diff -u php-src/ext/standard/file.c:1.470 php-src/ext/standard/file.c:1.471
--- php-src/ext/standard/file.c:1.470   Tue Dec  5 04:13:46 2006
+++ php-src/ext/standard/file.c Tue Dec  5 04:52:44 2006
@@ -21,7 +21,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: file.c,v 1.470 2006/12/05 04:13:46 pollita Exp $ */
+/* $Id: file.c,v 1.471 2006/12/05 04:52:44 pollita Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -2423,11 +2423,21 @@
 
                                /* Simple character */
                                p++;
+
+                               if (p == e) {
+                                       add_next_index_stringl(return_value, 
field_start, p - field_start, 1);
+                                       /* Reset scanner even though we're 
dying */
+                                       state = PHP_FGETCSV_READY;
+                                       field_start = field_end = NULL;
+                                       p += delimiter_len;
+                               }
                                break;
                }
        }
 
-       efree(buffer);
+       if (stream) {
+               efree(buffer);
+       }
 }
 /* }}} */
 
@@ -2617,11 +2627,21 @@
 
                                /* Simple character */
                                p++;
+
+                               if (p == e) {
+                                       add_next_index_unicodel(return_value, 
field_start, p - field_start, 1);
+                                       /* Reset scanner even though we're 
dying */
+                                       state = PHP_FGETCSV_READY;
+                                       field_start = field_end = NULL;
+                                       p += delimiter_len;
+                               }
                                break;
                }
        }
 
-       efree(buffer);
+       if (stream) {
+               efree(buffer);
+       }
 }
 /* }}} */
 
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/php_string.h?r1=1.103&r2=1.104&diff_format=u
Index: php-src/ext/standard/php_string.h
diff -u php-src/ext/standard/php_string.h:1.103 
php-src/ext/standard/php_string.h:1.104
--- php-src/ext/standard/php_string.h:1.103     Tue Oct  3 18:38:57 2006
+++ php-src/ext/standard/php_string.h   Tue Dec  5 04:52:44 2006
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_string.h,v 1.103 2006/10/03 18:38:57 tony2001 Exp $ */
+/* $Id: php_string.h,v 1.104 2006/12/05 04:52:44 pollita 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.618&r2=1.619&diff_format=u
Index: php-src/ext/standard/string.c
diff -u php-src/ext/standard/string.c:1.618 php-src/ext/standard/string.c:1.619
--- php-src/ext/standard/string.c:1.618 Tue Dec  5 02:54:07 2006
+++ php-src/ext/standard/string.c       Tue Dec  5 04:52:44 2006
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: string.c,v 1.618 2006/12/05 02:54:07 stas Exp $ */
+/* $Id: string.c,v 1.619 2006/12/05 04:52:44 pollita Exp $ */
 
 /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */
 
@@ -56,6 +56,9 @@
 #include "unicode/uchar.h"
 #include "unicode/ubrk.h"
 
+/* For str_getcsv() support */
+#include "ext/standard/file.h"
+
 #define STR_PAD_LEFT                   0
 #define STR_PAD_RIGHT                  1
 #define STR_PAD_BOTH                   2
@@ -6734,6 +6737,46 @@
 }
 /* }}} */
 
+/* {{{ proto array str_getcsv(string input[, string delimiter[, string 
enclosure[, string escape]]]) U
+Parse a CSV string into an array */
+PHP_FUNCTION(str_getcsv)
+{
+       zend_uchar str_type, delim_type = IS_STRING, enc_type = IS_STRING, 
esc_type = IS_STRING;
+       char *str, *delim = ",", *enc = "\"", *esc = "\\";
+       int str_len, delim_len = 1, enc_len = 1, esc_len = 1;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "T|TTT",
+                       &str,   &str_len,   &str_type,
+                       &delim, &delim_len, &delim_type,
+                       &enc,   &enc_len,   &enc_type,
+                       &esc,   &esc_len,   &esc_type) == FAILURE) {
+               return;
+       }
+
+       if (str_type == IS_UNICODE) {
+               UChar udelim = ',', uenc = '"', uesc = '\\';
+
+               /* Non-passed params would need to be upconverted, but we can 
cheat with some local declarations */
+               if (delim_type == IS_STRING) {
+                       delim = (char*)&udelim;
+                       delim_len = 1;
+               }
+               if (enc_type == IS_STRING) {
+                       enc = (char*)&uenc;
+                       enc_len = 1;
+               }
+               if (esc_type == IS_STRING) {
+                       esc = (char*)&uesc;
+                       esc_len = 1;
+               }
+
+               php_u_fgetcsv(NULL, (UChar*)delim, delim_len, (UChar*)enc, 
enc_len, (UChar*)esc, esc_len, (UChar*)str, str_len, return_value TSRMLS_CC);
+       } else {
+               php_fgetcsv_ex(NULL, delim, delim_len, enc, enc_len, esc, 
esc_len, str, str_len, return_value TSRMLS_CC);
+       }
+}
+/* }}} */
+
 /* {{{ proto string str_repeat(string input, int mult) U
    Returns the input string repeat mult times */
 PHP_FUNCTION(str_repeat)

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to