Created
October 15, 2019 00:18
-
-
Save vinniefalco/d416eefae1bc2d317c1dc712d75db2eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static | |
int | |
utf8_encode( | |
char* dest, | |
unsigned long cp) | |
{ | |
if(cp < 0x80) | |
{ | |
dest[0] = static_cast<char>(cp); | |
return 1; | |
} | |
if(cp < 0x800) | |
{ | |
dest[0] = static_cast<char>((cp >> 6) | 0xc0); | |
dest[1] = static_cast<char>((cp & 0x3f) | 0x80); | |
return 2; | |
} | |
if(cp < 0x10000) | |
{ | |
dest[0] = static_cast<char>((cp >> 12) | 0xe0); | |
dest[1] = static_cast<char>(((cp >> 6) & 0x3f) | 0x80); | |
dest[2] = static_cast<char>((cp & 0x3f) | 0x80); | |
return 3; | |
} | |
{ | |
dest[0] = static_cast<char>((cp >> 18) | 0xf0); | |
dest[1] = static_cast<char>(((cp >> 12) & 0x3f) | 0x80); | |
dest[2] = static_cast<char>(((cp >> 6) & 0x3f) | 0x80); | |
dest[3] = static_cast<char>((cp & 0x3f) | 0x80); | |
return 4; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment