@@ -1260,6 +1260,39 @@ impl String {
1260
1260
self . len ( ) == 0
1261
1261
}
1262
1262
1263
+ /// Divide one string into two at an index.
1264
+ ///
1265
+ /// The argument, `mid`, should be a byte offset from the start of the string. It must also
1266
+ /// be on the boundary of a UTF-8 code point.
1267
+ ///
1268
+ /// The two strings returned go from the start of the string to `mid`, and from `mid` to the end
1269
+ /// of the string.
1270
+ ///
1271
+ /// # Panics
1272
+ ///
1273
+ /// Panics if `mid` is not on a `UTF-8` code point boundary, or if it is beyond the last
1274
+ /// code point of the string.
1275
+ ///
1276
+ /// # Examples
1277
+ ///
1278
+ /// ```
1279
+ /// # #![feature(string_split_off)]
1280
+ /// # fn main() {
1281
+ /// let mut hello = String::from("Hello, World!");
1282
+ /// let world = hello.split_off(7);
1283
+ /// assert_eq!(hello, "Hello, ");
1284
+ /// assert_eq!(world, "World!");
1285
+ /// # }
1286
+ /// ```
1287
+ #[ inline]
1288
+ #[ unstable( feature = "string_split_off" , issue = "38080" ) ]
1289
+ pub fn split_off ( & mut self , mid : usize ) -> String {
1290
+ assert ! ( self . is_char_boundary( mid) ) ;
1291
+ assert ! ( mid <= self . len( ) ) ;
1292
+ let other = self . vec . split_off ( mid) ;
1293
+ unsafe { String :: from_utf8_unchecked ( other) }
1294
+ }
1295
+
1263
1296
/// Truncates this `String`, removing all contents.
1264
1297
///
1265
1298
/// While this means the `String` will have a length of zero, it does not
0 commit comments