mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-05 00:50:53 +00:00
calculate utf8 length
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@241 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
@@ -21,6 +21,13 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
MWDECL int MwUTF8ToUTF32(const char* input, int* output);
|
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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -58,3 +58,19 @@ int MwUTF8ToUTF32(const char* input, int* output) {
|
|||||||
|
|
||||||
return b;
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ static int create(MwWidget handle) {
|
|||||||
|
|
||||||
MwSetDefault(handle);
|
MwSetDefault(handle);
|
||||||
|
|
||||||
|
MwSetText(handle, MwNtext, "こんにちは、世界");
|
||||||
MwLLSetCursor(handle->lowlevel, &MwCursorText, &MwCursorTextMask);
|
MwLLSetCursor(handle->lowlevel, &MwCursorText, &MwCursorTextMask);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user