On Mar 25, 2008, at 17:50 , I=F1aki Baz Castillo wrote:

> Hi, AFAIK Ruby uses LF =3D \n to detect newline. But now I'm coding a
> parser for a protocol that uses CRLF =3D \r\n for newline. In fact, \n
> is not considered a newline.
>
> Is it possible to get Ruby working with CRLF instead of LF?
>
> For example, I want to declare this string (for testing):
>
> example =3D<-- END_STRING
> Version 4
> Request_Type: call
> From: sssss
> END_STRING
>
> and I want that string to match \r\n at the end of each line instead
> of \n, is it possible?

The whole question is a bit generic.

In the source code a hard-newline like the one in a here-document has =20=

only LFs as long as the file has the newline conventions of the =20
runtime platform. That's because the Ruby interpreter itself reads the =20=

program as a text file in text mode.

If you want to force CRLF in a here-document you can use a trick like =20=

this (off the top of my head):

   example =3D <<EOS.lf_to_crlf
     ...
   EOS

   class String
     def lf_to_crlf
       gsub(/\012/, "\015\012")
     end
   end

Then the I/O channel used to send the data needs to be in binary mode, =20=

etc.

-- fxn