diff --git a/include/Mw/Unicode.h b/include/Mw/Unicode.h index 3ac23a4..23893a1 100644 --- a/include/Mw/Unicode.h +++ b/include/Mw/Unicode.h @@ -21,6 +21,13 @@ extern "C" { */ MWDECL int MwUTF8ToUTF32(const char* input, int* output); +/*! + * %brief Calculates UTF-8 string length + * %brief input Input + * %return Length + */ +MWDECL int MwUTF8Length(const char* input); + #ifdef __cplusplus } #endif diff --git a/src/unicode.c b/src/unicode.c index e557dd1..04b2a34 100644 --- a/src/unicode.c +++ b/src/unicode.c @@ -58,3 +58,19 @@ int MwUTF8ToUTF32(const char* input, int* output) { return b; } + +int MwUTF8Length(const char* input) { + int out; + int len = 0; + + while(input[0] != 0) { + int new; + + input += (new = MwUTF8ToUTF32(input, &out)); + len++; + + if(new == 0) return -1; + } + + return len; +} diff --git a/src/widget/entry.c b/src/widget/entry.c index e75bd28..8f77a31 100644 --- a/src/widget/entry.c +++ b/src/widget/entry.c @@ -13,6 +13,7 @@ static int create(MwWidget handle) { MwSetDefault(handle); + MwSetText(handle, MwNtext, "こんにちは、世界"); MwLLSetCursor(handle->lowlevel, &MwCursorText, &MwCursorTextMask); return 0;