Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Commit 562a8a1

Browse files
author
Jakob Riedle
committed
Potentially fixed compilation warning in MSVC
1 parent d525494 commit 562a8a1

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

include/tinyutf8/tinyutf8.h

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -139,22 +139,18 @@ namespace tiny_utf8
139139

140140
//! Count leading zeros utility
141141
#if defined(__GNUC__)
142-
#ifndef TINY_UTF8_HAS_CLZ
143-
#define TINY_UTF8_HAS_CLZ true
144-
#endif
142+
#define TINY_UTF8_HAS_CLZ true
145143
static inline unsigned int clz( unsigned int value ) noexcept { return (unsigned int)__builtin_clz( value ); }
146144
static inline unsigned int clz( unsigned long int value ) noexcept { return (unsigned int)__builtin_clzl( value ); }
147145
static inline unsigned int clz( char32_t value ) noexcept {
148146
return sizeof(char32_t) == sizeof(unsigned long int) ? (unsigned int)__builtin_clzl( value ) : (unsigned int)__builtin_clz( value );
149147
}
150148
#elif defined(_MSC_VER)
151-
#ifndef TINY_UTF8_HAS_CLZ
152-
#define TINY_UTF8_HAS_CLZ true
153-
#endif
149+
#define TINY_UTF8_HAS_CLZ true
154150
template<typename T>
155151
static inline unsigned int lzcnt( T value ) noexcept {
156152
unsigned long value_log2;
157-
#if !defined( WIN32 ) && !defined( _WIN32 ) && !defined( __WIN32__ )
153+
#if INTPTR_MAX >= INT64_MAX
158154
_BitScanReverse64( &value_log2 , value );
159155
#else
160156
_BitScanReverse( &value_log2 , value );
@@ -163,11 +159,14 @@ namespace tiny_utf8
163159
}
164160
static inline unsigned int clz( std::uint16_t value ) noexcept { return lzcnt( value ); }
165161
static inline unsigned int clz( std::uint32_t value ) noexcept { return lzcnt( value ); }
166-
#ifndef WIN32
162+
#if INTPTR_MAX >= INT64_MAX
167163
static inline unsigned int clz( std::uint64_t value ) noexcept { return lzcnt( value ); }
168-
#endif // WIN32
164+
#endif
169165
static inline unsigned int clz( char32_t value ) noexcept { return lzcnt( value ); }
166+
#else
167+
#define TINY_UTF8_HAS_CLZ false
170168
#endif
169+
171170

172171
//! Helper to detect little endian
173172
class is_little_endian
@@ -883,7 +882,7 @@ namespace tiny_utf8
883882
* Returns the number of code units (bytes) using the supplied first byte of a utf8 codepoint
884883
*/
885884
// Data left is the number of bytes left in the buffer INCLUDING this one
886-
#if defined(TINY_UTF8_HAS_CLZ) && TINY_UTF8_HAS_CLZ == true
885+
#if TINY_UTF8_HAS_CLZ
887886
static inline width_type get_codepoint_bytes( data_type first_byte , size_type data_left ) noexcept
888887
{
889888
if( first_byte ){
@@ -906,7 +905,7 @@ namespace tiny_utf8
906905
*/
907906
static inline width_type get_codepoint_bytes( value_type cp ) noexcept
908907
{
909-
#if defined(TINY_UTF8_HAS_CLZ) && TINY_UTF8_HAS_CLZ == true
908+
#if TINY_UTF8_HAS_CLZ
910909
if( !cp )
911910
return 1;
912911
static const width_type lut[32] = {
@@ -3176,37 +3175,37 @@ namespace tiny_utf8
31763175
}
31773176
}
31783177

3179-
#if !defined(TINY_UTF8_HAS_CLZ) || TINY_UTF8_HAS_CLZ == false
3178+
#if !TINY_UTF8_HAS_CLZ
31803179
template<typename V, typename D, typename A>
31813180
typename basic_string<V, D, A>::width_type basic_string<V, D, A>::get_codepoint_bytes( typename basic_string<V, D, A>::data_type first_byte , typename basic_string<V, D, A>::size_type data_left ) noexcept
31823181
{
31833182
// Only Check the possibilities, that could appear
31843183
switch( data_left )
31853184
{
31863185
default:
3187-
if( ((unsigned char)first_byte & 0xFFu) == 0xFEu ) // 11111110 seven bytes
3186+
if( ( (unsigned char)first_byte & 0xFFu ) == 0xFEu ) // 11111110 -> seven bytes
31883187
return 7;
31893188
case 6:
3190-
if( ((unsigned char)first_byte & 0xFEu) == 0xFCu ) // 1111110X six bytes
3189+
if( ( (unsigned char)first_byte & 0xFEu ) == 0xFCu ) // 1111110X -> six bytes
31913190
return 6;
31923191
case 5:
3193-
if( ((unsigned char)first_byte & 0xFCu) == 0xF8u ) // 111110XX five bytes
3192+
if( ( (unsigned char)first_byte & 0xFCu ) == 0xF8u ) // 111110XX -> five bytes
31943193
return 5;
31953194
case 4:
3196-
if( ((unsigned char)first_byte & 0xF8u) == 0xF0u ) // 11110XXX four bytes
3195+
if( ( (unsigned char)first_byte & 0xF8u ) == 0xF0u ) // 11110XXX -> four bytes
31973196
return 4;
31983197
case 3:
3199-
if( ((unsigned char)first_byte & 0xF0u) == 0xE0u ) // 1110XXXX three bytes
3198+
if( ( (unsigned char)first_byte & 0xF0u ) == 0xE0u ) // 1110XXXX -> three bytes
32003199
return 3;
32013200
case 2:
3202-
if( ((unsigned char)first_byte & 0xE0u) == 0xC0u ) // 110XXXXX two bytes
3201+
if( ( (unsigned char)first_byte & 0xE0u ) == 0xC0u ) // 110XXXXX -> two bytes
32033202
return 2;
32043203
case 1:
32053204
case 0:
3206-
return 1;
3205+
return 1; // one byte
32073206
}
32083207
}
3209-
#endif // !defined(TINY_UTF8_HAS_CLZ) || TINY_UTF8_HAS_CLZ == false
3208+
#endif // !TINY_UTF8_HAS_CLZ
32103209

32113210
template<typename V, typename D, typename A>
32123211
basic_string<V, D, A>& basic_string<V, D, A>::operator=( const basic_string<V, D, A>& str ) noexcept(TINY_UTF8_NOEXCEPT)

0 commit comments

Comments
 (0)