@@ -44,7 +44,7 @@ pub enum RangeSpec {
4444 Range ( Option < isize > , Option < isize > , bool ) , // (start, end, inclusive)
4545}
4646
47- pub fn parse_template ( template : & str ) -> Result < Vec < StringOp > , String > {
47+ pub fn parse_template ( template : & str ) -> Result < ( Vec < StringOp > , bool ) , String > {
4848 parser:: parse_template ( template)
4949}
5050
@@ -150,10 +150,18 @@ fn unescape(s: &str) -> String {
150150 out
151151}
152152
153- pub fn apply_ops ( input : & str , ops : & [ StringOp ] ) -> Result < String , String > {
153+ pub fn apply_ops ( input : & str , ops : & [ StringOp ] , debug : bool ) -> Result < String , String > {
154154 let mut val = Value :: Str ( input. to_string ( ) ) ;
155- let mut default_sep = " " . to_string ( ) ; // Clear default
156- for op in ops {
155+ let mut default_sep = " " . to_string ( ) ;
156+
157+ if debug {
158+ eprintln ! ( "DEBUG: Initial value: {:?}" , val) ;
159+ }
160+
161+ for ( i, op) in ops. iter ( ) . enumerate ( ) {
162+ if debug {
163+ eprintln ! ( "DEBUG: Applying operation {}: {:?}" , i + 1 , op) ;
164+ }
157165 match op {
158166 StringOp :: Split { sep, range } => match & val {
159167 Value :: Str ( s) => {
@@ -306,6 +314,18 @@ pub fn apply_ops(input: &str, ops: &[StringOp]) -> Result<String, String> {
306314 }
307315 } ,
308316 }
317+ if debug {
318+ match & val {
319+ Value :: Str ( s) => eprintln ! ( "DEBUG: Result: String({:?})" , s) ,
320+ Value :: List ( list) => {
321+ eprintln ! ( "DEBUG: Result: List with {} items:" , list. len( ) ) ;
322+ for ( idx, item) in list. iter ( ) . enumerate ( ) {
323+ eprintln ! ( "DEBUG: [{}]: {:?}" , idx, item) ;
324+ }
325+ }
326+ }
327+ eprintln ! ( "DEBUG: ---" ) ;
328+ }
309329 }
310330
311331 // Note: If the final value is a List, we join using the last split separator
@@ -323,8 +343,8 @@ pub fn apply_ops(input: &str, ops: &[StringOp]) -> Result<String, String> {
323343}
324344
325345pub fn process ( input : & str , template : & str ) -> Result < String , String > {
326- let ops = parse_template ( template) ?;
327- apply_ops ( input, & ops)
346+ let ( ops, debug ) = parse_template ( template) ?;
347+ apply_ops ( input, & ops, debug )
328348}
329349
330350#[ cfg( test) ]
0 commit comments