Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Illuminate/Support/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,18 @@ public static function finish($value, $cap)
return preg_replace('/(?:'.$quoted.')+$/u', '', $value).$cap;
}

/**
* Wrap the string with the given strings.
*
* @param string $before
* @param string|null $after
* @return string
*/
public static function wrap($value, $before, $after = null)
{
return $before.$value.($after ??= $before);
}

/**
* Determine if a given string matches a given pattern.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Support/Stringable.php
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@ public function wordCount()
*/
public function wrap($before, $after = null)
{
return new static($before.$this->value.($after ??= $before));
return new static(Str::wrap($this->value, $before, $after));
}

/**
Expand Down
6 changes: 6 additions & 0 deletions tests/Support/SupportStrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,12 @@ public function testFinish()
$this->assertSame('abcbbc', Str::finish('abcbbcbc', 'bc'));
}

public function testWrap()
{
$this->assertEquals('"value"', Str::wrap('value', '"'));
$this->assertEquals('foo-bar-baz', Str::wrap('-bar-', 'foo', 'baz'));
}

public function testIs()
{
$this->assertTrue(Str::is('/', '/'));
Expand Down