Add script::dom::utils::validate_qualified_name()

This commit is contained in:
Anthony Ramine 2015-04-07 23:20:56 +02:00
parent 7e07dcc7ee
commit abc01d598a
4 changed files with 29 additions and 39 deletions

View file

@ -7,7 +7,7 @@
use dom::bindings::codegen::PrototypeList;
use dom::bindings::codegen::PrototypeList::MAX_PROTO_CHAIN_LENGTH;
use dom::bindings::conversions::{native_from_reflector_jsmanaged, is_dom_class};
use dom::bindings::error::throw_type_error;
use dom::bindings::error::{Error, ErrorResult, throw_type_error};
use dom::bindings::global::GlobalRef;
use dom::bindings::js::{Temporary, Root};
use dom::browsercontext;
@ -604,6 +604,21 @@ pub unsafe fn delete_property_by_id(cx: *mut JSContext, object: *mut JSObject,
return true;
}
/// Validate a qualified name. See https://dom.spec.whatwg.org/#validate for details.
pub fn validate_qualified_name(qualified_name: &str) -> ErrorResult {
match xml_name_type(qualified_name) {
XMLName::InvalidXMLName => {
// Step 1.
return Err(Error::InvalidCharacter);
},
XMLName::Name => {
// Step 2.
return Err(Error::Namespace);
},
XMLName::QName => Ok(())
}
}
/// Results of `xml_name_type`.
#[derive(PartialEq)]
#[allow(missing_docs)]