helly Thu Feb 7 18:41:35 2008 UTC Modified files: (Branch: PHP_5_3) /php-src/main snprintf.c spprintf.c Log: - MFH Add %Z to *printf http://cvs.php.net/viewvc.cgi/php-src/main/snprintf.c?r1=1.37.2.4.2.14.2.3&r2=1.37.2.4.2.14.2.4&diff_format=u Index: php-src/main/snprintf.c diff -u php-src/main/snprintf.c:1.37.2.4.2.14.2.3 php-src/main/snprintf.c:1.37.2.4.2.14.2.4 --- php-src/main/snprintf.c:1.37.2.4.2.14.2.3 Thu Feb 7 12:47:44 2008 +++ php-src/main/snprintf.c Thu Feb 7 18:41:35 2008 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: snprintf.c,v 1.37.2.4.2.14.2.3 2008/02/07 12:47:44 helly Exp $ */ +/* $Id: snprintf.c,v 1.37.2.4.2.14.2.4 2008/02/07 18:41:35 helly Exp $ */ #include "php.h" @@ -581,16 +581,17 @@ */ static int format_converter(register buffy * odp, const char *fmt, va_list ap) /* {{{ */ { - register char *sp; - register char *bep; - register int cc = 0; - register int i; + char *sp; + char *bep; + int cc = 0; + int i; - register char *s = NULL; + char *s = NULL; char *q; - int s_len; + int s_len, free_zcopy; + zval *zvp, zcopy; - register int min_width = 0; + int min_width = 0; int precision = 0; enum { LEFT, RIGHT @@ -634,6 +635,7 @@ alternate_form = print_sign = print_blank = NO; pad_char = ' '; prefix_char = NUL; + free_zcopy = 0; fmt++; @@ -780,6 +782,18 @@ * It is reset to ' ' by non-numeric formats */ switch (*fmt) { + case 'Z': + zvp = (zval*) va_arg(ap, zval*); + zend_make_printable_zval(zvp, &zcopy, &free_zcopy); + if (free_zcopy) { + zvp = &zcopy; + } + s_len = Z_STRLEN_P(zvp); + s = Z_STRVAL_P(zvp); + if (adjust_precision && precision < s_len) { + s_len = precision; + } + break; case 'u': switch(modifier) { default: @@ -1019,19 +1033,19 @@ } if (zend_isnan(fp_num)) { - s = "NAN"; - s_len = 3; - break; - } else if (zend_isinf(fp_num)) { - if (fp_num > 0) { - s = "INF"; - s_len = 3; - } else { - s = "-INF"; - s_len = 4; - } - break; - } + s = "NAN"; + s_len = 3; + break; + } else if (zend_isinf(fp_num)) { + if (fp_num > 0) { + s = "INF"; + s_len = 3; + } else { + s = "-INF"; + s_len = 4; + } + break; + } if (adjust_precision == NO) { precision = FLOAT_DIGITS; @@ -1161,6 +1175,9 @@ if (adjust_width && adjust == LEFT && min_width > s_len) PAD(min_width, s_len, pad_char); + if (free_zcopy) { + zval_dtor(&zcopy); + } } skip_output: fmt++; http://cvs.php.net/viewvc.cgi/php-src/main/spprintf.c?r1=1.25.2.2.2.10.2.3&r2=1.25.2.2.2.10.2.4&diff_format=u Index: php-src/main/spprintf.c diff -u php-src/main/spprintf.c:1.25.2.2.2.10.2.3 php-src/main/spprintf.c:1.25.2.2.2.10.2.4 --- php-src/main/spprintf.c:1.25.2.2.2.10.2.3 Thu Feb 7 12:47:44 2008 +++ php-src/main/spprintf.c Thu Feb 7 18:41:35 2008 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: spprintf.c,v 1.25.2.2.2.10.2.3 2008/02/07 12:47:44 helly Exp $ */ +/* $Id: spprintf.c,v 1.25.2.2.2.10.2.4 2008/02/07 18:41:35 helly Exp $ */ /* This is the spprintf implementation. * It has emerged from apache snprintf. See original header: @@ -185,11 +185,12 @@ */ static void xbuf_format_converter(smart_str *xbuf, const char *fmt, va_list ap) /* {{{ */ { - register char *s = NULL; + char *s = NULL; char *q; - int s_len; + int s_len, free_zcopy; + zval *zvp, zcopy; - register int min_width = 0; + int min_width = 0; int precision = 0; enum { LEFT, RIGHT @@ -230,6 +231,7 @@ alternate_form = print_sign = print_blank = NO; pad_char = ' '; prefix_char = NUL; + free_zcopy = 0; fmt++; @@ -376,6 +378,18 @@ * It is reset to ' ' by non-numeric formats */ switch (*fmt) { + case 'Z': + zvp = (zval*) va_arg(ap, zval*); + zend_make_printable_zval(zvp, &zcopy, &free_zcopy); + if (free_zcopy) { + zvp = &zcopy; + } + s_len = Z_STRLEN_P(zvp); + s = Z_STRVAL_P(zvp); + if (adjust_precision && precision < s_len) { + s_len = precision; + } + break; case 'u': switch(modifier) { default: @@ -751,6 +765,9 @@ if (adjust_width && adjust == LEFT && min_width > s_len) PAD(xbuf, min_width - s_len, pad_char); + if (free_zcopy) { + zval_dtor(&zcopy); + } } skip_output: fmt++;
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php