home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / std_unix / volume.22 / text0114.txt < prev    next >
Encoding:
Text File  |  1991-03-06  |  696 b   |  27 lines

  1. Submitted-by: eric@mks.com (Eric Gisin)
  2.  
  3. Does anyone have an complete description of how s///g and awk's gsub
  4. handle the special case of an empty pattern match?
  5. The System V documents and POSIX.2 don't cover this.
  6.  
  7. For example, the command s/[a-z]*/./g does the following on System V ed:
  8.     -bug-    becomes .-.-.
  9. The following algorithm produces an extra dot:
  10.     -bug-    becomes    .-..-.
  11.  
  12. gsub(pattern, replace, src, dst)
  13.     while (1) {
  14.         find next pattern in src
  15.         copy part before match from src to dst
  16.         copy replace to dst
  17.         advance src to end of match
  18.         if (at end of src)    break;
  19.         /* special case for empty match */
  20.         if (match was empty)
  21.             *dst++ = *src++;
  22.     }
  23.  
  24.  
  25. Volume-Number: Volume 22, Number 118
  26.  
  27.