This commit is contained in:
Justin Ethier 2017-10-25 17:21:53 +00:00
parent 96c3846b43
commit ccfde220ff

8
test.c
View file

@ -37,6 +37,12 @@ uint32_t Cyc_utf8_decode(uint32_t* state, uint32_t* codep, uint32_t byte) {
return *state; return *state;
} }
/**
* Simple macro to make it more convenient to convert a single char
*/
#define Cyc_utf8_encode_char(dest, dest_size, char_value) \
Cyc_utf8_encode(dest, dest_size, &char_value, 1)
/** /**
* This function takes one or more 32-bit chars and encodes them * This function takes one or more 32-bit chars and encodes them
* as an array of UTF-8 bytes. * as an array of UTF-8 bytes.
@ -102,7 +108,7 @@ void encode(uint32_t val) {
char dest[5]; char dest[5];
int rv, i; int rv, i;
rv = Cyc_utf8_encode(dest, 5, &val, 1); rv = Cyc_utf8_encode_char(dest, 5, val);
printf("%x %d \n", val, rv); printf("%x %d \n", val, rv);
for(i = 0; i < 5; i++) { for(i = 0; i < 5; i++) {
printf("[%x] ", (uint8_t)dest[i]); printf("[%x] ", (uint8_t)dest[i]);