X-Git-Url: https://pd.if.org/git/?p=pdclib.old;a=blobdiff_plain;f=internals%2F_PDCLIB_encoding.h;h=0178b12f70dcf6e338770caf4e1086c8ef7a7d91;hp=b29fe93d0a8acba5d715c1326cdb24740a14c60b;hb=4fe88a1c445105a96d08b808831d6fc7480a211d;hpb=f3d811f877df14a15abccb5d6f11b2800a727db0 diff --git a/internals/_PDCLIB_encoding.h b/internals/_PDCLIB_encoding.h index b29fe93..0178b12 100644 --- a/internals/_PDCLIB_encoding.h +++ b/internals/_PDCLIB_encoding.h @@ -9,13 +9,40 @@ #include "_PDCLIB_int.h" #ifndef __cplusplus -typedef _PDCLIB_int_least16_t _PDCLIB_char16_t; -typedef _PDCLIB_int_least32_t _PDCLIB_char32_t; +typedef _PDCLIB_int16_t _PDCLIB_char16_t; +typedef _PDCLIB_int32_t _PDCLIB_char32_t; #else typedef char16_t _PDCLIB_char16_t; typedef char32_t _PDCLIB_char32_t; #endif +/* -------------------------------------------------------------------------- */ +/* mbstate_t */ +/* -------------------------------------------------------------------------- */ + +typedef struct _PDCLIB_mbstate_t { + union { + /* Is this the best way to represent this? Is this big enough? */ + _PDCLIB_uint64_t _St64[15]; + _PDCLIB_uint32_t _St32[31]; + _PDCLIB_uint16_t _St16[62]; + unsigned char _StUC[124]; + signed char _StSC[124]; + char _StC [124]; + }; + + union { + /* c16/related functions: Surrogate storage + * + * If zero, no surrogate pending. If nonzero, surrogate. + */ + _PDCLIB_uint16_t _Surrogate; + + /* Reserved for potential mbtoutf8/etc functions */ + unsigned char _U8[4]; + }; +} _PDCLIB_mbstate_t; + #ifdef _PDCLIB_WCHAR_IS_UCS2 /* Must be cauued with bufsize >= 1, in != NULL, out != NULL, ps != NULL * @@ -27,7 +54,7 @@ typedef char32_t _PDCLIB_char32_t; static inline int _PDCLIB_wcrtoc32( _PDCLIB_char32_t *_PDCLIB_restrict out, const _PDCLIB_wchar_t *_PDCLIB_restrict in, - _PDCLIB__PDCLIB_size_t bufsize, + _PDCLIB_size_t bufsize, _PDCLIB_mbstate_t *_PDCLIB_restrict ps ) { @@ -68,7 +95,7 @@ static inline int _PDCLIB_wcrtoc32( static inline _PDCLIB_size_t _PDCLIB_c32rtowc( _PDCLIB_wchar_t *_PDCLIB_restrict out, const _PDCLIB_char32_t *_PDCLIB_restrict in, - _PDCLIB__PDCLIB_size_t bufsize, + _PDCLIB_size_t bufsize, _PDCLIB_mbstate_t *_PDCLIB_restrict ps ) { @@ -99,7 +126,7 @@ static inline _PDCLIB_size_t _PDCLIB_c32rtowc( static inline _PDCLIB_size_t _PDCLIB_wcrtoc32( _PDCLIB_char32_t *_PDCLIB_restrict out, const _PDCLIB_wchar_t *_PDCLIB_restrict in, - _PDCLIB__PDCLIB_size_t bufsize, + _PDCLIB_size_t bufsize, _PDCLIB_mbstate_t *_PDCLIB_restrict ps ) { @@ -110,7 +137,7 @@ static inline _PDCLIB_size_t _PDCLIB_wcrtoc32( static inline _PDCLIB_size_t _PDCLIB_c32rtowc( _PDCLIB_wchar_t *_PDCLIB_restrict out, const _PDCLIB_char32_t *_PDCLIB_restrict in, - _PDCLIB__PDCLIB_size_t bufsize, + _PDCLIB_size_t bufsize, _PDCLIB_mbstate_t *_PDCLIB_restrict ps ) { @@ -120,15 +147,21 @@ static inline _PDCLIB_size_t _PDCLIB_c32rtowc( #endif typedef struct { - /* Reads at most *_P_insz bytes from *_P_inbuf and writes the result into - * *_P_outbuf, writing at most *_P_outsz characters. Updates *_P_outbuf, - * *_P_outsz, *_P_inbuf, *_P_outsz with the resulting state + /* Reads at most *_P_insz code units from *_P_inbuf and writes the result + * into *_P_outbuf, writing at most *_P_outsz code units. Updates + * *_P_outbuf, *_P_outsz, *_P_inbuf, *_P_outsz with the resulting state + * + * If _P_outbuf is NULL, then the input must be processed but no output + * generated. _P_outsz may be processed as normal. * * Returns true if the conversion completed successfully (i.e. one of * _P_outsize or _P_insize reached zero and no coding errors were * encountered), else return false. */ - _PDCLIB_bool_t (*__mbtoc32)( + + /* UCS-4 variants. Mandatory. */ + + _PDCLIB_bool (*__mbstoc32s)( _PDCLIB_char32_t **_PDCLIB_restrict _P_outbuf, _PDCLIB_size_t *_PDCLIB_restrict _P_outsz, const char **_PDCLIB_restrict _P_inbuf, @@ -136,13 +169,35 @@ typedef struct { _PDCLIB_mbstate_t *_PDCLIB_restrict _P_ps ); - _PDCLIB_bool_t (*__c32tomb)( + _PDCLIB_bool (*__c32stombs)( char **_PDCLIB_restrict _P_outbuf, _PDCLIB_size_t *_PDCLIB_restrict _P_outsz, const _PDCLIB_char32_t **_PDCLIB_restrict _P_inbuf, _PDCLIB_size_t *_PDCLIB_restrict _P_insz, _PDCLIB_mbstate_t *_PDCLIB_restrict _P_ps ); + + /* UTF-16 variants; same as above except optional. + * + * If not provided, _PDCLib will internally synthesize on top of the UCS-4 + * variants above, albeit at a performance cost. + */ + + _PDCLIB_bool (*__mbstoc16s)( + _PDCLIB_char16_t **_PDCLIB_restrict _P_outbuf, + _PDCLIB_size_t *_PDCLIB_restrict _P_outsz, + const char **_PDCLIB_restrict _P_inbuf, + _PDCLIB_size_t *_PDCLIB_restrict _P_insz, + _PDCLIB_mbstate_t *_PDCLIB_restrict _P_ps + ); + + _PDCLIB_bool (*__c16stombs)( + char **_PDCLIB_restrict _P_outbuf, + _PDCLIB_size_t *_PDCLIB_restrict _P_outsz, + const _PDCLIB_char16_t **_PDCLIB_restrict _P_inbuf, + _PDCLIB_size_t *_PDCLIB_restrict _P_insz, + _PDCLIB_mbstate_t *_PDCLIB_restrict _P_ps + ); } _PDCLIB_charcodec; #endif