stas            Fri Jan 30 21:45:17 2009 UTC

  Modified files:              
    /php-src/ext/intl/formatter formatter_parse.c 
    /php-src/ext/intl/tests     bug14562.phpt 
  Log:
  fix bug #14562
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/intl/formatter/formatter_parse.c?r1=1.3&r2=1.4&diff_format=u
Index: php-src/ext/intl/formatter/formatter_parse.c
diff -u php-src/ext/intl/formatter/formatter_parse.c:1.3 
php-src/ext/intl/formatter/formatter_parse.c:1.4
--- php-src/ext/intl/formatter/formatter_parse.c:1.3    Mon Aug 11 19:46:57 2008
+++ php-src/ext/intl/formatter/formatter_parse.c        Fri Jan 30 21:45:16 2009
@@ -19,12 +19,15 @@
 #endif
 
 #include <unicode/ustring.h>
+#include <locale.h>
 
 #include "php_intl.h"
 #include "formatter_class.h"
 #include "formatter_format.h"
 #include "formatter_parse.h"
 
+#define ICU_LOCALE_BUG 1
+
 /* {{{ proto mixed NumberFormatter::parse( string $str[, int $type, int 
&$position ])
  * Parse a number. }}} */
 /* {{{ proto mixed numfmt_parse( NumberFormatter $nf, string $str[, int $type, 
int &$position ])
@@ -40,6 +43,7 @@
        double val_double;
        int32_t* position_p = NULL;
        zval *zposition = NULL;
+       char *oldlocale;
        FORMATTER_METHOD_INIT_VARS;
 
        /* Parse parameters. */
@@ -61,6 +65,10 @@
                position_p = &position;
        }
 
+#if ICU_LOCALE_BUG && defined(LC_NUMERIC)
+       oldlocale = setlocale(LC_NUMERIC, "C");
+#endif
+
        switch(type) {
                case FORMAT_TYPE_INT32:
                        val32 = unum_parse(FORMATTER_OBJECT(nfo), str, str_len, 
position_p, &INTL_DATA_ERROR_CODE(nfo));
@@ -84,6 +92,9 @@
                        RETVAL_FALSE;
                        break;
        }
+#if ICU_LOCALE_BUG && defined(LC_NUMERIC)
+       setlocale(LC_NUMERIC, oldlocale);
+#endif
        if(zposition) {
                zval_dtor(zposition);
                ZVAL_LONG(zposition, position);
http://cvs.php.net/viewvc.cgi/php-src/ext/intl/tests/bug14562.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/intl/tests/bug14562.phpt
diff -u /dev/null php-src/ext/intl/tests/bug14562.phpt:1.2
--- /dev/null   Fri Jan 30 21:45:17 2009
+++ php-src/ext/intl/tests/bug14562.phpt        Fri Jan 30 21:45:17 2009
@@ -0,0 +1,28 @@
+--TEST--
+Bug #14562 NumberFormatter breaks when locale changes
+--SKIPIF--
+<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
+--FILE--
+<?php
+
+function ut_main()
+{
+       $res_str = "";
+       $de_locale="de_DE.UTF-8";
+       $fmt = new NumberFormatter("de", NumberFormatter::DECIMAL );
+       $numeric = $fmt->parse("1234,56");
+       $res_str .= "$numeric\n";
+       setlocale(LC_ALL, $de_locale);
+       $fmt = new NumberFormatter("de", NumberFormatter::DECIMAL );
+       $numeric = $fmt->parse("1234,56");
+       $res_str .= "$numeric\n";
+       return $res_str;
+}
+
+include_once( 'ut_common.inc' );
+ut_run();
+
+?>
+--EXPECT--
+1234.56
+1234.56



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

Reply via email to