@@ -23,17 +23,21 @@ Option Explicit
2323'#
2424'////////////////////////////////////////////////////////////////////////////////////////////
2525' CONSTANTS:
26+ Private Const DualLFchar As String = vbLf & vbLf
27+ Private Const InverseCRLF As String = vbLf & vbCr
2628Private Const SizeFactor As Long = 524288
2729'////////////////////////////////////////////////////////////////////////////////////////////
2830'#
2931'////////////////////////////////////////////////////////////////////////////////////////////
3032' PROPERTIES VARIABLES:
3133Private P_ATENDOFSTREAM As Boolean '---------------Indicates if the file's end is reached.
3234Private 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).
3436Private P_ENDSTREAMONLINEBREAK As Boolean '--------If true, each stream ends on a line break.
3537Private P_ISOPENSTREAM As Boolean '----------------Indicates if the object is linked to a file
3638Private 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.
3741Private P_STREAMLENGTH As Long '-------------------File len.
3842Private P_TEXT As String '-------------------------Holds the current stream's text.
3943'////////////////////////////////////////////////////////////////////////////////////////////
@@ -84,6 +88,9 @@ Public Property Let bufferSize(value As Single)
8488End Property
8589Public Property Get bufferString() As String
8690Attribute bufferString.VB_Description = "Gets the text data stored in the buffer."
91+ If P_UNIFIEDLFOUTPUT Then
92+ NormalizeLineBreaks
93+ End If
8794 bufferString = P_TEXT
8895End Property
8996Public Property Get endStreamOnLineBreak() As Boolean
@@ -112,6 +119,13 @@ Public Property Get streamLength() As Long
112119Attribute streamLength.VB_Description = "Gets the current opened file’s size, in Bytes."
113120 streamLength = P_STREAMLENGTH
114121End 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
115129'////////////////////////////////////////////////////////////////////////////////////////////
116130'#
117131'////////////////////////////////////////////////////////////////////////////////////////////
@@ -136,10 +150,10 @@ Private Sub FindEOLcharacter()
136150
137151 Do
138152 bufferReverse = StrReverse(Buffer)
139- LastCrLfPos = InStrB(1 , bufferReverse, vbCrLf)
153+ LastCrLfPos = InStrB(1 , bufferReverse, InverseCRLF) + 2
140154 LastCrPos = InStrB(1 , bufferReverse, vbCr)
141155 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 )
143157 If missingEOLchar Then
144158 tmpBuffer = Buffer
145159 Get #FileHandled, , Buffer
@@ -186,6 +200,15 @@ Private Sub FindEOLcharacter()
186200 End If
187201 Seek #FileHandled, CorrectedPos
188202End 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
189212Public Sub OpenStream (filePath As String )
190213Attribute OpenStream.VB_Description = "Opens a stream over a text file."
191214 FileHandled = FreeFile
@@ -285,11 +308,12 @@ Private Sub Class_Initialize()
285308 P_BUFFERSIZE = 0.5
286309 P_BUFFERLENGTH = CLng(P_BUFFERSIZE * SizeFactor)
287310 P_ENDSTREAMONLINEBREAK = False
311+ P_UNIFIEDLFOUTPUT = False
288312 Buffer = SPACE$(P_BUFFERLENGTH)
289313 NullChar = ChrW(0 )
290314End Sub
291315Private Sub Class_Terminate ()
292316 If P_ISOPENSTREAM Then
293317 CloseStream
294318 End If
295- End Sub
319+ End Sub
0 commit comments