Fix counting of UTF-8 codepoints in TextFlow

For line-wrapping bytes were counted instead of codepoints. This
resulted in line-breaks being inserted at the wrong position and also
breaking UTF-8 characters.

Fixes #1022.
This commit is contained in:
Jan Niklas Hasse authored and Martin Hořeňovský committed 2026-04-01 16:12:08 +02:00
1 parent 8492fd444e
commit 572f96b8fe
2 files changed
+94

No files matched your search

+19
View File
@@ -26,6 +26,10 @@ namespace {
return std::memchr( chars, c, sizeof( chars ) - 1 ) != nullptr;
}
bool isUtf8ContinuationByte( char c ) {
return ( static_cast<unsigned char>( c ) & 0xC0 ) == 0x80;
}
} // namespace
namespace Catch {
@@ -52,6 +56,11 @@ namespace Catch {
if ( it != m_string.end() ) {
++m_size;
++it;
// Skip UTF-8 continuation bytes
while ( it != m_string.end() &&
isUtf8ContinuationByte( *it ) ) {
++it;
}
}
}
}
@@ -114,6 +123,11 @@ namespace Catch {
void AnsiSkippingString::const_iterator::advance() {
assert( m_it != m_string->end() );
m_it++;
// Skip UTF-8 continuation bytes
while ( m_it != m_string->end() &&
isUtf8ContinuationByte( *m_it ) ) {
m_it++;
}
tryParseAnsiEscapes();
}
@@ -133,6 +147,11 @@ namespace Catch {
assert( *m_it == '\033' );
m_it--;
}
// Skip back over UTF-8 continuation bytes to the leading byte
while ( isUtf8ContinuationByte( *m_it ) ) {
assert( m_it != m_string->begin() );
m_it--;
}
}
static bool isBoundary( AnsiSkippingString const& line,