76 #define STR(x) vstring_str(x)
77 #define LEN(x) VSTRING_LEN(x)
84 unsigned const char *cp;
87 for (cp = (
unsigned const char *) unquoted; (ch = *cp) != 0; cp++) {
89 if (ch !=
'\\' && ch > 32 && ch < 127
90 && (*special == 0 || strchr(special, ch) == 0)) {
104 }
else if ((ch & 0xe0) == 0xc0) {
106 unicode = (ch & 0x1f);
108 }
else if ((ch & 0xf0) == 0xe0) {
110 unicode = (ch & 0x0f);
112 }
else if ((ch & 0xf8) == 0xf0) {
114 unicode = (ch & 0x07);
116 }
else if ((ch & 0xfc) == 0xf8) {
118 unicode = (ch & 0x03);
120 }
else if ((ch & 0xfe) == 0xfc) {
122 unicode = (ch & 0x01);
129 if ((ch & 0xc0) != 0x80)
131 unicode = unicode << 6 | (ch & 0x3f);
154 const unsigned char *cp;
157 for (cp = (
const unsigned char *) quoted; (ch = *cp) != 0; cp++) {
158 if (ch ==
'\\' && cp[1] ==
'x' && cp[2] ==
'{') {
162 while ((ch = *++cp) !=
'}') {
164 unicode = (unicode << 4) + (ch -
'0');
165 else if (ch >=
'a' && ch <=
'f')
166 unicode = (unicode << 4) + (ch -
'a' + 10);
167 else if (ch >=
'A' && ch <=
'F')
168 unicode = (unicode << 4) + (ch -
'A' + 10);
172 if (unicode > 0x10ffff)
181 if (unicode < 0x80) {
183 }
else if (unicode < 0x800) {
186 }
else if (unicode < 0x10000) {
188 VSTRING_ADDCH(unquoted, 0x80 | ((
char) (unicode >> 6) & 0x3f));
190 }
else if (unicode < 0x200000) {
192 VSTRING_ADDCH(unquoted, 0x80 | ((
char) (unicode >> 12) & 0x3f));
193 VSTRING_ADDCH(unquoted, 0x80 | ((
char) (unicode >> 6) & 0x3f));
195 }
else if (unicode < 0x4000000) {
197 VSTRING_ADDCH(unquoted, 0x80 | ((
char) (unicode >> 18) & 0x3f));
198 VSTRING_ADDCH(unquoted, 0x80 | ((
char) (unicode >> 12) & 0x3f));
199 VSTRING_ADDCH(unquoted, 0x80 | ((
char) (unicode >> 6) & 0x3f));
203 VSTRING_ADDCH(unquoted, 0x80 | ((
char) (unicode >> 24) & 0x3f));
204 VSTRING_ADDCH(unquoted, 0x80 | ((
char) (unicode >> 18) & 0x3f));
205 VSTRING_ADDCH(unquoted, 0x80 | ((
char) (unicode >> 12) & 0x3f));
206 VSTRING_ADDCH(unquoted, 0x80 | ((
char) (unicode >> 6) & 0x3f));
245 int main(
int unused_argc,
char **unused_argv)
255 msg_warn(
"undetected error pattern 1");
257 msg_warn(
"undetected error pattern 2");
259 msg_warn(
"undetected error pattern 3");
264 while ((len = read_buf(
VSTREAM_IN, unquoted)) > 0) {
268 if (
LEN(unquoted) != len)
270 (
long) len, (
long)
LEN(unquoted));
VSTRING * uxtext_unquote_append(VSTRING *unquoted, const char *quoted)
int main(int argc, char **argv)
VSTRING * uxtext_quote_append(VSTRING *quoted, const char *unquoted, const char *special)
#define VSTRING_TERMINATE(vp)
#define VSTRING_ADDCH(vp, ch)
VSTRING * vstring_sprintf_append(VSTRING *vp, const char *format,...)
VSTRING * uxtext_quote(VSTRING *quoted, const char *unquoted, const char *special)
#define VSTRING_RESET(vp)
void msg_warn(const char *fmt,...)
VSTRING * vstring_alloc(ssize_t len)
#define vstring_avail(vp)
NORETURN msg_fatal(const char *fmt,...)
#define vstream_fread(v, b, n)
int vstream_fflush(VSTREAM *stream)
#define vstream_fwrite(v, b, n)
VSTRING * vstring_free(VSTRING *vp)
#define VSTRING_AT_OFFSET(vp, offset)
VSTRING * uxtext_unquote(VSTRING *unquoted, const char *quoted)