Do not use newline if within parenthesis.
This is useful for some arguments.
This commit is contained in:
@@ -58,6 +58,7 @@ pub fn work(in_path:Option<&str>, out_path:Option<&str>) -> Result<(), String>
|
|||||||
|
|
||||||
let mut last_ch = '\0';
|
let mut last_ch = '\0';
|
||||||
let mut tab_num = 0;
|
let mut tab_num = 0;
|
||||||
|
let mut in_paren = false;
|
||||||
let mut write_buf = String::new();
|
let mut write_buf = String::new();
|
||||||
|
|
||||||
for i in in_reader.bytes() {
|
for i in in_reader.bytes() {
|
||||||
@@ -65,18 +66,26 @@ pub fn work(in_path:Option<&str>, out_path:Option<&str>) -> Result<(), String>
|
|||||||
match ch {
|
match ch {
|
||||||
'[' | '{' => {
|
'[' | '{' => {
|
||||||
tab_num += 1;
|
tab_num += 1;
|
||||||
write_buf += format!("{ch}\n").as_str();
|
//write_buf += format!("{ch}\n").as_str();
|
||||||
|
write_buf.push(ch);
|
||||||
|
if !in_paren {
|
||||||
|
write_buf.push('\n');
|
||||||
for _ in 0..tab_num {
|
for _ in 0..tab_num {
|
||||||
write_buf += " ";
|
write_buf += " ";
|
||||||
}
|
}
|
||||||
last_ch = ' ';
|
last_ch = ' ';
|
||||||
|
} else {
|
||||||
|
last_ch = ch;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
']' | '}' => {
|
']' | '}' => {
|
||||||
tab_num -= 1;
|
tab_num -= 1;
|
||||||
|
if !in_paren {
|
||||||
write_buf += "\n";
|
write_buf += "\n";
|
||||||
for _ in 0..tab_num {
|
for _ in 0..tab_num {
|
||||||
write_buf += " ";
|
write_buf += " ";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
write_buf.push(ch);
|
write_buf.push(ch);
|
||||||
last_ch = 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 != ' ' || last_ch != ' ' {
|
||||||
|
if ch == '(' {
|
||||||
|
in_paren = true;
|
||||||
|
} else if ch == ')' {
|
||||||
|
in_paren = false;
|
||||||
|
}
|
||||||
write_buf.push(ch);
|
write_buf.push(ch);
|
||||||
last_ch = ch;
|
last_ch = ch;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user