@@ -92,10 +92,21 @@ public function setString(string $string): void
9292 */
9393 public function trim (string $ chars = " \t\n\r\0\x0B" ): self
9494 {
95- $ this ->string = trim ($ this ->string , $ chars );
95+ if ($ this ->string ) {
96+ $ this ->string = trim ($ this ->string , $ chars );
97+ }
98+
9699 return $ this ;
97100 }
98101
102+ /**
103+ * @return bool
104+ */
105+ public function isEmpty (): bool
106+ {
107+ return $ this ->string !== '' ;
108+ }
109+
99110 /**
100111 * @return int
101112 */
@@ -146,6 +157,14 @@ public function hasSuffix(string $suffix): bool
146157
147158 // ------------------ convert ------------------
148159
160+ /**
161+ * @return int
162+ */
163+ public function toInt (): int
164+ {
165+ return (int )$ this ->string ;
166+ }
167+
149168 /**
150169 * @return int
151170 */
@@ -157,19 +176,51 @@ public function getInt(): int
157176 /**
158177 * @return int[]
159178 */
160- public function getInts (string $ sep = ', ' ): array
179+ public function toInts (string $ sep = ', ' ): array
161180 {
162181 return Str::str2ints ($ this ->string , $ sep );
163182 }
164183
184+ /**
185+ * @return int[]
186+ */
187+ public function getInts (string $ sep = ', ' ): array
188+ {
189+ return $ this ->toInts ($ sep );
190+ }
191+
192+ /**
193+ * @return bool
194+ */
195+ public function toBool (): bool
196+ {
197+ return Str::toBool ($ this ->string );
198+ }
199+
165200 /**
166201 * @return string[]
167202 */
168- public function getStrings (string $ sep = ', ' , int $ limit = 0 ): array
203+ public function toArray (string $ sep = ', ' , int $ limit = 0 ): array
204+ {
205+ return $ this ->toStrings ($ sep , $ limit );
206+ }
207+
208+ /**
209+ * @return string[]
210+ */
211+ public function toStrings (string $ sep = ', ' , int $ limit = 0 ): array
169212 {
170213 return Str::explode ($ this ->string , $ sep , $ limit );
171214 }
172215
216+ /**
217+ * @return string[]
218+ */
219+ public function getStrings (string $ sep = ', ' , int $ limit = 0 ): array
220+ {
221+ return $ this ->toStrings ($ sep , $ limit );
222+ }
223+
173224 /**
174225 * @return string
175226 */
0 commit comments