跳轉至內容

Rebol 程式設計/enline

來自華夏公益教科書
ENLINE series /with end-of-line 

將標準字串終止符轉換為當前作業系統格式,例如 LF 到 CRLF。(修改)

ENLINE 是一個函式值。

  • series -- (型別:any-string 塊)
  • /with -- 指定備用行終止符。
    • end-of-line -- (型別:char 字串)

原始碼

[編輯 | 編輯原始碼]
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
    ]
]
華夏公益教科書