Source file segment.icn
############################################################################
#
#	File:     segment.icn
#
#	Subject:  Procedures to segment string
#
#	Author:   William H. Mitchell
#
#	Date:     June 10, 1988
#
############################################################################
#
#   This file is in the public domain.
#
############################################################################
#  
#     These procedures segment a string s into consecutive substrings
#  consisting of characters that respectively do/do not occur in c.
#  segment(s,c) generates the substrings, while seglist produces a list
#  of the segments.  For example,
#  
#          segment("Not a sentence.",&letters)
#  
#  generates
#  
#          "Not"
#          " "
#          "a"
#          " "
#          "sentence"
#          "."
#  while
#          seglist("Not a sentence.",&letters)
#
#  produces
#
#          ["Not"," ","a","sentence","."]
#
############################################################################

procedure segment(line,dlms)
   local ndlms

   dlms := (any(dlms,line[1]) & ~dlms)
   ndlms := ~dlms
   line ? repeat {
      suspend tab(many(ndlms)) \ 1
      suspend tab(many(dlms)) \ 1
      pos(0) & break
      }
end

procedure seglist(s,c)
   local L

   L := []
   c := (any(c,s[1]) & ~c)
   s ? while put(L,tab(many(c := ~c)))
   return L
end

This page produced by UniDoc on 2021/04/15 @ 23:59:45.