From 07667be733e1976bb7864bf54ad7c03e9464ee87 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 18 Jul 2018 12:23:31 +0200 Subject: [PATCH] utf8: modernize utf16 inline calls a bit Let's fix an indentation issue. Let's avoid yoda comparisons. Let's drop unnecessary (). Let's make sure we convert 16bit values to 32bit before shifting them by 10bit to the left, to avoid overflows. Let's avoid comparisons between signed literals and unsigned variables, in particular if the literals are outside of the minimum range C requires for "int". --- src/basic/utf8.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/basic/utf8.h b/src/basic/utf8.h index f5e9f8c..63991bf 100644 --- a/src/basic/utf8.h +++ b/src/basic/utf8.h @@ -31,15 +31,15 @@ int utf8_encoded_valid_unichar(const char *str); int utf8_encoded_to_unichar(const char *str, char32_t *ret_unichar); static inline bool utf16_is_surrogate(char16_t c) { - return (0xd800 <= c && c <= 0xdfff); + return c >= 0xd800U && c <= 0xdfffU; } static inline bool utf16_is_trailing_surrogate(char16_t c) { - return (0xdc00 <= c && c <= 0xdfff); + return c >= 0xdc00U && c <= 0xdfffU; } static inline char32_t utf16_surrogate_pair_to_unichar(char16_t lead, char16_t trail) { - return ((lead - 0xd800) << 10) + (trail - 0xdc00) + 0x10000; + return ((((char32_t) lead - 0xd800U) << 10) + ((char32_t) trail - 0xdc00U) + 0x10000U); } size_t utf8_n_codepoints(const char *str); -- 2.7.4