diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2013-04-30 16:34:30 +0300 |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2013-04-30 16:34:30 +0300 |
commit | c6666f2ecc6dfd60aa6fe88950c5dfb2eb8d6687 (patch) | |
tree | d32b1b16efb870f6f89d2b7cced40620296efa00 /Python/formatter_unicode.c | |
parent | 14a057272cda4f9703954afaa0156517bb0b321f (diff) | |
parent | 2ee4b800e8fc729e008e576bd7e12aa1c0935098 (diff) | |
download | cpython-c6666f2ecc6dfd60aa6fe88950c5dfb2eb8d6687.tar.gz |
#17881: merge with 3.3.
Diffstat (limited to 'Python/formatter_unicode.c')
-rw-r--r-- | Python/formatter_unicode.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/Python/formatter_unicode.c b/Python/formatter_unicode.c index 17eb9789e0..009bc5fd03 100644 --- a/Python/formatter_unicode.c +++ b/Python/formatter_unicode.c @@ -757,7 +757,8 @@ format_string_internal(PyObject *value, const InternalFormatSpec *format, goto done; } - if (format->width == -1 && format->precision == -1) { + if ((format->width == -1 || format->width <= len) + && (format->precision == -1 || format->precision >= len)) { /* Fast path */ return _PyUnicodeWriter_WriteStr(writer, value); } @@ -770,9 +771,13 @@ format_string_internal(PyObject *value, const InternalFormatSpec *format, calc_padding(len, format->width, format->align, &lpad, &rpad, &total); - maxchar = _PyUnicode_FindMaxChar(value, 0, len); + maxchar = writer->maxchar; if (lpad != 0 || rpad != 0) maxchar = Py_MAX(maxchar, format->fill_char); + if (PyUnicode_MAX_CHAR_VALUE(value) > maxchar) { + Py_UCS4 valmaxchar = _PyUnicode_FindMaxChar(value, 0, len); + maxchar = Py_MAX(maxchar, valmaxchar); + } /* allocate the resulting string */ if (_PyUnicodeWriter_Prepare(writer, total, maxchar) == -1) |