]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Implement _Escaping_sink to avoid construction of string
authorTomasz Kamiński <tkaminsk@redhat.com>
Tue, 8 Jul 2025 16:50:50 +0000 (18:50 +0200)
committerTomasz Kamiński <tkaminsk@redhat.com>
Tue, 14 Oct 2025 13:40:26 +0000 (15:40 +0200)
commit59cabe08b57a262d5d7d041515889a012189c908
tree850c9fef737f4992c55e3c0afee46d1d147982c6
parent9f13fd1b076d041cde15245fb14aa641dafd32f0
libstdc++: Implement _Escaping_sink to avoid construction of string

This patch implements _Escaping_sink that stores characters in a local (stack)
buffer. When the buffer is full, the range of characters is escaped and written
to the underlying sink.

To support above, the __write_escaped_unicode_part function are defined.
It takes __str and __prev_esc by reference. The __prev_esc value is updated
based on the last character written. If the buffer ends with an incomplete
code point sequence, __str is left non-empty and last code points are not
written. _Escaping_sink then copies these characters to the front of the
buffer to reconstruct the full code point.

__formatter__str::_M_format_range now uses _Escaping_sink to escape any
non-continuous character sequences.

libstdc++-v3/ChangeLog:

* include/std/format (__format::__write_escape_seqs)
(__format::_Escaping_sink): Define.
(__format::__write_escaped_unicode_part): Extract from
__format::__write_escaped_unicode.
(__format::__write_escaped_unicode): Forward to
__write_escaped_unicode_part.
(__formatter_str::_M_format_range): Use _Escaping sink.
* testsuite/std/format/ranges/string.cc: New tests for
character which codepoints will be split in buffer and
escaping. Invoked test_padding.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
libstdc++-v3/include/std/format
libstdc++-v3/testsuite/std/format/ranges/string.cc