ast2firm: Factorise code to convert a value to its storage type.
[cparser] / unicode.h
index 2088197..b6a16e3 100644 (file)
--- a/unicode.h
+++ b/unicode.h
@@ -2,6 +2,7 @@
 #define UNICODE_H
 
 #include <assert.h>
+#include "adt/obst.h"
 
 typedef unsigned int utf32;
 #define UTF32_PRINTF_FORMAT "%u"
@@ -44,4 +45,24 @@ static inline utf32 read_utf8_char(const char **p)
        return result;
 }
 
+static inline void obstack_grow_utf8(struct obstack *const obst, utf32 const c)
+{
+       if (c < 0x80U) {
+               obstack_1grow(obst, c);
+       } else if (c < 0x800) {
+               obstack_1grow(obst, 0xC0 |  (c >>  6));
+               goto one_more;
+       } else if (c < 0x10000) {
+               obstack_1grow(obst, 0xE0 |  (c >> 12));
+               goto two_more;
+       } else {
+               obstack_1grow(obst, 0xF0 |  (c >> 18));
+               obstack_1grow(obst, 0x80 | ((c >> 12) & 0x3F));
+two_more:
+               obstack_1grow(obst, 0x80 | ((c >>  6) & 0x3F));
+one_more:
+               obstack_1grow(obst, 0x80 | ( c        & 0x3F));
+       }
+}
+
 #endif