X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=string_rep.h;h=f3a1e6b882533142d588a4dd942ecb6648ddff2f;hb=451c15e3a53e601d449512e71b1a9ab7960fa9ec;hp=e24b40c496527adeb71f0e9ddf2328f5d89ec79e;hpb=6d7d61de445629e1590d3a2ba2990ef7a651368a;p=cparser diff --git a/string_rep.h b/string_rep.h index e24b40c..f3a1e6b 100644 --- a/string_rep.h +++ b/string_rep.h @@ -20,18 +20,25 @@ #ifndef STRING_REP_H #define STRING_REP_H -#include - -typedef wchar_t wchar_rep_t; +#include +#include "unicode.h" typedef struct string_t { - const char *begin; - size_t size; + const char *begin; /**< UTF-8 encoded string, the last character is + * guaranteed to be 0 */ + size_t size; /**< size of string in bytes (not characters) */ } string_t; -typedef struct wide_string_t { - const wchar_rep_t *begin; - size_t size; -} wide_string_t; +static inline size_t wstrlen(const string_t *string) +{ + size_t result = 0; + const char *p = string->begin; + const char *end = p + string->size; + while (p < end) { + read_utf8_char(&p); + ++result; + } + return result; +} #endif