@@ -171,9 +171,9 @@ std::vector<std::string> narrow_argv(int argc, const wchar_t **argv_wide)
171171// / \return A 16-bit integer with bytes swapped
172172uint16_t do_swap_bytes (uint16_t x)
173173{
174- uint16_t b1= x & 0xFF ;
175- uint16_t b2= x & 0xFF00 ;
176- return ( b1 << 8 ) | (b2 >> 8 );
174+ const uint16_t b1 = x & 0xFFu ;
175+ const uint16_t b2 = x & 0xFF00u ;
176+ return static_cast < uint16_t >(( b1 << 8 ) | (b2 >> 8 ) );
177177}
178178
179179
@@ -185,7 +185,8 @@ void utf16_append_code(unsigned int code, bool swap_bytes, std::wstring &result)
185185 if (code<0xFFFF )
186186 { // code is encoded as one UTF16 character
187187 // we just take the code and possibly swap the bytes
188- unsigned int a=(swap_bytes)?do_swap_bytes (code):code;
188+ const unsigned int a =
189+ swap_bytes ? do_swap_bytes (static_cast <uint16_t >(code)) : code;
189190 result+=static_cast <wchar_t >(a);
190191 }
191192 else // code is encoded as two UTF16 characters
@@ -196,11 +197,11 @@ void utf16_append_code(unsigned int code, bool swap_bytes, std::wstring &result)
196197
197198 // encode the code in UTF16, possibly swapping bytes.
198199 code=code-0x10000 ;
199- unsigned int i1=(( code>> 10 ) & 0x3ff ) | 0xD800 ;
200- unsigned int a1=( swap_bytes)? do_swap_bytes (static_cast < uint16_t >( i1)): i1;
200+ const uint16_t i1 = static_cast < uint16_t >((( code >> 10 ) & 0x3ff ) | 0xD800 ) ;
201+ const uint16_t a1 = swap_bytes ? do_swap_bytes (i1) : i1;
201202 result+=static_cast <wchar_t >(a1);
202- unsigned int i2=( code & 0x3ff ) | 0xDC00 ;
203- unsigned int a2=( swap_bytes)? do_swap_bytes (static_cast < uint16_t >( i2)): i2;
203+ const uint16_t i2 = static_cast < uint16_t >(( code & 0x3ff ) | 0xDC00 ) ;
204+ const uint16_t a2 = swap_bytes ? do_swap_bytes (i2) : i2;
204205 result+=static_cast <wchar_t >(a2);
205206 }
206207}
0 commit comments