Index: zend_strtod.c =================================================================== RCS file: /repository/ZendEngine2/zend_strtod.c,v retrieving revision 1.23 diff -u -r1.23 zend_strtod.c --- zend_strtod.c 15 Apr 2006 12:54:26 -0000 1.23 +++ zend_strtod.c 31 Jul 2006 08:23:10 -0000 @@ -90,6 +90,7 @@ */ #include +#include #include #include @@ -1801,15 +1802,79 @@ /* UTODO: someone can reimplement this using the code above, if they really want to. */ ZEND_API double zend_u_strtod(const UChar *nptr, UChar **endptr) { + const UChar *u = nptr, *nstart; + UChar c = *u; + int any = 0; double value = 0.0; - int32_t num_conv = 0, num_read = 0; - num_conv = u_sscanf(nptr, "%f%n", &value, &num_read); - if (num_conv != EOF) { - if (endptr != 0) { - *endptr = (UChar *)nptr + num_read; + while (u_isspace(c)) { + c = *++u; + } + nstart = u; + + if (c == '-' || c == '+') { + c = *++u; + } + + while (u_digit(c, 10) >= 0) { + any = 1; + c = *++u; + } + + if (c == '.') { + c = *++u; + while (u_digit(c, 10) >= 0) { + any = 1; + c = *++u; + } + } + + if ((c == 'e' || c == 'E') && any) { + const UChar *e = u; + int any_exp = 0; + + c = *++u; + if (c == '-' || c == '+') { + c = *++u; + } + + while (u_digit(c, 10) >= 0) { + any_exp = 1; + c = *++u; + } + + if (!any_exp) { + u = e; + } + } + + if (any) { + UErrorCode status = U_ZERO_ERROR; + char *s = NULL; + int s_len; + + TSRMLS_FETCH(); + + zend_convert_from_unicode(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &s, &s_len, nstart, u - nstart, &status); + + if (U_FAILURE(status)) { + if (s) { + efree(s); + } + + if (endptr != 0) { + *endptr = (UChar *)nptr; + } + return 0; + } else { + value = zend_strtod(s, NULL); + efree(s); + + if (endptr != 0) { + *endptr = (UChar *)u; + } + return value; } - return value; } else { if (endptr != 0) { *endptr = (UChar *)nptr;