-
-
Save elextr/994dcf61b7f009297e229aba7f46f93d to your computer and use it in GitHub Desktop.
unchecked utf-8 decoding
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
typedef unsigned int Codepoint; // any unsigned int > 21 bits | |
Codepoint getcp(const char* &c){ | |
if(*c == 0)return 0; | |
Codepoint cp = static_cast<Codepoint>(*c++) & 0xff; // works for signed or unsigned chars | |
if(cp < 0x80)goto onebyte; | |
if(cp < 0xe0){ cp &= 0x1f; goto twobyte; } | |
if(cp < 0xf0){ cp &= 0x0f; goto threebyte; } | |
cp &= 0x07; | |
cp = (cp << 6) + (*c++ & 0x3f); | |
threebyte: | |
cp = (cp << 6) + (*c++ & 0x3f); | |
twobyte: | |
cp = (cp << 6) + (*c++ & 0x3f); | |
onebyte: | |
return cp; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment