10 defined(
'JPATH_PLATFORM') or die;
15 if (extension_loaded('mbstring'))
18 @ini_set(
'mbstring.internal_encoding',
'UTF-8');
19 @ini_set(
'mbstring.http_input',
'UTF-8');
20 @ini_set(
'mbstring.http_output',
'UTF-8');
24 if (function_exists(
'iconv'))
27 iconv_set_encoding(
"internal_encoding",
"UTF-8");
28 iconv_set_encoding(
"input_encoding",
"UTF-8");
29 iconv_set_encoding(
"output_encoding",
"UTF-8");
61 array(
'#\((\d+)\)$#',
'#\(\d+\)$#'),
62 array(
' (%d)',
'(%d)'),
86 JLog::add(
'JString::splitCamelCase has been deprecated. Use JStringNormalise::fromCamelCase.',
JLog::WARNING,
'deprecated');
107 public static function increment($string, $style =
'default', $n = 0)
109 $styleSpec = isset(self::$incrementStyles[$style]) ? self::$incrementStyles[$style] : self::$incrementStyles[
'default'];
112 if (is_array($styleSpec[0]))
114 $rxSearch = $styleSpec[0][0];
115 $rxReplace = $styleSpec[0][1];
119 $rxSearch = $rxReplace = $styleSpec[0];
123 if (is_array($styleSpec[1]))
125 $newFormat = $styleSpec[1][0];
126 $oldFormat = $styleSpec[1][1];
130 $newFormat = $oldFormat = $styleSpec[1];
134 if (preg_match($rxSearch, $string, $matches))
136 $n = empty($n) ? ($matches[1] + 1) : $n;
137 $string = preg_replace($rxReplace, sprintf($oldFormat, $n), $string);
141 $n = empty($n) ? 2 : $n;
142 $string .= sprintf($newFormat, $n);
162 public static function strpos($str, $search, $offset =
false)
164 if ($offset ===
false)
187 public static function strrpos($str, $search, $offset = 0)
205 public static function substr($str, $offset, $length =
false)
207 if ($length ===
false)
289 public static function str_ireplace($search, $replace, $str, $count = null)
291 jimport(
'phputf8.str_ireplace');
293 if ($count ===
false)
337 public static function strcasecmp($str1, $str2, $locale =
false)
342 $locale0 = setlocale(LC_COLLATE, 0);
344 if (!$locale = setlocale(LC_COLLATE, $locale))
350 if (!
stristr($locale,
'UTF-8') &&
stristr($locale,
'_') && preg_match(
'~\.(\d+)$~', $locale, $m))
352 $encoding =
'CP' . $m[1];
360 $encoding =
'nonrecodable';
364 if ($encoding ==
'UTF-8' || $encoding ==
'nonrecodable')
397 public static function strcmp($str1, $str2, $locale =
false)
402 $locale0 = setlocale(LC_COLLATE, 0);
404 if (!$locale = setlocale(LC_COLLATE, $locale))
410 if (!
stristr($locale,
'UTF-8') &&
stristr($locale,
'_') && preg_match(
'~\.(\d+)$~', $locale, $m))
412 $encoding =
'CP' . $m[1];
420 $encoding =
'nonrecodable';
424 if ($encoding ==
'UTF-8' || $encoding ==
'nonrecodable')
426 return strcoll($str1, $str2);
430 return strcoll(self::transcode($str1,
'UTF-8', $encoding), self::transcode($str2,
'UTF-8', $encoding));
435 return strcmp($str1, $str2);
453 public static function strcspn($str, $mask, $start = null, $length = null)
457 if ($start ===
false && $length ===
false)
461 elseif ($length ===
false)
524 public static function strspn($str, $mask, $start = null, $length = null)
528 if ($start === null && $length === null)
532 elseif ($length === null)
559 if ($length ===
false)
585 public static function ltrim($str, $charlist =
false)
587 if (empty($charlist) && $charlist !==
false)
594 if ($charlist ===
false)
619 public static function rtrim($str, $charlist =
false)
621 if (empty($charlist) && $charlist !==
false)
628 if ($charlist ===
false)
653 public static function trim($str, $charlist =
false)
655 if (empty($charlist) && $charlist !==
false)
662 if ($charlist ===
false)
687 public static function ucfirst($str, $delimiter = null, $newDelimiter = null)
691 if ($delimiter === null)
697 if ($newDelimiter === null)
699 $newDelimiter = $delimiter;
701 return implode($newDelimiter, array_map(
'utf8_ucfirst', explode($delimiter, $str)));
736 public static function transcode($source, $from_encoding, $to_encoding)
738 if (is_string($source))
743 return @iconv($from_encoding, $to_encoding .
'//TRANSLIT,IGNORE', $source);
746 return iconv($from_encoding, $to_encoding .
'//IGNORE//TRANSLIT', $source);
781 for ($i = 0; $i < $len; $i++)
789 if (0 == (0x80 & ($in)))
794 elseif (0xC0 == (0xE0 & ($in)))
798 $mUcs4 = ($mUcs4 & 0x1F) << 6;
802 elseif (0xE0 == (0xF0 & ($in)))
806 $mUcs4 = ($mUcs4 & 0x0F) << 12;
810 elseif (0xF0 == (0xF8 & ($in)))
814 $mUcs4 = ($mUcs4 & 0x07) << 18;
818 elseif (0xF8 == (0xFC & ($in)))
829 $mUcs4 = ($mUcs4 & 0x03) << 24;
833 elseif (0xFC == (0xFE & ($in)))
837 $mUcs4 = ($mUcs4 & 1) << 30;
854 if (0x80 == (0xC0 & ($in)))
857 $shift = ($mState - 1) * 6;
859 $tmp = ($tmp & 0x0000003F) << $shift;
872 if (((2 == $mBytes) && ($mUcs4 < 0x0080)) || ((3 == $mBytes) && ($mUcs4 < 0x0800)) || ((4 == $mBytes) && ($mUcs4 < 0x10000))
874 || (($mUcs4 & 0xFFFFF800) == 0xD800)
875 || ($mUcs4 > 0x10FFFF))
932 return (preg_match(
'/^.{1}/us', $str, $ar) == 1);
950 $entities = array(
'%21',
'%2A',
'%27',
'%28',
'%29',
'%3B',
'%3A',
'%40',
'%26',
'%3D',
'%24',
'%2C',
'%2F',
'%3F',
'%23',
'%5B',
'%5D');
951 $replacements = array(
'!',
'*',
"'",
"(",
")",
";",
":",
"@",
"&",
"=",
"$",
",",
"/",
"?",
"#",
"[",
"]");
955 $encodedURL = str_replace($entities, $replacements, urlencode($url));
963 foreach ($encodedParts as $key => $value)
965 $result[$key] = urldecode(str_replace($replacements, $entities, $value));