function SearchTokenizerTestCase::code2utf

Like PHP chr() function, but for unicode characters.

chr() only works for ASCII characters up to character 255. This function converts a number to the corresponding unicode character. Adapted from functions supplied in comments on several functions on php.net.

1 call to SearchTokenizerTestCase::code2utf()
SearchTokenizerTestCase::testTokenizer in modules/search/search.test
Verifies that strings of CJK characters are tokenized.

File

modules/search/search.test, line 1847

Class

SearchTokenizerTestCase
Test the CJK tokenizer.

Code

function code2utf($num) {
    if ($num < 128) {
        return chr($num);
    }
    if ($num < 2048) {
        return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
    }
    if ($num < 65536) {
        return chr(($num >> 12) + 224) . chr(($num >> 6 & 63) + 128) . chr(($num & 63) + 128);
    }
    if ($num < 2097152) {
        return chr(($num >> 18) + 240) . chr(($num >> 12 & 63) + 128) . chr(($num >> 6 & 63) + 128) . chr(($num & 63) + 128);
    }
    return '';
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.