Line delimiters
As of VA Smalltalk 9.1, a stream auto-detects the line delimiter when using the nextLine method. Prior to this behavior, the stream would use the platform line delimiter which made it difficult to create multiline string content on one platform that could be seamlessly read on another with nextLine. By default, a stream continues to use the platform file system's line delimiter for the stream’s cr operation.
A string representing the current line delimiter can be obtained by sending the lineDelimiter message to a file stream instance and can be changed to an arbitrary string by sending the lineDelimiter: message. This makes it possible to enforce a specific line delimiter regardless of the running platform. For example, the desired behavior might be, for certain socket protocols to write out the Windows line delimiter default, CrLf, even when the application is running on Linux.
The following table lists the line delimiter constants defined in the CldtConstants pool dictionary:
Table 9. Line Delimiter constants in the CldtConstants pool dictionary
Pool variable
Description
LineDelimiter
The default platform line delimiter
PMLineDelimiter
The line delimiter used by OS/2 Presentation Manager
UNIXLineDelimiter
The line delimiter used by Unix
WINLineDelimiter
The line delimiter used by Windows
The following example demonstrates the use of the lineDelimiter: message and line delimiter constants, as well as their effect on the cr message:
| file |
file := CfsReadWriteFileStream openEmpty: 'testing.txt'.
"Use OS/2 line delimiter"
file lineDelimiter: PMLineDelimiter.
file cr; nextPutAll: '<-os/2 line delimiter'.
"Set back to default line delimiter"
file lineDelimiter: LineDelimiter.
file cr; nextPutAll: '<-default line delimiter'.
"Use an arbitrary line delimiter"
file lineDelimiter: 'end of line]'.
file cr; nextPutAll: '<-arbitrary line delimiter'.
file close.
 
Tip:
As of 9.1, you no longer need to choose Cr, Lf or CrLf for nextLine as the stream auto-detects the line ending. Use upToAll: and skipToAll: to scan up to various special characters sequences. This is better than changing the line delimiter to the special sequence with lineDelimiter: and then using nextLine.
Last modified date: 05/12/2020