]> pd.if.org Git - pdclib.old/blobdiff - opt/basecodecs/_PDCLIB_ascii.c
Minimize the amount of internal definitions which get exposed via the user-visible...
[pdclib.old] / opt / basecodecs / _PDCLIB_ascii.c
index ca70a667af84069938925c81605a836c35883317..e84563f747a68b7a50ed8b3a3dfc63f6e3322dcc 100644 (file)
@@ -7,6 +7,7 @@
 #include <stdbool.h>
 #ifndef REGTEST
 #include <uchar.h>
+#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