mirror of
https://github.com/NeoFlock/neonucleus.git
synced 2025-09-24 09:03:32 +02:00
Merge branch 'main' of https://github.com/NeoFlock/neonucleus
This commit is contained in:
commit
f3fb794e76
@ -45,9 +45,44 @@ size_t nn_unicode_len(const char *s) {
|
|||||||
|
|
||||||
int nn_unicode_codepointAt(const char *s, size_t byteOffset);
|
int nn_unicode_codepointAt(const char *s, size_t byteOffset);
|
||||||
|
|
||||||
size_t nn_unicode_codepointSize(int codepoint);
|
size_t nn_unicode_codepointSize(int codepoint) {
|
||||||
|
if (codepoint <= 0x007f) {
|
||||||
|
return 1;
|
||||||
|
} else if (codepoint <= 0x07ff) {
|
||||||
|
return 2;
|
||||||
|
} else if (codepoint <= 0xffff) {
|
||||||
|
return 3;
|
||||||
|
} else if (codepoint <= 0x10ffff) {
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
|
||||||
const char *nn_unicode_codepointToChar(int codepoint, size_t *len);
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *nn_unicode_codepointToChar(int codepoint, size_t *len) {
|
||||||
|
size_t codepointSize = nn_unicode_codepointSize(codepoint);
|
||||||
|
*len = codepointSize;
|
||||||
|
|
||||||
|
static char buffer[4];
|
||||||
|
|
||||||
|
if (codepointSize == 1) {
|
||||||
|
buffer[0] = (char)codepoint;
|
||||||
|
} else if (codepointSize == 2) {
|
||||||
|
buffer[0] = 0b11000000 + (codepoint & 0b11111);
|
||||||
|
buffer[1] = 0b10000000 + (codepoint >> 5);
|
||||||
|
} else if (codepointSize == 3) {
|
||||||
|
buffer[0] = 0b11100000 + (codepoint & 0b1111);
|
||||||
|
buffer[1] = 0b10000000 + ((codepoint >> 4) & 0b111111);
|
||||||
|
buffer[2] = 0b10000000 + (codepoint >> 10);
|
||||||
|
} else if (codepointSize == 4) {
|
||||||
|
buffer[0] = 0b11110000 + (codepoint & 0b111);
|
||||||
|
buffer[1] = 0b10000000 + ((codepoint >> 3) & 0b111111);
|
||||||
|
buffer[2] = 0b10000000 + ((codepoint >> 9) & 0b111111);
|
||||||
|
buffer[3] = 0b10000000 + (codepoint >> 15);
|
||||||
|
}
|
||||||
|
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
size_t nn_unicode_charWidth(int codepoint);
|
size_t nn_unicode_charWidth(int codepoint);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user