home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OL.LZH / PROCS.LZH / SEGMENT.ICN < prev    next >
Text File  |  1991-07-13  |  1KB  |  57 lines

  1. ############################################################################
  2. #
  3. #    Name:    segment.icn
  4. #
  5. #    Title:    Segment string
  6. #
  7. #    Author:    William H. Mitchell
  8. #
  9. #    Date:    June 10, 1988
  10. #
  11. ############################################################################
  12. #  
  13. #     These procedures segment a string s into consecutive substrings
  14. #  consisting of characters that respectively do/do not occur in c.
  15. #  segment(s,c) generates the substrings, while seglist produces a list
  16. #  of the segments.  For example,
  17. #  
  18. #          segment("Not a sentence.",&letters)
  19. #  
  20. #  generates
  21. #  
  22. #          "Not"
  23. #          " "
  24. #          "a"
  25. #          " "
  26. #          "sentence"
  27. #          "."
  28. #  while
  29. #          seglist("Not a sentence.",&letters)
  30. #
  31. #  produces
  32. #
  33. #          ["Not"," ","a","sentence","."]
  34. #
  35. ############################################################################
  36.  
  37. procedure segment(line,dlms)
  38.    local ndlms
  39.  
  40.    dlms := (any(dlms,line[1]) & ~dlms)
  41.    ndlms := ~dlms
  42.    line ? repeat {
  43.       suspend tab(many(ndlms)) \ 1
  44.       suspend tab(many(dlms)) \ 1
  45.       pos(0) & break
  46.       }
  47. end
  48.  
  49. procedure seglist(s,c)
  50.    local L
  51.  
  52.    L := []
  53.    c := (any(c,s[1]) & ~c)
  54.    s ? while put(L,tab(many(c := ~c)))
  55.    return L
  56. end
  57.