Last active
December 16, 2015 10:28
-
-
Save mfukar/5419950 to your computer and use it in GitHub Desktop.
Epic Fail UCS-2 to UTF-8 conversion.
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
/* This is how a PhD holder thinks UCS-2 is converted to UTF-8 */ | |
size_t gsm_convert_ucs2(const uint8_t *buf, size_t length, unsigned char *dest) | |
{ | |
size_t i; | |
size_t j; | |
for (i=0,j=0;i<length;i+=2) { | |
if (buf[i] == 0) | |
dest[j++] = buf[i+1]; | |
else { | |
snprintf((char *)&dest[j], 256-j, "\\%02x%02x", buf[i], buf[i+1]); | |
j+=5; | |
} | |
return j; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment