From: Charles O Nutter Date: 2006-08-01T02:27:36+09:00 Subject: Re: Does Ruby need a "line separator" class? ------=_Part_29996_1376527.1154366853051 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 7/31/06, Xavier Noria wrote: > > On Jul 31, 2006, at 6:23 PM, Wes Gamble 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. > A large part of our problem is that we currently tend to normalize everything to \n....all the time. That has the effect of also writing out \n to the filesystem for newlines, which as you describe above causes problems when trying to re-read. So for the case in question, we run Rails...it generates files with newlines...we normalize those newlines to \n and write such to disk...and then future use of those files (in this case, ERB templates) fails because the newlines aren't handled correctly (i.e. we can't normalize \r\n to \n again because they're already \n on disk). So it seems the IO approach may do well for us, where newlines are read from platform-specific and written to platform-specific. -- Contribute to RubySpec! @ www.headius.com/rubyspec Charles Oliver Nutter @ headius.blogspot.com Ruby User @ ruby.mn JRuby Developer @ www.jruby.org Application Architect @ www.ventera.com ------=_Part_29996_1376527.1154366853051--