--- /dev/null
+/* mbsinit(mbstate_t *ps);\r
+\r
+ This file is part of the Public Domain C Library (PDCLib).\r
+ Permission is granted to use, modify, and / or redistribute at will.\r
+*/\r
+\r
+#include <wchar.h>\r
+#ifndef REGTEST\r
+#include <_PDCLIB_encoding.h>\r
+#include <_PDCLIB_locale.h>\r
+\r
+int _PDCLIB_mbsinit_l( const mbstate_t *ps, locale_t l )\r
+{\r
+ if( ps ) {\r
+ return ps->_Surrogate == 0\r
+ && ps->_PendState == 0\r
+ && l->_Codec->__mbsinit(ps);\r
+ } else return 1;\r
+}\r
+\r
+int mbsinit( const mbstate_t * ps )\r
+{\r
+ return _PDCLIB_mbsinit_l(ps, _PDCLIB_threadlocale());\r
+}\r
+\r
+#endif\r
+\r
+#ifdef TEST\r
+#include <_PDCLIB_test.h>\r
+\r
+int main( void )\r
+{\r
+ mbstate_t mbs;\r
+ memset(&mbs, 0, sizeof mbs);\r
+\r
+ TESTCASE(mbsinit(NULL) != 0);\r
+ TESTCASE(mbsinit(&mbs) != 0);\r
+\r
+#ifndef REGTEST\r
+ // Surrogate pending\r
+ mbs._Surrogate = 0xFEED;\r
+ TESTCASE(mbsinit(&mbs) == 0);\r
+\r
+ mbs._Surrogate = 0;\r
+ mbs._PendState = 1;\r
+ TESTCASE(mbsinit(&mbs) == 0);\r
+#endif\r
+ return TEST_RESULTS;\r
+}\r
+#endif\r
+\r
+\r
+\r
* encountered), else return false.
*/
+ /* mbsinit. Mandatory. */
+ _PDCLIB_bool (*__mbsinit)(const _PDCLIB_mbstate_t *_P_ps);
+
/* UCS-4 variants. Mandatory. */
_PDCLIB_bool (*__mbstoc32s)(
--- /dev/null
+.\" This file is part of the Public Domain C Library (PDCLib).\r
+.\" Permission is granted to use, modify, and / or redistribute at will.\r
+.\"\r
+.Dd\r
+.Dt MBSINIT 3\r
+.Os\r
+.\"\r
+.Sh NAME\r
+.Nm mbsinit\r
+.Nd determines multibyte conversion state\r
+.\"\r
+.Sh SYNOPSIS\r
+.In wchar.h\r
+.Fn "int mbsinit" "const mbstate_t *ps"\r
+.In xlocale.h\r
+.Fn "int mbsinit_l" "const mbstate_t *ps" "locale_t loc"\r
+.\"\r
+.Sh DESCRIPTION\r
+.Fn mbsinit \r
+and\r
+.Fn mbsinit_l \r
+shall return a nonzero value if the multibyte converison state pointed to by\r
+.Va ps\r
+corresponds to an initial conversion state. The interpretation of \r
+.Va *ps\r
+is locale dependent; the only guarantee is that an\r
+.Vt mbstate_t\r
+object initialized to zero shall correspond to an initial conversion state. If\r
+.Va ps\r
+is\r
+.Dv NULL ,\r
+then a nonzero value shall be returned.\r
+.\"\r
+.Pp\r
+The locale used for \r
+.Fn mbsinit\r
+shall be the currently active locale; either the current thread locale as set by\r
+.Xr uselocale 3\r
+if one has been specified, or otherwise the global locale controlled by\r
+.Xr setlocale 3 .\r
+The locale used by \r
+.Fn mbsinit_l\r
+is that specified by\r
+.Va loc .\r
+.\"\r
+.Sh SEE ALSO\r
+.Xr mbrtowc 3\r
+.Xr wcrtomb 3\r
+.Xr setlocale 3\r
+.Xr uselocale 3\r
+.\"\r
+.Sh STANDARDS\r
+.Fn mbsinit\r
+is first defined in\r
+.St -isoC-amd1 ;\r
+.Fn mbsinit_l\r
+is a nonstandard extension originating in Darwin. See\r
+.Xr xlocale.h 3
\ No newline at end of file
#include <uchar.h>
#include <_PDCLIB_encoding.h>
+static bool ascii_mbsinit( const mbstate_t *ps )
+{ return 1; }
+
static bool asciitoc32(
char32_t *restrict *restrict p_outbuf,
size_t *restrict p_outsz,
}
struct _PDCLIB_charcodec _PDCLIB_ascii_codec = {
+ .__mbsinit = ascii_mbsinit,
.__mbstoc32s = asciitoc32,
.__c32stombs = c32toascii,
.__mb_max = 1,
#include <uchar.h>
#include <_PDCLIB_encoding.h>
+static bool latin1_mbsinit( const mbstate_t *ps )
+{ return 1; }
+
static bool latin1toc32(
char32_t *restrict *restrict p_outbuf,
size_t *restrict p_outsz,
}
struct _PDCLIB_charcodec _PDCLIB_latin1_codec = {
+ .__mbsinit = latin1_mbsinit,
.__mbstoc32s = latin1toc32,
.__c32stombs = c32tolatin1,
.__mb_max = 1,
* _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,
_PDCLIB_UNDEFINED(accum); \
state = DecStart; \
} while(0)
+
#define CHECK_CONTINUATION \
do { if((c & 0xC0) != 0x80) return false; } while(0)
}
struct _PDCLIB_charcodec _PDCLIB_utf8_codec = {
+ .__mbsinit = utf8_mbsinit,
.__mbstoc32s = utf8toc32,
.__c32stombs = c32toutf8,
.__mb_max = 4,