%% options copyright owner = Dirk Krause copyright year = 2017-xxxx SPDX-License-Identifier: BSD-3-Clause %% header /** @file dk4rec26.h Recode characters to unsigned long. We can not simply convert unsing the (unsigned long) cast as on some systems wchar_t may be a signed integer type and unsigned long may be larger than 32 bits. Promoting negative wchar_t or wxChar values to 64 bit unsigned long will result in conversions for instance from wchar_t=0xFFFE0000 to ul=0xFFFFFFFFFFFE0000. So after an (unsigned long) cast we have to apply a mask, i.e. 0xFFFFFFFFUL when wchar_t is 4 bytes long or 0xFFFFU when wchar_t is 2 bytes long. */ #ifndef DK4CONF_H_INCLUDED #if DK4_BUILDING_DKTOOLS4 #include "dk4conf.h" #else #include #endif #endif #ifndef DK4TYPES_H_INCLUDED #if DK4_BUILDING_DKTOOLS4 #include "dk4types.h" #else #include #endif #endif #ifdef __cplusplus extern "C" { #endif /** Convert char to unsigned long. @param back Character to convert. @return Conversion result. */ unsigned long dk4recode_char_to_ul(unsigned long back); /** Convert 16 bit character to unsigned long. @param back Character to convert. @return Conversion result. */ unsigned long dk4recode_c16_to_ul(unsigned long back); /** Convert 32 bit character to unsigned long. @param back Character to convert. @return Conversion result. */ unsigned long dk4recode_c32_to_ul(unsigned long back); /** Convert dkChar to unsigned long. @param back Character to convert. @return Conversion result. */ unsigned long dk4recode_dk_to_ul(unsigned long back); /** Convert wchar_t to unsigned long. @param back Character to convert. @return Conversion result. */ unsigned long dk4recode_wc_to_ul(unsigned long back); #if 0 /** Convert wxChar to unsigned long. @param back Character to convert. @return Conversion result. */ unsigned long dk4recode_wx_to_ul(unsigned long back); #endif #ifdef __cplusplus } #endif %% module #include "dk4conf.h" #include "dk4rec26.h" unsigned long dk4recode_char_to_ul(unsigned long back) { back &= 0x000000FFUL; return back; } unsigned long dk4recode_c16_to_ul(unsigned long back) { back &= 0x0000FFFFUL; return back; } unsigned long dk4recode_c32_to_ul(unsigned long back) { back &= 0xFFFFFFFFUL; return back; } unsigned long dk4recode_dk_to_ul(unsigned long back) { #if DK4_CHAR_SIZE > 1 #if DK4_CHAR_SIZE > 2 back &= 0xFFFFFFFFUL; #else back &= 0x0000FFFFUL; #endif #else back &= 0x000000FFUL; #endif return back; } unsigned long dk4recode_wc_to_ul(unsigned long back) { #if DK4_SIZEOF_WCHAR_T > 1 #if DK4_SIZEOF_WCHAR_T > 2 back &= 0xFFFFFFFFUL; #else back &= 0x0000FFFFUL; #endif #else back &= 0x000000FFUL; #endif return back; } #if 0 unsigned long dk4recode_wx_to_ul(unsigned long back) { #if DK4_SIZEOF_WXCHAR > 1 #if DK4_SIZEOF_WXCHAR > 2 back &= 0xFFFFFFFFUL; #else back &= 0x0000FFFFUL; #endif #else back &= 0x000000FFUL; #endif return back; } #endif