X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=opt%2Fbasecodecs%2F_PDCLIB_ascii.c;h=e84563f747a68b7a50ed8b3a3dfc63f6e3322dcc;hb=0e35e82c5e9a0804864839e8fc0e985b1ae41f07;hp=ca70a667af84069938925c81605a836c35883317;hpb=8a7a5dad5d84a3afbfd6b5833d4c97bd146a4d70;p=pdclib.old diff --git a/opt/basecodecs/_PDCLIB_ascii.c b/opt/basecodecs/_PDCLIB_ascii.c index ca70a66..e84563f 100644 --- a/opt/basecodecs/_PDCLIB_ascii.c +++ b/opt/basecodecs/_PDCLIB_ascii.c @@ -7,6 +7,7 @@ #include #ifndef REGTEST #include +#include <_PDCLIB_encoding.h> static bool asciitoc32( char32_t **restrict p_outbuf, @@ -20,10 +21,13 @@ static bool asciitoc32( 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)--; } @@ -42,15 +46,24 @@ static bool c32toascii( 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; } + +_PDCLIB_charcodec_t _PDCLIB_ascii_codec = { + .__mbstoc32s = asciitoc32, + .__c32stombs = c32toascii, +}; + #endif #ifdef TEST