Last modified on 27 October 2012, at 22:14

REBOL Programming/decode-cgi

USAGE:Edit

DECODE-CGI args 

DESCRIPTION:Edit

Converts CGI argument string to a block of set-words and value strings.

DECODE-CGI is a function value.

ARGUMENTSEdit

  • args -- Starts at first argument word. (Type: any-string)

SOURCE CODEEdit

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
]