src/SlugGenerator.php
private function transformWithContext(\Transliterator $transliterator, string $text, int $index, int $length): string
	{
		$left = mb_substr(substr($text, 0, $index), -1, null, 'UTF-8');
		$right = mb_substr(substr($text, $index + $length), 0, 1, 'UTF-8');

		$leftLength = strlen($left);
		$rightLength = strlen($right);

		$text = substr($text, $index, $length);

		$transformed = $transliterator->transliterate($left.$text.$right);

		if (
			(!$leftLength || strncmp($transformed, $left, $leftLength) === 0)
			&& (!$rightLength || substr_compare($transformed, $right, -$rightLength) === 0)
		) {
			return substr($transformed, $leftLength, $rightLength ? -$rightLength : strlen($transformed));
		} else {
			return $transliterator->transliterate($text);
		}
	}
private function transformWithContext(\Transliterator $transliterator, string $text, int $index, int $length): string
	{
		$left = mb_substr(substr($text, 0, $index), -1, null, 'UTF-8');
		$right = mb_substr(substr($text, $index + $length), 0, 1, 'UTF-8');

		$leftLength = strlen($left);
		$rightLength = strlen($right);

		$text = substr($text, $index, $length);

		$transformed = $transliterator->transliterate($left.$text.$right);

		if (
			(!$leftLength || strncmp($transformed, $left, $leftLength) === 0)
			&& (!$rightLength || substr_compare($transformed, $right, -$rightLength) === 0)
		) {
			return substr($transformed, $leftLength, $rightLength ? -$rightLength : strlen($transformed));
		} else {
			return $transliterator->transliterate($text);
		}
	}
private function transformWithContext ( \ Transliterator $ transliterator , string $ text , int $ index , int $ length ) : string { $ left = mb_substr ( substr ( $ text , 0 , $ index ) , - 1 , null , 'UTF-8' ) ; $ right = mb_substr ( substr ( $ text , $ index + $ length ) , 0 , 1 , 'UTF-8' ) ; $ leftLength = strlen ( $ left ) ; $ rightLength = strlen ( $ right ) ; $ text = substr ( $ text , $ index , $ length ) ; $ transformed = $ transliterator -> transliterate ( $ left . $ text . $ right ) ; if ( ( ! $ leftLength || strncmp ( $ transformed , $ left , $ leftLength ) === 0 ) && ( ! $ rightLength || substr_compare ( $ transformed , $ right , - $ rightLength ) === 0 ) ) { return substr ( $ transformed , $ leftLength , $ rightLength ? - $ rightLength : strlen ( $ transformed ) ) ; } else { return $ transliterator -> transliterate ( $ text ) ; } }
Transform the text at the specified position
and use a one character context if possible.

`Transliterator::transliterate()` doesn’t yet support context parameters
of the underlying ICU implementation.
Because of that, we add the context before the transform
and check afterwards that the context didn’t change.

@param \Transliterator $transliterator
@param string          $text
@param int             $index
@param int             $length

@return string
Transform the text at the specified position and use a one character context if possible .