From 77d4198091d89116a7b2ece1848a3d11889720b7 Mon Sep 17 00:00:00 2001 From: Anthony Nicholls Date: Fri, 27 Sep 2024 13:24:53 +0100 Subject: [PATCH] Text: Refactor UTF-8 test to prevent warnings --- .../juce_core/text/juce_CharPointer_UTF8_test.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/juce_core/text/juce_CharPointer_UTF8_test.cpp b/modules/juce_core/text/juce_CharPointer_UTF8_test.cpp index c6fbe592db..2a5f2e7bcd 100644 --- a/modules/juce_core/text/juce_CharPointer_UTF8_test.cpp +++ b/modules/juce_core/text/juce_CharPointer_UTF8_test.cpp @@ -44,31 +44,33 @@ public: { beginTest ("String validation - empty string / null-terminator"); { - const std::vector string { 0x0 }; + const std::vector string { '\0' }; expect (CharPointer_UTF8::isValidString (string.data(), (int) string.size())); } beginTest ("String validation - ascii"); { - const std::vector string { 0x54, 0x65, 0x73, 0x74, 0x21, 0x0 }; // Test! + const std::vector string { 'T', 'e', 's', 'T', '!', '\0' }; // Test! expect (CharPointer_UTF8::isValidString (string.data(), (int) string.size())); } + constexpr auto continuationCharacter = static_cast (0x80); + beginTest ("String validation - continuation characters are invalid when not proceeded by the correct bytes"); { - const std::vector string { -1 }; + const std::vector string { continuationCharacter }; expect (! CharPointer_UTF8::isValidString (string.data(), (int) string.size())); } beginTest ("String validation - characters after a null terminator are ignored"); { - const std::vector string { 0x54, 0x65, 0x73, 0x74, 0x0, -1 }; + const std::vector string { 'T', 'e', 's', 'T', '\0', continuationCharacter }; expect (CharPointer_UTF8::isValidString (string.data(), (int) string.size())); } beginTest ("String validation - characters exceeding max bytes are ignored"); { - const std::vector string { 0x54, 0x65, 0x73, 0x74, -1 }; + const std::vector string { 'T', 'e', 's', 'T', continuationCharacter }; expect (CharPointer_UTF8::isValidString (string.data(), 4)); }