clean-ups

This commit is contained in:
Astro 2019-10-07 00:20:42 +02:00
parent 7a3935987e
commit 258a859a76
3 changed files with 10 additions and 11 deletions

View File

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

View File

@ -55,10 +55,6 @@ impl Tokenizer {
self.byte_state = ByteState::Char; self.byte_state = ByteState::Char;
[None; 2] [None; 2]
} }
(ByteState::Newline, ' ') => {
self.byte_state = ByteState::Char;
[None; 2]
}
(ByteState::Newline, _) => { (ByteState::Newline, _) => {
self.byte_state = ByteState::Char; self.byte_state = ByteState::Char;
[Some('\n' as u8), Some(*b)] [Some('\n' as u8), Some(*b)]
@ -79,9 +75,11 @@ impl Tokenizer {
self.line_state = LineState::Value; self.line_state = LineState::Value;
} }
(LineState::Key, '\n') => { (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.line_state = LineState::Key;
self.buffer = vec![];
} }
(LineState::Key, ';') => { (LineState::Key, ';') => {
let buffer = replace(&mut self.buffer, vec![]); let buffer = replace(&mut self.buffer, vec![]);

View File

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