home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / BIPL.ZIP / PROCS.ZIP / SEGMENT.ICN < prev    next >
Encoding:
Text File  |  1992-09-28  |  1.3 KB  |  57 lines

  1. ############################################################################
  2. #
  3. #    File:     segment.icn
  4. #
  5. #    Subject:  Procedures to 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.