Use local slice_chars

StrExt::slice_chars is deprecated and will be removed in Rust. This
lifts the implementation from Rust libstd and puts it in util::str.

This fixes a bunch of deprecation warnings in Servo.
This commit is contained in:
Jack Moffitt 2015-07-31 12:23:13 -06:00
parent ca9f9226b0
commit dae1a398a4
7 changed files with 41 additions and 17 deletions

View file

@ -17,7 +17,7 @@ use dom::element::Element;
use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::node::{Node, NodeHelpers, NodeTypeId};
use util::str::DOMString;
use util::str::{DOMString, slice_chars};
use std::borrow::ToOwned;
use std::cell::Ref;
@ -74,7 +74,7 @@ impl<'a> CharacterDataMethods for &'a CharacterData {
}
// Steps 3-4.
let end = if length - offset < count { length } else { offset + count };
Ok(data.slice_chars(offset as usize, end as usize).to_owned())
Ok(slice_chars(&*data, offset as usize, end as usize).to_owned())
}
// https://dom.spec.whatwg.org/#dom-characterdata-appenddatadata
@ -107,9 +107,9 @@ impl<'a> CharacterDataMethods for &'a CharacterData {
};
// Step 4: Mutation observers.
// Step 5.
let mut data = self.data.borrow().slice_chars(0, offset as usize).to_owned();
let mut data = slice_chars(&*self.data.borrow(), 0, offset as usize).to_owned();
data.push_str(&arg);
data.push_str(&self.data.borrow().slice_chars((offset + count) as usize, length as usize));
data.push_str(slice_chars(&*self.data.borrow(), (offset + count) as usize, length as usize));
*self.data.borrow_mut() = data;
// FIXME: Once we have `Range`, we should implement step7 to step11
Ok(())

View file

@ -21,7 +21,6 @@
#![feature(plugin)]
#![feature(ref_slice)]
#![feature(rc_unique)]
#![feature(slice_chars)]
#![feature(str_utf16)]
#![feature(unicode)]
#![feature(vec_push_all)]

View file

@ -8,7 +8,7 @@ use clipboard_provider::ClipboardProvider;
use dom::keyboardevent::{KeyboardEvent, KeyboardEventHelpers, key_value};
use msg::constellation_msg::{SHIFT, CONTROL, ALT, SUPER};
use msg::constellation_msg::{Key, KeyModifiers};
use util::str::DOMString;
use util::str::{DOMString, slice_chars};
use std::borrow::ToOwned;
use std::cmp::{min, max};
@ -159,16 +159,16 @@ impl<T: ClipboardProvider> TextInput<T> {
self.get_sorted_selection().map(|(begin, end)| {
if begin.line != end.line {
let mut s = String::new();
s.push_str(self.lines[begin.line].slice_chars(begin.index, self.lines[begin.line].len()));
s.push_str(slice_chars(&self.lines[begin.line], begin.index, self.lines[begin.line].len()));
for (_, line) in self.lines.iter().enumerate().filter(|&(i,_)| begin.line < i && i < end.line) {
s.push_str("\n");
s.push_str(line);
}
s.push_str("\n");
s.push_str(self.lines[end.line].slice_chars(0, end.index));
s.push_str(slice_chars(&self.lines[end.line], 0, end.index));
s
} else {
self.lines[begin.line].slice_chars(begin.index, end.index).to_owned()
slice_chars(&self.lines[begin.line], begin.index, end.index).to_owned()
}
})
}
@ -178,8 +178,8 @@ impl<T: ClipboardProvider> TextInput<T> {
self.clear_selection();
let new_lines = {
let prefix = self.lines[begin.line].slice_chars(0, begin.index);
let suffix = self.lines[end.line].slice_chars(end.index, self.lines[end.line].chars().count());
let prefix = slice_chars(&self.lines[begin.line], 0, begin.index);
let suffix = slice_chars(&self.lines[end.line], end.index, self.lines[end.line].chars().count());
let lines_prefix = &self.lines[..begin.line];
let lines_suffix = &self.lines[end.line + 1..];