]> pd.if.org Git - pdclib.old/blobdiff - opt/basecodecs/_PDCLIB_utf8.c
PDCLIB-2 PDCLIB-9 mbsinit
[pdclib.old] / opt / basecodecs / _PDCLIB_utf8.c
index 8183aef254ecd69e2126b06ea9d1d7686f2b3863..a93454194fb04ea3a845168351a0ee86df2a46e8 100644 (file)
@@ -9,6 +9,7 @@
 #include <stdint.h>
 #include <uchar.h>
 #include <assert.h>
+#include <_PDCLIB_encoding.h>
 
 /* Use of the mbstate:
  *
@@ -16,6 +17,9 @@
  * _St32[1] is the character accumulated so far
  */
 
+static bool utf8_mbsinit( const mbstate_t *p_s )
+{ return p_s->_StUC[0] == 0; }
+
 enum {
     DecStart = 0,
 
@@ -51,15 +55,16 @@ end_conversion:             \
     _PDCLIB_UNDEFINED(accum);       \
     state = DecStart;               \
 } while(0)
+
 #define CHECK_CONTINUATION \
     do { if((c & 0xC0) != 0x80) return false; } while(0)
 
 static bool utf8toc32(
-    char32_t       **restrict   p_outbuf,
-    size_t          *restrict   p_outsz,
-    const char     **restrict   p_inbuf,
-    size_t          *restrict   p_insz,
-    mbstate_t       *restrict   p_s
+    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_s
 )
 {
     START_CONVERSION
@@ -164,11 +169,11 @@ enum {
 };
 
 static bool c32toutf8(
-    char           **restrict  p_outbuf,
-    size_t          *restrict  p_outsz,
-    const char32_t **restrict  p_inbuf,
-    size_t          *restrict  p_insz,
-    mbstate_t       *restrict  p_s
+    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_s
 )
 {
     START_CONVERSION
@@ -227,9 +232,11 @@ static bool c32toutf8(
     END_CONVERSION;
 }
 
-_PDCLIB_charcodec _PDCLIB_utf8_codec = {
+struct _PDCLIB_charcodec _PDCLIB_utf8_codec = {
+    .__mbsinit   = utf8_mbsinit,
     .__mbstoc32s = utf8toc32,
     .__c32stombs = c32toutf8,
+    .__mb_max    = 4,
 };
 
 #endif