mirror of
https://github.com/getformwork/formwork.git
synced 2025-03-14 19:19:48 +01:00
Add Str::append()
and Str::prepend()
This commit is contained in:
parent
97f571ae60
commit
ddefc5db9b
@ -109,12 +109,28 @@ class Str
|
||||
return preg_replace(['/^-|-$|[^a-z0-9-]/', '/-+/'], ['', '-'], strtr(strtolower($string), self::SLUG_TRANSLATE_MAP));
|
||||
}
|
||||
|
||||
/**
|
||||
* Append a suffix to a given string if missing
|
||||
*/
|
||||
public static function append(string $string, string $suffix): string
|
||||
{
|
||||
return static::endsWith($string, $suffix) ? $string : $string . $suffix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepend a prefix to a given string if missing
|
||||
*/
|
||||
public static function prepend(string $string, string $prefix): string
|
||||
{
|
||||
return static::startsWith($string, $prefix) ? $string : $prefix . $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap a string with another
|
||||
*/
|
||||
public static function wrap(string $string, string $wrap): string
|
||||
{
|
||||
return (static::startsWith($string, $wrap) ? '' : $wrap) . $string . (static::endsWith($string, $wrap) ? '' : $wrap);
|
||||
return static::append(static::prepend($string, $wrap), $wrap);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user