From 9881b489f3e716120a89a82c3c6d1646f2b3e704 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sat, 6 Jun 2026 11:09:06 -0400 Subject: [PATCH] Adding function --- src/parser/mod.rs | 71 ++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 0c11ace..4f5797e 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -28,6 +28,43 @@ impl NumberParser { println!("Total numbers: {:?}", numbers.len()); } + + fn remove_dups(&self, contacts: &Vec) -> Vec { + let mut unique_contacts: Vec = Vec::new(); + let mut unique_items = std::collections::HashSet::new(); + + for val in contacts { + unique_items.insert(val.phone_number.clone()); + } + + for unique_item in unique_items { + let contact = textsender_models::contact::Contact { + phone_number: unique_item, + ..Default::default() + }; + unique_contacts.push(contact); + } + + unique_contacts + } + + fn add_prefix(&self, raw: &String) -> String { + let mut parsed: String = String::new(); + let first_char = raw.chars().nth(0).unwrap(); + let second_char = raw.chars().nth(1).unwrap(); + + if first_char == '1' { + parsed = format!("+{raw}"); + } else if first_char != '+' { + if second_char != '1' { + parsed = format!("+1{raw}"); + } else { + parsed = format!("+1{raw}"); + } + } + + parsed + } } @@ -75,6 +112,7 @@ func (prsr *NumberParser) updateContacts(contacts []contact.Contact) []contact.C return updated } + func (prsr *NumberParser) removeDups(contacts []contact.Contact) []contact.Contact { updated := []contact.Contact{} uniqueItems := make(map[string]string) @@ -90,18 +128,6 @@ func (prsr *NumberParser) removeDups(contacts []contact.Contact) []contact.Conta return updated } -func (prsr NumberParser) PrintValues(contacts []contact.Contact, printTotal bool) { - fmt.Println("Printing numbers") - - for _, ct := range contacts { - fmt.Println("Number:", ct.PhoneNumber) - } - - if printTotal { - fmt.Println("Total Numbers:", len(contacts)) - } -} - func (prsr NumberParser) SaveFile(vals []contact.Contact) { filename := "numbers.json" @@ -162,24 +188,5 @@ func (prsr NumberParser) removeSomeData(unparsed string) string { return parsed } - -func (prsr NumberParser) addPrefix(raw string) string { - parsed := raw - - firstChar := raw[0] - secondChar := raw[1] - - if firstChar == '1' { - parsed = "+" + parsed - } else if firstChar != '+' { - if secondChar != '1' { - parsed = "+1" + parsed - } else { - parsed = "+1" + parsed - } - } - - return parsed -} - */ +