%% options copyright owner = Dirk Krause copyright year = 2015-xxxx license = bsd %% header /** @file dk4recwx.h Recoding with wxChar. */ #ifndef DK4CONF_H_INCLUDED #include "dk4conf.h" #endif #ifndef DK4TYPES_H_INCLUDED #include "dk4types.h" #endif #ifndef DK4CONST_H_INCLUDED #include "dk4const.h" #endif #ifndef DK4ERROR_H_INCLUDED #include "dk4error.h" #endif #ifndef DK4WXCS_H_INCLUDED #include "dk4wxcs.h" #endif #if DK4_SIZEOF_WXCHAR == DK4_CHAR_SIZE #ifndef DK4STRD_H_INCLUDED #include "dk4strd.h" #endif #endif #ifndef WX_WXPREC_H_INCLUDED #include #define WX_WXPREC_H_INCLUDED 1 #endif #ifdef __BORLANDC__ #pragma hdrstop #endif #ifndef WX_PRECOMP #if DK4_HAVE_WX_CHARTYPE_H #ifndef WX_CHARTYPE_H_INCLUDED #include #define WX_CHARTYPE_H_INCLUDED 1 #endif #else #if DK4_HAVE_WX_WXCHAR_H #ifndef WX_WXCHAR_H_INCLUDED #include #define WX_WXCHAR_H_INCLUDED 1 #endif #else #ifndef WX_WX_H_INCLUDED #include #define WX_WX_H_INCLUDED #endif #endif #endif #endif #ifdef __cplusplus extern "C" { #endif /** Convert dkChar string to wxChar. @param dptr Destination buffer pointer. @param dsz Size of destination buffer (number of wxChar). @param de Encoding for wxChar strings. @param sptr Source string pointer. @param se Source string encoding. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if dptr or sptr is NULL or dsz is 0, - DK4_E_BUFFER_TOO_SMALL
if the destination buffer is too small, - DK4_E_SYNTAX
if the source string can not be decoded properly. */ int dk4recwx_dkchar_to_wxchar( wxChar *dptr, size_t dsz, int de, const dkChar *sptr, int se, dk4_er_t *erp ); /** Convert wxChar string to dkChar. @param dptr Destination buffer pointer. @param dsz Size of destination buffer (number of dkChar). @param de Encoding for dkChar strings. @param sptr Source string pointer. @param se Source string encoding. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if dptr or sptr is NULL or dsz is 0, - DK4_E_BUFFER_TOO_SMALL
if the destination buffer is too small, - DK4_E_SYNTAX
if the source string can not be decoded properly. */ int dk4recwx_wxchar_to_dkchar( dkChar *dptr, size_t dsz, int de, const wxChar *sptr, int se, dk4_er_t *erp ); /** Convert wxChar string to char. @param dptr Destination buffer pointer. @param dsz Size of destination buffer. @param de Encoding for char strings. @param sptr Source string pointer. @param se Source string encoding. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if dptr or sptr is NULL or dsz is 0, - DK4_E_BUFFER_TOO_SMALL
if the destination buffer is too small, - DK4_E_SYNTAX
if the source string can not be decoded properly. */ int dk4recwx_wxchar_to_char( char *dptr, size_t dsz, int de, const wxChar *sptr, int se, dk4_er_t *erp ); #ifdef __cplusplus } #endif %% module #include "dk4recwx.h" #include "dk4rec.h" #include "dk4enc.h" $!trace-include int dk4recwx_dkchar_to_wxchar( wxChar *dptr, size_t dsz, int de, const dkChar *sptr, int se, dk4_er_t *erp ) { int back = 0; if ((NULL != dptr) && (NULL != sptr) && (0 < dsz)) { #if DK4_SIZEOF_WXCHAR > 1 #if DK4_SIZEOF_WXCHAR > 2 /* +++++ wxChar=4 */ #if DK4_CHAR_SIZE > 1 #if DK4_CHAR_SIZE > 2 /* +++++ wxChar=4 dkChar=4 */ back = dk4str_cpy_s((dkChar *)dptr, dsz, sptr, erp); /* ----- wxChar=4 dkChar=4 */ #else /* +++++ wxChar=4 dkChar=2 */ back = dk4recode_utf16_to_c32((dk4_c32_t *)dptr, dsz, (dk4_c16_t *)sptr, erp); /* ----- wxChar=4 dkChar=2 */ #endif #else /* +++++ wxChar=4 dkChar=1 */ switch (se) { case DK4_ENCODING_UTF8 : { back = dk4recode_utf8_to_c32((dk4_c32_t *)dptr, dsz, sptr, erp); } break; case DK4_ENCODING_ANSI : { back = dk4recode_ansi_to_c32((dk4_c32_t *)dptr, dsz, sptr, erp); } break; default : { /* ASCII */ back = dk4recode_ascii_to_c32((dk4_c32_t *)dptr, dsz, sptr, erp); } break; } /* ----- wxChar=4 dkChar=1 */ #endif /* ----- wxChar=4 */ #else /* +++++ wxChar=2 */ #if DK4_CHAR_SIZE > 1 #if DK4_CHAR_SIZE > 2 /* +++++ wxChar=2 dkChar=4 */ back = dk4recode_c32_to_utf16((dk4_c16_t *)dptr, dsz, (dk4_c32_t *)sptr, erp); /* ----- wxChar=2 dkChar=4 */ #else /* +++++ wxChar=2 dkChar=2 */ back = dk4str_cpy_s((dkChar *)dptr, dsz, sptr, erp); /* ----- wxChar=2 dkChar=2 */ #endif #else /* +++++ wxChar=2 dkChar=1 */ switch (se) { case DK4_ENCODING_UTF8 : { back = dk4recode_utf8_to_utf16((dk4_c16_t *)dptr, dsz, sptr, erp); } break; case DK4_ENCODING_ANSI : { back = dk4recode_ansi_to_utf16((dk4_c16_t *)dptr, dsz, sptr, erp); } break; default : { /* ASCII */ back = dk4recode_ascii_to_utf16((dk4_c16_t *)dptr, dsz, sptr, erp); } break; } /* ----- wxChar=2 dkChar=1 */ #endif /* ----- wxChar=2 */ #endif #else /* +++++ wxChar=1 */ #if DK4_CHAR_SIZE > 1 #if DK4_CHAR_SIZE > 2 /* +++++ wxChar=1 dkChar=4 */ switch (de) { case DK4_ENCODING_UTF8 : { back = dk4recode_c32_to_utf8(dptr, dsz, (dk4_c32_t *)sptr, erp); } break; case DK4_ENCODING_ANSI : { back = dk4recode_c32_to_ansi(dptr, dsz, (dk4_c32_t *)sptr, erp); } break; default : { /* ASCII */ back = dk4recode_c32_to_ascii(dptr, dsz, (dk4_c32_t *)sptr, erp); } break; } /* ----- wxChar=1 dkChar=4 */ #else /* +++++ wxChar=1 dkChar=2 */ switch (de) { case DK4_ENCODING_UTF8 : { back = dk4recode_utf16_to_utf8(dptr, dsz, (dk4_c16_t *)sptr, erp); } break; case DK4_ENCODING_ANSI : { back = dk4recode_utf16_to_ansi(dptr, dsz, (dk4_c16_t *)sptr, erp); } break; default : { /* ASCII */ back = dk4recode_utf16_to_ascii(dptr, dsz, (dk4_c16_t *)sptr, erp); } break; } /* ----- wxChar=1 dkChar=2 */ #endif #else /* +++++ wxChar=1 dkChar=1 */ back = dk4str_cpy_s(dptr, dsz, sptr, erp); /* ----- wxChar=1 dkChar=1 */ #endif /* ----- wxChar=1 */ #endif } else { dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); } return back; } int dk4recwx_wxchar_to_dkchar( dkChar *dptr, size_t dsz, int de, const wxChar *sptr, int se, dk4_er_t *erp ) { int back = 0; $? "+ dk4recwx_wxchar_to_dkchar" if ((NULL != dptr) && (NULL != sptr) && (0 < dsz)) { #if DK4_SIZEOF_WXCHAR > 1 #if DK4_SIZEOF_WXCHAR > 2 /* +++++ wxChar=4 */ #if DK4_CHAR_SIZE > 1 #if DK4_CHAR_SIZE > 2 /* +++++ wxChar=4 dkChar=4 */ $? ". wx=4 dk=4" back = dk4str_cpy_s(dptr, dsz, (dkChar *)sptr, erp); /* ----- wxChar=4 dkChar=4 */ #else /* +++++ wxChar=4 dkChar=2 */ $? ". wx=4 dk=2" back = dk4recode_c32_to_utf16((dk4_c16_t *)dptr, dsz, (dk4_c32_t *)sptr, erp); /* ----- wxChar=4 dkChar=2 */ #endif #else /* +++++ wxChar=4 dkChar=1 */ $? ". wx=4 dk=1" switch (de) { case DK4_ENCODING_UTF8 : { $? ". dk utf-8" back = dk4recode_c32_to_utf8(dptr, dsz, (dk4_c32_t *)sptr, erp); } break; case DK4_ENCODING_ANSI : { $? ". dk ansi" back = dk4recode_c32_to_ansi(dptr, dsz, (dk4_c32_t *)sptr, erp); } break; default : { /* ASCII */ $? ". dk ascii" back = dk4recode_c32_to_ascii(dptr, dsz, (dk4_c32_t *)sptr, erp); } break; } /* ----- wxChar=4 dkChar=1 */ #endif /* ----- wxChar=4 */ #else /* +++++ wxChar=2 */ #if DK4_CHAR_SIZE > 1 #if DK4_CHAR_SIZE > 2 /* +++++ wxChar=2 dkChar=4 */ $? ". wx=2 dk=4" back = dk4recode_utf16_to_c32((dk4_c32_t *)dptr, dsz, (dk4_c16_t *)sptr, erp); /* ----- wxChar=2 dkChar=4 */ #else /* +++++ wxChar=2 dkChar=2 */ $? ". wx=2 dk=2" back = dk4str_cpy_s(dptr, dsz, (dkChar *)sptr, erp); /* ----- wxChar=2 dkChar=2 */ #endif #else /* +++++ wxChar=2 dkChar=1 */ $? ". wx=2 dk=1" switch (de) { case DK4_ENCODING_UTF8 : { $? ". dk utf-8" back = dk4recode_utf16_to_utf8(dptr, dsz, (dk4_c16_t *)sptr, erp); } break; case DK4_ENCODING_ANSI : { $? ". dk ansi" back = dk4recode_utf16_to_ansi(dptr, dsz, (dk4_c16_t *)sptr, erp); } break; default : { /* ASCII */ $? ". dk ascii" back = dk4recode_utf16_to_ascii(dptr, dsz, (dk4_c16_t *)sptr, erp); } break; } /* ----- wxChar=2 dkChar=1 */ #endif /* ----- wxChar=2 */ #endif #else /* +++++ wxChar=1 */ #if DK4_CHAR_SIZE > 1 #if DK4_CHAR_SIZE > 2 /* +++++ wxChar=1 dkChar=4 */ $? ". wx=1 dk=4" switch (se) { case DK4_ENCODING_UTF8 : { $? ". wx utf-8" back = dk4recode_utf8_to_c32((dk4_c32_t *)dptr, dsz, sptr, erp); } break; case DK4_ENCODING_ANSI : { $? ". wx ansi" back = dk4recode_ansi_to_c32((dk4_c32_t *)dptr, dsz, sptr, erp); } break; default : { /* ASCII */ $? ". wx ascii" back = dk4recode_ascii_to_c32((dk4_c32_t *)dptr, dsz, sptr, erp); } break; } /* ----- wxChar=1 dkChar=4 */ #else /* +++++ wxChar=1 dkChar=2 */ $? ". wx=1 dk=2" switch (se) { case DK4_ENCODING_UTF8 : { $? ". wx utf-8" back = dk4recode_utf8_to_utf16((dk4_c16_t *)dptr, dsz, sptr, erp); } break; case DK4_ENCODING_ANSI : { $? ". wx ansi" back = dk4recode_ansi_to_utf16((dk4_c16_t *)dptr, dsz, sptr, erp); } break; default : { /* ASCII */ $? ". wx ascii" back = dk4recode_ascii_to_utf16((dk4_c16_t *)dptr, dsz, sptr, erp); } break; } /* ----- wxChar=1 dkChar=2 */ #endif #else /* +++++ wxChar=1 dkChar=1 */ $? ". wx=1 dk=1" back = dk4str8_cpy_s(dptr, dsz, sptr, erp); /* ----- wxChar=1 dkChar=1 */ #endif /* ----- wxChar=1 */ #endif } else { $? "! invalid arguments" dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); } $? "- dk4recwx_wxchar_to_dkchar %d", back return back; } int dk4recwx_wxchar_to_char( char *dptr, size_t dsz, int de, const wxChar *sptr, int se, dk4_er_t *erp ) { int back = 0; if ((NULL != dptr) && (NULL != sptr) && (0 < dsz)) { switch (de) { case DK4_ENCODING_UTF8 : { #if DK4_SIZEOF_WXCHAR > 1 #if DK4_SIZEOF_WXCHAR > 2 /* +++ wxChar 4 +++ */ back = dk4recode_c32_to_utf8(dptr, dsz, (const dk4_c32_t *)sptr, erp); /* --- wxChar 4 --- */ #else /* +++ wxChar 2 +++ */ back = dk4recode_utf16_to_utf8(dptr, dsz, (const dk4_c16_t *)sptr, erp); /* --- wxChar 2 --- */ #endif #else /* +++ wxChar 1 +++ */ switch (se) { case DK4_ENCODING_UTF8 : { back = dk4str8_cpy_s(dptr, dsz, sptr, erp); } break; case DK4_ENCODING_ANSI : { back = dk4recode_ansi_to_utf8(dptr, dsz, sptr, erp); } break; default : { back = dk4recode_ascii_to_utf8(dptr, dsz, sptr, erp); } break; } /* --- wxChar 1 --- */ #endif } break; case DK4_ENCODING_ANSI : { #if DK4_SIZEOF_WXCHAR > 1 #if DK4_SIZEOF_WXCHAR > 2 /* +++ wxChar 4 +++ */ back = dk4recode_c32_to_ansi(dptr, dsz, (const dk4_c32_t *)sptr, erp); /* --- wxChar 4 --- */ #else /* +++ wxChar 2 +++ */ back = dk4recode_utf16_to_ansi(dptr, dsz, (const dk4_c16_t *)sptr, erp); /* --- wxChar 2 --- */ #endif #else /* +++ wxChar 1 +++ */ switch (se) { case DK4_ENCODING_UTF8 : { back = dk4recode_utf8_to_ansi(dptr, dsz, sptr, erp); } break; case DK4_ENCODING_ANSI : { back = dk4str8_cpy_s(dptr, dsz, sptr, erp); } break; default : { back = dk4recode_ascii_to_ansi(dptr, dsz, sptr, erp); } break; } /* --- wxChar 1 --- */ #endif } break; default : { #if DK4_SIZEOF_WXCHAR > 1 #if DK4_SIZEOF_WXCHAR > 2 /* +++ wxChar 4 +++ */ back = dk4recode_c32_to_ascii(dptr, dsz, (const dk4_c32_t *)sptr, erp); /* --- wxChar 4 --- */ #else /* +++ wxChar 2 +++ */ back = dk4recode_utf16_to_ascii(dptr,dsz,(const dk4_c16_t *)sptr,erp); /* --- wxChar 2 --- */ #endif #else /* +++ wxChar 1 +++ */ switch (se) { case DK4_ENCODING_UTF8 : { back = dk4recode_utf8_to_ascii(dptr, dsz, sptr, erp); } break; case DK4_ENCODING_ANSI : { back = dk4recode_ansi_to_ascii(dptr, dsz, sptr, erp); } break; default : { back = dk4str8_cpy_s(dptr, dsz, sptr, erp); } break; } /* --- wxChar 1 --- */ #endif } break; } } else { dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); } return back; }