Skip to content

Commit

Permalink
Now the old after path position is always the serialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
emilio committed Sep 18, 2016
1 parent 5a77f26 commit 7225866
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,20 +789,21 @@ impl Url {
form_urlencoded::Serializer::for_suffix(query, query_start + "?".len())
}

fn take_after_path(&mut self) -> (u32, String) {
fn take_after_path(&mut self) -> String {
match (self.query_start, self.fragment_start) {
(Some(i), _) | (None, Some(i)) => {
let after_path = self.slice(i..).to_owned();
self.serialization.truncate(i as usize);
(i, after_path)
after_path
},
(None, None) => (to_u32(self.serialization.len()).unwrap(), String::new())
(None, None) => String::new(),
}
}

/// Change this URL’s path.
pub fn set_path(&mut self, mut path: &str) {
let (old_after_path_pos, after_path) = self.take_after_path();
let after_path = self.take_after_path();
let old_after_path_pos = to_u32(self.serialization.len()).unwrap();
let cannot_be_a_base = self.cannot_be_a_base();
let scheme_type = SchemeType::from(self.scheme());
self.serialization.truncate(self.path_start as usize);
Expand Down
5 changes: 3 additions & 2 deletions src/path_segments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use parser::{self, SchemeType};
use parser::{self, SchemeType, to_u32};
use std::str;
use Url;

Expand Down Expand Up @@ -35,7 +35,8 @@ pub struct PathSegmentsMut<'a> {

// Not re-exported outside the crate
pub fn new(url: &mut Url) -> PathSegmentsMut {
let (old_after_path_position, after_path) = url.take_after_path();
let after_path = url.take_after_path();
let old_after_path_position = to_u32(url.serialization.len()).unwrap();
debug_assert!(url.byte_at(url.path_start) == b'/');
PathSegmentsMut {
after_first_slash: url.path_start as usize + "/".len(),
Expand Down

0 comments on commit 7225866

Please sign in to comment.