diff --git a/hubbub.rs b/hubbub.rs index aeb745a..7ae4524 100644 --- a/hubbub.rs +++ b/hubbub.rs @@ -47,7 +47,7 @@ pub struct Attribute { pub struct Tag { pub ns: Ns, pub name: ~str, - pub attributes: ~[Attribute], + pub attributes: Vec, pub self_closing: bool } @@ -56,8 +56,8 @@ pub type NodeDataPtr = uint; pub struct TreeHandler<'a> { pub create_comment: |data: ~str|: 'a -> NodeDataPtr, - pub create_doctype: |doctype: ~Doctype|: 'a -> NodeDataPtr, - pub create_element: |tag: ~Tag|: 'a -> NodeDataPtr, + pub create_doctype: |doctype: Box|: 'a -> NodeDataPtr, + pub create_element: |tag: Box|: 'a -> NodeDataPtr, pub create_text: |data: ~str|: 'a -> NodeDataPtr, pub ref_node: |node: NodeDataPtr|: 'a, pub unref_node: |node: NodeDataPtr|: 'a, @@ -69,7 +69,7 @@ pub struct TreeHandler<'a> { pub get_parent: |node: NodeDataPtr, element_only: bool|: 'a -> NodeDataPtr, pub has_children: |node: NodeDataPtr|: 'a -> bool, pub form_associate: |form: NodeDataPtr, node: NodeDataPtr|: 'a, - pub add_attributes: |node: NodeDataPtr, attributes: ~[Attribute]|: 'a, + pub add_attributes: |node: NodeDataPtr, attributes: Vec|: 'a, pub set_quirks_mode: |mode: QuirksMode|: 'a, pub encoding_change: |encname: ~str|: 'a, pub complete_script: |script: NodeDataPtr|: 'a, @@ -77,7 +77,7 @@ pub struct TreeHandler<'a> { } pub struct TreeHandlerPair<'a> { - pub tree_handler: &'a TreeHandler<'a>, + pub tree_handler: &'a mut TreeHandler<'a>, pub ll_tree_handler: ll::TreeHandler } @@ -109,7 +109,7 @@ pub fn Parser(encoding: &str, fix_encoding: bool) -> Parser { } impl<'a> Parser<'a> { - pub fn set_tree_handler(&mut self, tree_handler: &'a TreeHandler) { + pub fn set_tree_handler(&mut self, tree_handler: &'a mut TreeHandler<'a>) { self.tree_handler = Some(TreeHandlerPair { tree_handler: tree_handler, ll_tree_handler: ll::TreeHandler { @@ -211,7 +211,6 @@ pub mod tree_callbacks { use libc::{c_void, c_char}; use std::cast; use std::ptr::RawPtr; - use std::slice; use std::str; use super::{NodeDataPtr, Ns, NullNs, HtmlNs, MathMlNs, SvgNs, XLinkNs, XmlNs, XmlNsNs}; use super::{QuirksMode, NoQuirks, LimitedQuirks, FullQuirks}; @@ -242,7 +241,7 @@ pub mod tree_callbacks { 4 => XLinkNs, 5 => XmlNs, 6 => XmlNsNs, - _ => fail!(~"unknown namespace") + _ => fail!("unknown namespace") } } @@ -251,14 +250,14 @@ pub mod tree_callbacks { 0 => NoQuirks, 1 => LimitedQuirks, 2 => FullQuirks, - _ => fail!(~"unknown quirks mode") + _ => fail!("unknown quirks mode") } } - pub fn from_hubbub_attributes(attributes: *ll::Attribute, n_attributes: u32) -> ~[Attribute] { + pub fn from_hubbub_attributes(attributes: *ll::Attribute, n_attributes: u32) -> Vec { debug!("from_hubbub_attributes n={:u}", n_attributes as uint); unsafe { - slice::from_fn(n_attributes as uint, |i| { + Vec::from_fn(n_attributes as uint, |i| { let attribute = attributes.offset(i as int); Attribute { ns: from_hubbub_ns((*attribute).ns), @@ -269,8 +268,8 @@ pub mod tree_callbacks { } } - pub fn from_hubbub_tag(tag: &ll::Tag) -> ~Tag { - ~Tag { + pub fn from_hubbub_tag(tag: &ll::Tag) -> Box { + box Tag { ns: from_hubbub_ns((*tag).ns), name: from_hubbub_string(&(*tag).name), attributes: from_hubbub_attributes((*tag).attributes, (*tag).n_attributes), @@ -278,8 +277,8 @@ pub mod tree_callbacks { } } - pub fn from_hubbub_doctype(doctype: &ll::Doctype) -> ~Doctype { - ~Doctype { + pub fn from_hubbub_doctype(doctype: &ll::Doctype) -> Box { + box Doctype { name: from_hubbub_string(&doctype.name), public_id: if doctype.public_missing { @@ -306,8 +305,8 @@ pub mod tree_callbacks { pub extern fn create_comment(ctx: *c_void, data: *ll::String, result: *mut *c_void) -> ll::Error { debug!("ll create comment"); - let self_opt: &Option = unsafe { cast::transmute(ctx) }; - let this = self_opt.get_ref(); + let self_opt: &mut Option = unsafe { cast::transmute(ctx) }; + let this = self_opt.get_mut_ref(); unsafe { let data: &ll::String = cast::transmute(data); *result = to_hubbub_node((this.tree_handler.create_comment)(from_hubbub_string(data))); @@ -318,8 +317,8 @@ pub mod tree_callbacks { pub extern fn create_doctype(ctx: *c_void, doctype: *ll::Doctype, result: *mut *c_void) -> ll::Error { debug!("ll create doctype"); - let self_opt: &Option = unsafe { cast::transmute(ctx) }; - let this = self_opt.get_ref(); + let self_opt: &mut Option = unsafe { cast::transmute(ctx) }; + let this = self_opt.get_mut_ref(); unsafe { let doctype: &ll::Doctype = cast::transmute(doctype); *result = to_hubbub_node((this.tree_handler.create_doctype)(from_hubbub_doctype(doctype))); @@ -330,8 +329,8 @@ pub mod tree_callbacks { pub extern fn create_element(ctx: *c_void, tag: *ll::Tag, result: *mut *c_void) -> ll::Error { debug!("ll create element"); - let self_opt: &Option = unsafe { cast::transmute(ctx) }; - let this = self_opt.get_ref(); + let self_opt: &mut Option = unsafe { cast::transmute(ctx) }; + let this = self_opt.get_mut_ref(); unsafe { let tag: &ll::Tag = cast::transmute(tag); *result = to_hubbub_node((this.tree_handler.create_element)(from_hubbub_tag(tag))); @@ -342,8 +341,8 @@ pub mod tree_callbacks { pub extern fn create_text(ctx: *c_void, data: *ll::String, result: *mut *c_void) -> ll::Error { debug!("ll create text"); - let self_opt: &Option = unsafe { cast::transmute(ctx) }; - let this = self_opt.get_ref(); + let self_opt: &mut Option = unsafe { cast::transmute(ctx) }; + let this = self_opt.get_mut_ref(); unsafe { let data: &ll::String = cast::transmute(data); *result = to_hubbub_node((this.tree_handler.create_text)(from_hubbub_string(data))); @@ -353,16 +352,16 @@ pub mod tree_callbacks { pub extern fn ref_node(ctx: *c_void, node: *c_void) -> ll::Error { debug!("ll ref node"); - let self_opt: &Option = unsafe { cast::transmute(ctx) }; - let this = self_opt.get_ref(); + let self_opt: &mut Option = unsafe { cast::transmute(ctx) }; + let this = self_opt.get_mut_ref(); (this.tree_handler.ref_node)(from_hubbub_node(node)); return ll::OK; } pub extern fn unref_node(ctx: *c_void, node: *c_void) -> ll::Error { debug!("ll unref node"); - let self_opt: &Option = unsafe { cast::transmute(ctx) }; - let this = self_opt.get_ref(); + let self_opt: &mut Option = unsafe { cast::transmute(ctx) }; + let this = self_opt.get_mut_ref(); (this.tree_handler.unref_node)(from_hubbub_node(node)); return ll::OK; } @@ -370,8 +369,8 @@ pub mod tree_callbacks { pub extern fn append_child(ctx: *c_void, parent: *c_void, child: *c_void, result: *mut *c_void) -> ll::Error { debug!("ll append child"); - let self_opt: &Option = unsafe { cast::transmute(ctx) }; - let this = self_opt.get_ref(); + let self_opt: &mut Option = unsafe { cast::transmute(ctx) }; + let this = self_opt.get_mut_ref(); unsafe { *result = to_hubbub_node((this.tree_handler.append_child)(from_hubbub_node(parent), from_hubbub_node(child))); @@ -382,8 +381,8 @@ pub mod tree_callbacks { pub extern fn insert_before(ctx: *c_void, parent: *c_void, child: *c_void, result: *mut *c_void) -> ll::Error { debug!("ll insert before"); - let self_opt: &Option = unsafe { cast::transmute(ctx) }; - let this = self_opt.get_ref(); + let self_opt: &mut Option = unsafe { cast::transmute(ctx) }; + let this = self_opt.get_mut_ref(); unsafe { *result = to_hubbub_node((this.tree_handler.insert_before)(from_hubbub_node(parent), from_hubbub_node(child))); @@ -395,8 +394,8 @@ pub mod tree_callbacks { -> ll::Error { debug!("ll remove child"); - let self_opt: &Option = unsafe { cast::transmute(ctx) }; - let this = self_opt.get_ref(); + let self_opt: &mut Option = unsafe { cast::transmute(ctx) }; + let this = self_opt.get_mut_ref(); unsafe { *result = to_hubbub_node((this.tree_handler.remove_child)(from_hubbub_node(parent), from_hubbub_node(child))); @@ -408,8 +407,8 @@ pub mod tree_callbacks { -> ll::Error { debug!("ll clone node"); - let self_opt: &Option = unsafe { cast::transmute(ctx) }; - let this = self_opt.get_ref(); + let self_opt: &mut Option = unsafe { cast::transmute(ctx) }; + let this = self_opt.get_mut_ref(); unsafe { *result = to_hubbub_node((this.tree_handler.clone_node)(from_hubbub_node(node), deep)); } @@ -420,8 +419,8 @@ pub mod tree_callbacks { -> ll::Error { debug!("ll reparent children"); - let self_opt: &Option = unsafe { cast::transmute(ctx) }; - let this = self_opt.get_ref(); + let self_opt: &mut Option = unsafe { cast::transmute(ctx) }; + let this = self_opt.get_mut_ref(); (this.tree_handler.reparent_children)(from_hubbub_node(node), from_hubbub_node(new_parent)); return ll::OK; @@ -431,8 +430,8 @@ pub mod tree_callbacks { -> ll::Error { debug!("ll get parent"); - let self_opt: &Option = unsafe { cast::transmute(ctx) }; - let this = self_opt.get_ref(); + let self_opt: &mut Option = unsafe { cast::transmute(ctx) }; + let this = self_opt.get_mut_ref(); unsafe { *result = to_hubbub_node((this.tree_handler.get_parent)(from_hubbub_node(node), element_only)); @@ -444,8 +443,8 @@ pub mod tree_callbacks { -> ll::Error { debug!("ll has children"); - let self_opt: &Option = unsafe { cast::transmute(ctx) }; - let this = self_opt.get_ref(); + let self_opt: &mut Option = unsafe { cast::transmute(ctx) }; + let this = self_opt.get_mut_ref(); unsafe { *result = (this.tree_handler.has_children)(from_hubbub_node(node)); } @@ -455,8 +454,8 @@ pub mod tree_callbacks { pub extern fn form_associate(ctx: *c_void, form: *c_void, node: *c_void) -> ll::Error { debug!("ll form associate"); - let self_opt: &Option = unsafe { cast::transmute(ctx) }; - let this = self_opt.get_ref(); + let self_opt: &mut Option = unsafe { cast::transmute(ctx) }; + let this = self_opt.get_mut_ref(); (this.tree_handler.form_associate)(from_hubbub_node(form), from_hubbub_node(node)); return ll::OK; } @@ -468,8 +467,8 @@ pub mod tree_callbacks { -> ll::Error { debug!("ll add attributes"); - let self_opt: &Option = unsafe { cast::transmute(ctx) }; - let this = self_opt.get_ref(); + let self_opt: &mut Option = unsafe { cast::transmute(ctx) }; + let this = self_opt.get_mut_ref(); (this.tree_handler.add_attributes)(from_hubbub_node(node), from_hubbub_attributes(attributes, n_attributes)); return ll::OK; @@ -478,8 +477,8 @@ pub mod tree_callbacks { pub extern fn set_quirks_mode(ctx: *c_void, mode: ll::QuirksMode) -> ll::Error { debug!("ll set quirks mode"); - let self_opt: &Option = unsafe { cast::transmute(ctx) }; - let this = self_opt.get_ref(); + let self_opt: &mut Option = unsafe { cast::transmute(ctx) }; + let this = self_opt.get_mut_ref(); (this.tree_handler.set_quirks_mode)(from_hubbub_quirks_mode(mode)); return ll::OK; } @@ -487,8 +486,8 @@ pub mod tree_callbacks { pub extern fn encoding_change(ctx: *c_void, encname: *c_char) -> ll::Error { debug!("ll encoding change"); - let self_opt: &Option = unsafe { cast::transmute(ctx) }; - let this = self_opt.get_ref(); + let self_opt: &mut Option = unsafe { cast::transmute(ctx) }; + let this = self_opt.get_mut_ref(); (this.tree_handler.encoding_change)(unsafe { str::raw::from_c_str(encname) }); return ll::OK; } @@ -496,8 +495,8 @@ pub mod tree_callbacks { pub extern fn complete_script(ctx: *c_void, script: *c_void) -> ll::Error { debug!("ll complete script"); - let self_opt: &Option = unsafe { cast::transmute(ctx) }; - let this = self_opt.get_ref(); + let self_opt: &mut Option = unsafe { cast::transmute(ctx) }; + let this = self_opt.get_mut_ref(); (this.tree_handler.complete_script)(from_hubbub_node(script)); return ll::OK; } @@ -505,8 +504,8 @@ pub mod tree_callbacks { pub extern fn complete_style(ctx: *c_void, style: *c_void) -> ll::Error { debug!("ll complete style"); - let self_opt: &Option = unsafe { cast::transmute(ctx) }; - let this = self_opt.get_ref(); + let self_opt: &mut Option = unsafe { cast::transmute(ctx) }; + let this = self_opt.get_mut_ref(); (this.tree_handler.complete_style)(from_hubbub_node(style)); return ll::OK; }