X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=unicode.h;h=18b19d56d5ead4e7bee30316b3da447234fa6675;hb=f7f1fcc7021a3c622316b6415c16f83d0a64ae4a;hp=208819766e46c877de3ec3e987baa4992b24eb19;hpb=5e80d9852edea8472cd478655d70f5c4a1eddbdc;p=cparser diff --git a/unicode.h b/unicode.h index 2088197..18b19d5 100644 --- a/unicode.h +++ b/unicode.h @@ -2,6 +2,7 @@ #define UNICODE_H #include +#include "adt/obst.h" typedef unsigned int utf32; #define UTF32_PRINTF_FORMAT "%u" @@ -44,4 +45,23 @@ static inline utf32 read_utf8_char(const char **p) return result; } +static inline void obstack_grow_symbol(struct obstack *obstack, utf32 const tc) +{ + if (tc < 0x80U) { + obstack_1grow(obstack, tc); + } else if (tc < 0x800) { + obstack_1grow(obstack, 0xC0 | (tc >> 6)); + obstack_1grow(obstack, 0x80 | (tc & 0x3F)); + } else if (tc < 0x10000) { + obstack_1grow(obstack, 0xE0 | ( tc >> 12)); + obstack_1grow(obstack, 0x80 | ((tc >> 6) & 0x3F)); + obstack_1grow(obstack, 0x80 | ( tc & 0x3F)); + } else { + obstack_1grow(obstack, 0xF0 | ( tc >> 18)); + obstack_1grow(obstack, 0x80 | ((tc >> 12) & 0x3F)); + obstack_1grow(obstack, 0x80 | ((tc >> 6) & 0x3F)); + obstack_1grow(obstack, 0x80 | ( tc & 0x3F)); + } +} + #endif