End of the multi-octet sequence. mUcs4 now contains the final Unicode codepoint to be output
((0xC0 & (*in) != 0x80) && (mState != 0)) Incomplete multi-octet sequence.
{
$mState = 0;
$mUcs4 = 0;
$mBytes = 1;
$len = strlen($str);
for($i = 0; $i < $len; $i++) {
$in = ord($str{$i});
if ( $mState == 0) {
if (0 == (0x80 & ($in))) {
$mBytes = 1;
} else if (0xC0 == (0xE0 & ($in))) {
$mUcs4 = ($in);
$mUcs4 = ($mUcs4 & 0x1F) << 6;
$mState = 1;
$mBytes = 2;
} else if (0xE0 == (0xF0 & ($in))) {
$mUcs4 = ($in);
$mUcs4 = ($mUcs4 & 0x0F) << 12;
$mState = 2;
$mBytes = 3;
} else if (0xF0 == (0xF8 & ($in))) {
$mUcs4 = ($in);
$mUcs4 = ($mUcs4 & 0x07) << 18;
$mState = 3;
$mBytes = 4;
} else if (0xF8 == (0xFC & ($in))) {
$mUcs4 = ($in);
$mUcs4 = ($mUcs4 & 0x03) << 24;
$mState = 4;
$mBytes = 5;
} else if (0xFC == (0xFE & ($in))) {
$mUcs4 = ($in);
$mUcs4 = ($mUcs4 & 1) << 30;
$mState = 5;
$mBytes = 6;
} else {
return FALSE;
}
} else {
if (0x80 == (0xC0 & ($in))) {
$shift = ($mState - 1) * 6;
$tmp = $in;
$tmp = ($tmp & 0x0000003F) << $shift;
$mUcs4 |= $tmp;
if (0 == --$mState) {
if (((2 == $mBytes) && ($mUcs4 < 0x0080)) ||
((3 == $mBytes) && ($mUcs4 < 0x0800)) ||
((4 == $mBytes) && ($mUcs4 < 0x10000)) ||
(4 < $mBytes) ||
(($mUcs4 & 0xFFFFF800) == 0xD800) ||
($mUcs4 > 0x10FFFF)) {
return FALSE;
}
$mState = 0;
$mUcs4 = 0;
$mBytes = 1;
}
} else {
return FALSE;
}
}
}
return TRUE;
}