MCPcopy Create free account
hub / github.com/GraphiteEditor/Graphite / parse

Function parse

tools/third-party-licenses/src/cef.rs:31–65  ·  view source on GitHub ↗
(html: &str)

Source from the content-addressed store, hash-verified

29}
30
31fn parse(html: &str) -> Vec<LicenseEntry> {
32 let document = Html::parse_document(html);
33
34 let product_sel = Selector::parse("div.product").unwrap();
35 let title_sel = Selector::parse("span.title").unwrap();
36 let homepage_sel = Selector::parse("span.homepage a").unwrap();
37 let license_sel = Selector::parse("div.license pre").unwrap();
38
39 document
40 .select(&product_sel)
41 .filter_map(|product| {
42 let name: String = product.select(&title_sel).next().map(|el| el.text().collect()).unwrap_or_default();
43
44 if name.is_empty() {
45 return None;
46 }
47
48 let homepage = product.select(&homepage_sel).next().and_then(|el| el.value().attr("href").map(String::from));
49
50 let license_text: String = product.select(&license_sel).next().map(|el| el.text().collect::<String>()).unwrap_or_default().trim().to_string();
51
52 let pkg = Package {
53 name,
54 url: homepage,
55 authors: Vec::new(),
56 };
57
58 Some(LicenseEntry {
59 name: None,
60 text: license_text,
61 packages: vec![pkg],
62 })
63 })
64 .collect()
65}
66
67fn read() -> Result<String, Error> {
68 let cef_path = PathBuf::from(env!("CEF_PATH"));

Callers 1

licensesMethod · 0.70

Calls 4

nextMethod · 0.45
textMethod · 0.45
is_emptyMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected