On Jul 31, 2006, at 6:23 PM, Wes G. wrote:
In a pure Ruby (Rails) app, I’ve had to modify regexps to handle the
\r\n sequence so that my regexps will work in a Windows environment.
I’m guessing that this is related to the “file follows runtime
conventions” in your post. Meaning that the file that I’m processing
(which is actually sourced externally) did not conform to C runtime
conventions when it was written.
Yes, that is an important point.
When we talk about portability as far as newlines is concerned we are
assuming the newline conventions of the platform and the data match.
A portable line-oriented script might fail if it is running on Linux
processing text files from a FAT32 partition that were generated by
some Windows program. There a lot of common situations when
conventions may not match. A portable line-oriented script is not
supposed to handle those situation, a robust line-oriented script
should do something sensible with foreign conventions.
Web programming is one of them, because you cannot assume anything in
the input that comes from a text area or an uploaded text file for
instance. In that case you better normalize first (written on the way):
normalized_text_area = text_area.gsub(/\015\012/, “\n”).gsub(/
Now text_area has been normalized and all standard line-oriented
idioms will work.
In Ruby we are done because “\n” is “\012” everywhere, in Perl that
gets slightly more complicated because “\n” is eq “\015” on MacOS pre-
X. But you see the idea and why you do that.
– fxn (<-- whose article about newlines for O’Reilly is about to