]> granicus.if.org Git - php/commitdiff
- MFH4.3: Cleaned up some of the locale mess:
authorDerick Rethans <derick@php.net>
Mon, 15 Nov 2004 13:42:22 +0000 (13:42 +0000)
committerDerick Rethans <derick@php.net>
Mon, 15 Nov 2004 13:42:22 +0000 (13:42 +0000)
  * all internal use of sprintf, snprintf and the like will always
    use the . as thousands seperator (if php.h is included only!).
  * echo, printf() and sprintf() always render locale-aware
  * added the %F modifier for non-locale aware rendering for floats

configure.in
ext/standard/formatted_print.c
main/php.h
main/php_sprintf.c
main/snprintf.c
main/snprintf.h

index 463c4a3b4f73191961a15631c27e27451445dd45..9e47f2706d17a0ef7aa638453afa4501346d9beb 100644 (file)
@@ -619,8 +619,8 @@ fi
 AC_REPLACE_FUNCS(strlcat strlcpy getopt)
 AC_FUNC_UTIME_NULL
 AC_FUNC_ALLOCA
-PHP_AC_BROKEN_SPRINTF
-PHP_AC_BROKEN_SNPRINTF
+dnl PHP_AC_BROKEN_SPRINTF
+dnl PHP_AC_BROKEN_SNPRINTF
 PHP_DECLARED_TIMEZONE
 PHP_TIME_R_TYPE
 PHP_READDIR_R_TYPE
index e35946fa1064a1e40e327880092c72ab0755404a..75cf0205d86a9df22be8bf0dd99ac1de496ac1de 100644 (file)
@@ -303,13 +303,14 @@ php_sprintf_appenddouble(char **buffer, int *pos,
        char *cvt;
        register int i = 0, j = 0;
        int sign, decpt, cvt_len;
+       char decimal_point = '.';
 #ifdef HAVE_LOCALE_H
        struct lconv lc;
-       char decimal_point;
+       char locale_decimal_point;
        localeconv_r(&lc);
-       decimal_point = (lc.decimal_point)[0];
+       locale_decimal_point = (lc.decimal_point)[0];
 #else
-       char decimal_point = '.';
+       char locale_decimal_point = '.';
 #endif
 
        PRINTF_DEBUG(("sprintf: appenddouble(%x, %x, %x, %f, %d, '%c', %d, %c)\n",
@@ -343,12 +344,12 @@ php_sprintf_appenddouble(char **buffer, int *pos,
                numbuf[i++] = '+';
        }
 
-       if (fmt == 'f') {
+       if (fmt == 'f' || fmt == 'F') {
                if (decpt <= 0) {
                        numbuf[i++] = '0';
                        if (precision > 0) {
                                int k = precision;
-                               numbuf[i++] = decimal_point;
+                               numbuf[i++] = fmt == 'F' ? decimal_point : locale_decimal_point;
                                while ((decpt++ < 0) && k--) {
                                        numbuf[i++] = '0';
                                }
@@ -358,7 +359,7 @@ php_sprintf_appenddouble(char **buffer, int *pos,
                                numbuf[i++] = j < cvt_len ? cvt[j++] : '0';
                        }
                        if (precision > 0) {
-                               numbuf[i++] = decimal_point;
+                               numbuf[i++] = fmt == 'F' ? decimal_point : locale_decimal_point;
                                while (precision-- > 0) {
                                        numbuf[i++] = j < cvt_len ? cvt[j++] : '0';
                                }
@@ -697,6 +698,7 @@ php_formatted_print(int ht, int *len, int use_array, int format_offset TSRMLS_DC
 
                                case 'e':
                                case 'f':
+                               case 'F':
                                        /* XXX not done */
                                        convert_to_double(tmp);
                                        php_sprintf_appenddouble(&result, &outpos, &size,
index 6e5612bde2e457497b3addda9170e8a25928a967..1ea49e623fb4da250519ccca4acc3f521684bc43 100644 (file)
 
 #include "zend_API.h"
 
-#if PHP_BROKEN_SPRINTF
 #undef sprintf
 #define sprintf php_sprintf
-#endif
 
 /* PHP's DEBUG value must match Zend's ZEND_DEBUG value */
 #undef PHP_DEBUG
@@ -228,9 +226,7 @@ char *strerror(int);
 #define PHP_ATTRIBUTE_MALLOC ZEND_ATTRIBUTE_MALLOC
 #define PHP_ATTRIBUTE_FORMAT ZEND_ATTRIBUTE_FORMAT
 
-#if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) || PHP_BROKEN_SPRINTF || PHP_BROKEN_SNPRINTF || PHP_BROKEN_VSNPRINTF
 #include "snprintf.h"
-#endif
 #include "spprintf.h"
 
 #define EXEC_INPUT_BUF 4096
index f7daab2952d79b8936ca1811a0d7b1778d7530c1..b0589c20a2f0665635af996076bc5925e823d57b 100644 (file)
@@ -26,8 +26,6 @@
 #include "php_config.h"
 #endif
 
-#if PHP_BROKEN_SPRINTF
-
 int
 php_sprintf (char*s, const char* format, ...)
 {
@@ -43,8 +41,6 @@ php_sprintf (char*s, const char* format, ...)
   return strlen (s);
 }
 
-#endif /* PHP_BROKEN_SPRINTF */
-
 /*
  * Local variables:
  * tab-width: 4
index fa0e7f1e8815bb6c9be3ecd3f4b6532672f36a79..e0804b07d706831e685e57d6b255b3c3a9eaf6ae 100644 (file)
@@ -466,8 +466,6 @@ ap_php_gcvt(double number, int ndigit, char *buf, boolean_e altform)
        return (buf);
 }
 
-#if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) || PHP_BROKEN_SNPRINTF || PHP_BROKEN_VSNPRINTF
-
 /*
  * NUM_BUF_SIZE is the size of the buffer used for arithmetic conversions
  *
@@ -1157,8 +1155,6 @@ int ap_php_vsnprintf(char *buf, size_t len, const char *format, va_list ap)
        return (cc);
 }
 
-#endif                                                 /* HAVE_SNPRINTF */
-
 /*
  * Local variables:
  * tab-width: 4
index 76b7b6a6ca1afdd75e513be499ccd46f803a37de..a6d98793b2e7e23fe7b8664baf77ea757cf82756 100644 (file)
@@ -64,20 +64,14 @@ Example:
 #ifndef SNPRINTF_H
 #define SNPRINTF_H
 
-#if !defined(HAVE_SNPRINTF) || PHP_BROKEN_SNPRINTF
 int ap_php_snprintf(char *, size_t, const char *, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4);
 #define snprintf ap_php_snprintf
-#endif
 
-#if !defined(HAVE_VSNPRINTF) || PHP_BROKEN_VSNPRINTF
 int ap_php_vsnprintf(char *, size_t, const char *, va_list ap) PHP_ATTRIBUTE_FORMAT(printf, 3, 0);
 #define vsnprintf ap_php_vsnprintf
-#endif
 
-#if PHP_BROKEN_SPRINTF
 int php_sprintf (char* s, const char* format, ...) PHP_ATTRIBUTE_FORMAT(printf, 2, 3);
 #define sprintf php_sprintf
-#endif
 
 typedef enum {
        NO = 0, YES = 1