Skip to content

Commit

Permalink
parse-zoneinfo: use simple Rust code to parse empty lines
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed May 6, 2024
1 parent a538210 commit 0a7f262
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
5 changes: 0 additions & 5 deletions parse-zoneinfo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,5 @@ readme = "README.md"
license = "MIT"
keywords = ["date", "time", "timezone", "zone", "calendar"]

[dependencies.regex]
version = "1.3.1"
default-features = false
features = ["std", "unicode-perl"]

[dev-dependencies]
insta = "1.38"
24 changes: 9 additions & 15 deletions parse-zoneinfo/src/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,8 @@
use std::fmt;
use std::str::FromStr;

use regex::Regex;

pub struct LineParser {
empty_line: Regex,
}
#[derive(Clone, Copy)]
pub struct LineParser {}

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

impl Default for LineParser {
fn default() -> Self {
LineParser {
empty_line: Regex::new(
r##"(?x) ^
\s*
(\#.*)?
$"##,
)
.unwrap(),
}
LineParser {}
}
}

Expand Down Expand Up @@ -1290,7 +1279,12 @@ impl LineParser {
/// Attempt to parse this line, returning a `Line` depending on what
/// type of line it was, or an `Error` if it couldn't be parsed.
pub fn parse_str<'a>(&self, input: &'a str) -> Result<Line<'a>, Error> {
if self.empty_line.is_match(input) {
let input = match input.split_once('#') {
Some((input, _)) => input,
None => input,
};

if input.trim().is_empty() {
return Ok(Line::Space);
}

Expand Down

0 comments on commit 0a7f262

Please sign in to comment.