| @@ 25-41 (lines=17) @@ | ||
| 22 | * |
|
| 23 | * @return static String being the first $n chars. |
|
| 24 | */ |
|
| 25 | public function first($n) |
|
| 26 | { |
|
| 27 | $first = ''; |
|
| 28 | ||
| 29 | if ($n > 0) |
|
| 30 | { |
|
| 31 | $first = UTF8::substr |
|
| 32 | ( |
|
| 33 | $this->scalarString, |
|
| 34 | 0, |
|
| 35 | $n, |
|
| 36 | $this->encoding |
|
| 37 | ); |
|
| 38 | } |
|
| 39 | ||
| 40 | return $this->newSelf($first); |
|
| 41 | } |
|
| 42 | ||
| 43 | /** |
|
| 44 | * Returns the last $n characters of the string. |
|
| @@ 50-66 (lines=17) @@ | ||
| 47 | * |
|
| 48 | * @return static String being the last $n chars. |
|
| 49 | */ |
|
| 50 | public function last($n) |
|
| 51 | { |
|
| 52 | $last = ''; |
|
| 53 | ||
| 54 | if ($n > 0) |
|
| 55 | { |
|
| 56 | $last = UTF8::substr |
|
| 57 | ( |
|
| 58 | $this->scalarString, |
|
| 59 | -$n, |
|
| 60 | null, |
|
| 61 | $this->encoding |
|
| 62 | ); |
|
| 63 | } |
|
| 64 | ||
| 65 | return $this->newSelf($last); |
|
| 66 | } |
|
| 67 | } |
|
| 68 | ||