big brained it, labels work now

This commit is contained in:
abbie 2022-06-15 19:18:20 +01:00
parent 44d508a15a
commit cac3721605
No known key found for this signature in database
GPG key ID: 04DDE463F9200F87

View file

@ -24,10 +24,12 @@ pub fn split_u16(number: u16) -> (u8, u8) {
pub fn detect_labels(mut chunks: Vec<String>) -> (Vec<String>, Vec<Label>) { pub fn detect_labels(mut chunks: Vec<String>) -> (Vec<String>, Vec<Label>) {
let mut stripped_chunks: Vec<String> = vec![]; let mut stripped_chunks: Vec<String> = vec![];
let mut labels: Vec<Label> = vec![]; let mut labels: Vec<Label> = vec![];
let mut encountered_labels: usize = 0; // I had a feeling of serendipity when I realised what was screwing with labels.
for (index, element) in chunks.iter().enumerate() { for (index, element) in chunks.iter().enumerate() {
if element.chars().next() == Some(';') { if element.chars().next() == Some(';') {
println!("{}", index); let label = Label { label: element.replace(";","").to_string(), index: (index - encountered_labels) * 4 };
let label = Label { label: element.replace(";","").to_string(), index: index*4 }; encountered_labels = encountered_labels + 1;
labels.push(label); labels.push(label);
} else { } else {
stripped_chunks.push(element.to_string()); stripped_chunks.push(element.to_string());