File: capturedump.rs

package info (click to toggle)
rust-coreutils 0.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 505,620 kB
  • sloc: ansic: 103,594; asm: 28,570; sh: 8,910; python: 5,581; makefile: 472; cpp: 97; javascript: 72
file content (38 lines) | stat: -rw-r--r-- 1,064 bytes parent folder | download | duplicates (17)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use onig::*;
use std::collections::HashMap;
use std::env;
use std::io;
use std::io::prelude::*;

fn main() {
    let mut regexes = HashMap::new();
    for arg in env::args().skip(1) {
        println!("Compiling '{}'", arg);
        let regex_compilation = Regex::new(&arg);
        match regex_compilation {
            Ok(regex) => {
                regexes.insert(arg, regex);
            }
            Err(error) => {
                panic!("{:?}", error);
            }
        }
    }

    let stdin = io::stdin();
    for line in stdin.lock().lines() {
        if let Ok(line) = line {
            for (name, regex) in regexes.iter() {
                let res = regex.captures(&line);
                match res {
                    Some(captures) => {
                        for (i, mat) in captures.iter().enumerate() {
                            println!("{} => '{}'", i, mat.unwrap());
                        }
                    }
                    None => println!("{} => did not match", name),
                }
            }
        }
    }
}