[BACK]Return to regsub.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Diff for /src/usr.bin/tmux/regsub.c between version 1.1 and 1.2

version 1.1, 2019/06/13 19:46:00 version 1.2, 2019/06/20 15:40:14
Line 63 
Line 63 
 {  {
         regex_t          r;          regex_t          r;
         regmatch_t       m[10];          regmatch_t       m[10];
         size_t           start, end, len = 0;          ssize_t          start, end, last, len = 0;
           int              empty = 0;
         char            *buf = NULL;          char            *buf = NULL;
   
         if (*text == '\0')          if (*text == '\0')
Line 72 
Line 73 
                 return (NULL);                  return (NULL);
   
         start = 0;          start = 0;
           last = 0;
         end = strlen(text);          end = strlen(text);
   
         while (start != end) {          while (start <= end) {
                 m[0].rm_so = start;                  m[0].rm_so = start;
                 m[0].rm_eo = end;                  m[0].rm_eo = end;
   
Line 82 
Line 84 
                         regsub_copy(&buf, &len, text, start, end);                          regsub_copy(&buf, &len, text, start, end);
                         break;                          break;
                 }                  }
                 if (m[0].rm_so == m[0].rm_eo) {  
                         regsub_copy(&buf, &len, text, start, end);  
                         break;  
                 }  
   
                 regsub_copy(&buf, &len, text, start, m[0].rm_so);                  /*
                 regsub_expand(&buf, &len, with, text, m, nitems(m));                   * Append any text not part of this match (from the end of the
                 start = m[0].rm_eo;                   * last match).
                    */
                   regsub_copy(&buf, &len, text, last, m[0].rm_so);
   
                   /*
                    * If the last match was empty and this one isn't (it is either
                    * later or has matched text), expand this match. If it is
                    * empty, move on one character and try again from there.
                    */
                   if (empty || m[0].rm_so != last || m[0].rm_so != m[0].rm_eo) {
                           regsub_expand(&buf, &len, with, text, m, nitems(m));
   
                           last = m[0].rm_eo;
                           start = m[0].rm_eo;
                           empty = 0;
                   } else {
                           last = m[0].rm_eo;
                           start = m[0].rm_eo + 1;
                           empty = 1;
                   }
         }          }
         buf[len] = '\0';          buf[len] = '\0';
   

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2