[String] improve fix
This commit is contained in:
parent
3c5a4ed06e
commit
db4b1df062
@ -143,12 +143,12 @@ class UnicodeString extends AbstractUnicodeString
|
||||
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;
|
||||
}
|
||||
|
||||
@ -266,12 +266,12 @@ class UnicodeString extends AbstractUnicodeString
|
||||
|
||||
public function slice(int $start = 0, int $length = null): AbstractString
|
||||
{
|
||||
if ($this->length() <= $start) {
|
||||
return new self();
|
||||
}
|
||||
|
||||
$str = clone $this;
|
||||
try {
|
||||
$str->string = (string) grapheme_substr($this->string, $start, $length ?? \PHP_INT_MAX);
|
||||
} catch (\ValueError $e) {
|
||||
$str->string = '';
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
Reference in New Issue
Block a user