diff options
author | Benjamin Peterson <benjamin@python.org> | 2013-05-17 22:34:30 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2013-05-17 22:34:30 (GMT) |
commit | d2b58a9880d119b20e1fc1c82a3e2e2d9eaa0817 (patch) | |
tree | 2b45e6e8db8d100937e4e0edfefc5470216c3f1d /Objects/stringlib/unicode_format.h | |
parent | 36f74aa7f711c9defc01ab8522117b2b7db8ccd3 (diff) | |
download | cpython-d2b58a9880d119b20e1fc1c82a3e2e2d9eaa0817.zip cpython-d2b58a9880d119b20e1fc1c82a3e2e2d9eaa0817.tar.gz cpython-d2b58a9880d119b20e1fc1c82a3e2e2d9eaa0817.tar.bz2 |
only recursively expand in the format spec (closes #17644)
Diffstat (limited to 'Objects/stringlib/unicode_format.h')
-rw-r--r-- | Objects/stringlib/unicode_format.h | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/Objects/stringlib/unicode_format.h b/Objects/stringlib/unicode_format.h index e9be516..c1c2cf3 100644 --- a/Objects/stringlib/unicode_format.h +++ b/Objects/stringlib/unicode_format.h @@ -638,7 +638,7 @@ MarkupIterator_next(MarkupIterator *self, SubString *literal, SubString *format_spec, Py_UCS4 *conversion, int *format_spec_needs_expanding) { - int at_end; + int at_end, hit_format_spec; Py_UCS4 c = 0; Py_ssize_t start; int count; @@ -723,12 +723,18 @@ MarkupIterator_next(MarkupIterator *self, SubString *literal, /* we know we can't have a zero length string, so don't worry about that case */ + hit_format_spec = 0; while (self->str.start < self->str.end) { switch (c = PyUnicode_READ_CHAR(self->str.str, self->str.start++)) { + case ':': + hit_format_spec = 1; + count = 1; + break; case '{': /* the format spec needs to be recursively expanded. this is an optimization, and not strictly needed */ - *format_spec_needs_expanding = 1; + if (hit_format_spec) + *format_spec_needs_expanding = 1; count++; break; case '}': |