Skip to content

Commit

Permalink
chomp_int is technically still used
Browse files Browse the repository at this point in the history
  • Loading branch information
SSheldon committed May 5, 2019
1 parent 93f7b04 commit aa345a8
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,18 @@ fn rm_enc_prefix<'a>(s: &'a str, enc: &Encoding) -> Option<&'a str> {
rm_prefix(s, code)
}

fn rm_int_prefix(s: &str, other: u32) -> Option<&str> {
fn chomp_int(s: &str) -> Option<(u32, &str)> {
// Chomp until we hit a non-digit
let (num, t) = match s.find(|c: char| !c.is_digit(10)) {
Some(i) => s.split_at(i),
None => (s, ""),
};
num.parse().ok()
.and_then(|n| if other == n { Some(t) } else { None })
num.parse().map(|n| (n, t)).ok()
}

fn rm_int_prefix(s: &str, other: u32) -> Option<&str> {
chomp_int(s)
.and_then(|(n, t)| if other == n { Some(t) } else { None })
}

fn rm_prefix<'a>(s: &'a str, other: &str) -> Option<&'a str> {
Expand Down

0 comments on commit aa345a8

Please sign in to comment.