跳轉到內容

Rebol 程式設計/decode-cgi

來自華夏公益教科書,自由的教學讀物
DECODE-CGI args 

將 CGI 引數字串轉換為設定字和值字串塊。

DECODE-CGI 是一個函式值。

  • args -- 從第一個引數字開始。 (型別: any-string)

原始碼

[編輯 | 編輯原始碼]
decode-cgi: func [
    {Converts CGI argument string to a block of set-words and value strings.} 
    args [any-string!] "Starts at first argument word." 
    /local block name value here tmp
][
    block: make block! 7 
    parse/all args [
        any [
            copy name [to #"=" | to #"&" | to end] skip here: (
                if tmp: find name #"&" [
                    here: skip here (offset? tmp name) - 2 
                    clear tmp
                ] 
                name: to-set-word dehex name 
                either tmp: find block name [
                    tmp: next tmp 
                    if not block? value: first tmp [
                        change/only tmp reduce [value]
                    ] 
                    tmp: first tmp
                ] [
                    append tmp: block name
                ]
            ) :here [
                [copy value to #"&" skip | copy value to end] 
                (
                    append tmp either none? value [copy ""] [
                        replace/all dehex replace/all value #"+" #" " crlf newline
                    ]
                )
            ]
        ] 
        end
    ] 
    block
]
華夏公益教科書