55 karma · joined May 23, 2009 (17y ago) · 9 submissions
comment 14y ago · link · parent
comment 17y ago · link · parent
Using violence for any reason other than defense against violence is wrong. I don't understand why so many people have so much trouble with such a simple concept.
comment 17y ago · link · parent
comment 17y ago · link · parent
comment 17y ago · link · parent
comment 17y ago · link · parent
if (c < 0x80) *(s++) = c; // US-ASCII subset
else { // multi-byte UTF-8 sequence
for (b = 0, d = c; d; d /= 2) b++; // number of bits in c
b = (b - 2) / 5; // number of bytes in payload
*(s++) = (0xFF << (7 - b)) | (c >> (6 * b)); // head
while (b) *(s++) = 0x80 | ((c >> (6 * --b)) & 0x3F); // payload
}