forked from dmcoles/ReBuild
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stringStreamer.e
87 lines (74 loc) · 1.76 KB
/
stringStreamer.e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
OPT MODULE,OSVERSION=37
MODULE 'dos/dos'
MODULE '*stringlist','*baseStreamer'
EXPORT OBJECT stringStreamer OF baseStreamer
PRIVATE
data:PTR TO stringlist
currpos:LONG
ENDOBJECT
PROC create() OF stringStreamer
DEF str:PTR TO stringlist
NEW str.stringlist(100)
self.currpos:=0
self.data:=str
ENDPROC
PROC end() OF stringStreamer
END self.data
ENDPROC
PROC clear() OF stringStreamer
self.data.clear()
self.currpos:=0
ENDPROC
PROC writeLine(str:PTR TO CHAR) OF stringStreamer
self.write(str)
self.currpos:=self.currpos+1
ENDPROC
PROC write(str:PTR TO CHAR) OF stringStreamer
DEF newval
IF self.data
IF self.data.count()>self.currpos
newval:=String(StrLen(self.data.item(self.currpos))+StrLen(str))
StrCopy(newval,self.data.item(self.currpos))
StrAdd(newval,str)
self.data.setItem(self.currpos,newval)
DisposeLink(newval)
ELSE
self.data.add(str)
ENDIF
ENDIF
ENDPROC
PROC readLine(outStr:PTR TO CHAR) OF stringStreamer
DEF r,l
IF self.data
IF (self.currpos<(self.data.count()))
AstrCopy(outStr,self.data.item(self.currpos),200)
r:=StrLen(outStr)
self.currpos:=self.currpos+1
ELSE
r:=-1
ENDIF
ENDIF
ENDPROC r
PROC reset() OF stringStreamer
self.currpos:=0
ENDPROC
PROC getSize() OF stringStreamer
//very rough size estimation
DEF r=0,i
FOR i:=0 TO self.data.count()-1
r:=r+EstrLen(self.data.item(i))+8
ENDFOR
r:=r+32
ENDPROC r
PROC compareTo(otherStream:PTR TO stringStreamer) OF stringStreamer
DEF i
IF otherStream.data.count()<>self.data.count()
RETURN FALSE
ELSE
i:=otherStream.data.count()-1
WHILE (i>=0)
IF StrCmp(otherStream.data.item(i),self.data.item(i))=FALSE THEN RETURN FALSE
i--
ENDWHILE
ENDIF
ENDPROC TRUE