Chronos is one of the many Smalltalk-related blogs syndicated on Planet Smalltalk
χρόνος

Discussion of the Essence# programming language, and related issues and technologies.

Blog Timezone: America/Los_Angeles [Winter: -0800 hhmm | Summer: -0700 hhmm] 
Your local time:  

2007-02-16

Handling various text file line-end conventions in VW

Martin Kobetic has posted an excellent tutorial on handling different text file line-end conventions in VisualWorks.

The Passport inter-Smalltalk portability library (on which the Chronos Date/Time Library depends) also provides a solution to the same problem:


  • UtilityFunction nextLineFrom: aStream

  • UtilityFunction skipToNextLineOf: aStream

Both of the above functions will work with any of the three text file line-end conventions currently encountered in the wild: CRLF (Windows,) LF (Unix/Linix/MacOS X) and CR (classic MacOS.)

Passport does not provide any support for writing text files using different line-end conventions, for two reasons:

  1. The external WriteStreams provided by most Smalltalk implementations will already convert CR to the host platform's line-end convention.

  2. Given the ability to read text files correctly, regardless of line-end convetion, there is not as much need to be able to write files with any particular line-end convention.

Chronos uses both of the above Passport functions in order to read time zone and other information from text files stored in the Chronos Time Zone Repository. Using those two Passport functions not only provides Chronos with inter-Smalltalk portability, it also means that a single version of the Chronos Time Zone Repository can be used on all host platforms, even when the text files were generated on a different operating system.


No comments: