[PHP-CVS] cvs: php-src /ext/standard php_smart_str.h /main spprintf.c

2005-08-16 Thread Derick Rethans
derick  Tue Aug 16 14:02:41 2005 EDT

  Modified files:  
/php-src/ext/standard   php_smart_str.h 
/php-src/main   spprintf.c 
  Log:
  - Fixed a couple of bugs in the new smart_str macros, and allow them to
allocate two extra bytes (so that we can pad them with two \0's for UTF-16)
  - Fixed usage of smart_str's in the PAD and INS_STRING macros.
  
  
http://cvs.php.net/diff.php/php-src/ext/standard/php_smart_str.h?r1=1.31&r2=1.32&ty=u
Index: php-src/ext/standard/php_smart_str.h
diff -u php-src/ext/standard/php_smart_str.h:1.31 
php-src/ext/standard/php_smart_str.h:1.32
--- php-src/ext/standard/php_smart_str.h:1.31   Sun Aug 14 13:14:40 2005
+++ php-src/ext/standard/php_smart_str.hTue Aug 16 14:02:39 2005
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: php_smart_str.h,v 1.31 2005/08/14 17:14:40 helly Exp $ */
+/* $Id: php_smart_str.h,v 1.32 2005/08/16 18:02:39 derick Exp $ */
 
 #ifndef PHP_SMART_STR_H
 #define PHP_SMART_STR_H
@@ -28,9 +28,12 @@
 #include 
 #endif
 
+/* It's safe to write to "one behind the length" as we allocate two extra bytes
+ * to allow for Unicode trailers */
 #define smart_str_0(x) do {
\
if ((x)->c) {   
\
(x)->c[(x)->len] = '\0';
\
+   (x)->c[(x)->len + 1] = '\0';
\
}   
\
 } while (0)
 
@@ -49,7 +52,7 @@
 #endif
 
 #define SMART_STR_DO_REALLOC(d, what) \
-   (d)->c = SMART_STR_REALLOC((d)->c, (d)->a + 1, (what))
+   (d)->c = SMART_STR_REALLOC((d)->c, (d)->a + 2, (what))
 
 #define smart_str_alloc4(d, n, what, newlen) do {  
\
if (!(d)->c) {  
\
@@ -78,15 +81,15 @@
 #define smart_str_appends(dest, src) \
smart_str_appendl((dest), (src), strlen(src))
 
-/* normall character appending */
+/* normal character appending */
 #define smart_str_appendc(dest, c) \
smart_str_appendc_ex((dest), (c), 0)
 
 /* appending of a single UTF-16 code unit (2 byte)*/
-#define smart_str_append2c(dest, c) while (0) {\
+#define smart_str_append2c(dest, c) do {   \
smart_str_appendc_ex((dest), (c&0xFF), 0);  \
smart_str_appendc_ex((dest), (c&0xFF00 ? c>>8 : '\0'), 0);  \
-}
+} while (0)
 
 #define smart_str_free(s) \
smart_str_free_ex((s), 0)
http://cvs.php.net/diff.php/php-src/main/spprintf.c?r1=1.31&r2=1.32&ty=u
Index: php-src/main/spprintf.c
diff -u php-src/main/spprintf.c:1.31 php-src/main/spprintf.c:1.32
--- php-src/main/spprintf.c:1.31Mon Aug 15 03:19:10 2005
+++ php-src/main/spprintf.c Tue Aug 16 14:02:41 2005
@@ -16,7 +16,7 @@
+--+
 */
 
-/* $Id: spprintf.c,v 1.31 2005/08/15 07:19:10 dmitry Exp $ */
+/* $Id: spprintf.c,v 1.32 2005/08/16 18:02:41 derick Exp $ */
 
 /* This is the spprintf implementation.
  * It has emerged from apache snprintf. See original header:
@@ -126,22 +126,22 @@
}   
\
 } while (0)
 
-#define INS_STRING(unicode, s_uni, xbuf, s, slen)  \
+#define INS_STRING(unicode, s_unicode, xbuf, s, s_len) \
 do {   
\
if (unicode) {  
\
-   size_t newlen, p, sz = 2*(slen);\
+   size_t newlen, p, sz = 2*(s_len);   \
smart_str_alloc(xbuf, (sz), 0); \
-   if (s_uni) {
\
+   if (s_unicode) {
\
memcpy(xbuf->c + xbuf->len, s, (sz));   \
} else {
\
-   p = (slen); 
\
+   p = (s_len);
\
while(p--) {\
-   smart_str_append2c(xbuf, *s++); \
+   smart_str_append2c(xbuf, *s);   \
+   *s++;  

Re: [PHP-CVS] cvs: php-src /ext/standard php_smart_str.h /main spprintf.c spprintf.h

2005-08-14 Thread Derick Rethans
On Sun, 14 Aug 2005, Andrei Zmievski wrote:

> Why not use what ICU gives us?

A reason might be that we might have implemented more modifiers, or some 
slightly different. I think it's a good idea to use our own too.

Derick

> On Aug 14, 2005, at 10:14 AM, Marcus Boerger wrote:
> 
> > hellySun Aug 14 13:14:43 2005 EDT
> >
> >   Modified files:
> > /php-src/ext/standardphp_smart_str.h
> > /php-src/mainspprintf.c spprintf.h
> >   Log:
> >   - Initial support of easy way to generate unicode strings: [v]
> > uspprinf()
> >  # Same semantics as [v]spprintf, only it prints unicode strings instead of
> >  # native strings. Atm it has a little problem since it length doesn't take
> >  # the difference between UTF-16 code points vs units into account. But as
> >  # long as no 4 byte codes are involved it should already run everything.
> >
> >
> > 
> > -- 
> > PHP CVS Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

-- 
Derick Rethans
http://derickrethans.nl | http://ez.no | http://xdebug.org

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



Re: [PHP-CVS] cvs: php-src /ext/standard php_smart_str.h /main spprintf.c spprintf.h

2005-08-14 Thread Andrei Zmievski

Why not use what ICU gives us?

http://icu.sourceforge.net/apiref/icu4c/ustdio_8h.html#a36

-Andrei


On Aug 14, 2005, at 10:14 AM, Marcus Boerger wrote:


hellySun Aug 14 13:14:43 2005 EDT

  Modified files:
/php-src/ext/standardphp_smart_str.h
/php-src/mainspprintf.c spprintf.h
  Log:
  - Initial support of easy way to generate unicode strings: [v] 
uspprinf()
  # Same semantics as [v]spprintf, only it prints unicode strings  
instead of
  # native strings. Atm it has a little problem since it length  
doesn't take
  # the difference between UTF-16 code points vs units into  
account. But as
  # long as no 4 byte codes are involved it should already run  
everything.




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


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



[PHP-CVS] cvs: php-src /ext/standard php_smart_str.h /main spprintf.c spprintf.h

2005-08-14 Thread Marcus Boerger
helly   Sun Aug 14 13:14:43 2005 EDT

  Modified files:  
/php-src/ext/standard   php_smart_str.h 
/php-src/main   spprintf.c spprintf.h 
  Log:
  - Initial support of easy way to generate unicode strings: [v]uspprinf()
  # Same semantics as [v]spprintf, only it prints unicode strings instead of
  # native strings. Atm it has a little problem since it length doesn't take
  # the difference between UTF-16 code points vs units into account. But as
  # long as no 4 byte codes are involved it should already run everything.
  
  http://cvs.php.net/diff.php/php-src/ext/standard/php_smart_str.h?r1=1.30&r2=1.31&ty=u
Index: php-src/ext/standard/php_smart_str.h
diff -u php-src/ext/standard/php_smart_str.h:1.30 
php-src/ext/standard/php_smart_str.h:1.31
--- php-src/ext/standard/php_smart_str.h:1.30   Wed Aug  3 10:08:11 2005
+++ php-src/ext/standard/php_smart_str.hSun Aug 14 13:14:40 2005
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: php_smart_str.h,v 1.30 2005/08/03 14:08:11 sniper Exp $ */
+/* $Id: php_smart_str.h,v 1.31 2005/08/14 17:14:40 helly Exp $ */
 
 #ifndef PHP_SMART_STR_H
 #define PHP_SMART_STR_H
@@ -78,8 +78,16 @@
 #define smart_str_appends(dest, src) \
smart_str_appendl((dest), (src), strlen(src))
 
+/* normall character appending */
 #define smart_str_appendc(dest, c) \
smart_str_appendc_ex((dest), (c), 0)
+
+/* appending of a single UTF-16 code unit (2 byte)*/
+#define smart_str_append2c(dest, c) while (0) {\
+   smart_str_appendc_ex((dest), (c&0xFF), 0);  \
+   smart_str_appendc_ex((dest), (c&0xFF00 ? c>>8 : '\0'), 0);  \
+}
+
 #define smart_str_free(s) \
smart_str_free_ex((s), 0)
 #define smart_str_appendl(dest, src, len) \
http://cvs.php.net/diff.php/php-src/main/spprintf.c?r1=1.26&r2=1.27&ty=u
Index: php-src/main/spprintf.c
diff -u php-src/main/spprintf.c:1.26 php-src/main/spprintf.c:1.27
--- php-src/main/spprintf.c:1.26Thu Aug 11 19:36:06 2005
+++ php-src/main/spprintf.c Sun Aug 14 13:14:42 2005
@@ -16,7 +16,7 @@
+--+
 */
 
-/* $Id: spprintf.c,v 1.26 2005/08/11 23:36:06 andrei Exp $ */
+/* $Id: spprintf.c,v 1.27 2005/08/14 17:14:42 helly Exp $ */
 
 /* This is the spprintf implementation.
  * It has emerged from apache snprintf. See original header:
@@ -118,42 +118,60 @@
  *
  * NOTE: Evaluation of the ch argument should not have any side-effects
  */
-#define INS_CHAR_NR(xbuf, ch) do { \
-   smart_str_appendc(xbuf, ch);\
+#define INS_CHAR_NR(unicode, xbuf, ch) do {\
+   if (unicode) {  
\
+   smart_str_append2c(xbuf, ch);   \
+   } else {
\
+   smart_str_appendc(xbuf, ch);\
+   }   
\
 } while (0)
 
-#define INS_STRING(xbuf, s, slen) do { \
-   smart_str_appendl(xbuf, s, slen);   \
+#define INS_STRING(unicode, xbuf, s, slen) do {\
+   if (unicode) {  
\
+   smart_str_appendl(xbuf, s, slen);   \
+   } else {
\
+   size_t newlen, sz = 2*(slen);   \
+   smart_str_alloc(xbuf, (sz), 0); \
+   memcpy(xbuf->c + xbuf->len, s, (sz));   \
+   xbuf->len += (sz);  
\
+   }   
\
 } while (0)

-#define INS_CHAR(xbuf, ch)  \
-   INS_CHAR_NR(xbuf, ch)
+#define INS_CHAR(unicode, xbuf, ch)\
+   INS_CHAR_NR(unicode, xbuf, ch)
 
 /*
  * Macro that does padding. The padding is done by printing
  * the character ch.
  */
-#define PAD(xbuf, count, ch) do {  \
+#define PAD(unicode, xbuf, count, ch) do { \
if ((count) > 0) {  \
-   size_t newlen;  
\
-   smart_str_alloc(xbuf, (count), 0);  \
-   memset(xbuf->c + xbuf->len, ch, (count));   \
-   xbuf->len += (count);   \
+   size_t newlen, p, sz = (count); \
+   if (unicode) {  
\
+   p = sz;