]> pd.if.org Git - pdclib/blobdiff - opt/basecodecs/_PDCLIB_utf8.c
Compiler warnings regarding const > non-const assignments. Fixed.
[pdclib] / opt / basecodecs / _PDCLIB_utf8.c
index bac0e824a7f9b5a1d0b662058778f32f34eceb79..7966d882afb520a9435c816c1c66f5db0b6ce70e 100644 (file)
@@ -17,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,
 
@@ -52,6 +55,7 @@ end_conversion:             \
     _PDCLIB_UNDEFINED(accum);       \
     state = DecStart;               \
 } while(0)
+
 #define CHECK_CONTINUATION \
     do { if((c & 0xC0) != 0x80) return false; } while(0)
 
@@ -228,7 +232,8 @@ static bool c32toutf8(
     END_CONVERSION;
 }
 
-struct _PDCLIB_charcodec _PDCLIB_utf8_codec = {
+const struct _PDCLIB_charcodec _PDCLIB_utf8_codec = {
+    .__mbsinit   = utf8_mbsinit,
     .__mbstoc32s = utf8toc32,
     .__c32stombs = c32toutf8,
     .__mb_max    = 4,
@@ -249,11 +254,11 @@ int main( void )
 
     char32_t c32out[8];
 
-    char32_t *c32ptr = &c32out[0];
-    size_t    c32rem = 8;
-    char     *chrptr = (char*) &input[0];
-    size_t    chrrem = strlen(input);
-    mbstate_t mbs = { 0 };
+    char32_t   *c32ptr = &c32out[0];
+    size_t      c32rem = 8;
+    const char *chrptr = (char*) &input[0];
+    size_t      chrrem = strlen(input);
+    mbstate_t   mbs = { 0 };
 
     TESTCASE(utf8toc32(&c32ptr, &c32rem, &chrptr, &chrrem, &mbs));
     TESTCASE(c32rem == 0);