Skip to content

Commit

Permalink
Optimize findBetween method to remove calling function mb_substr()
Browse files Browse the repository at this point in the history
  • Loading branch information
salehhashemi1992 committed Nov 1, 2023
1 parent 6804fbe commit 5ce3b4e
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions framework/helpers/BaseStringHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -546,14 +546,13 @@ public static function findBetween($string, $start, $end)
return null;
}

// Cut the string from the start position
$subString = mb_substr($string, $startPos + mb_strlen($start));
$endPos = mb_strrpos($subString, $end);
$startPos += mb_strlen($start);
$endPos = mb_strrpos($string, $end, $startPos);

Check warning on line 550 in framework/helpers/BaseStringHelper.php

View check run for this annotation

Codecov / codecov/patch

framework/helpers/BaseStringHelper.php#L549-L550

Added lines #L549 - L550 were not covered by tests

if ($endPos === false) {
return null;
}

return mb_substr($subString, 0, $endPos);
return mb_substr($string, $startPos, $endPos - $startPos);

Check warning on line 556 in framework/helpers/BaseStringHelper.php

View check run for this annotation

Codecov / codecov/patch

framework/helpers/BaseStringHelper.php#L556

Added line #L556 was not covered by tests
}
}

0 comments on commit 5ce3b4e

Please sign in to comment.