retroforth/vm/nga-c/utf32.c
crc f734da8780 nga-c: implement more utf32_ functions
FossilOrigin-Name: 528dbf1960c805bee6c2048fda5b354e0c5bd02dc44bca787df9c7845c12039e
2024-09-18 16:42:22 +00:00

41 lines
826 B
C

size_t utf32_strlen(const int32_t *utf32_str) {
size_t length = 0;
while (utf32_str[length] != 0) {
length++;
}
return length;
}
void utf32_strcpy(int32_t *dest, const int32_t *src) {
while ((*dest++ = *src++) != 0);
}
int utf32_strcmp(const int32_t *str1, const int32_t *str2) {
while (*str1 && (*str1 == *str2)) {
str1++;
str2++;
}
return *str1 - *str2;
}
void c_to_utf32(const char *source, int32_t *dest, int max) {
int i = 0;
while (source[i] != '\0' && i < max - 1) {
dest[i] = (int32_t)source[i];
i++;
}
dest[i] = 0;
}
void utf32_to_c(const int32_t *source, char *dest, int max) {
int i = 0;
while (source[i] != 0 && i < max - 1) {
if (source[i] <= 0x7F) {
dest[i] = (char)source[i];
} else {
dest[i] = '?';
}
i++;
}
dest[i] = '\0';
}