| @@ 299-308 (lines=10) @@ | ||
| 296 | * |
|
| 297 | * @return static <p>Object with a trimmed $str.</p> |
|
| 298 | */ |
|
| 299 | public function trim(string $chars = null): self |
|
| 300 | { |
|
| 301 | if (!$chars) { |
|
| 302 | $chars = '[:space:]'; |
|
| 303 | } else { |
|
| 304 | $chars = \preg_quote($chars, '/'); |
|
| 305 | } |
|
| 306 | ||
| 307 | return $this->regexReplace("^[$chars]+|[$chars]+\$", ''); |
|
| 308 | } |
|
| 309 | ||
| 310 | /** |
|
| 311 | * Replaces all occurrences of $pattern in $str by $replacement. |
|
| @@ 2447-2456 (lines=10) @@ | ||
| 2444 | * |
|
| 2445 | * @return static <p>Object with a trimmed $str.</p> |
|
| 2446 | */ |
|
| 2447 | public function trimLeft(string $chars = null): self |
|
| 2448 | { |
|
| 2449 | if (!$chars) { |
|
| 2450 | $chars = '[:space:]'; |
|
| 2451 | } else { |
|
| 2452 | $chars = \preg_quote($chars, '/'); |
|
| 2453 | } |
|
| 2454 | ||
| 2455 | return $this->regexReplace("^[$chars]+", ''); |
|
| 2456 | } |
|
| 2457 | ||
| 2458 | /** |
|
| 2459 | * Returns a string with whitespace removed from the end of the string. |
|
| @@ 2467-2476 (lines=10) @@ | ||
| 2464 | * |
|
| 2465 | * @return static <p>Object with a trimmed $str.</p> |
|
| 2466 | */ |
|
| 2467 | public function trimRight(string $chars = null): self |
|
| 2468 | { |
|
| 2469 | if (!$chars) { |
|
| 2470 | $chars = '[:space:]'; |
|
| 2471 | } else { |
|
| 2472 | $chars = \preg_quote($chars, '/'); |
|
| 2473 | } |
|
| 2474 | ||
| 2475 | return $this->regexReplace("[$chars]+\$", ''); |
|
| 2476 | } |
|
| 2477 | ||
| 2478 | /** |
|
| 2479 | * Truncates the string to a given length. If $substring is provided, and |
|