Created
January 28, 2014 00:53
-
-
Save soldair/8660477 to your computer and use it in GitHub Desktop.
utf8 js functions
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
var UTF8_MASK = [0x80,0xc0,0xe0,0xf0]; | |
function utf8l(b){ | |
if (!(b & 0x80)) { | |
return 1; | |
} else if ((b & 0xE0) === 0xC0){ | |
return 2; | |
} else if ((b & 0xF0) === 0xE0) { | |
return 3; | |
} else if ((b & 0xF8) === 0xF0) { | |
return 4; | |
} else { | |
return 0; | |
} | |
} | |
// length,byte,character so far,number charater | |
function utf8c(l,b,c,n){ | |
c |= (b&~UTF8_MASK[l-1])<<(n-1)*6; | |
return c; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment