diff options
| author | Martin Hořeňovský | 2026-07-26 22:19:31 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2026-07-26 22:19:31 +0200 |
| commit | 8b08d4d79514f45f7e4ce2a607ac9c94e920d1bb (patch) | |
| tree | 6ae81663dc4ea2fd5024129daf8d3187ec1433a6 /extras/catch_amalgamated.cpp | |
| parent | 1079da4c5f5fea2a31d795bba95eacaa2f622849 (diff) | |
| download | catch3-3.15.3.tar.gz | |
v3.15.3v3.15.3
Diffstat (limited to 'extras/catch_amalgamated.cpp')
| -rw-r--r-- | extras/catch_amalgamated.cpp | 88 |
1 files changed, 68 insertions, 20 deletions
diff --git a/extras/catch_amalgamated.cpp b/extras/catch_amalgamated.cpp index 4e1e631e..abf540b4 100644 --- a/extras/catch_amalgamated.cpp +++ b/extras/catch_amalgamated.cpp @@ -6,8 +6,8 @@ // SPDX-License-Identifier: BSL-1.0 -// Catch v3.15.2 -// Generated: 2026-07-07 20:39:49.445081 +// Catch v3.15.3 +// Generated: 2026-07-26 22:17:52.418168 // ---------------------------------------------------------- // This file is an amalgamation of multiple different files. // You probably shouldn't edit it directly. @@ -2394,7 +2394,7 @@ namespace Catch { } Version const& libraryVersion() { - static Version version( 3, 15, 2, "", 0 ); + static Version version( 3, 15, 3, "", 0 ); return version; } @@ -2541,7 +2541,7 @@ namespace Catch { bool isValid = next(); if ( !isValid ) { Detail::throw_generator_exception( - "Coud not jump to Nth element: not enough elements" ); + "Could not jump to Nth element: not enough elements" ); } } } @@ -4678,12 +4678,28 @@ namespace Detail { +#include <cmath> +#include <locale> + namespace Catch { namespace { - static bool needsEscape( char c ) { - return c == '"' || c == '\\' || c == '\b' || c == '\f' || - c == '\n' || c == '\r' || c == '\t'; + struct EscapeLUT { + bool escape[256] = {}; + constexpr EscapeLUT() { + escape[static_cast<unsigned char>( '"' )] = true; + escape[static_cast<unsigned char>( '\\' )] = true; + escape[static_cast<unsigned char>( '\b' )] = true; + escape[static_cast<unsigned char>( '\f' )] = true; + escape[static_cast<unsigned char>( '\n' )] = true; + escape[static_cast<unsigned char>( '\r' )] = true; + escape[static_cast<unsigned char>( '\t' )] = true; + } + }; + static constexpr EscapeLUT escapeLUT{}; + + static constexpr bool needsEscape( char c ) { + return escapeLUT.escape[static_cast<unsigned char>( c )]; } static Catch::StringRef makeEscapeStringRef( char c ) { @@ -4795,7 +4811,10 @@ namespace Catch { JsonValueWriter::JsonValueWriter( std::ostream& os, std::uint64_t indent_level ): - m_os{ os }, m_indent_level{ indent_level } {} + m_os{ os }, m_indent_level{ indent_level } { + // We use C locale so that writing of numerical values is locale-independent. + m_sstream.imbue( std::locale::classic() ); + } JsonObjectWriter JsonValueWriter::writeObject() && { return JsonObjectWriter{ m_os, m_indent_level }; @@ -4809,26 +4828,55 @@ namespace Catch { writeImpl( value, true ); } + void JsonValueWriter::write( float value ) && { + writeFloatingPoint( value ); + } + + void JsonValueWriter::write( double value ) && { + writeFloatingPoint( value ); + } + void JsonValueWriter::write( bool value ) && { writeImpl( value ? "true"_sr : "false"_sr, false ); } + template <typename T> + void JsonValueWriter::writeFloatingPoint( T value ) { + if ( Catch::isnan( value ) ) { + writeImpl( "NaN"_sr, false ); + } else if ( std::isinf( value ) ) { + writeImpl( value < 0 ? "-Infinity"_sr : "Infinity"_sr, false ); + } else { + m_sstream << value; + writeImpl( m_sstream.str(), false ); + } + } + void JsonValueWriter::writeImpl( Catch::StringRef value, bool quote ) { - if ( quote ) { m_os << '"'; } - size_t current_start = 0; - for ( size_t i = 0; i < value.size(); ++i ) { - if ( needsEscape( value[i] ) ) { - if ( current_start < i ) { - m_os << value.substr( current_start, i - current_start ); + // Escaping only makes sense for actual strings, which are passed + // with `quote == true`. Non-quoted values are things like bools + // and numbers, which cannot create inputs that need escaping. + if ( !quote ) { + m_os << value; + } else { + m_os << '"'; + size_t current_start = 0; + for ( size_t i = 0; i < value.size(); ++i ) { + if ( needsEscape( value[i] ) ) { + if ( current_start < i ) { + m_os + << value.substr( current_start, i - current_start ); + } + m_os << makeEscapeStringRef( value[i] ); + current_start = i + 1; } - m_os << makeEscapeStringRef( value[i] ); - current_start = i + 1; } + if ( current_start < value.size() ) { + m_os << value.substr( current_start, + value.size() - current_start ); + } + m_os << '"'; } - if ( current_start < value.size() ) { - m_os << value.substr( current_start, value.size() - current_start ); - } - if ( quote ) { m_os << '"'; } } } // namespace Catch |