3 This file is part of the Public Domain C Library (PDCLib).
4 Permission is granted to use, modify, and / or redistribute at will.
11 static bool asciitoc32(
12 char32_t **restrict p_outbuf,
13 size_t *restrict p_outsz,
14 const char **restrict p_inbuf,
15 size_t *restrict p_insz,
16 mbstate_t *restrict p_ps
19 while(*p_outsz && *p_insz) {
20 unsigned char c = **p_inbuf;
33 static bool c32toascii(
34 char **restrict p_outbuf,
35 size_t *restrict p_outsz,
36 const char32_t **restrict p_inbuf,
37 size_t *restrict p_insz,
38 mbstate_t *restrict p_ps
41 while(*p_outsz && *p_insz) {
42 char32_t c = **p_inbuf;
57 #include <_PDCLIB_test.h>
62 // Valid conversion & back
66 char32_t *c32ptr = &c32out[0];
68 char *chrptr = (char*) &abcde[0];
70 mbstate_t mbs = { 0 };
72 TESTCASE(asciitoc32(&c32ptr, &c32rem, &chrptr, &chrrem, &mbs) == true);
73 TESTCASE(c32rem == 0);
74 TESTCASE(chrrem == 0);
75 TESTCASE(c32ptr == &c32out[5]);
76 TESTCASE(chrptr == &abcde[5]);
77 TESTCASE(c32out[0] == 'a' && c32out[1] == 'b' && c32out[2] == 'c' && \
78 c32out[3] == 'd' && c32out[4] == 'e');
87 TESTCASE(c32toascii(&chrptr, &chrrem, &c32ptr, &c32rem, &mbs) == true);
88 TESTCASE(c32rem == 0);
89 TESTCASE(chrrem == 0);
90 TESTCASE(c32ptr == &c32out[5]);
91 TESTCASE(chrptr == &chrout[5]);
92 TESTCASE(memcmp(chrout, abcde, 5) == 0);
94 // Invalid conversions
95 char badascii = '\xC0';
100 TESTCASE(asciitoc32(&c32ptr, &c32rem, &chrptr, &chrrem, &mbs) == false);
101 TESTCASE(c32ptr == &c32out[0]);
102 TESTCASE(c32rem == 5);
103 TESTCASE(chrptr == &badascii);
104 TESTCASE(chrrem == 1);
106 char32_t baduni = 0xC0;
111 TESTCASE(c32toascii(&chrptr, &chrrem, &c32ptr, &c32rem, &mbs) == false);
112 TESTCASE(c32ptr == &baduni);
113 TESTCASE(c32rem == 1);
114 TESTCASE(chrptr == &chrout[0]);
115 TESTCASE(chrrem == 5);