From 96f72cd271bfd853126ccc581d0d7ecf4bb80e48 Mon Sep 17 00:00:00 2001 From: Andrea Ricchi Date: Mon, 13 May 2024 11:02:40 +0200 Subject: [PATCH] dart_to_csv: fix dart parsing When .tr key is on next line we need to store the previous one. Signed-off-by: Andrea Ricchi --- src/dart_to_csv.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/dart_to_csv.rs b/src/dart_to_csv.rs index 11f5257..459b0fa 100644 --- a/src/dart_to_csv.rs +++ b/src/dart_to_csv.rs @@ -21,15 +21,22 @@ fn read_file(path: String) -> Vec { let mut translations = Vec::new(); if let Ok(lines) = read_lines(path) { - for ip in lines.map_while(Result::ok) { - if !ip.contains("'.tr") { - continue; - } + let mut previous_line = String::new(); + for ip in lines.map_while(Result::ok) { let start_bytes = ip.find('\'').unwrap_or(0); let end_bytes = ip.find("'.tr").unwrap_or(ip.len()); let mut result = (ip[start_bytes..end_bytes]).to_string(); + if !ip.contains(".tr,") && !ip.contains(".tr;") { + previous_line = result; + continue; + } + + if !previous_line.is_empty() && previous_line.ends_with('\'') && ip.ends_with(".tr,") { + result = previous_line.clone(); + } + if result.trim().is_empty() { continue; }