Makes int_getter macro, and uses -1 as default maxlength instead of maxint

This commit is contained in:
Sam Gibson 2015-09-01 11:14:29 +12:00
parent d26c555e2a
commit eecdfdf6c1
4 changed files with 51 additions and 11 deletions

View file

@ -1090,6 +1090,27 @@ impl Element {
self.set_attribute(local_name, AttrValue::from_atomic_tokens(tokens));
}
pub fn get_int_attribute(&self, local_name: &Atom, default: i32) -> i32 {
// TODO: Is this assert necessary?
assert!(local_name.chars().all(|ch| {
!ch.is_ascii() || ch.to_ascii_lowercase() == ch
}));
let attribute = self.get_attribute(&ns!(""), local_name);
match attribute {
Some(ref attribute) => {
match *attribute.r().value() {
AttrValue::Int(_, value) => value,
_ => panic!("Expected an AttrValue::Int: \
implement parse_plain_attribute"),
}
}
None => default,
}
}
// TODO: set_int_attribute(...)
pub fn get_uint_attribute(&self, local_name: &Atom, default: u32) -> u32 {
assert!(local_name.chars().all(|ch| !ch.is_ascii() || ch.to_ascii_lowercase() == ch));
let attribute = self.get_attribute(&ns!(), local_name);