Skip to content

Commit dd64b82

Browse files
committed
parse-zoneinfo: use simple Rust code to parse empty lines
1 parent 06c22eb commit dd64b82

File tree

2 files changed

+9
-20
lines changed

2 files changed

+9
-20
lines changed

parse-zoneinfo/Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,5 @@ readme = "README.md"
99
license = "MIT"
1010
keywords = ["date", "time", "timezone", "zone", "calendar"]
1111

12-
[dependencies.regex]
13-
version = "1.3.1"
14-
default-features = false
15-
features = ["std", "unicode-perl"]
16-
1712
[dev-dependencies]
1813
insta = "1.38"

parse-zoneinfo/src/line.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,8 @@
7171
use std::fmt;
7272
use std::str::FromStr;
7373

74-
use regex::Regex;
75-
76-
pub struct LineParser {
77-
empty_line: Regex,
78-
}
74+
#[derive(Clone, Copy)]
75+
pub struct LineParser {}
7976

8077
#[derive(PartialEq, Debug, Clone)]
8178
pub enum Error {
@@ -126,15 +123,7 @@ impl std::error::Error for Error {}
126123

127124
impl Default for LineParser {
128125
fn default() -> Self {
129-
LineParser {
130-
empty_line: Regex::new(
131-
r##"(?x) ^
132-
\s*
133-
(\#.*)?
134-
$"##,
135-
)
136-
.unwrap(),
137-
}
126+
LineParser {}
138127
}
139128
}
140129

@@ -1313,7 +1302,12 @@ impl LineParser {
13131302
/// Attempt to parse this line, returning a `Line` depending on what
13141303
/// type of line it was, or an `Error` if it couldn't be parsed.
13151304
pub fn parse_str<'a>(&self, input: &'a str) -> Result<Line<'a>, Error> {
1316-
if self.empty_line.is_match(input) {
1305+
let input = match input.split_once('#') {
1306+
Some((input, _)) => input,
1307+
None => input,
1308+
};
1309+
1310+
if input.trim().is_empty() {
13171311
return Ok(Line::Space);
13181312
}
13191313

0 commit comments

Comments
 (0)