mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Implement CharacterData.{deleteData, insertData, replaceData}
This commit is contained in:
parent
bb8a037cb2
commit
fd9541357f
3 changed files with 34 additions and 1 deletions
|
@ -6,7 +6,7 @@
|
|||
|
||||
use dom::bindings::codegen::InheritTypes::CharacterDataDerived;
|
||||
use dom::bindings::js::JS;
|
||||
use dom::bindings::error::{Fallible, ErrorResult};
|
||||
use dom::bindings::error::{Fallible, ErrorResult, IndexSize};
|
||||
use dom::bindings::utils::{Reflectable, Reflector};
|
||||
use dom::document::Document;
|
||||
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
|
||||
|
@ -59,6 +59,32 @@ impl CharacterData {
|
|||
self.data.push_str(arg);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn InsertData(&mut self, offset: u32, arg: DOMString) -> ErrorResult {
|
||||
self.ReplaceData(offset, 0, arg)
|
||||
}
|
||||
|
||||
pub fn DeleteData(&mut self, offset: u32, count: u32) -> ErrorResult {
|
||||
self.ReplaceData(offset, count, ~"")
|
||||
}
|
||||
|
||||
pub fn ReplaceData(&mut self, offset: u32, count: u32, arg: DOMString) -> ErrorResult {
|
||||
let length = self.data.len() as u32;
|
||||
if offset > length {
|
||||
return Err(IndexSize);
|
||||
}
|
||||
let count = if offset + count > length {
|
||||
length - offset
|
||||
} else {
|
||||
count
|
||||
};
|
||||
let mut data = self.data.slice(0, offset as uint).to_owned();
|
||||
data.push_str(arg);
|
||||
data.push_str(self.data.slice((offset + count) as uint, length as uint));
|
||||
self.data = data;
|
||||
// FIXME: Once we have `Range`, we should implement step7 to step11
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Reflectable for CharacterData {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue