mirror of
https://github.com/php/php-src.git
synced 2025-08-18 15:08:55 +02:00
- Added the H modifier to create non-locale-aware non-fixed-precision float
representations. - Fixed var_export() to use the new H modifier so that it can generate parsable PHP code for floats again, independent of the locale.
This commit is contained in:
parent
60db2300d7
commit
ad8eca0b05
4 changed files with 1066 additions and 3 deletions
1061
ext/standard/tests/general_functions/var_export-locale.phpt
Normal file
1061
ext/standard/tests/general_functions/var_export-locale.phpt
Normal file
File diff suppressed because it is too large
Load diff
|
@ -584,7 +584,7 @@ PHPAPI void php_var_export(zval **struc, int level TSRMLS_DC)
|
||||||
php_printf("%ld", Z_LVAL_PP(struc));
|
php_printf("%ld", Z_LVAL_PP(struc));
|
||||||
break;
|
break;
|
||||||
case IS_DOUBLE:
|
case IS_DOUBLE:
|
||||||
php_printf("%.*G", (int) EG(precision), Z_DVAL_PP(struc));
|
php_printf("%.*H", (int) EG(precision), Z_DVAL_PP(struc));
|
||||||
break;
|
break;
|
||||||
case IS_STRING:
|
case IS_STRING:
|
||||||
tmp_str = php_addcslashes(Z_STRVAL_PP(struc), Z_STRLEN_PP(struc), &tmp_len, 0, "'\\\0", 3 TSRMLS_CC);
|
tmp_str = php_addcslashes(Z_STRVAL_PP(struc), Z_STRLEN_PP(struc), &tmp_len, 0, "'\\\0", 3 TSRMLS_CC);
|
||||||
|
|
|
@ -1043,6 +1043,7 @@ fmt_string:
|
||||||
|
|
||||||
case 'g':
|
case 'g':
|
||||||
case 'G':
|
case 'G':
|
||||||
|
case 'H':
|
||||||
switch(modifier) {
|
switch(modifier) {
|
||||||
case LM_LONG_DOUBLE:
|
case LM_LONG_DOUBLE:
|
||||||
fp_num = (double) va_arg(ap, long double);
|
fp_num = (double) va_arg(ap, long double);
|
||||||
|
@ -1081,7 +1082,7 @@ fmt_string:
|
||||||
lconv = localeconv();
|
lconv = localeconv();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
s = php_gcvt(fp_num, precision, LCONV_DECIMAL_POINT, (*fmt == 'G')?'E':'e', &num_buf[1]);
|
s = php_gcvt(fp_num, precision, *fmt=='H' ? '.' : LCONV_DECIMAL_POINT, (*fmt == 'G')?'E':'e', &num_buf[1]);
|
||||||
if (*s == '-')
|
if (*s == '-')
|
||||||
prefix_char = *s++;
|
prefix_char = *s++;
|
||||||
else if (print_sign)
|
else if (print_sign)
|
||||||
|
|
|
@ -670,6 +670,7 @@ fmt_string:
|
||||||
|
|
||||||
case 'g':
|
case 'g':
|
||||||
case 'G':
|
case 'G':
|
||||||
|
case 'H':
|
||||||
switch(modifier) {
|
switch(modifier) {
|
||||||
case LM_LONG_DOUBLE:
|
case LM_LONG_DOUBLE:
|
||||||
fp_num = (double) va_arg(ap, long double);
|
fp_num = (double) va_arg(ap, long double);
|
||||||
|
@ -708,7 +709,7 @@ fmt_string:
|
||||||
lconv = localeconv();
|
lconv = localeconv();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
s = php_gcvt(fp_num, precision, LCONV_DECIMAL_POINT, (*fmt == 'G')?'E':'e', &num_buf[1]);
|
s = php_gcvt(fp_num, precision, *fmt=='H' ? '.' : LCONV_DECIMAL_POINT, (*fmt == 'G')?'E':'e', &num_buf[1]);
|
||||||
if (*s == '-')
|
if (*s == '-')
|
||||||
prefix_char = *s++;
|
prefix_char = *s++;
|
||||||
else if (print_sign)
|
else if (print_sign)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue