Migrate #4

Merged
phoenix merged 14 commits from migrate into v1.x 2026-06-06 12:48:59 -04:00
2 changed files with 38 additions and 35 deletions
Showing only changes of commit 3d2ecd2c45 - Show all commits
+10 -5
View File
@@ -11,10 +11,15 @@ fn main() {
let filepath = &args[1];
println!("Filepath: {filepath:?}");
let prsr = parser::NumberParser{filepath: *filepath};
let prsr = parser::NumberParser{filepath: filepath.clone()};
let numbers = prsr.file_dump();
prsr.print_values(&numbers);
prsr.save_file(numbers);
match prsr.file_dump() {
Ok(numbers) => {
prsr.print_values(&numbers);
prsr.save_file(numbers);
}
Err(err) => {
eprintln!("Error: {err:?}");
}
};
}
+28 -30
View File
@@ -1,3 +1,4 @@
use std::io::{BufRead, BufReader};
pub const LETTERS: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
@@ -7,13 +8,25 @@ pub struct 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");
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>) {
@@ -29,6 +42,18 @@ impl NumberParser {
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> {
let mut unique_contacts: Vec<textsender_models::contact::Contact> = Vec::new();
let mut unique_items = std::collections::HashSet::new();
@@ -162,31 +187,4 @@ func (prsr NumberParser) SaveFile(vals []contact.Contact) {
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
}
*/