type: Add missing space for printing complex types.
[cparser] / string_rep.c
1 #include "adt/error.h"
2 #include "string_rep.h"
3
4 static inline size_t wstrlen(const string_t *string)
5 {
6         size_t      result = 0;
7         const char *p      = string->begin;
8         const char *end    = p + string->size;
9         while (p < end) {
10                 read_utf8_char(&p);
11                 ++result;
12         }
13         return result;
14 }
15
16 size_t get_string_len(string_t const *const str)
17 {
18         switch (str->encoding) {
19         case STRING_ENCODING_CHAR:
20         case STRING_ENCODING_UTF8:   return str->size;
21         case STRING_ENCODING_CHAR16:
22         case STRING_ENCODING_CHAR32:
23         case STRING_ENCODING_WIDE:   return wstrlen(str);
24         }
25         panic("invalid string encoding");
26 }