@@ -268,23 +268,6 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
268
268
self . extension ( ) . and_then ( str:: from_utf8_slice_opt)
269
269
}
270
270
271
- /// Replaces the directory portion of the path with the given byte vector or string.
272
- /// If `self` represents the root of the filesystem hierarchy, the last path component
273
- /// of the argument becomes the filename.
274
- ///
275
- /// # Failure
276
- ///
277
- /// Raises the `null_byte` condition if the dirname contains a NUL.
278
- #[ inline]
279
- fn set_dirname < T : BytesContainer > ( & mut self , dirname : T ) {
280
- if contains_nul ( dirname. container_as_bytes ( ) ) {
281
- let dirname = self :: null_byte:: cond. raise ( dirname. container_into_owned_bytes ( ) ) ;
282
- assert ! ( !contains_nul( dirname) ) ;
283
- unsafe { self . set_dirname_unchecked ( dirname) }
284
- } else {
285
- unsafe { self . set_dirname_unchecked ( dirname) }
286
- }
287
- }
288
271
/// Replaces the filename portion of the path with the given byte vector or string.
289
272
/// If the replacement name is [], this is equivalent to popping the path.
290
273
///
@@ -301,53 +284,6 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
301
284
unsafe { self . set_filename_unchecked ( filename) }
302
285
}
303
286
}
304
- /// Replaces the filestem with the given byte vector or string.
305
- /// If there is no extension in `self` (or `self` has no filename), this is equivalent
306
- /// to `set_filename`. Otherwise, if the argument is [] or "", the extension (including
307
- /// the preceding '.') becomes the new filename.
308
- ///
309
- /// # Failure
310
- ///
311
- /// Raises the `null_byte` condition if the filestem contains a NUL.
312
- fn set_filestem < T : BytesContainer > ( & mut self , filestem : T ) {
313
- // borrowck is being a pain here
314
- enum Value < T > {
315
- Checked ( T ) ,
316
- Unchecked ( ~[ u8 ] )
317
- }
318
- let val = {
319
- match self . filename ( ) {
320
- None => Checked ( filestem) ,
321
- Some ( name) => {
322
- let dot = '.' as u8 ;
323
- match name. rposition_elem ( & dot) {
324
- None | Some ( 0 ) => Checked ( filestem) ,
325
- Some ( idx) => {
326
- let mut v;
327
- if contains_nul ( filestem. container_as_bytes ( ) ) {
328
- let filestem = filestem. container_into_owned_bytes ( ) ;
329
- let filestem = self :: null_byte:: cond. raise ( filestem) ;
330
- assert ! ( !contains_nul( filestem) ) ;
331
- v = filestem;
332
- let n = v. len ( ) ;
333
- v. reserve ( n + name. len ( ) - idx) ;
334
- } else {
335
- let filestem = filestem. container_as_bytes ( ) ;
336
- v = vec:: with_capacity ( filestem. len ( ) + name. len ( ) - idx) ;
337
- v. push_all ( filestem) ;
338
- }
339
- v. push_all ( name. slice_from ( idx) ) ;
340
- Unchecked ( v)
341
- }
342
- }
343
- }
344
- }
345
- } ;
346
- match val {
347
- Checked ( v) => self . set_filename ( v) ,
348
- Unchecked ( v) => unsafe { self . set_filename_unchecked ( v) }
349
- }
350
- }
351
287
/// Replaces the extension with the given byte vector or string.
352
288
/// If there is no extension in `self`, this adds one.
353
289
/// If the argument is [] or "", this removes the extension.
@@ -417,61 +353,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
417
353
Some ( v) => unsafe { self . set_filename_unchecked ( v) }
418
354
}
419
355
}
420
- /// Adds the given extension (as a byte vector or string) to the file.
421
- /// This does not remove any existing extension.
422
- /// `foo.bar`.add_extension(`baz`) becomes `foo.bar.baz`.
423
- /// If `self` has no filename, this is a no-op.
424
- /// If the argument is [] or "", this is a no-op.
425
- ///
426
- /// # Failure
427
- ///
428
- /// Raises the `null_byte` condition if the extension contains a NUL.
429
- fn add_extension < T : BytesContainer > ( & mut self , extension : T ) {
430
- if extension. container_as_bytes ( ) . is_empty ( ) { return ; }
431
- // appease borrowck
432
- let val = {
433
- match self . filename ( ) {
434
- None => None ,
435
- Some ( name) => {
436
- let mut v;
437
- if contains_nul ( extension. container_as_bytes ( ) ) {
438
- let ext = extension. container_into_owned_bytes ( ) ;
439
- let extension = self :: null_byte:: cond. raise ( ext) ;
440
- assert ! ( !contains_nul( extension) ) ;
441
- v = vec:: with_capacity ( name. len ( ) + 1 + extension. len ( ) ) ;
442
- v. push_all ( name) ;
443
- v. push ( '.' as u8 ) ;
444
- v. push_all ( extension) ;
445
- } else {
446
- let extension = extension. container_as_bytes ( ) ;
447
- v = vec:: with_capacity ( name. len ( ) + 1 + extension. len ( ) ) ;
448
- v. push_all ( name) ;
449
- v. push ( '.' as u8 ) ;
450
- v. push_all ( extension) ;
451
- }
452
- Some ( v)
453
- }
454
- }
455
- } ;
456
- match val {
457
- None => ( ) ,
458
- Some ( v) => unsafe { self . set_filename_unchecked ( v) }
459
- }
460
- }
461
356
462
- /// Returns a new Path constructed by replacing the dirname with the given
463
- /// byte vector or string.
464
- /// See `set_dirname` for details.
465
- ///
466
- /// # Failure
467
- ///
468
- /// Raises the `null_byte` condition if the dirname contains a NUL.
469
- #[ inline]
470
- fn with_dirname < T : BytesContainer > ( & self , dirname : T ) -> Self {
471
- let mut p = self . clone ( ) ;
472
- p. set_dirname ( dirname) ;
473
- p
474
- }
475
357
/// Returns a new Path constructed by replacing the filename with the given
476
358
/// byte vector or string.
477
359
/// See `set_filename` for details.
@@ -485,19 +367,6 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
485
367
p. set_filename ( filename) ;
486
368
p
487
369
}
488
- /// Returns a new Path constructed by setting the filestem to the given
489
- /// byte vector or string.
490
- /// See `set_filestem` for details.
491
- ///
492
- /// # Failure
493
- ///
494
- /// Raises the `null_byte` condition if the filestem contains a NUL.
495
- #[ inline]
496
- fn with_filestem < T : BytesContainer > ( & self , filestem : T ) -> Self {
497
- let mut p = self . clone ( ) ;
498
- p. set_filestem ( filestem) ;
499
- p
500
- }
501
370
/// Returns a new Path constructed by setting the extension to the given
502
371
/// byte vector or string.
503
372
/// See `set_extension` for details.
@@ -518,12 +387,6 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
518
387
// self.dirname() returns a NUL-free vector
519
388
unsafe { GenericPathUnsafe :: new_unchecked ( self . dirname ( ) ) }
520
389
}
521
- /// Returns the file component of `self`, as a relative Path.
522
- /// If `self` represents the root of the filesystem hierarchy, returns None.
523
- fn file_path ( & self ) -> Option < Self > {
524
- // self.filename() returns a NUL-free vector
525
- self . filename ( ) . map_move ( |v| unsafe { GenericPathUnsafe :: new_unchecked ( v) } )
526
- }
527
390
528
391
/// Returns a Path that represents the filesystem root that `self` is rooted in.
529
392
///
@@ -561,16 +424,10 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
561
424
}
562
425
}
563
426
}
564
- /// Pops the last path component off of `self` and returns it.
565
- /// If `self` represents the root of the file hierarchy, None is returned.
566
- fn pop ( & mut self ) -> Option < ~[ u8 ] > ;
567
- /// Pops the last path component off of `self` and returns it as a string, if possible.
568
- /// `self` will still be modified even if None is returned.
569
- /// See `pop` for details.
570
- #[ inline]
571
- fn pop_str ( & mut self ) -> Option < ~str > {
572
- self . pop ( ) . and_then ( |v| str:: from_utf8_owned_opt ( v) )
573
- }
427
+ /// Removes the last path component from the receiver.
428
+ /// Returns `true` if the receiver was modified, or `false` if it already
429
+ /// represented the root of the file hierarchy.
430
+ fn pop ( & mut self ) -> bool ;
574
431
575
432
/// Returns a new Path constructed by joining `self` with the given path
576
433
/// (as a byte vector or string).
@@ -658,11 +515,6 @@ pub trait GenericPathUnsafe {
658
515
/// The resulting Path will always be normalized.
659
516
unsafe fn new_unchecked < T : BytesContainer > ( path : T ) -> Self ;
660
517
661
- /// Replaces the directory portion of the path without checking for null
662
- /// bytes.
663
- /// See `set_dirname` for details.
664
- unsafe fn set_dirname_unchecked < T : BytesContainer > ( & mut self , dirname : T ) ;
665
-
666
518
/// Replaces the filename portion of the path without checking for null
667
519
/// bytes.
668
520
/// See `set_filename` for details.
0 commit comments