You are here

function _transliteration_replace in Transliteration 6

Same name and namespace in other branches
  1. 5.2 transliteration.inc \_transliteration_replace()
  2. 5 transliteration.inc \_transliteration_replace()
  3. 6.3 transliteration.inc \_transliteration_replace()
  4. 6.2 transliteration.inc \_transliteration_replace()
  5. 7.3 transliteration.inc \_transliteration_replace()

Load transliteration database and replace a character.

Parameters

integer $ord: A unicode ordinal character code.

string $unknown: Replacement for unknown characters.

Return value

string Plain ASCII replacement character.

See also

transliteration_get()

1 call to _transliteration_replace()
_transliteration_process in ./transliteration.inc
Based on Mediawiki's UtfNormal::quickIsNFCVerify().

File

./transliteration.inc, line 160

Code

function _transliteration_replace($ord, $unknown = '?') {
  global $locale;
  static $banks = array();
  $bank = $ord >> 8;
  if (!isset($banks[$bank])) {
    $file = drupal_get_path('module', 'transliteration') . '/data/' . sprintf('x%02x', $bank) . '.php';
    if (file_exists($file)) {
      $charmap = (include $file);

      // Merge locale specific replacements
      if ($locale && isset($charmap[$locale])) {
        $banks[$bank] = array_merge($charmap['default'], $charmap[$locale]);
      }
      else {
        $banks[$bank] = $charmap['default'];
      }
    }
    else {
      $banks[$bank] = array();
    }
  }
  $ord = $ord & 255;
  return isset($banks[$bank][$ord]) ? $banks[$bank][$ord] : $unknown;
}