From 75a0b80888e54be6f9ed25b4a40e7a66b948dc07 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 18 May 2020 01:05:38 -0400 Subject: [PATCH] Add new Strings::startsWith method - Move previous method to Strings::startsWithChars and update every known call --- src/Model/Tag.php | 2 +- src/Util/Strings.php | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Model/Tag.php b/src/Model/Tag.php index 87383fbbca..d8c252ca2b 100644 --- a/src/Model/Tag.php +++ b/src/Model/Tag.php @@ -535,6 +535,6 @@ class Tag } } - return Strings::startsWith($tag, $tag_chars); + return Strings::startsWithChars($tag, $tag_chars); } } diff --git a/src/Util/Strings.php b/src/Util/Strings.php index 3dd91193d2..04d676ef57 100644 --- a/src/Util/Strings.php +++ b/src/Util/Strings.php @@ -369,13 +369,27 @@ class Strings * @param array $chars * @return bool */ - public static function startsWith($string, array $chars) + public static function startsWithChars($string, array $chars) { $return = in_array(substr(trim($string), 0, 1), $chars); return $return; } + /** + * Check if the first string starts with the second + * + * @param string $string + * @param string $start + * @return bool + */ + public static function startsWith(string $string, string $start) + { + $return = substr_compare($string, $start, 0, strlen($start)) === 0; + + return $return; + } + /** * Returns the regular expression string to match URLs in a given text * -- 2.39.5