X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=string_rep.h;h=f3a1e6b882533142d588a4dd942ecb6648ddff2f;hb=127a634aa53da8c37ee50f365184cccad67df0d8;hp=4b64fe1dcb668d6e5346c850e0aa399185b63978;hpb=fd16b92f058181088a385c3224c8814831c006d3;p=cparser diff --git a/string_rep.h b/string_rep.h index 4b64fe1..f3a1e6b 100644 --- a/string_rep.h +++ b/string_rep.h @@ -1,6 +1,6 @@ /* * This file is part of cparser. - * Copyright (C) 2007-2008 Matthias Braun + * Copyright (C) 2007-2009 Matthias Braun * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -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