From c8dbd65ff5c82d0ffd8046d95b9e08c285898e14 Mon Sep 17 00:00:00 2001 From: ZXShady <153229951+ZXShady@users.noreply.github.com> Date: Sun, 29 Sep 2024 22:57:57 +0100 Subject: [PATCH] use if constexpr instead of a switch statement The condition is a constant expression, it makes more sense here to use `if constexpr` --- include/SFML/System/Utf.inl | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/include/SFML/System/Utf.inl b/include/SFML/System/Utf.inl index daaab9be9..124283db9 100644 --- a/include/SFML/System/Utf.inl +++ b/include/SFML/System/Utf.inl @@ -710,25 +710,19 @@ Out Utf<32>::encodeWide(std::uint32_t codepoint, Out output, wchar_t replacement // For UCS-2 we need to check if the source characters fits in (UCS-2 is a subset of UCS-4). // For UCS-4 we can do a direct copy (UCS-4 *is* UTF-32). - switch (sizeof(wchar_t)) + if constexpr (sizeof(wchar_t) == 4) { - case 4: + *output++ = static_cast(codepoint); + } + else + { + if ((codepoint <= 0xFFFF) && ((codepoint < 0xD800) || (codepoint > 0xDFFF))) { *output++ = static_cast(codepoint); - break; } - - default: + else if (replacement) { - if ((codepoint <= 0xFFFF) && ((codepoint < 0xD800) || (codepoint > 0xDFFF))) - { - *output++ = static_cast(codepoint); - } - else if (replacement) - { - *output++ = replacement; - } - break; + *output++ = replacement; } }