MCPcopy Create free account
hub / github.com/chatmail/core / parse

Method parse

src/location.rs:109–137  ·  view source on GitHub ↗

Parses a KML document.

(to_parse: &[u8])

Source from the content-addressed store, hash-verified

107
108 /// Parses a KML document.
109 pub fn parse(to_parse: &[u8]) -> Result<Self> {
110 ensure!(to_parse.len() <= 1024 * 1024, "kml-file is too large");
111
112 let mut reader = quick_xml::Reader::from_reader(to_parse);
113 reader.config_mut().trim_text(true);
114
115 let mut kml = Kml::new();
116 kml.locations = Vec::with_capacity(100);
117
118 let mut buf = Vec::new();
119
120 loop {
121 match reader.read_event_into(&mut buf).with_context(|| {
122 format!(
123 "location parsing error at position {}",
124 reader.buffer_position()
125 )
126 })? {
127 quick_xml::events::Event::Start(ref e) => kml.starttag_cb(e, &reader),
128 quick_xml::events::Event::End(ref e) => kml.endtag_cb(e),
129 quick_xml::events::Event::Text(ref e) => kml.text_cb(e),
130 quick_xml::events::Event::Eof => break,
131 _ => (),
132 }
133 buf.clear();
134 }
135
136 Ok(kml)
137 }
138
139 fn text_cb(&mut self, event: &BytesText) {
140 if self.tag == KmlTag::PlacemarkTimestampWhen

Callers 15

mainFunction · 0.80
cmdlineFunction · 0.80
system_build_flagsFunction · 0.80
decrypting.rsFile · 0.80
getTargetDirFunction · 0.80
constructorMethod · 0.80
get_config_opt_parsedMethod · 0.80
get_config_parsedMethod · 0.80
update_timestampMethod · 0.80
get_by_id_optionalMethod · 0.80

Calls 3

starttag_cbMethod · 0.80
endtag_cbMethod · 0.80
text_cbMethod · 0.80

Tested by 2

test_dc_paramFunction · 0.64