Jump to content

Rebol Programming/decode-cgi

From Wikibooks, open books for an open world

USAGE:

[edit | edit source]
DECODE-CGI args 

DESCRIPTION:

[edit | edit source]

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

DECODE-CGI is a function value.

ARGUMENTS

[edit | edit source]
  • args -- Starts at first argument word. (Type: any-string)

SOURCE CODE

[edit | edit source]
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
]