Esempio n. 1
0
 /**
  * @param        $s
  * @param int    $normalization_form
  * @param string $leading_combining
  *
  * @return array|bool|mixed|string
  */
 public static function filterString($s, $normalization_form = 4, $leading_combining = '◌')
 {
     if (false !== strpos($s, "\r")) {
         // Workaround https://bugs.php.net/65732
         $s = str_replace(array("\r\n", "\r"), "\n", $s);
     }
     if (preg_match('/[\\x80-\\xFF]/', $s)) {
         if (Normalizer::isNormalized($s, $normalization_form)) {
             $n = '-';
         } else {
             $n = Normalizer::normalize($s, $normalization_form);
             if (isset($n[0])) {
                 $s = $n;
             } else {
                 $s = UTF8::encode('UTF-8', $s);
             }
         }
         if ($s[0] >= "€" && isset($n[0], $leading_combining[0]) && preg_match('/^\\p{Mn}/u', $s)) {
             // Prevent leading combining chars
             // for NFC-safe concatenations.
             $s = $leading_combining . $s;
         }
     }
     return $s;
 }
Esempio n. 2
0
/**
 * @param string $str
 * @param int    $form
 *
 * @return string
 */
function normalizer_normalize($str, $form = s\Normalizer::NFC)
{
    return s\Normalizer::normalize($str, $form);
}
Esempio n. 3
0
File: UTF8.php Progetto: hhgr/hhgolf
 /**
  * string comparison
  *
  * @param string $a
  * @param string $b
  *
  * @return int Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal.
  */
 public static function strcmp($a, $b)
 {
     return $a . '' === $b . '' ? 0 : strcmp(Normalizer::normalize($a, Normalizer::NFD), Normalizer::normalize($b, Normalizer::NFD));
 }