MCPcopy Create free account
hub / github.com/denoland/rust-urlpattern / compile

Method compile

src/component.rs:29–65  ·  view source on GitHub ↗

Ref: https://wicg.github.io/urlpattern/#compile-a-component

(
    input: Option<&str>,
    encoding_callback: F,
    options: Options,
  )

Source from the content-addressed store, hash-verified

27impl<R: RegExp> Component<R> {
28 // Ref: https://wicg.github.io/urlpattern/#compile-a-component
29 pub(crate) fn compile<F>(
30 input: Option<&str>,
31 encoding_callback: F,
32 options: Options,
33 ) -> Result<Self, Error>
34 where
35 F: Fn(&str) -> Result<String, Error>,
36 {
37 let part_list = crate::parser::parse_pattern_string(
38 input.unwrap_or("*"),
39 &options,
40 encoding_callback,
41 )?;
42 let (regexp_string, name_list) =
43 generate_regular_expression_and_name_list(&part_list, &options);
44 let flags = if options.ignore_case { "ui" } else { "u" };
45 let mut regexp =
46 R::parse(&regexp_string, flags, false).map_err(Error::RegExp);
47 if regexp.is_ok() && R::syntax() == RegexSyntax::EcmaScript {
48 for part in part_list.iter() {
49 if part.kind == PartType::Regexp {
50 regexp = R::parse(&regexp_string, flags, true).map_err(Error::RegExp);
51 }
52 }
53 }
54 let pattern_string = generate_pattern_string(&part_list, &options);
55 let matcher = generate_matcher::<R>(&part_list, &options, flags);
56 Ok(Component {
57 pattern_string,
58 regexp,
59 group_name_list: name_list,
60 matcher,
61 has_regexp_group: part_list
62 .iter()
63 .any(|part| part.kind == PartType::Regexp),
64 })
65 }
66
67 // Ref: https://wicg.github.io/urlpattern/#protocol-component-matches-a-special-scheme
68 pub(crate) fn protocol_component_matches_special_scheme(&self) -> bool {

Callers

nothing calls this directly

Tested by

no test coverage detected