Skip to content

Commit

Permalink
dart_to_csv: fix dart parsing
Browse files Browse the repository at this point in the history
When .tr key is on next line we need to store the previous one.

Signed-off-by: Andrea Ricchi <[email protected]>
  • Loading branch information
AndreaRicchi committed May 13, 2024
1 parent 4733ce7 commit 96f72cd
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/dart_to_csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,22 @@ fn read_file(path: String) -> Vec<String> {
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;
}
Expand Down

0 comments on commit 96f72cd

Please sign in to comment.