diff --git a/modules/juce_core/text/juce_CharPointer_UTF32_test.cpp b/modules/juce_core/text/juce_CharPointer_UTF32_test.cpp index b46788c459..de45e288e7 100644 --- a/modules/juce_core/text/juce_CharPointer_UTF32_test.cpp +++ b/modules/juce_core/text/juce_CharPointer_UTF32_test.cpp @@ -42,10 +42,7 @@ public: void runTest() final { - const auto toCharType = [] (const std::vector& str) - { - return reinterpret_cast (str.data()); - }; + using Utf32Vector = std::vector; const auto getNumBytes = [] (const auto& str) { @@ -54,50 +51,50 @@ public: beginTest ("String validation - empty string / null-terminator"); { - const std::vector string { 0x0 }; + const Utf32Vector string { 0x0 }; expect (CharPointer_UTF32::isValidString (string.data(), getNumBytes (string))); } beginTest ("String validation - ascii"); { - const std::vector string { 0x54, 0x65, 0x73, 0x74, 0x21, 0x0 }; // Test! - expect (CharPointer_UTF32::isValidString (toCharType (string), getNumBytes (string))); + const Utf32Vector string { 0x54, 0x65, 0x73, 0x74, 0x21, 0x0 }; // Test! + expect (CharPointer_UTF32::isValidString (string.data(), getNumBytes (string))); } beginTest ("String validation - 2-byte code points"); { - const std::vector string { 0x54, 0x65, 0x73, 0x74, 0x20ac, 0x0 }; // Test€ - expect (CharPointer_UTF32::isValidString (toCharType (string), getNumBytes (string))); + const Utf32Vector string { 0x54, 0x65, 0x73, 0x74, 0x20ac, 0x0 }; // Test€ + expect (CharPointer_UTF32::isValidString (string.data(), getNumBytes (string))); } beginTest ("String validation - maximum code point"); { - const std::vector string1 { 0x54, 0x65, 0x73, 0x74, 0x10ffff, 0x0 }; - expect (CharPointer_UTF32::isValidString (toCharType (string1), getNumBytes (string1))); + const Utf32Vector string1 { 0x54, 0x65, 0x73, 0x74, 0x10ffff, 0x0 }; + expect (CharPointer_UTF32::isValidString (string1.data(), getNumBytes (string1))); - const std::vector string2 { 0x54, 0x65, 0x73, 0x74, 0x110000, 0x0 }; - expect (! CharPointer_UTF32::isValidString (toCharType (string2), getNumBytes (string2))); + const Utf32Vector string2 { 0x54, 0x65, 0x73, 0x74, 0x110000, 0x0 }; + expect (! CharPointer_UTF32::isValidString (string2.data(), getNumBytes (string2))); } beginTest ("String validation - characters after a null terminator are ignored"); { - const std::vector string { 0x54, 0x65, 0x73, 0x74, 0x0, 0x110000 }; - expect (CharPointer_UTF32::isValidString (toCharType (string), getNumBytes (string))); + const Utf32Vector string { 0x54, 0x65, 0x73, 0x74, 0x0, 0x110000 }; + expect (CharPointer_UTF32::isValidString (string.data(), getNumBytes (string))); } beginTest ("String validation - characters exceeding max bytes are ignored"); { - const std::vector string { 0x54, 0x65, 0x73, 0x74, 0x110000 }; - expect (CharPointer_UTF32::isValidString (toCharType (string), 8)); + const Utf32Vector string { 0x54, 0x65, 0x73, 0x74, 0x110000 }; + expect (CharPointer_UTF32::isValidString (string.data(), 8)); } beginTest ("String validation - surrogate code points are invalid"); { - const std::vector highSurrogate { 0xd800 }; - expect (! CharPointer_UTF32::isValidString (toCharType (highSurrogate), getNumBytes (highSurrogate))); + const Utf32Vector highSurrogate { 0xd800 }; + expect (! CharPointer_UTF32::isValidString (highSurrogate.data(), getNumBytes (highSurrogate))); - const std::vector lowSurrogate { 0xdfff }; - expect (! CharPointer_UTF32::isValidString (toCharType (lowSurrogate), getNumBytes (lowSurrogate))); + const Utf32Vector lowSurrogate { 0xdfff }; + expect (! CharPointer_UTF32::isValidString (lowSurrogate.data(), getNumBytes (lowSurrogate))); } } }; diff --git a/modules/juce_core/text/juce_CharPointer_UTF8_test.cpp b/modules/juce_core/text/juce_CharPointer_UTF8_test.cpp index 2a5f2e7bcd..7e8a1e4684 100644 --- a/modules/juce_core/text/juce_CharPointer_UTF8_test.cpp +++ b/modules/juce_core/text/juce_CharPointer_UTF8_test.cpp @@ -42,15 +42,17 @@ public: void runTest() final { + using Utf8Vector = std::vector; + beginTest ("String validation - empty string / null-terminator"); { - const std::vector string { '\0' }; + const Utf8Vector string { '\0' }; expect (CharPointer_UTF8::isValidString (string.data(), (int) string.size())); } beginTest ("String validation - ascii"); { - const std::vector string { 'T', 'e', 's', 'T', '!', '\0' }; // Test! + const Utf8Vector string { 'T', 'e', 's', 'T', '!', '\0' }; // Test! expect (CharPointer_UTF8::isValidString (string.data(), (int) string.size())); } @@ -58,19 +60,19 @@ public: beginTest ("String validation - continuation characters are invalid when not proceeded by the correct bytes"); { - const std::vector string { continuationCharacter }; + const Utf8Vector 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 { 'T', 'e', 's', 'T', '\0', continuationCharacter }; + const Utf8Vector 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 { 'T', 'e', 's', 'T', continuationCharacter }; + const Utf8Vector string { 'T', 'e', 's', 'T', continuationCharacter }; expect (CharPointer_UTF8::isValidString (string.data(), 4)); }