home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
OL.LZH
/
PROCS.LZH
/
SEGMENT.ICN
< prev
next >
Wrap
Text File
|
1991-07-13
|
1KB
|
57 lines
############################################################################
#
# Name: segment.icn
#
# Title: Segment string
#
# Author: William H. Mitchell
#
# Date: June 10, 1988
#
############################################################################
#
# 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