summaryrefslogtreecommitdiff
path: root/xs_encdec.h
diff options
context:
space:
mode:
Diffstat (limited to 'xs_encdec.h')
-rw-r--r--xs_encdec.h33
1 files changed, 0 insertions, 33 deletions
diff --git a/xs_encdec.h b/xs_encdec.h
index 2502520..d3178f4 100644
--- a/xs_encdec.h
+++ b/xs_encdec.h
@@ -14,7 +14,6 @@
14 xs_str *xs_base64_enc(const xs_val *data, int sz); 14 xs_str *xs_base64_enc(const xs_val *data, int sz);
15 xs_val *xs_base64_dec(const xs_str *data, int *size); 15 xs_val *xs_base64_dec(const xs_str *data, int *size);
16 int xs_is_base64(const char *str); 16 int xs_is_base64(const char *str);
17 xs_str *xs_utf8_enc(xs_str *str, unsigned int cpoint);
18 17
19 18
20#ifdef XS_IMPLEMENTATION 19#ifdef XS_IMPLEMENTATION
@@ -383,38 +382,6 @@ int xs_is_base64(const char *str)
383} 382}
384 383
385 384
386/** utf-8 **/
387
388xs_str *xs_utf8_enc(xs_str *str, unsigned int cpoint)
389/* encodes an Unicode codepoint to utf8 */
390{
391 unsigned char tmp[4];
392 int n = 0;
393
394 if (cpoint < 0x80)
395 tmp[n++] = cpoint & 0xff;
396 else
397 if (cpoint < 0x800) {
398 tmp[n++] = 0xc0 | (cpoint >> 6);
399 tmp[n++] = 0x80 | (cpoint & 0x3f);
400 }
401 else
402 if (cpoint < 0x10000) {
403 tmp[n++] = 0xe0 | (cpoint >> 12);
404 tmp[n++] = 0x80 | ((cpoint >> 6) & 0x3f);
405 tmp[n++] = 0x80 | (cpoint & 0x3f);
406 }
407 else
408 if (cpoint < 0x200000) {
409 tmp[n++] = 0xf0 | (cpoint >> 18);
410 tmp[n++] = 0x80 | ((cpoint >> 12) & 0x3f);
411 tmp[n++] = 0x80 | ((cpoint >> 6) & 0x3f);
412 tmp[n++] = 0x80 | (cpoint & 0x3f);
413 }
414
415 return xs_append_m(str, (char *)tmp, n);
416}
417
418#endif /* XS_IMPLEMENTATION */ 385#endif /* XS_IMPLEMENTATION */
419 386
420#endif /* _XS_ENCDEC_H */ 387#endif /* _XS_ENCDEC_H */