diff --git a/src/Utils/Strings.php b/src/Utils/Strings.php index c25919a79..d66f66f38 100644 --- a/src/Utils/Strings.php +++ b/src/Utils/Strings.php @@ -353,51 +353,51 @@ public static function reverse(string $s): string /** * Returns part of $haystack before $nth occurence of $needle (negative value means searching from the end). - * @return string|FALSE returns FALSE if the needle was not found + * @return string|NULL returns NULL if the needle was not found */ public static function before(string $haystack, string $needle, int $nth = 1) { $pos = self::pos($haystack, $needle, $nth); - return $pos === FALSE - ? FALSE + return $pos === NULL + ? NULL : substr($haystack, 0, $pos); } /** * Returns part of $haystack after $nth occurence of $needle (negative value means searching from the end). - * @return string|FALSE returns FALSE if the needle was not found + * @return string|NULL returns NULL if the needle was not found */ public static function after(string $haystack, string $needle, int $nth = 1) { $pos = self::pos($haystack, $needle, $nth); - return $pos === FALSE - ? FALSE + return $pos === NULL + ? NULL : substr($haystack, $pos + strlen($needle)); } /** * Returns position of $nth occurence of $needle in $haystack (negative value means searching from the end). - * @return int|FALSE offset in characters or FALSE if the needle was not found + * @return int|NULL offset in characters or NULL if the needle was not found */ public static function indexOf(string $haystack, string $needle, int $nth = 1) { $pos = self::pos($haystack, $needle, $nth); - return $pos === FALSE - ? FALSE + return $pos === NULL + ? NULL : self::length(substr($haystack, 0, $pos)); } /** * Returns position of $nth occurence of $needle in $haystack. - * @return int|FALSE offset in bytes or FALSE if the needle was not found + * @return int|NULL offset in bytes or NULL if the needle was not found */ private static function pos(string $haystack, string $needle, int $nth = 1) { if (!$nth) { - return FALSE; + return NULL; } elseif ($nth > 0) { if (strlen($needle) === 0) { return 0; @@ -416,7 +416,7 @@ private static function pos(string $haystack, string $needle, int $nth = 1) $pos--; } } - return $pos; + return $pos === FALSE ? NULL : $pos; } diff --git a/tests/Utils/Strings.after().phpt b/tests/Utils/Strings.after().phpt index e333ed5ce..eae7621da 100644 --- a/tests/Utils/Strings.after().phpt +++ b/tests/Utils/Strings.after().phpt @@ -27,10 +27,10 @@ test(function () { Assert::same('c', Strings::after($foo, '789', 3)); Assert::same('a123456789b123456789c', Strings::after($foo, '9', -3)); Assert::same('a123456789b123456789c', Strings::after($foo, '789', -3)); - Assert::false(Strings::after($foo, '9', 0)); - Assert::false(Strings::after($foo, 'not-in-string')); - Assert::false(Strings::after($foo, 'b', -2)); - Assert::false(Strings::after($foo, 'b', 2)); + Assert::null(Strings::after($foo, '9', 0)); + Assert::null(Strings::after($foo, 'not-in-string')); + Assert::null(Strings::after($foo, 'b', -2)); + Assert::null(Strings::after($foo, 'b', 2)); }); diff --git a/tests/Utils/Strings.before().phpt b/tests/Utils/Strings.before().phpt index 1866dcfa2..68eff6cfc 100644 --- a/tests/Utils/Strings.before().phpt +++ b/tests/Utils/Strings.before().phpt @@ -26,10 +26,10 @@ test(function () { Assert::same('0123456789a123456789b123456', Strings::before($foo, '789', 3)); Assert::same('012345678', Strings::before($foo, '9', -3)); Assert::same('0123456', Strings::before($foo, '789', -3)); - Assert::false(Strings::before($foo, '9', 0)); - Assert::false(Strings::before($foo, 'not-in-string')); - Assert::false(Strings::before($foo, 'b', -2)); - Assert::false(Strings::before($foo, 'b', 2)); + Assert::null(Strings::before($foo, '9', 0)); + Assert::null(Strings::before($foo, 'not-in-string')); + Assert::null(Strings::before($foo, 'b', -2)); + Assert::null(Strings::before($foo, 'b', 2)); }); diff --git a/tests/Utils/Strings.indexOf().phpt b/tests/Utils/Strings.indexOf().phpt index eceae79d9..8738b0386 100644 --- a/tests/Utils/Strings.indexOf().phpt +++ b/tests/Utils/Strings.indexOf().phpt @@ -27,10 +27,10 @@ test(function () { Assert::same(27, Strings::indexOf($foo, '789', 3)); Assert::same(9, Strings::indexOf($foo, '9', -3)); Assert::same(7, Strings::indexOf($foo, '789', -3)); - Assert::false(Strings::indexOf($foo, '9', 0)); - Assert::false(Strings::indexOf($foo, 'not-in-string')); - Assert::false(Strings::indexOf($foo, 'b', -2)); - Assert::false(Strings::indexOf($foo, 'b', 2)); + Assert::null(Strings::indexOf($foo, '9', 0)); + Assert::null(Strings::indexOf($foo, 'not-in-string')); + Assert::null(Strings::indexOf($foo, 'b', -2)); + Assert::null(Strings::indexOf($foo, 'b', 2)); });