private static function calc_adjacent_length( $current_length, $adjacent_character, $haystack, array $needles, callable $substr, callable $strlen, $reverse = false ) {
		if ( $current_length > 0 && $adjacent_character !== $substr( $haystack, $reverse ? -$current_length : 0, $current_length ) ) {
			foreach ( $needles as $needle ) {
				$len = $strlen( $needle );

				if ( $needle === $substr( $haystack, ( $reverse ? -$len : 0 ), $len ) ) {
					return $len;
				}
			}
		}

		return $current_length;
	}