Browse Source

transform: fix replacement of particular pattern instance

This fixes handling of expressions like 's/s/@/2'

Fix suggested by Anthony Heading.

* src/transform.c (_single_transform_name_to_obstack): Avoid duplicating
initial prefix if replace is not needed.
Sergey Poznyakoff 3 years ago
parent
commit
193eb8f81d
1 changed files with 3 additions and 3 deletions
  1. 3 3
      src/transform.c

+ 3 - 3
src/transform.c

@@ -493,9 +493,6 @@ _single_transform_name_to_obstack (struct transform *tf, char *input)
 
 	  disp = rmp[0].rm_eo;
 
-	  if (rmp[0].rm_so)
-	    obstack_grow (&stk, input, rmp[0].rm_so);
-
 	  nmatches++;
 	  if (tf->match_number && nmatches < tf->match_number)
 	    {
@@ -504,6 +501,9 @@ _single_transform_name_to_obstack (struct transform *tf, char *input)
 	      continue;
 	    }
 
+	  if (rmp[0].rm_so)
+	    obstack_grow (&stk, input, rmp[0].rm_so);
+
 	  for (segm = tf->repl_head; segm; segm = segm->next)
 	    {
 	      switch (segm->type)