Rebol Programming/enline

USAGE:

edit
ENLINE series /with end-of-line 

DESCRIPTION:

edit

Converts standard string terminators to current OS format, e.g. LF to CRLF. (Modifies)

ENLINE is a function value.

ARGUMENTS

edit
  • series -- (Type: any-string block)

REFINEMENTS

edit
  • /with -- Specifies alternate line termination.
    • end-of-line -- (Type: char string)

SOURCE CODE

edit
enline: func [
    {Converts standard string terminators to current OS format, e.g. LF to CRLF. (Modifies)} 
    series [any-string! block!] 
    /with "Specifies alternate line termination." 
    end-of-line [char! string!] /local 
    platform-line 
    len len-eol 
    output a
][
    platform-line: "^M^/" 
    switch type?/word end-of-line [
        none! [end-of-line: platform-line] 
        char! [end-of-line: to-string end-of-line]
    ] 
    either block? series [
        len: 0 len-eol: length? end-of-line 
        foreach s series [len: len + len-eol + length? s] 
        output: make string! len 
        foreach s series [insert insert tail output s end-of-line] 
        also output set [series output] none
    ] [
        unless end-of-line = "^/" [
            parse/all/case either binary? series [as-string series] [series] [
                any [to lf a: lf (a: change/part a end-of-line 1) :a] to end
            ]
        ] 
        also series set [series a] none
    ]
]