helos1/runtime/test_utf8.c

31 lines
607 B
C
Raw Permalink Normal View History

2021-10-10 14:39:17 +08:00
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include "Unicode.h"
int main(int argc, char *argv[]) {
char str[] = {"天王盖地虎,宝塔镇河妖"};
int len = strlen(str);
printf("String: %s, Length: %d\n", str, len);
uint32_t codepoint, buffer[128];
int count = 0;
for (int i = 0;
i < len;
i += utf8_Decode(str + i, len - i, buffer + count), count++) {}
printf("Count=%d\n", count);
for (int i = 0; i < count; i++) {
printf("Buffer[%d] = %d, ", i, buffer[i]);
char bytes[5] = {};
utf8_Encode(bytes, buffer[i]);
printf("%s\n", bytes);
}
return 0;
}