Remove dependency on regex_macros

This reduces the amount of code using unstable features that we depend on.
The hand-written IP address parser is probably just as fast.
This commit is contained in:
Simon Sapin 2015-11-23 14:01:00 +01:00
parent 0dfdc94cb2
commit 45ec900745
9 changed files with 7 additions and 52 deletions

View file

@ -2,11 +2,11 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use ::{IPV4_REGEX, IPV6_REGEX};
use std::collections::HashMap;
use std::env;
use std::fs::File;
use std::io::{BufReader, Read};
use std::net::{Ipv4Addr, Ipv6Addr};
use url::Url;
static mut HOST_TABLE: Option<*mut HashMap<String, String>> = None;
@ -43,7 +43,9 @@ pub fn parse_hostsfile(hostsfile_content: &str) -> Box<HashMap<String, String>>
for line in &lines {
let ip_host: Vec<&str> = line.trim().split(|c: char| c == ' ' || c == '\t').collect();
if ip_host.len() > 1 {
if !IPV4_REGEX.is_match(ip_host[0]) && !IPV6_REGEX.is_match(ip_host[0]) { continue; }
if ip_host[0].parse::<Ipv4Addr>().is_err() && ip_host[0].parse::<Ipv6Addr>().is_err() {
continue
}
let address = ip_host[0].to_owned();
for token in ip_host.iter().skip(1) {