andrei          Thu Dec  7 22:00:55 2006 UTC

  Modified files:              
    /php-src/ext/standard       datetime.c 
  Log:
  Unicode support in strptime(). Uses runtime encoding for conversion.
  
  # Blah, those new _ut_ macros might be necessary after all.
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/datetime.c?r1=1.140&r2=1.141&diff_format=u
Index: php-src/ext/standard/datetime.c
diff -u php-src/ext/standard/datetime.c:1.140 
php-src/ext/standard/datetime.c:1.141
--- php-src/ext/standard/datetime.c:1.140       Tue Sep 19 10:38:31 2006
+++ php-src/ext/standard/datetime.c     Thu Dec  7 22:00:55 2006
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: datetime.c,v 1.140 2006/09/19 10:38:31 dmitry Exp $ */
+/* $Id: datetime.c,v 1.141 2006/12/07 22:00:55 andrei Exp $ */
 
 #include "php.h"
 #include "zend_operators.h"
@@ -85,25 +85,39 @@
 char *strptime(const char *s, const char *format, struct tm *tm);
 #endif
 
-/* {{{ proto string strptime(string timestamp, string format)
+/* {{{ proto string strptime(string timestamp, string format) U
    Parse a time/date generated with strftime() */
 PHP_FUNCTION(strptime)
 {
-       char      *ts;
+       zstr       ts;
        int        ts_length;
-       char      *format;
+       zstr       format;
        int        format_length;
        struct tm  parsed_time;
        char      *unparsed_part;
+       zend_uchar type;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", 
-               &ts, &ts_length, &format, &format_length) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "TT", 
+               &ts, &ts_length, &type, &format, &format_length, &type) == 
FAILURE) {
                return;
        }
 
+       if (type == IS_UNICODE) {
+               char *temp;
+               int temp_len;
+
+               
zend_unicode_to_string(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &temp, 
&temp_len, ts.u, ts_length TSRMLS_CC);
+               ts.s = temp;
+               ts_length = temp_len;
+
+               
zend_unicode_to_string(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &temp, 
&temp_len, format.u, format_length TSRMLS_CC);
+               format.s = temp;
+               format_length = temp_len;
+       }
+
        memset(&parsed_time, 0, sizeof(parsed_time));
 
-       unparsed_part = strptime(ts, format, &parsed_time);
+       unparsed_part = strptime(ts.s, format.s, &parsed_time);
        if (unparsed_part == NULL) {
                RETURN_FALSE;
        }
@@ -117,7 +131,18 @@
        add_ascii_assoc_long(return_value, "tm_year",  parsed_time.tm_year);
        add_ascii_assoc_long(return_value, "tm_wday",  parsed_time.tm_wday);
        add_ascii_assoc_long(return_value, "tm_yday",  parsed_time.tm_yday);
-       add_ascii_assoc_string(return_value, "unparsed", unparsed_part, 1);
+       if (type == IS_UNICODE) {
+               UChar *temp;
+               int temp_len;
+
+               
zend_string_to_unicode(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &temp, 
&temp_len, unparsed_part, strlen(unparsed_part) TSRMLS_CC);
+               add_ascii_assoc_unicodel(return_value, "unparsed", temp, 
temp_len, 0);
+
+               efree(ts.s);
+               efree(format.s);
+       } else {
+               add_ascii_assoc_string(return_value, "unparsed", unparsed_part, 
1);
+       }
 }
 /* }}} */
 #endif

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

Reply via email to