|
@@ 738-754 (lines=17) @@
|
| 735 |
|
* |
| 736 |
|
* @return Stringy Object with the resulting $str after the insertion |
| 737 |
|
*/ |
| 738 |
|
public function insert($substring, $index) |
| 739 |
|
{ |
| 740 |
|
$stringy = static::create($this->str, $this->encoding); |
| 741 |
|
if ($index > $stringy->length()) { |
| 742 |
|
return $stringy; |
| 743 |
|
} |
| 744 |
|
|
| 745 |
|
$start = UTF8::substr($stringy->str, 0, $index, $stringy->encoding); |
| 746 |
|
$end = UTF8::substr($stringy->str, $index, $stringy->length(), $stringy->encoding); |
| 747 |
|
|
| 748 |
|
$stringy->str = $start . $substring . $end; |
| 749 |
|
|
| 750 |
|
return $stringy; |
| 751 |
|
} |
| 752 |
|
|
| 753 |
|
/** |
| 754 |
|
* Returns true if the string contains only alphabetic chars, false |
| 755 |
|
* otherwise. |
| 756 |
|
* |
| 757 |
|
* @return bool Whether or not $str contains only alphabetic chars |
|
@@ 2021-2036 (lines=16) @@
|
| 2018 |
|
* |
| 2019 |
|
* @return Stringy Object with the resulting $str after truncating |
| 2020 |
|
*/ |
| 2021 |
|
public function truncate($length, $substring = '') |
| 2022 |
|
{ |
| 2023 |
|
$stringy = static::create($this->str, $this->encoding); |
| 2024 |
|
if ($length >= $stringy->length()) { |
| 2025 |
|
return $stringy; |
| 2026 |
|
} |
| 2027 |
|
|
| 2028 |
|
// Need to further trim the string so we can append the substring |
| 2029 |
|
$substringLength = UTF8::strlen($substring, $stringy->encoding); |
| 2030 |
|
$length -= $substringLength; |
| 2031 |
|
|
| 2032 |
|
$truncated = UTF8::substr($stringy->str, 0, $length, $stringy->encoding); |
| 2033 |
|
$stringy->str = $truncated . $substring; |
| 2034 |
|
|
| 2035 |
|
return $stringy; |
| 2036 |
|
} |
| 2037 |
|
|
| 2038 |
|
/** |
| 2039 |
|
* Returns a lowercase and trimmed string separated by underscores. |