vg4->misc->utf8_next()
Find next UTF8-character in an UTF8-string.
SYNTAX
int
vg4->misc->utf8_next(const char *string, size_t size, int *codept)
FUNCTION PARAMETERS
string | String |
size | Number of bytes in string |
codept | For returning Unicode-codepoint of found UTF8-character, if not NULL |
RETURN VALUE
Returns integer:
- >0: of how many bytes UTF8-character consists
- 0: end of string
- -1: invalid character found
DESCRIPTION
Find next UTF8-character in an UTF8-string.
EXAMPLE
/* show characters of cstring */ const char *cstring = "Wörd"; const char *strptr; size_t strsize; int no_bytes, codept; /* set strptr at the beginning of the UTF8-string */ strptr = cstring; strsize = strlen(strptr); for (;;) { /* get next UTF8-character */ no_bytes = vg4->misc->utf8_next(strptr, strsize, &codept); if (no_bytes <= 0) { break; } printf("UTF8-character: codepoint = %d, number of bytes = %d: %.*s\n", codept, no_bytes, no_bytes, strptr); /* set strptr to next UTF8-character */ strptr += no_bytes; strsize -= no_bytes; } Output: UTF8-character: codepoint = 87, number of bytes = 1: W UTF8-character: codepoint = 246, number of bytes = 2: ö UTF8-character: codepoint = 114, number of bytes = 1: r UTF8-character: codepoint = 100, number of bytes = 1: d
SEE ALSO