import core.stdc.string;
import core.stdc.stdlib;
import core.stdc.stdio;
import utf8proc;
@nogc nothrow:
extern (C) int main()
{
string mstring = "ğüşöç ııİıııŞıÜııÇıı"; // 20 entries
// duplicate mstring and cast it to ubyte*
ubyte* mstr = cast(ubyte*)malloc(mstring.length + 1);
memcpy(mstr, mstring.ptr, mstring.length + 1);
// some buffer for output.
ubyte* dst;
auto sz = utf8proc_map(mstr, mstring.length, &dst, UTF8PROC_NULLTERM);
printf("your string: %s \n", cast(char*)dst);
utf8proc_ssize_t size = sz;
utf8proc_int32_t data;
utf8proc_ssize_t n;
ubyte* char_ptr = mstr;
printf("Those are your utf8 characters one by one: \n".ptr);
size_t nchar;
while ((n = utf8proc_iterate(char_ptr, size, &data)) > 0) {
printf("%.*s \n", cast(int)n, char_ptr);
char_ptr += n;
size -= n;
nchar++;
}
// assert(nchar == 20);
printf("You have %d entries in your string!", nchar);
free(mstr);
free(dst);
return 0;
}
-
Notifications
You must be signed in to change notification settings - Fork 0
A D port of utf8proc
License
aferust/utf8proc-d
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|