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

From "C" to Rebol: - decode-cgi-special/Object Methods

 [1/2] from: tim::johnsons-web::com at: 3-Aug-2001 9:15


Hi Anton: I will check out your code later. In the meantime, have a look at what I have below. Implementation - wise, these are "methods" for a large object .... they are evaluated by a "constructor" On Fri, Aug 03, 2001 at 02:30:29PM +1000, Anton wrote:
> I suggest modifying the decode-cgi function. > I changed the 'equate rule to look like the
<<quoted lines omitted: 4>>
> decode-cgi. > See code below, which I haven't tried.
; "helper" functions: no-data?: func[arg][either any[none? arg arg = false empty? arg][return true][return false]] has-data?: func[arg][either any[none? arg arg = false empty? arg][return false][return true]] ; data "fetch" method: ; ============================================================================================ read-data: func[/local tmp stdin dstr] [ either system/options/cgi/request-method = "POST"[ either (tmp: to-integer load any[system/options/cgi/content-length "0"])> 0[ stdin: make string! tmp ; allocate storage space read-io system/ports/input stdin tmp return stdin ][none] ; data string empty ][;OR dstr: system/options/cgi/query-string either has-data? dstr[dstr][none] ]; end either ]; end read-data -------------------- ; parses data string into a block in which names and values alternate: ; A value can then be retrieved by a name string, or by a numeric reference ; ============================================================================================ decode-data: func[/local cgi-form data-string][ either data-string: read-data[ data-string: dehex replace/all data-string "+" " " pairs: (length? pair-list: parse/all data-string "&=") / 2 ][none] ]; end decode-data ;=== I've rewritten the code above from some much "sloppier" implementations. ;=== I have tested this above and seems to work... Thanks for the contribution, I will test Anton's code soon. regards tim -- Tim Johnson <[tim--johnsons-web--com]> http://www.johnsons-web.com

 [2/2] from: tim:johnsons-web at: 3-Aug-2001 9:59


It looks like the previous transmission on this topic munched the code. Here it is again: To recap: In the meantime, have a look at what I have below. Implementation - wise, these are "methods" for a large object .... they are evaluated by a "constructor" ; "helper" functions: no-data?: func[arg][either any[none? arg arg = false empty? arg] [return true][return false]] has-data?: func[arg][either any[none? arg arg = false empty? arg] [return false][return true]] ; data "fetch" method: read-data: func[/local tmp stdin dstr] [ either system/options/cgi/request-method = "POST"[ either (tmp: to-integer load any[system/options/cgi/content-length "0"])> 0[ stdin: make string! tmp ; allocate storage space read-io system/ports/input stdin tmp return stdin ][none] ; data string empty ][;OR dstr: system/options/cgi/query-string either has-data? dstr[dstr][none] ]; end either ]; end read-data -------------------- ; parses data-string into a block of alternating ; names and values. Both names and values are dehexed decode-data: func[/local cgi-form data-string][ either data-string: read-data[ data-string: dehex replace/all data-string "+" " " pairs: (length? pair-list: parse/all data-string "&=") / 2 ][none] ]; end decode-data ; I hope thats more readable. tim

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted