Skip to content

Commit 9372c87

Browse files
committed
feat(parser): make split consistent with the other operations and don't flatten
1 parent 333585d commit 9372c87

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/pipeline/mod.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,18 +155,25 @@ pub fn apply_ops(input: &str, ops: &[StringOp]) -> Result<String, String> {
155155
let mut default_sep = " ".to_string(); // Clear default
156156
for op in ops {
157157
match op {
158-
StringOp::Split { sep, range } => {
159-
let parts: Vec<String> = match &val {
160-
Value::Str(s) => s.split(sep).map(|s| s.to_string()).collect(),
161-
Value::List(list) => list
158+
StringOp::Split { sep, range } => match &val {
159+
Value::Str(s) => {
160+
let parts: Vec<String> = s.split(sep).map(|s| s.to_string()).collect();
161+
default_sep = sep.clone();
162+
let result = apply_range(&parts, range);
163+
val = Value::List(result);
164+
}
165+
Value::List(list) => {
166+
let result: Vec<String> = list
162167
.iter()
163-
.flat_map(|s| s.split(sep).map(|s| s.to_string()))
164-
.collect(),
165-
};
166-
default_sep = sep.clone(); // Track for final output
167-
let result = apply_range(&parts, range);
168-
val = Value::List(result);
169-
}
168+
.flat_map(|s| {
169+
let parts: Vec<String> = s.split(sep).map(|s| s.to_string()).collect();
170+
apply_range(&parts, range)
171+
})
172+
.collect();
173+
default_sep = sep.clone();
174+
val = Value::List(result);
175+
}
176+
},
170177
StringOp::Slice { range } => match &val {
171178
Value::Str(s) => {
172179
let chars: Vec<char> = s.chars().collect();

0 commit comments

Comments
 (0)