grapheme_strlen example

if (!function_exists('grapheme_extract')) {
    function grapheme_extract(?string $haystack, ?int $size, ?int $type = GRAPHEME_EXTR_COUNT, ?int $offset = 0, &$next = null): string|false { return p\Grapheme::grapheme_extract((string) $haystack(int) $size(int) $type(int) $offset$next)}
}
if (!function_exists('grapheme_stripos')) {
    function grapheme_stripos(?string $haystack, ?string $needle, ?int $offset = 0): int|false { return p\Grapheme::grapheme_stripos((string) $haystack(string) $needle(int) $offset)}
}
if (!function_exists('grapheme_stristr')) {
    function grapheme_stristr(?string $haystack, ?string $needle, ?bool $beforeNeedle = false): string|false { return p\Grapheme::grapheme_stristr((string) $haystack(string) $needle(bool) $beforeNeedle)}
}
if (!function_exists('grapheme_strlen')) {
    function grapheme_strlen(?string $string): int|false|null { return p\Grapheme::grapheme_strlen((string) $string)}
}
if (!function_exists('grapheme_strpos')) {
    function grapheme_strpos(?string $haystack, ?string $needle, ?int $offset = 0): int|false { return p\Grapheme::grapheme_strpos((string) $haystack(string) $needle(int) $offset)}
}
if (!function_exists('grapheme_strripos')) {
    function grapheme_strripos(?string $haystack, ?string $needle, ?int $offset = 0): int|false { return p\Grapheme::grapheme_strripos((string) $haystack(string) $needle(int) $offset)}
}
if (!function_exists('grapheme_strrpos')) {
    function grapheme_strrpos(?string $haystack, ?string $needle, ?int $offset = 0): int|false { return p\Grapheme::grapheme_strrpos((string) $haystack(string) $needle(int) $offset)}
}
if (!function_exists('grapheme_strstr')) {
    
0xC3, 0xA4], 'Späßchen', 2],
                [[0xC3, 0x9F], 'Späßchen', -5],
            ]
        );
    }

    /** * @dataProvider provideCodePointsAt */
    public function testCodePointsAt(array $expected, string $string, int $offset, int $form = null)
    {
        if (2 !== grapheme_strlen('च्छे') && 'नमस्ते' === $string) {
            $this->markTestSkipped('Skipping due to issue ICU-21661.');
        }

        $instance = static::createFromString($string);
        $instance = $form ? $instance->normalize($form) : $instance;

        $this->assertSame($expected$instance->codePointsAt($offset));
    }

    public static function provideCodePointsAt(): array
    {
        
 catch (\ValueError $e) {
            if (!str_starts_with($e->getMessage(), 'mb_check_encoding(): Argument #2 ($encoding) must be a valid encoding')) {
                throw $e;
            }

            $invalidCharset = true;
        }

        $length = $invalidCharset ? 0 : match ($constraint->countUnit) {
            Length::COUNT_BYTES => \strlen($stringValue),
            Length::COUNT_CODEPOINTS => mb_strlen($stringValue$constraint->charset),
            Length::COUNT_GRAPHEMES => grapheme_strlen($stringValue),
        };

        if ($invalidCharset || false === ($length ?? false)) {
            $this->context->buildViolation($constraint->charsetMessage)
                ->setParameter('{{ value }}', $this->formatValue($stringValue))
                ->setParameter('{{ charset }}', $constraint->charset)
                ->setInvalidValue($value)
                ->setCode(Length::INVALID_CHARACTERS_ERROR)
                ->addViolation();

            return;
        }
$form = null === $this->ignoreCase ? \Normalizer::NFD : \Normalizer::NFC;
        normalizer_is_normalized($needle$form) ?: $needle = normalizer_normalize($needle$form);

        if ('' === $needle || false === $needle) {
            return null;
        }

        $string = $this->string;

        if (0 > $offset) {
            // workaround https://bugs.php.net/74264             if (0 > $offset += grapheme_strlen($needle)) {
                $string = grapheme_substr($string, 0, $offset);
            }
            $offset = 0;
        }

        $i = $this->ignoreCase ? grapheme_strripos($string$needle$offset) : grapheme_strrpos($string$needle$offset);

        return false === $i ? null : $i;
    }

    public function join(array $strings, string $lastGlue = null)static
    {
if (!function_exists('grapheme_extract')) {
    function grapheme_extract($haystack$size$type = 0, $start = 0, &$next = 0) { return p\Grapheme::grapheme_extract($haystack$size$type$start$next)}
}
if (!function_exists('grapheme_stripos')) {
    function grapheme_stripos($haystack$needle$offset = 0) { return p\Grapheme::grapheme_stripos($haystack$needle$offset)}
}
if (!function_exists('grapheme_stristr')) {
    function grapheme_stristr($haystack$needle$beforeNeedle = false) { return p\Grapheme::grapheme_stristr($haystack$needle$beforeNeedle)}
}
if (!function_exists('grapheme_strlen')) {
    function grapheme_strlen($input) { return p\Grapheme::grapheme_strlen($input)}
}
if (!function_exists('grapheme_strpos')) {
    function grapheme_strpos($haystack$needle$offset = 0) { return p\Grapheme::grapheme_strpos($haystack$needle$offset)}
}
if (!function_exists('grapheme_strripos')) {
    function grapheme_strripos($haystack$needle$offset = 0) { return p\Grapheme::grapheme_strripos($haystack$needle$offset)}
}
if (!function_exists('grapheme_strrpos')) {
    function grapheme_strrpos($haystack$needle$offset = 0) { return p\Grapheme::grapheme_strrpos($haystack$needle$offset)}
}
if (!function_exists('grapheme_strstr')) {
    
$form = null === $this->ignoreCase ? \Normalizer::NFD : \Normalizer::NFC;
        normalizer_is_normalized($needle$form) ?: $needle = normalizer_normalize($needle$form);

        if ('' === $needle || false === $needle) {
            return null;
        }

        $string = $this->string;

        if (0 > $offset) {
            // workaround https://bugs.php.net/74264             if (0 > $offset += grapheme_strlen($needle)) {
                $string = grapheme_substr($string, 0, $offset);
            }
            $offset = 0;
        }

        $i = $this->ignoreCase ? grapheme_strripos($string$needle$offset) : grapheme_strrpos($string$needle$offset);

        return false === $i ? null : $i;
    }

    public function join(array $strings, string $lastGlue = null)static
    {
$this->assertSame('', (string) $instance);
        $this->assertSame(0, $instance->length());
        $this->assertTrue($instance->isEmpty());
    }

    /** * @dataProvider provideBytesAt */
    public function testBytesAt(array $expected, string $string, int $offset, int $form = null)
    {
        if (2 !== grapheme_strlen('च्छे') && 'नमस्ते' === $string) {
            $this->markTestSkipped('Skipping due to issue ICU-21661.');
        }

        $instance = static::createFromString($string);
        $instance = $form ? $instance->normalize($form) : $instance;

        $this->assertSame($expected$instance->bytesAt($offset));
    }

    public static function provideBytesAt(): array
    {
        
 catch (\ValueError $e) {
            if (!str_starts_with($e->getMessage(), 'mb_check_encoding(): Argument #2 ($encoding) must be a valid encoding')) {
                throw $e;
            }

            $invalidCharset = true;
        }

        $length = $invalidCharset ? 0 : match ($constraint->countUnit) {
            Length::COUNT_BYTES => \strlen($stringValue),
            Length::COUNT_CODEPOINTS => mb_strlen($stringValue$constraint->charset),
            Length::COUNT_GRAPHEMES => grapheme_strlen($stringValue),
        };

        if ($invalidCharset || false === ($length ?? false)) {
            $this->context->buildViolation($constraint->charsetMessage)
                ->setParameter('{{ value }}', $this->formatValue($stringValue))
                ->setParameter('{{ charset }}', $constraint->charset)
                ->setInvalidValue($value)
                ->setCode(Length::INVALID_CHARACTERS_ERROR)
                ->addViolation();

            return;
        }
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;
            }
        }

        
Home | Imprint | This part of the site doesn't use cookies.