- * @param string $char
- * @return string
- */
-function valid_3byte($char) {
- if(!is_int($char)) return false;
- return ($char & 0xF0) == 0xE0;
-}
-
-/**
- * @package WordPress
- * @subpackage Dotclear_Import
- *
- * @param string $char
- * @return string
- */
-function valid_4byte($char) {
- if(!is_int($char)) return false;
- return ($char & 0xF8) == 0xF0;
-}
-
-/**
- * @package WordPress
- * @subpackage Dotclear_Import
- *
- * @param string $char
- * @return string
- */
-function valid_nextbyte($char) {
- if(!is_int($char)) return false;
- return ($char & 0xC0) == 0x80;
-}
-
-/**
- * @package WordPress
- * @subpackage Dotclear_Import
- *
- * @param string $string
- * @return string
- */
-function valid_utf8($string) {
- $len = strlen($string);
- $i = 0;
- while( $i < $len ) {
- $char = ord(substr($string, $i++, 1));
- if(valid_1byte($char)) { // continue
- continue;
- } else if(valid_2byte($char)) { // check 1 byte
- if(!valid_nextbyte(ord(substr($string, $i++, 1))))
- return false;
- } else if(valid_3byte($char)) { // check 2 bytes
- if(!valid_nextbyte(ord(substr($string, $i++, 1))))
- return false;
- if(!valid_nextbyte(ord(substr($string, $i++, 1))))
- return false;
- } else if(valid_4byte($char)) { // check 3 bytes
- if(!valid_nextbyte(ord(substr($string, $i++, 1))))
- return false;
- if(!valid_nextbyte(ord(substr($string, $i++, 1))))
- return false;
- if(!valid_nextbyte(ord(substr($string, $i++, 1))))
- return false;
- } // goto next char
- }
- return true; // done
-}
-
-/**