Skip to content

Commit

Permalink
[String] improve fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Sep 10, 2020
1 parent 74faf61 commit d732ad8
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions UnicodeString.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ public function indexOf($needle, int $offset = 0): ?int
return null;
}

if ($this->length() <= $offset) {
try {
$i = $this->ignoreCase ? grapheme_stripos($this->string, $needle, $offset) : grapheme_strpos($this->string, $needle, $offset);
} catch (\ValueError $e) {
return null;
}

$i = $this->ignoreCase ? grapheme_stripos($this->string, $needle, $offset) : grapheme_strpos($this->string, $needle, $offset);

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

Expand Down Expand Up @@ -266,12 +266,12 @@ public function replaceMatches(string $fromRegexp, $to): AbstractString

public function slice(int $start = 0, int $length = null): AbstractString
{
if ($this->length() <= $start) {
return new self();
}

$str = clone $this;
$str->string = (string) grapheme_substr($this->string, $start, $length ?? \PHP_INT_MAX);
try {
$str->string = (string) grapheme_substr($this->string, $start, $length ?? \PHP_INT_MAX);
} catch (\ValueError $e) {
$str->string = '';
}

return $str;
}
Expand Down

0 comments on commit d732ad8

Please sign in to comment.