You are here

function persiantools_get_char_type in PersianTools 7

Detects and returns a character's type.

2 calls to persiantools_get_char_type()
persiantools_convert_sm in ./persiantools.module
Main function for multiple features and fixes of persiantools module.
persiantools_fix_mixed_path in ./persiantools.module
Fix mixed-up paths in rtl blocks. Logic: Gets triggered once a starting '.' or '/' is detected after a whitespace. The correcting symbol is inserted once an english char is seen inside the path.

File

./persiantools.module, line 330
Adds common features and fixes for persian pages.

Code

function persiantools_get_char_type($ch) {
  if ($ch >= 'آ' && $ch <= 'ي' || $ch == 'ی') {
    $type = PERSIANTOOLS_CONST::FA;
  }
  elseif ($ch >= 'a' && $ch <= 'z' || $ch >= 'A' && $ch <= 'Z') {
    $type = PERSIANTOOLS_CONST::EN;
  }
  elseif (in_array($ch, PERSIANTOOLS_CONST::$OPENING_SYMS)) {
    $type = PERSIANTOOLS_CONST::OPENING;
  }
  elseif ($ch >= '0' && $ch <= '9') {
    $type = PERSIANTOOLS_CONST::DIGIT;
  }
  elseif (in_array($ch, PERSIANTOOLS_CONST::$STATMENT_END)) {
    $type = PERSIANTOOLS_CONST::EOS;
  }
  elseif ($ch == '/') {
    $type = PERSIANTOOLS_CONST::SLASH;
  }
  elseif ($ch == ' ' || $ch == '\\n') {
    $type = PERSIANTOOLS_CONST::WS;
  }
  else {

    // Type not detected.
    $type = PERSIANTOOLS_CONST::UN;
  }
  return $type;
}