function SearchTokenizerTestCase::code2utf

7.x search.test SearchTokenizerTestCase::code2utf($num)

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 drupal-7.x/modules/search/search.test
Verifies that strings of CJK characters are tokenized.

File

drupal-7.x/modules/search/search.test, line 1800
Tests for search.module.

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 '';
}