| @@ 296-305 (lines=10) @@ | ||
| 293 | * |
|
| 294 | * @return static <p>Object with a trimmed $str.</p> |
|
| 295 | */ |
|
| 296 | public function trim(string $chars = null): Stringy |
|
| 297 | { |
|
| 298 | if (!$chars) { |
|
| 299 | $chars = '[:space:]'; |
|
| 300 | } else { |
|
| 301 | $chars = \preg_quote($chars, '/'); |
|
| 302 | } |
|
| 303 | ||
| 304 | return $this->regexReplace("^[$chars]+|[$chars]+\$", ''); |
|
| 305 | } |
|
| 306 | ||
| 307 | /** |
|
| 308 | * Replaces all occurrences of $pattern in $str by $replacement. |
|
| @@ 2300-2309 (lines=10) @@ | ||
| 2297 | * |
|
| 2298 | * @return static <p>Object with a trimmed $str.</p> |
|
| 2299 | */ |
|
| 2300 | public function trimLeft(string $chars = null): Stringy |
|
| 2301 | { |
|
| 2302 | if (!$chars) { |
|
| 2303 | $chars = '[:space:]'; |
|
| 2304 | } else { |
|
| 2305 | $chars = \preg_quote($chars, '/'); |
|
| 2306 | } |
|
| 2307 | ||
| 2308 | return $this->regexReplace("^[$chars]+", ''); |
|
| 2309 | } |
|
| 2310 | ||
| 2311 | /** |
|
| 2312 | * Returns a string with whitespace removed from the end of the string. |
|
| @@ 2320-2329 (lines=10) @@ | ||
| 2317 | * |
|
| 2318 | * @return static <p>Object with a trimmed $str.</p> |
|
| 2319 | */ |
|
| 2320 | public function trimRight(string $chars = null): Stringy |
|
| 2321 | { |
|
| 2322 | if (!$chars) { |
|
| 2323 | $chars = '[:space:]'; |
|
| 2324 | } else { |
|
| 2325 | $chars = \preg_quote($chars, '/'); |
|
| 2326 | } |
|
| 2327 | ||
| 2328 | return $this->regexReplace("[$chars]+\$", ''); |
|
| 2329 | } |
|
| 2330 | ||
| 2331 | /** |
|
| 2332 | * Truncates the string to a given length. If $substring is provided, and |
|