function Grapheme::grapheme_position
4 calls to Grapheme::grapheme_position()
- Grapheme::grapheme_stripos in vendor/
symfony/ polyfill-intl-grapheme/ Grapheme.php - Grapheme::grapheme_strpos in vendor/
symfony/ polyfill-intl-grapheme/ Grapheme.php - Grapheme::grapheme_strripos in vendor/
symfony/ polyfill-intl-grapheme/ Grapheme.php - Grapheme::grapheme_strrpos in vendor/
symfony/ polyfill-intl-grapheme/ Grapheme.php
File
-
vendor/
symfony/ polyfill-intl-grapheme/ Grapheme.php, line 194
Class
- Grapheme
- Partial intl implementation in pure PHP.
Namespace
Symfony\Polyfill\Intl\GraphemeCode
private static function grapheme_position($s, $needle, $offset, $mode) {
$needle = (string) $needle;
if (80000 > \PHP_VERSION_ID && !preg_match('/./us', $needle)) {
return false;
}
$s = (string) $s;
if (!preg_match('/./us', $s)) {
return false;
}
if ($offset > 0) {
$s = self::grapheme_substr($s, $offset);
}
elseif ($offset < 0) {
if (2 > $mode) {
$offset += self::grapheme_strlen($s);
$s = self::grapheme_substr($s, $offset);
if (0 > $offset) {
$offset = 0;
}
}
elseif (0 > ($offset += self::grapheme_strlen($needle))) {
$s = self::grapheme_substr($s, 0, $offset);
$offset = 0;
}
else {
$offset = 0;
}
}
// As UTF-8 is self-synchronizing, and we have ensured the strings are valid UTF-8,
// we can use normal binary string functions here. For case-insensitive searches,
// case fold the strings first.
$caseInsensitive = $mode & 1;
$reverse = $mode & 2;
if ($caseInsensitive) {
// Use the same case folding mode as mbstring does for mb_stripos().
// Stick to SIMPLE case folding to avoid changing the length of the string, which
// might result in offsets being shifted.
$mode = \defined('MB_CASE_FOLD_SIMPLE') ? \MB_CASE_FOLD_SIMPLE : \MB_CASE_LOWER;
$s = mb_convert_case($s, $mode, 'UTF-8');
$needle = mb_convert_case($needle, $mode, 'UTF-8');
if (!\defined('MB_CASE_FOLD_SIMPLE')) {
$s = str_replace(self::CASE_FOLD[0], self::CASE_FOLD[1], $s);
$needle = str_replace(self::CASE_FOLD[0], self::CASE_FOLD[1], $needle);
}
}
if ($reverse) {
$needlePos = strrpos($s, $needle);
}
else {
$needlePos = strpos($s, $needle);
}
return false !== $needlePos ? self::grapheme_strlen(substr($s, 0, $needlePos)) + $offset : false;
}