X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=opt%2Fbasecodecs%2F_PDCLIB_ascii.c;h=e07e2ba217a341c5199d798f3979d6394ea11d49;hb=fb44227179cd8d0dbaaf694fba2d4861106add75;hp=ca70a667af84069938925c81605a836c35883317;hpb=8a7a5dad5d84a3afbfd6b5833d4c97bd146a4d70;p=pdclib.old diff --git a/opt/basecodecs/_PDCLIB_ascii.c b/opt/basecodecs/_PDCLIB_ascii.c index ca70a66..e07e2ba 100644 --- a/opt/basecodecs/_PDCLIB_ascii.c +++ b/opt/basecodecs/_PDCLIB_ascii.c @@ -7,23 +7,27 @@ #include #ifndef REGTEST #include +#include <_PDCLIB_encoding.h> static bool asciitoc32( - char32_t **restrict p_outbuf, - size_t *restrict p_outsz, - const char **restrict p_inbuf, - size_t *restrict p_insz, - mbstate_t *restrict p_ps + char32_t *restrict *restrict p_outbuf, + size_t *restrict p_outsz, + const char *restrict *restrict p_inbuf, + size_t *restrict p_insz, + mbstate_t *restrict p_ps ) { while(*p_outsz && *p_insz) { unsigned char c = **p_inbuf; if(c > 127) return false; - **p_outbuf = c; + + if(p_outbuf) { + **p_outbuf = c; + (*p_outbuf)++; + } (*p_inbuf)++; - (*p_outbuf)++; (*p_insz)--; (*p_outsz)--; } @@ -31,26 +35,36 @@ static bool asciitoc32( } static bool c32toascii( - char **restrict p_outbuf, - size_t *restrict p_outsz, - const char32_t **restrict p_inbuf, - size_t *restrict p_insz, - mbstate_t *restrict p_ps + char *restrict *restrict p_outbuf, + size_t *restrict p_outsz, + const char32_t *restrict *restrict p_inbuf, + size_t *restrict p_insz, + mbstate_t *restrict p_ps ) { while(*p_outsz && *p_insz) { char32_t c = **p_inbuf; if(c > 127) return false; - **p_outbuf = c; + + if(p_outbuf) { + **p_outbuf = c; + (*p_outbuf)++; + } (*p_inbuf)++; - (*p_outbuf)++; (*p_insz)--; (*p_outsz)--; } return true; } + +struct _PDCLIB_charcodec _PDCLIB_ascii_codec = { + .__mbstoc32s = asciitoc32, + .__c32stombs = c32toascii, + .__mb_max = 1, +}; + #endif #ifdef TEST