Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jun 27, 2024
1 parent be01fa5 commit 7bf4d41
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
16 changes: 8 additions & 8 deletions src/Illuminate/Support/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,35 +243,35 @@ public static function charAt($subject, $index)
}

/**
* Remove the given string(s) if it exists at the end of the haystack.
* Remove the given string(s) if it exists at the start of the haystack.
*
* @param string $subject
* @param string|array $needle
* @return string
*/
public static function chopEnd($subject, $needle)
public static function chopStart($subject, $needle)
{
foreach ((array) $needle as $n) {
if (str_ends_with($subject, $n)) {
return substr($subject, 0, -strlen($n));
if (str_starts_with($subject, $n)) {
return substr($subject, strlen($n));
}
}

return $subject;
}

/**
* Remove the given string(s) if it exists at the start of the haystack.
* Remove the given string(s) if it exists at the end of the haystack.
*
* @param string $subject
* @param string|array $needle
* @return string
*/
public static function chopStart($subject, $needle)
public static function chopEnd($subject, $needle)
{
foreach ((array) $needle as $n) {
if (str_starts_with($subject, $n)) {
return substr($subject, strlen($n));
if (str_ends_with($subject, $n)) {
return substr($subject, 0, -strlen($n));
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/Illuminate/Support/Stringable.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,25 +112,25 @@ public function charAt($index)
}

/**
* Remove the given string if it exists at the end of the current string.
* Remove the given string if it exists at the start of the current string.
*
* @param string|array $needle
* @return static
*/
public function chopEnd($needle)
public function chopStart($needle)
{
return new static(Str::chopEnd($this->value, $needle));
return new static(Str::chopStart($this->value, $needle));
}

/**
* Remove the given string if it exists at the start of the current string.
* Remove the given string if it exists at the end of the current string.
*
* @param string|array $needle
* @return static
*/
public function chopStart($needle)
public function chopEnd($needle)
{
return new static(Str::chopStart($this->value, $needle));
return new static(Str::chopEnd($this->value, $needle));
}

/**
Expand Down

0 comments on commit 7bf4d41

Please sign in to comment.