Add _PyUnicodeWriter_WriteASCIIString() function

This commit is contained in:
Victor Stinner 2013-11-19 12:54:53 +01:00
parent 4d3f109ad3
commit 4a58707a34
4 changed files with 96 additions and 38 deletions

View file

@ -1053,24 +1053,24 @@ format_float_internal(PyObject *value,
n_digits += 1;
}
/* Since there is no unicode version of PyOS_double_to_string,
just use the 8 bit version and then convert to unicode. */
unicode_tmp = _PyUnicode_FromASCII(buf, n_digits);
PyMem_Free(buf);
if (unicode_tmp == NULL)
goto done;
if (format->sign != '+' && format->sign != ' '
&& format->width == -1
&& format->type != 'n'
&& !format->thousands_separators)
{
/* Fast path */
result = _PyUnicodeWriter_WriteStr(writer, unicode_tmp);
Py_DECREF(unicode_tmp);
result = _PyUnicodeWriter_WriteASCIIString(writer, buf, n_digits);
PyMem_Free(buf);
return result;
}
/* Since there is no unicode version of PyOS_double_to_string,
just use the 8 bit version and then convert to unicode. */
unicode_tmp = _PyUnicode_FromASCII(buf, n_digits);
PyMem_Free(buf);
if (unicode_tmp == NULL)
goto done;
/* Is a sign character present in the output? If so, remember it
and skip it */
index = 0;