fix sep reduction, trim leading/trailing seps
fix separator reduction to single underscore and trim leading as well as trailing separators from output
This commit is contained in:
parent
81cf35c69e
commit
f878fbc0a0
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "snakify"
|
||||
version = "1.1.0"
|
||||
version = "1.1.1"
|
||||
edition = "2021"
|
||||
|
||||
authors = ["mxhagen"]
|
||||
|
||||
17
src/main.rs
17
src/main.rs
@ -42,6 +42,7 @@ fn main() {
|
||||
|
||||
let mut arg_warned = false;
|
||||
let mut output = String::new();
|
||||
let mut last = '_';
|
||||
for arg in std::env::args().skip(1 + arg_start) {
|
||||
if !arg_warned
|
||||
&& matches!(
|
||||
@ -55,11 +56,14 @@ fn main() {
|
||||
arg_warned = true;
|
||||
}
|
||||
|
||||
let last_was_separator = output.bytes().last().map(|x| x == b'_').unwrap_or(true);
|
||||
for c in arg.chars() {
|
||||
match c {
|
||||
' ' | '-' | '_' if last_was_separator => {}
|
||||
' ' | '-' | '_' => output.push('_'),
|
||||
' ' | '-' | '_' if last == '_' => {},
|
||||
' ' | '-' | '_' => {
|
||||
output.push('_');
|
||||
last = '_';
|
||||
continue;
|
||||
},
|
||||
|
||||
'a'..='z' | 'A'..='Z' | '0'..='9' => output.push(c.to_ascii_lowercase()),
|
||||
_ if flag == Some(Force) => output.push(c),
|
||||
@ -69,8 +73,13 @@ fn main() {
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
last = c;
|
||||
}
|
||||
|
||||
if last != '_' {
|
||||
output.push('_');
|
||||
last = '_';
|
||||
}
|
||||
output.push('_')
|
||||
}
|
||||
output.pop();
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user