Browse Source

cell regex

marion 3 years ago
parent
commit
038eb13e1e
2 changed files with 37 additions and 1 deletions
  1. 36 0
      src/cell_regex_test/mod.rs
  2. 1 1
      src/main.rs

+ 36 - 0
src/cell_regex_test/mod.rs

@@ -2,13 +2,16 @@
 // regex = "1.5"
 // walkdir = "2"
 
+use std::borrow::Borrow;
 use std::fs::File;
 use std::io;
 use std::io::{BufRead, Write};
 use std::path::Path;
+use regex::internal::Input;
 use walkdir::{DirEntry, WalkDir};
 use regex::Regex;
 
+#[cfg(test)]
 pub fn main() {
     // 手机号正则
     let pattern = Regex::new(r"\D+((13[0-9]|14[5-9]|15[0-3,5-9]|16[2,5,6,7]|17[0-8]|18[0-9]|19[0-3,5-9])\d{8})\D+").unwrap();
@@ -46,6 +49,39 @@ pub fn main() {
     }
 }
 
+pub fn distinct() {
+    let files = ["input_dir_path", "input_dir_path"];
+    let mut outfile = File::create("output_file_path").expect("create failed");
+
+    let mut v = Vec::new();
+    for f in files {
+        if let Ok(lines) = read_lines(f) {
+            for line in lines {
+                if let Ok(text) = line {
+                    v.push(text);
+                }
+            }
+        }
+    }
+    if v.len() == 0 {
+        return;
+    }
+
+    let mut rs = Vec::new();
+    v.sort();
+    rs.push(v.get(0).unwrap().as_str());
+    for i in 1..v.len() {
+        if v.get(i) != v.get(i - 1) {
+            rs.push(v.get(i).unwrap().as_str())
+        }
+    }
+
+    for s in rs {
+        let context = format!("{}\n", s);
+        outfile.write_all(context.as_bytes()).expect("write failed");
+    }
+}
+
 fn is_hidden(entry: &DirEntry) -> bool {
     entry.file_name()
         .to_str()

+ 1 - 1
src/main.rs

@@ -22,6 +22,6 @@ fn main()  {
     // spider_test::test("https://www.baidu.com").unwrap();
     // actix_test::http_listener() // return -> std::io::Result<()>
     // jwt_test::main();
-    cell_regex_test::main();
+    cell_regex_test::distinct();
 }