update regex to 0.2 (#25)

This commit is contained in:
drevilt 2017-03-02 23:16:22 +01:00 committed by Matt McCoy
parent 257cf90f46
commit 59163929d3
2 changed files with 11 additions and 11 deletions

View file

@ -17,7 +17,7 @@ path = "src/lib.rs"
[dependencies] [dependencies]
openssl = "0.8" openssl = "0.8"
regex = "0.1" regex = "0.2"
[dev-dependencies] [dev-dependencies]
base64 = "0.2" base64 = "0.2"

View file

@ -7,7 +7,7 @@ pub fn parse_authenticate_response(line: String) -> Result<String> {
let authenticate_regex = Regex::new("^+(.*)\r\n").unwrap(); let authenticate_regex = Regex::new("^+(.*)\r\n").unwrap();
for cap in authenticate_regex.captures_iter(line.as_str()) { for cap in authenticate_regex.captures_iter(line.as_str()) {
let data = cap.at(1).unwrap_or(""); let data = cap.get(1).map(|x|x.as_str()).unwrap_or("");
return Ok(String::from(data)); return Ok(String::from(data));
} }
@ -26,7 +26,7 @@ pub fn parse_capability(lines: Vec<String>) -> Result<Vec<String>> {
for line in lines.iter() { for line in lines.iter() {
if capability_regex.is_match(line) { if capability_regex.is_match(line) {
let cap = capability_regex.captures(line).unwrap(); let cap = capability_regex.captures(line).unwrap();
let capabilities_str = cap.at(1).unwrap(); let capabilities_str = cap.get(1).unwrap().as_str();
return Ok(capabilities_str.split(' ').map(|x| x.to_string()).collect()); return Ok(capabilities_str.split(' ').map(|x| x.to_string()).collect());
} }
} }
@ -49,7 +49,7 @@ pub fn parse_response(lines: Vec<String>) -> Result<Vec<String>> {
}; };
for cap in regex.captures_iter(last_line) { for cap in regex.captures_iter(last_line) {
let response_type = cap.at(2).unwrap_or(""); let response_type = cap.get(2).map(|x|x.as_str()).unwrap_or("");
match response_type { match response_type {
"OK" => return Ok(lines.clone()), "OK" => return Ok(lines.clone()),
"BAD" => return Err(Error::BadResponse(lines.clone())), "BAD" => return Err(Error::BadResponse(lines.clone())),
@ -87,25 +87,25 @@ pub fn parse_select_or_examine(lines: Vec<String>) -> Result<Mailbox> {
for line in lines.iter() { for line in lines.iter() {
if exists_regex.is_match(line) { if exists_regex.is_match(line) {
let cap = exists_regex.captures(line).unwrap(); let cap = exists_regex.captures(line).unwrap();
mailbox.exists = cap.at(1).unwrap().parse::<u32>().unwrap(); mailbox.exists = cap.get(1).unwrap().as_str().parse::<u32>().unwrap();
} else if recent_regex.is_match(line) { } else if recent_regex.is_match(line) {
let cap = recent_regex.captures(line).unwrap(); let cap = recent_regex.captures(line).unwrap();
mailbox.recent = cap.at(1).unwrap().parse::<u32>().unwrap(); mailbox.recent = cap.get(1).unwrap().as_str().parse::<u32>().unwrap();
} else if flags_regex.is_match(line) { } else if flags_regex.is_match(line) {
let cap = flags_regex.captures(line).unwrap(); let cap = flags_regex.captures(line).unwrap();
mailbox.flags = cap.at(1).unwrap().to_string(); mailbox.flags = cap.get(1).unwrap().as_str().to_string();
} else if unseen_regex.is_match(line) { } else if unseen_regex.is_match(line) {
let cap = unseen_regex.captures(line).unwrap(); let cap = unseen_regex.captures(line).unwrap();
mailbox.unseen = Some(cap.at(1).unwrap().parse::<u32>().unwrap()); mailbox.unseen = Some(cap.get(1).unwrap().as_str().parse::<u32>().unwrap());
} else if uid_validity_regex.is_match(line) { } else if uid_validity_regex.is_match(line) {
let cap = uid_validity_regex.captures(line).unwrap(); let cap = uid_validity_regex.captures(line).unwrap();
mailbox.uid_validity = Some(cap.at(1).unwrap().parse::<u32>().unwrap()); mailbox.uid_validity = Some(cap.get(1).unwrap().as_str().parse::<u32>().unwrap());
} else if uid_next_regex.is_match(line) { } else if uid_next_regex.is_match(line) {
let cap = uid_next_regex.captures(line).unwrap(); let cap = uid_next_regex.captures(line).unwrap();
mailbox.uid_next = Some(cap.at(1).unwrap().parse::<u32>().unwrap()); mailbox.uid_next = Some(cap.get(1).unwrap().as_str().parse::<u32>().unwrap());
} else if permanent_flags_regex.is_match(line) { } else if permanent_flags_regex.is_match(line) {
let cap = permanent_flags_regex.captures(line).unwrap(); let cap = permanent_flags_regex.captures(line).unwrap();
mailbox.permanent_flags = Some(cap.at(1).unwrap().to_string()); mailbox.permanent_flags = Some(cap.get(1).unwrap().as_str().to_string());
} }
} }