improve digit parsing
This commit is contained in:
parent
74f19d779d
commit
8cf7e97808
18
src/main.rs
18
src/main.rs
@ -22,7 +22,7 @@ fn main() {
|
|||||||
|
|
||||||
let input = args[1].to_string();
|
let input = args[1].to_string();
|
||||||
for char in input.chars() {
|
for char in input.chars() {
|
||||||
println!();
|
// println!();
|
||||||
if char.is_ascii_alphabetic() {
|
if char.is_ascii_alphabetic() {
|
||||||
// println!("matched alphabetic");
|
// println!("matched alphabetic");
|
||||||
if char_before.is_some() {
|
if char_before.is_some() {
|
||||||
@ -181,14 +181,24 @@ fn main() {
|
|||||||
} else if char.is_ascii_digit() {
|
} else if char.is_ascii_digit() {
|
||||||
// println!("matched ascii digit");
|
// println!("matched ascii digit");
|
||||||
// println!("{char_before:?}");
|
// println!("{char_before:?}");
|
||||||
if char_before.is_none() {
|
// if char_before.is_none() {
|
||||||
if char != '1' {
|
|
||||||
if let Some(last) = element_line.last_mut() {
|
if let Some(last) = element_line.last_mut() {
|
||||||
|
// if last.nr > 1 {
|
||||||
|
if char_before.is_some() {
|
||||||
|
if char_before.unwrap().is_ascii_digit() {
|
||||||
|
let mut number = last.nr.to_string();
|
||||||
|
number.push(char);
|
||||||
|
println!("{number}");
|
||||||
|
last.nr = number.parse().unwrap();
|
||||||
|
} else {
|
||||||
last.nr = char.to_digit(10).unwrap();
|
last.nr = char.to_digit(10).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// }
|
||||||
|
// last.nr = char.to_digit(10).unwrap();
|
||||||
}
|
}
|
||||||
char_before = None
|
// }
|
||||||
|
char_before = Some(char);
|
||||||
}
|
}
|
||||||
if element.is_some() && char.is_ascii_alphabetic() {
|
if element.is_some() && char.is_ascii_alphabetic() {
|
||||||
element_line.push( ElementNr { element: element.unwrap(), nr: 1 });
|
element_line.push( ElementNr { element: element.unwrap(), nr: 1 });
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user