Last modified on 27 October 2012, at 22:13

REBOL Programming/deline

USAGE:Edit

DELINE string /lines 

DESCRIPTION:Edit

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

DELINE is a function value.

ARGUMENTSEdit

  • string -- (Type: any-string)

REFINEMENTSEdit

  • /lines -- Convert to block of lines (does not modify)

SOURCE CODEEdit

deline: func [
    {Converts string terminators to standard format, e.g. CRLF to LF. (Modifies)} 
    string [any-string!] 
    /lines "Convert to block of lines (does not modify)" /local 
    linechar a b 
    output
][
    linechar: make bitset! #{
FFDBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
} 
    also case [
        not lines [
            parse/all/case either binary? string [as-string string] [string] [
                any [to cr a: cr opt lf b: (
                        b: change/part a lf b
                    ) :b] to end
            ] 
            string
        ] 
        empty? string [copy []] 
        'else [
            output: make block! divide length? string 50 
            if binary? string [string: as-string string] 
            parse/all/case string [any [
                    copy a some linechar (output: insert output a) [crlf | cr | lf | end] 
                    | 
                    [crlf | cr | lf] (output: insert output copy "")
                ]] 
            head output
        ]
    ] set [string output a b] none
]