@@ -209,6 +209,37 @@ impl GString {
209
209
sys:: i64_to_ordering ( self . as_inner ( ) . filenocasecmp_to ( to) )
210
210
}
211
211
212
+ /// Splits the string using a string delimiter and returns the substring at index `slice`.
213
+ ///
214
+ /// Returns the original string if delimiter does not occur in the string. Returns `None` if `slice` is out of bounds.
215
+ ///
216
+ /// This is faster than [`split()`][Self::split], if you only need one substring.
217
+ pub fn get_slice ( & self , delimiter : impl AsArg < GString > , slice : usize ) -> Option < GString > {
218
+ let sliced = self . as_inner ( ) . get_slice ( delimiter, slice as i64 ) ;
219
+
220
+ // Note: self="" always returns None.
221
+ super :: populated_or_none ( sliced)
222
+ }
223
+
224
+ /// Returns the total number of slices, when the string is split with the given delimiter.
225
+ ///
226
+ /// See also [`split()`][Self::split] and [`get_slice()`][Self::get_slice].
227
+ pub fn get_slice_count ( & self , delimiter : impl AsArg < GString > ) -> usize {
228
+ self . as_inner ( ) . get_slice_count ( delimiter) as usize
229
+ }
230
+
231
+ /// Splits the string using a Unicode char `delimiter` and returns the substring at index `slice`.
232
+ ///
233
+ /// Returns the original string if delimiter does not occur in the string. Returns `None` if `slice` is out of bounds.
234
+ ///
235
+ /// This is faster than [`split()`][Self::split], if you only need one substring.
236
+ pub fn get_slicec ( & self , delimiter : char , slice : usize ) -> Option < GString > {
237
+ let sliced = self . as_inner ( ) . get_slicec ( delimiter as i64 , slice as i64 ) ;
238
+
239
+ // Note: self="" always returns None.
240
+ super :: populated_or_none ( sliced)
241
+ }
242
+
212
243
ffi_methods ! {
213
244
type sys:: GDExtensionStringPtr = * mut Self ;
214
245
0 commit comments