Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: areas, text, and read/binary

From: brett:codeconscious at: 13-Feb-2002 17:14

Hi Alan, Joel, Alan your demo script proves to me at least what I said before.
> I have found that if I write/binary and then convert-lines it is ok.
Actually no it is not. If you read/binary, add some text after the new space , save it with write/binary, convert-lines, then read it in again, you'll see that your new text dropped to the next line. To demonstrate what is happening add these two functions to your demo script: tag-crlf: func[ data [string! binary!]][ replace/all replace/all data CR "<CR>" NEWLINE "<LF>" ] detag-crlf: func[ data [string! binary!]][ replace/all replace/all data "<CR>" CR "<LF>" NEWLINE ] Then add these two buttons: button "tag text" [tag-crlf my-area/text show my-area] button "detag text" [detag-crlf my-area/text show my-area] Play with these buttons and see how you are dealing with Carriage Return characters (CR) and Line Feed (LF), with the various write, read and edit combinations. The point to understand is that Linefeed / LF / NEWLINE is the delimiter between lines in REBOL. Text files in Windows, MS-DOS, are delimited by two characters CR+LF. The following statements apply to the windows platform (I haven't used Win2000, nor XP nor CE.). 1) When Notepad sees CRLF in some text it breaks the text at that point and puts the following text on the next line. 2) When a REBOL AREA sees a LF it does the same. 3) AREA ignores CR. Try this code in your console - note that 0D is the hex representation for CR and 0A for LF: possibilities: [#{0a} #{0d} #{0a0d} #{0d0a}] repeat p possibilities [ print "**********************************" print ["Possibility: " mold p] print ["write/binary %test.dat"] write/binary %test.dat p print ["write %test.txt"] write %test.txt p print [ "Read/binary %test.dat: " mold r: read/binary %test.dat either equal? p r [""]["<-- Changed"] ] print ["Read/binary %test.txt: " mold r: read/binary %test.txt either equal? p r [""]["<-- Changed"] ] print [ "Read %test.dat: " mold r: to-binary read %test.dat either equal? p r [""]["<-- Changed"] ] print [ "Read %test.txt: " mold r: to-binary read %test.txt either equal? p r [""]["<-- Changed"] ] ] Regards, Brett.