Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: From "C" to Rebol: - decode-cgi-special

From: arolls::bigpond::net::au at: 3-Aug-2001 14:30

I suggest modifying the decode-cgi function. I changed the 'equate rule to look like the 'value rule just below it. Of course, you won't be able to make an object out of it, since some of the names might have spaces in them, but for that you can still use decode-cgi. See code below, which I haven't tried.
> Hey Joe: > Unfortunately, you caught me with a number of things on my > plate today: > So I can't give it the immediate attention that it deserves... but - > 1)When I originally wrote this module, I was not able to make > rebol's decode-cgi function decode that 'name part of the pair > example results below: > from >>cgi: make object! decode-cgi data-string > print mold cgi > ; I get: > make object! [ required: {First Name;Last Name;Street > address;State/Province;Country;Phone;E-mail;password;ccnum;expdate > ;Subscription Type;City;Zip/Postal > Code} optional: "Fax;referred" First+Name: "Tim" Last+Name: > "Johnson" Street+address: "P.O. Box 3341" City: "Palmer" > State%2FProvince: "Alaska" > Zip%2FPostal+Code: "99645" Country: "United States" Phone: > "907.745.5392" Fax: "" E-mail: "[tim--johnsons-web--com]" password: > "extra" referred: "" ccnum: > "234190345908" expdate: "01022002" Subscription+Type: "Selection > Required!" ] > ;and you see that only the 'values are decoded. > ; Perhaps I missed something here? > ; For my purposes, the 'names must be decoded as well, thus the > hand-rolled > ; function > ; BTW: However, I believe I see the solution for my original question in > ; the mezzanine code:
decode-cgi-special: func [ {Converts CGI argument string to a list of words and value strings.} args [any-string!] "Starts at first argument word" /local list equate value name val plus-to-space ][ plus-to-space: func [arg /local seek chr] [ if any [none? arg empty? arg] [return ""] seek: arg while [seek: find seek #"+"] [ change seek #" " seek: next seek ] head arg ] list: make block! 8 equate: [copy name to "=" "=" (append list rejoin [form dehex plus-to-space name ":"] ; <- different!! ) value] value: ["&" (append list copy "") | [copy val to "&" "&" | copy val to end] (append list either none? val [copy ""] [form dehex plus-to-space val])] parse/all args [some equate | none] list ] and a quick test: decode-cgi-special {fe+e=eenie&fi+e=meenie&foe=miney&fum=moe} == ["fe e:" "eenie" "fi e:" "meenie" "foe:" "miney" "fum:" "moe"]