private function normalize($str, $opts)
 {
     if ($opts['nfc'] || $opts['nfkc']) {
         if (class_exists('Normalizer', false)) {
             if ($opts['nfc'] && !Normalizer::isNormalized($str, Normalizer::FORM_C)) {
                 $str = Normalizer::normalize($str, Normalizer::FORM_C);
             }
             if ($opts['nfkc'] && !Normalizer::isNormalized($str, Normalizer::FORM_KC)) {
                 $str = Normalizer::normalize($str, Normalizer::FORM_KC);
             }
         } else {
             if (!class_exists('I18N_UnicodeNormalizer', false)) {
                 @(include_once 'I18N/UnicodeNormalizer.php');
             }
             if (class_exists('I18N_UnicodeNormalizer', false)) {
                 $normalizer = new I18N_UnicodeNormalizer();
                 if ($opts['nfc']) {
                     $str = $normalizer->normalize($str, 'NFC');
                 }
                 if ($opts['nfkc']) {
                     $str = $normalizer->normalize($str, 'NFKC');
                 }
             }
         }
     }
     if ($opts['lowercase']) {
         $str = strtolower($str);
     }
     if ($opts['convmap'] && is_array($opts['convmap'])) {
         $str = strtr($str, $opts['convmap']);
     }
     return $str;
 }
Beispiel #2
0
 public static function normalize_platform_dependent_chars($value, $is_use_normalizer = false)
 {
     $value = self::normalize_platform_dependent_chars_simple($value);
     if (!$is_use_normalizer) {
         return $value;
     }
     require_once APPPATH . 'vendor' . DS . 'PEAR' . DS . 'I18N_UnicodeNormalizer' . DS . 'UnicodeNormalizer.php';
     $normalizer = new I18N_UnicodeNormalizer();
     return $normalizer->normalize($value, 'NFKC');
 }
Beispiel #3
0
 private function normalize($str, $opts)
 {
     if (class_exists('Normalizer')) {
         if ($opts['nfc'] && !Normalizer::isNormalized($str, Normalizer::FORM_C)) {
             $str = Normalizer::normalize($str, Normalizer::FORM_C);
         }
         if ($opts['nfkc'] && !Normalizer::isNormalized($str, Normalizer::FORM_KC)) {
             $str = Normalizer::normalize($str, Normalizer::FORM_KC);
         }
     } else {
         if (!class_exists('I18N_UnicodeNormalizer')) {
             @(include_once 'I18N/UnicodeNormalizer.php');
         }
         if (class_exists('I18N_UnicodeNormalizer')) {
             $normalizer = new I18N_UnicodeNormalizer();
             if ($opts['nfc']) {
                 $str = $normalizer->normalize($str, 'NFC');
             }
             if ($opts['nfkc']) {
                 $str = $normalizer->normalize($str, 'NFKC');
             }
         }
     }
     return $str;
 }
Beispiel #4
0
 /**
  * The class constructor
  *
  * Sets the Unicode code point format, the force-compilation option,
  * the code points range limit. Sets the paths of the data and compiled
  * file names
  *
  * @param  string  $dir            the data/compiled files base directory,
  *                                 the default is set by the normalizer
  * @param  string  $codeFormat     'utf8': for production, or 'ucn': for
  *                                 testing purposes, the default is 'utf8'
  * @param  boolean $forceCompile   compilation option: files are to be
  *                                 (re)compiled if true,
  *                                 files are recompiled as needed if false
  * @param  integer $limitedDataSet compiles a small subset of data
  *                                 for testing/coverage purposes if true,
  *                                 or use all data otherwise
  * @return void   
  * @access public 
  */
 public function __construct($dir = '', $codeFormat = '', $forceCompile = false, $limitedDataSet = false)
 {
     // sets the Unicode code point format, the force compilation flag, the range limit for tests
     $this->codeFormat = $codeFormat == 'ucn' ? 'ucn' : 'utf8';
     $this->forceCompile = $forceCompile;
     $this->rangeLimit = $limitedDataSet ? 2 : 12000;
     // gets the file names to compile, changes the file names to UCN if requested
     $this->compiled = I18N_UnicodeNormalizer::getFileNames($dir);
     $this->codeFormat == 'ucn' and $this->compiled = str_replace('utf8', 'ucn', $this->compiled);
     // builds the unicodeata file base paths, prepends the path to the file names
     $dir or $dir = I18N_UnicodeNormalizer::getDataDir();
     $dir .= '/unicodedata/';
     $data = substr_replace($this->data, $dir, 0, 0);
     $this->data = array_combine(array_keys($this->data), $data);
     $this->file = new I18N_UnicodeNormalizer_File();
     $this->string = new I18N_UnicodeNormalizer_String();
 }