Skip to content

Commit d732ad8

Browse files
[String] improve fix
1 parent 74faf61 commit d732ad8

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

UnicodeString.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,12 @@ public function indexOf($needle, int $offset = 0): ?int
143143
return null;
144144
}
145145

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

150-
$i = $this->ignoreCase ? grapheme_stripos($this->string, $needle, $offset) : grapheme_strpos($this->string, $needle, $offset);
151-
152152
return false === $i ? null : $i;
153153
}
154154

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

267267
public function slice(int $start = 0, int $length = null): AbstractString
268268
{
269-
if ($this->length() <= $start) {
270-
return new self();
271-
}
272-
273269
$str = clone $this;
274-
$str->string = (string) grapheme_substr($this->string, $start, $length ?? \PHP_INT_MAX);
270+
try {
271+
$str->string = (string) grapheme_substr($this->string, $start, $length ?? \PHP_INT_MAX);
272+
} catch (\ValueError $e) {
273+
$str->string = '';
274+
}
275275

276276
return $str;
277277
}

0 commit comments

Comments
 (0)