Browse Source

clean-ups

master
Astro 2 years ago
parent
commit
258a859a76
  1. 2
      src/ics/mod.rs
  2. 10
      src/ics/tokenizer.rs
  3. 9
      src/main.rs

2
src/ics/mod.rs

@ -15,6 +15,6 @@ pub struct Object {
impl Object {
pub fn get(&self, key: &'_ str) -> Option<&str> {
self.content.get(key)
.map(|(props, value)| value.as_ref())
.map(|(_props, value)| value.as_ref())
}
}

10
src/ics/tokenizer.rs

@ -55,10 +55,6 @@ impl Tokenizer {
self.byte_state = ByteState::Char;
[None; 2]
}
(ByteState::Newline, ' ') => {
self.byte_state = ByteState::Char;
[None; 2]
}
(ByteState::Newline, _) => {
self.byte_state = ByteState::Char;
[Some('\n' as u8), Some(*b)]
@ -79,9 +75,11 @@ impl Tokenizer {
self.line_state = LineState::Value;
}
(LineState::Key, '\n') => {
println!("Key without value: {:?}", self.buffer);
if self.buffer.len() > 0 {
println!("Key without value: {:?}", self.buffer);
self.buffer = vec![];
}
self.line_state = LineState::Key;
self.buffer = vec![];
}
(LineState::Key, ';') => {
let buffer = replace(&mut self.buffer, vec![]);

9
src/main.rs

@ -6,8 +6,7 @@ use ics::Parser;
fn fetch(client: &reqwest::Client, url: &str) -> Result<(), Box<dyn std::error::Error>> {
let mut res = client.get(url).send()?;
println!("Status: {}", res.status());
println!("Headers:\n{:?}", res.headers());
println!("{} {}", res.status(), url);
let mut p = Parser::new();
let mut buf = [0; 8192];
@ -16,8 +15,10 @@ fn fetch(client: &reqwest::Client, url: &str) -> Result<(), Box<dyn std::error::
len if len > 0 => {
let data = &buf[..len];
p.feed(data, |obj| {
println!("{} {}", obj.get("DTSTART").unwrap_or("?"), obj.get("SUMMARY").unwrap_or("?"));
println!("{}", obj.get("LOCATION").unwrap_or("?"));
println!("- [{}] {}", obj.get("DTSTART").unwrap_or("?"), obj.get("SUMMARY").unwrap_or("?"));
print!(" {}", obj.get("LOCATION").unwrap_or("?"));
obj.get("URL").map(|url| print!(" <{}>", url));
println!("");
});
}
_ => break,

Loading…
Cancel
Save