From 87b316fb2082a84f8a00bb2170fa659e200e77b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ortega=20Froysa?= Date: Fri, 3 Oct 2025 09:13:27 +0200 Subject: [PATCH] Do not use newline if within parenthesis. This is useful for some arguments. --- src/worker.rs | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/worker.rs b/src/worker.rs index 781eb8d..67f3ad7 100644 --- a/src/worker.rs +++ b/src/worker.rs @@ -58,6 +58,7 @@ pub fn work(in_path:Option<&str>, out_path:Option<&str>) -> Result<(), String> let mut last_ch = '\0'; let mut tab_num = 0; + let mut in_paren = false; let mut write_buf = String::new(); for i in in_reader.bytes() { @@ -65,17 +66,25 @@ pub fn work(in_path:Option<&str>, out_path:Option<&str>) -> Result<(), String> match ch { '[' | '{' => { tab_num += 1; - write_buf += format!("{ch}\n").as_str(); - for _ in 0..tab_num { - write_buf += " "; + //write_buf += format!("{ch}\n").as_str(); + write_buf.push(ch); + if !in_paren { + write_buf.push('\n'); + for _ in 0..tab_num { + write_buf += " "; + } + last_ch = ' '; + } else { + last_ch = ch; } - last_ch = ' '; }, ']' | '}' => { tab_num -= 1; - write_buf += "\n"; - for _ in 0..tab_num { - write_buf += " "; + if !in_paren { + write_buf += "\n"; + for _ in 0..tab_num { + write_buf += " "; + } } write_buf.push(ch); last_ch = ch; @@ -94,6 +103,11 @@ pub fn work(in_path:Option<&str>, out_path:Option<&str>) -> Result<(), String> }, _ => { if ch != ' ' || last_ch != ' ' { + if ch == '(' { + in_paren = true; + } else if ch == ')' { + in_paren = false; + } write_buf.push(ch); last_ch = ch; }