Saving changes
Rust Build / Check (pull_request) Failing after 26s
Rust Build / Rustfmt (pull_request) Failing after 32s
Rust Build / Test Suite (pull_request) Failing after 1m0s
Rust Build / Clippy (pull_request) Failing after 40s
Rust Build / build (pull_request) Failing after 49s
Rust Build / Check (pull_request) Failing after 26s
Rust Build / Rustfmt (pull_request) Failing after 32s
Rust Build / Test Suite (pull_request) Failing after 1m0s
Rust Build / Clippy (pull_request) Failing after 40s
Rust Build / build (pull_request) Failing after 49s
This commit is contained in:
+8
-3
@@ -11,10 +11,15 @@ fn main() {
|
|||||||
|
|
||||||
let filepath = &args[1];
|
let filepath = &args[1];
|
||||||
println!("Filepath: {filepath:?}");
|
println!("Filepath: {filepath:?}");
|
||||||
let prsr = parser::NumberParser{filepath: *filepath};
|
let prsr = parser::NumberParser{filepath: filepath.clone()};
|
||||||
|
|
||||||
let numbers = prsr.file_dump();
|
match prsr.file_dump() {
|
||||||
|
Ok(numbers) => {
|
||||||
prsr.print_values(&numbers);
|
prsr.print_values(&numbers);
|
||||||
|
|
||||||
prsr.save_file(numbers);
|
prsr.save_file(numbers);
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Error: {err:?}");
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
+28
-30
@@ -1,3 +1,4 @@
|
|||||||
|
use std::io::{BufRead, BufReader};
|
||||||
|
|
||||||
pub const LETTERS: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
pub const LETTERS: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
|
|
||||||
@@ -7,13 +8,25 @@ pub struct NumberParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl NumberParser {
|
impl NumberParser {
|
||||||
pub fn file_dump(&self) -> Vec<textsender_models::contact::Contact> {
|
pub fn file_dump(&self) -> Result<Vec<textsender_models::contact::Contact>, std::io::Error> {
|
||||||
println!("Dumping files");
|
println!("Dumping files");
|
||||||
let mut objs: Vec<textsender_models::contact::Contact> = Vec::new();
|
let mut objs: Vec<textsender_models::contact::Contact> = Vec::new();
|
||||||
|
|
||||||
for line in self.read_lines(&self.filepath) {
|
match self.read_lines(&self.filepath) {
|
||||||
|
Ok(lines) => {
|
||||||
|
for line in lines {
|
||||||
|
let contains_letters = line.chars().any(|c| LETTERS.contains(c));
|
||||||
|
if contains_letters {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(objs)
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
Err(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Vec::new()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn save_file(&self, numbers: Vec<textsender_models::contact::Contact>) {
|
pub fn save_file(&self, numbers: Vec<textsender_models::contact::Contact>) {
|
||||||
@@ -29,6 +42,18 @@ impl NumberParser {
|
|||||||
println!("Total numbers: {:?}", numbers.len());
|
println!("Total numbers: {:?}", numbers.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn read_lines(&self, filename: &String) -> Result<Vec<String>, std::io::Error> {
|
||||||
|
match std::fs::File::open(filename) {
|
||||||
|
Ok(file) => {
|
||||||
|
let reader = std::io::BufReader::new(file);
|
||||||
|
reader.lines().collect()
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
Err(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn remove_dups(&self, contacts: &Vec<textsender_models::contact::Contact>) -> Vec<textsender_models::contact::Contact> {
|
fn remove_dups(&self, contacts: &Vec<textsender_models::contact::Contact>) -> Vec<textsender_models::contact::Contact> {
|
||||||
let mut unique_contacts: Vec<textsender_models::contact::Contact> = Vec::new();
|
let mut unique_contacts: Vec<textsender_models::contact::Contact> = Vec::new();
|
||||||
let mut unique_items = std::collections::HashSet::new();
|
let mut unique_items = std::collections::HashSet::new();
|
||||||
@@ -162,31 +187,4 @@ func (prsr NumberParser) SaveFile(vals []contact.Contact) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (prsr NumberParser) readLines(filename string) []string {
|
|
||||||
// Open the file
|
|
||||||
file, err := os.Open(filename)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
// Create a scanner to read the file line by line
|
|
||||||
scanner := bufio.NewScanner(file)
|
|
||||||
lines := []string{}
|
|
||||||
|
|
||||||
// Read line by line
|
|
||||||
for scanner.Scan() {
|
|
||||||
line := scanner.Text()
|
|
||||||
lines = append(lines, line)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for any errors during scanning
|
|
||||||
if err := scanner.Err(); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return lines
|
|
||||||
}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user