Code refactoring
Rust Build / Check (pull_request) Successful in 25s
Rust Build / Test Suite (pull_request) Successful in 27s
Rust Build / Rustfmt (pull_request) Successful in 45s
Rust Build / Clippy (pull_request) Failing after 49s
Rust Build / build (pull_request) Successful in 35s
Rust Build / Check (pull_request) Successful in 25s
Rust Build / Test Suite (pull_request) Successful in 27s
Rust Build / Rustfmt (pull_request) Successful in 45s
Rust Build / Clippy (pull_request) Failing after 49s
Rust Build / build (pull_request) Successful in 35s
This commit is contained in:
+23
-19
@@ -115,35 +115,39 @@ impl NumberParser {
|
|||||||
|
|
||||||
let pars = self.remove_some_data(&phone_number).await;
|
let pars = self.remove_some_data(&phone_number).await;
|
||||||
|
|
||||||
// println!("Parsed: {pars:?}");
|
match self.add_prefix(&pars) {
|
||||||
|
Ok(updated_parsed) => {
|
||||||
let updated_parsed = self.add_prefix(&pars);
|
let contact = textsender_models::contact::Contact {
|
||||||
let contact = textsender_models::contact::Contact {
|
phone_number: updated_parsed,
|
||||||
phone_number: updated_parsed,
|
..Default::default()
|
||||||
..Default::default()
|
};
|
||||||
|
updated.push(contact);
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Error: {err:?}");
|
||||||
|
std::process::exit(-2);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
updated.push(contact);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updated
|
updated
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_prefix(&self, raw: &String) -> String {
|
fn add_prefix(&self, raw: &String) -> Result<String, std::io::Error> {
|
||||||
let mut parsed: String = String::new();
|
if raw.is_empty() {
|
||||||
let first_char = raw.chars().nth(0).unwrap();
|
Err(std::io::Error::other("Empty"))
|
||||||
let second_char = raw.chars().nth(1).unwrap();
|
} else {
|
||||||
|
let mut parsed: String = String::new();
|
||||||
|
let first_char = raw.chars().nth(0).unwrap();
|
||||||
|
|
||||||
if first_char == '1' {
|
if first_char == '1' {
|
||||||
parsed = format!("+{raw}");
|
parsed = format!("+{raw}");
|
||||||
} else if first_char != '+' {
|
} else if first_char != '+' {
|
||||||
if second_char != '1' {
|
|
||||||
parsed = format!("+1{raw}");
|
|
||||||
} else {
|
|
||||||
parsed = format!("+1{raw}");
|
parsed = format!("+1{raw}");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
parsed
|
Ok(parsed)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn remove_some_data(&self, unparsed: &String) -> String {
|
async fn remove_some_data(&self, unparsed: &String) -> String {
|
||||||
|
|||||||
Reference in New Issue
Block a user