Hello everyone,
I often needs to read some streams these days and to get some infos
related to the lines returns for example.
Because of the CRLF it is a little complicated sometimes.
I have an example of code here:
| lfShouldBeCounted char count remaining |
lfShouldBeCounted := false.
remaining := 0.
count := 0.
stream position: startPos.
[ stream position = endPos ]
�� whileFalse: [
�� �� "13 is a CR, 10 a LF"
�� �� (char := stream next asInteger) = 13
�� �� �� ifTrue: [ count := count + 1. remaining := 0. lfShouldBeCounted := false ]
�� �� �� ifFalse: [
�� �� �� �� char = 10
�� �� �� �� �� ifTrue: [
�� �� �� �� �� �� lfShouldBeCounted
�� �� �� �� �� �� �� ifTrue: [ count := count + 1. remaining := 0 ]
�� �� �� �� �� �� �� ifFalse: [ lfShouldBeCounted := true ] ]
�� �� �� �� �� ifFalse: [ remaining := remaining + 1 ] ] ]
With this example I know how many lines where passed between the
startPos and the endPos in a stream. I also know how many char there
is between the last line return and the endPos.
��I wanted to know if you had a better way to do that? The way need to
be as performant than this snippet. I know some people here can
produce a snippet more readable and easier to maintain :)
--
Cyril Ferlicot
https://ferlicot.fr
http://www.synectique.eu
2 rue Jacques Pr��vert 01,
59650 Villeneuve d'ascq France