X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=internals%2F_PDCLIB_locale.h;h=dbedc8093e1829b1ed32e1c956aeca2573483830;hb=495dc4306cf5b9437faa86b8c7a6eaeaa51ee83a;hp=09fa3c0128f877e4e85108fc02dcec839fcf2450;hpb=3682010e5b8bcd48fd82f3e604829f045c7ada29;p=pdclib diff --git a/internals/_PDCLIB_locale.h b/internals/_PDCLIB_locale.h index 09fa3c0..dbedc80 100644 --- a/internals/_PDCLIB_locale.h +++ b/internals/_PDCLIB_locale.h @@ -69,12 +69,55 @@ typedef struct _PDCLIB_ctype typedef struct _PDCLIB_wcinfo { - _PDCLIB_uint32_t num; + _PDCLIB_wint_t num; _PDCLIB_uint16_t flags; - _PDCLIB_uint32_t lower; - _PDCLIB_uint32_t upper; + _PDCLIB_wint_t lower; + _PDCLIB_wint_t upper; } _PDCLIB_wcinfo_t; +extern _PDCLIB_wcinfo_t _PDCLIB_wcinfo[]; +extern size_t _PDCLIB_wcinfo_size; + +static inline int _PDCLIB_wcinfo_cmp( const void * _key, const void * _obj ) +{ + _PDCLIB_uint32_t * key = (_PDCLIB_uint32_t *) _key; + _PDCLIB_wcinfo_t * obj = (_PDCLIB_wcinfo_t *) _obj; + return *key - obj->num; +} + +static inline _PDCLIB_wcinfo_t * _PDCLIB_wcgetinfo( _PDCLIB_uint32_t num ) +{ + _PDCLIB_wcinfo_t *info = (_PDCLIB_wcinfo_t*) + bsearch( &num, _PDCLIB_wcinfo, _PDCLIB_wcinfo_size, + sizeof( _PDCLIB_wcinfo[0] ), _PDCLIB_wcinfo_cmp ); + + return info; +} + +static inline _PDCLIB_wint_t _PDCLIB_unpackwint( _PDCLIB_wint_t wc ) +{ + if( sizeof(_PDCLIB_wchar_t) == 2 && sizeof(_PDCLIB_wint_t) == 4 ) { + /* On UTF-16 platforms, as an extension accept a "packed surrogate" + * encoding. We accept the surrogate pairs either way + */ + + _PDCLIB_wint_t c = (wc & 0xF800F800); + if(c == (_PDCLIB_wint_t) 0xD800DC00) { + // MSW: Lead, LSW: Trail + _PDCLIB_wint_t lead = wc >> 16 & 0x3FF; + _PDCLIB_wint_t trail = wc & 0x3FF; + wc = lead << 10 | trail; + } else if(c == (_PDCLIB_wint_t) 0xDC00D800) { + // MSW: Trail, LSW: Lead + _PDCLIB_wint_t trail = wc >> 16 & 0x3FF; + _PDCLIB_wint_t lead = wc & 0x3FF; + wc = lead << 10 | trail; + } + + } + return wc; +} + struct _PDCLIB_locale { _PDCLIB_charcodec_t _Codec; struct lconv _Conv;