/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
externcrate urlpattern; use urlpattern::quirks; use urlpattern::regexp::RegExp;
type SpiderMonkeyUrlPattern = urlpattern::UrlPattern<SpiderMonkeyRegexp>;
externcrate nsstring; use nsstring::nsACString; use nsstring::nsCString; use thin_vec::ThinVec;
// When dom::URLPattern goes out of scope destructor will drop the underlying // urlpattern::UrlPattern<R> (lib.rs) #[no_mangle] pubunsafeextern"C"fn urlpattern_pattern_free(pattern: UrlPatternGlue) {
drop(Box::from_raw(pattern.0as *mut SpiderMonkeyUrlPattern));
}
#[no_mangle] pubunsafeextern"C"fn urlpattern_component_get_group_name_list(
component_ptr: *mut UrlPatternComponentPtr,
res: &mut ThinVec<nsCString>,
) { let component = &*(component_ptr as *const Component); for name in &component.group_name_list {
res.push(nsCString::from(name.as_str()));
}
}
// note: the ThinVec<MaybeString> is being returned as an out-param // because if you attempt to return the vector in the normal way // we end up with an incongruent ABI layout between C++ and rust // which re-orders the input parameter pointers such that we cannot reference them // by address reliably. // Ie. ThinVec/nsTArray is a non-trivial for the purpose of calls // so we use an out-param instead. We see similar patterns elsewhere in this file // for return values on the C++/rust ffi boundary #[no_mangle] pubunsafeextern"C"fn urlpattern_component_matches(
component_ptr: *mut UrlPatternComponentPtr,
input: &nsACString,
match_only: bool,
res: &mut ThinVec<MaybeString>,
) -> bool { let component = &*(component_ptr as *const Component); let input_str = input.to_utf8();
let matcher_ptr = &component.matcher as *const _ as *mut UrlPatternMatcherPtr; let matches = matcher_matches(matcher_ptr, input_str.as_ref(), match_only);
iflet Some(inner_vec) = matches { // urlpattern::test() does not need to populate matcher results // it just needs to know if we got a match. // So only iterate across results if it was Exec() that called if !match_only { for item in inner_vec { match item {
Some(s) => {
res.push(MaybeString {
string: nsCString::from(s),
valid: true,
});
}
None => {
res.push(MaybeString {
string: nsCString::new(),
valid: false,
});
}
}
}
} true
} else { false
}
}
// note: can't return Result<Option<...>> since cbindgen doesn't handle well // so we need to return a type that can be used in C++ and rust #[no_mangle] pubunsafeextern"C"fn urlpattern_process_match_input_from_string(
url_str: *const nsACString,
base_url: *const nsACString,
res: *mut UrlPatternMatchInputAndInputs,
) -> bool {
debug!("urlpattern_process_match_input_from_string()"); iflet Some(url) = unsafe { url_str.as_ref().map(|x| x.to_utf8()) } { let str_or_init = quirks::StringOrInit::String(url); let maybe_base_url = if base_url.is_null() {
None
} else { let x = unsafe { (*base_url).as_str_unchecked() };
Some(x)
};
let match_input_and_inputs = quirks::process_match_input(str_or_init, maybe_base_url); iflet Ok(Some(tuple_struct)) = match_input_and_inputs { // parse "input" let match_input = tuple_struct.0; let maybe_match_input = quirks::parse_match_input(match_input);
if maybe_match_input.is_none() { returnfalse;
}
// convert "inputs" let tuple_soi_and_string = tuple_struct.1; let string = match tuple_soi_and_string.0 {
quirks::StringOrInit::String(x) => x,
_ => {
assert!( false, "Pulling init out of StringOrInit shouldn't happen in _from_string"
); returnfalse;
}
}; let base = match tuple_soi_and_string.1 {
Some(x) => MaybeString::new(&nsCString::from(x)),
_ => MaybeString::none(),
}; let tmp = UrlPatternMatchInputAndInputs {
input: maybe_match_input.unwrap().into(),
inputs: UrlPatternInput {
string_or_init_type: UrlPatternStringOrInitType::String,
str: nsCString::from(string.as_ref()),
init: UrlPatternInit::none(),
base,
},
}; unsafe { *res = tmp }; returntrue;
} else { returnfalse;
}
} false
}
let maybe_base_url = if base_url.is_null() {
None
} else {
Some(unsafe { (*base_url).as_str_unchecked() })
}; let match_input_and_inputs = quirks::process_match_input(str_or_init, maybe_base_url); // an empty string passed to base_url will cause url-parsing failure // in process_match_input, which we handle here iflet Ok(Some(tuple_struct)) = match_input_and_inputs { let match_input = tuple_struct.0; let maybe_match_input = quirks::parse_match_input(match_input); if maybe_match_input.is_none() { returnfalse;
} let tuple_soi_and_string = tuple_struct.1; let init = match tuple_soi_and_string.0 {
quirks::StringOrInit::Init(x) => x,
_ => {
assert!( false, "Pulling string out of StringOrInit shouldn't happen in _from_init"
); returnfalse;
}
};
let base = match tuple_soi_and_string.1 {
Some(x) => MaybeString::new(&nsCString::from(x)),
_ => MaybeString::none(),
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.