@@ -23,17 +23,21 @@ Option Explicit
23
23
'#
24
24
'////////////////////////////////////////////////////////////////////////////////////////////
25
25
' CONSTANTS:
26
+ Private Const DualLFchar As String = vbLf & vbLf
27
+ Private Const InverseCRLF As String = vbLf & vbCr
26
28
Private Const SizeFactor As Long = 524288
27
29
'////////////////////////////////////////////////////////////////////////////////////////////
28
30
'#
29
31
'////////////////////////////////////////////////////////////////////////////////////////////
30
32
' PROPERTIES VARIABLES:
31
33
Private P_ATENDOFSTREAM As Boolean '---------------Indicates if the file's end is reached.
32
34
Private P_BUFFERLENGTH As Long '-------------------Number of chars in buffer.
33
- Private P_BUFFERSIZE As Single '-------------------Buffer's size in MB (0.5 by default).
35
+ Private P_BUFFERSIZE As Single '-------------------Buffer's size x10 MB (0.5 by default).
34
36
Private P_ENDSTREAMONLINEBREAK As Boolean '--------If true, each stream ends on a line break.
35
37
Private P_ISOPENSTREAM As Boolean '----------------Indicates if the object is linked to a file
36
38
Private P_LINEBREAK As String '--------------------Holds the char used to end a Stream.
39
+ Private P_UNIFIEDLFOUTPUT As Boolean '-------------If true, the buffer string will be returned
40
+ ' with the LF char as Line Break.
37
41
Private P_STREAMLENGTH As Long '-------------------File len.
38
42
Private P_TEXT As String '-------------------------Holds the current stream's text.
39
43
'////////////////////////////////////////////////////////////////////////////////////////////
@@ -84,6 +88,9 @@ Public Property Let bufferSize(value As Single)
84
88
End Property
85
89
Public Property Get bufferString() As String
86
90
Attribute bufferString.VB_Description = "Gets the text data stored in the buffer."
91
+ If P_UNIFIEDLFOUTPUT Then
92
+ NormalizeLineBreaks
93
+ End If
87
94
bufferString = P_TEXT
88
95
End Property
89
96
Public Property Get endStreamOnLineBreak() As Boolean
@@ -112,6 +119,13 @@ Public Property Get streamLength() As Long
112
119
Attribute streamLength.VB_Description = "Gets the current opened file’s size, in Bytes."
113
120
streamLength = P_STREAMLENGTH
114
121
End Property
122
+ Public Property Get unifiedLFOutput() As Boolean
123
+ Attribute unifiedLFOutput.VB_Description = "Determines whether the buffer string is returned using only the LF character as a linefeed."
124
+ unifiedLFOutput = P_UNIFIEDLFOUTPUT
125
+ End Property
126
+ Public Property Let unifiedLFOutput(value As Boolean )
127
+ P_UNIFIEDLFOUTPUT = value
128
+ End Property
115
129
'////////////////////////////////////////////////////////////////////////////////////////////
116
130
'#
117
131
'////////////////////////////////////////////////////////////////////////////////////////////
@@ -136,10 +150,10 @@ Private Sub FindEOLcharacter()
136
150
137
151
Do
138
152
bufferReverse = StrReverse(Buffer)
139
- LastCrLfPos = InStrB(1 , bufferReverse, vbCrLf)
153
+ LastCrLfPos = InStrB(1 , bufferReverse, InverseCRLF) + 2
140
154
LastCrPos = InStrB(1 , bufferReverse, vbCr)
141
155
LastLfPos = InStrB(1 , bufferReverse, vbLf)
142
- missingEOLchar = (LastCrLfPos = 0 And LastCrPos = 0 And LastLfPos = 0 )
156
+ missingEOLchar = (LastCrLfPos - 2 = 0 And LastCrPos = 0 And LastLfPos = 0 )
143
157
If missingEOLchar Then
144
158
tmpBuffer = Buffer
145
159
Get #FileHandled, , Buffer
@@ -186,6 +200,15 @@ Private Sub FindEOLcharacter()
186
200
End If
187
201
Seek #FileHandled, CorrectedPos
188
202
End Sub
203
+ Private Sub NormalizeLineBreaks ()
204
+ If InStrB(1 , P_TEXT, vbCr, vbBinaryCompare) > 0 Then
205
+ P_TEXT = Replace(P_TEXT, vbCr, vbLf, 1 )
206
+ End If
207
+ Do While InStrB(1 , P_TEXT, DualLFchar, vbBinaryCompare) > 0
208
+ P_TEXT = Replace(P_TEXT, DualLFchar, vbLf, 1 )
209
+ Loop
210
+ P_LINEBREAK = vbLf
211
+ End Sub
189
212
Public Sub OpenStream (filePath As String )
190
213
Attribute OpenStream.VB_Description = "Opens a stream over a text file."
191
214
FileHandled = FreeFile
@@ -285,11 +308,12 @@ Private Sub Class_Initialize()
285
308
P_BUFFERSIZE = 0.5
286
309
P_BUFFERLENGTH = CLng(P_BUFFERSIZE * SizeFactor)
287
310
P_ENDSTREAMONLINEBREAK = False
311
+ P_UNIFIEDLFOUTPUT = False
288
312
Buffer = SPACE$(P_BUFFERLENGTH)
289
313
NullChar = ChrW(0 )
290
314
End Sub
291
315
Private Sub Class_Terminate ()
292
316
If P_ISOPENSTREAM Then
293
317
CloseStream
294
318
End If
295
- End Sub
319
+ End Sub
0 commit comments