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

[REBOL] Re: Need some url purification functions

From: rebol:techscribe at: 10-Jan-2001 22:15

Hi, if I understand your problem correctly, then the following code - adapted from REBOL's built-in net-utils (source net-utils) - should be helpful (Code follows after my sign-off). Usage:
>> print mold url-parser/parse-url
make object! [ scheme: "http" username: none password: none host: "" port: none path: "sub-directory/" target: "temp.html" tag: none ] Hope this helps, Elan REBOL [] URL-Parser: make object! [ scheme: none user: none pass: none host: none port-id: none path: none target: none tag: none p2: none digit: make bitset! #{ 000000000000FF03000000000000000000000000000000000000000000000000 } alpha-num: make bitset! #{ 000000000000FF03FEFFFF07FEFFFF0700000000000000000000000000000000 } scheme-char: make bitset! #{ 000000000068FF03FEFFFF07FEFFFF0700000000000000000000000000000000 } path-char: make bitset! #{ 00000000F17FFFA7FFFFFFAFFEFFFF5700000000000000000000000000000000 } user-char: make bitset! #{ 00000000F87CFF23FEFFFF87FEFFFF1700000000000000000000000000000000 } pass-char: make bitset! #{ FFF9FFFFFEFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF } url-rules: [scheme-part user-part host-part path-part file-part tag-part] scheme-part: [copy scheme some scheme-char #":" ["//" | none]] user-part: [copy user uchars [#":" pass-part | none] #"@" | none (user: pass: none)] pass-part: [copy pass to #"@" [skip copy p2 to "@" (append append pass "@" p2) | none]] host-part: [copy host uchars [#":" copy port-id digits | none]] path-part: [slash copy path path-node | none] path-node: [pchars slash path-node | none] file-part: [copy target pchars | none] tag-part: [#"#" copy tag pchars | none] uchars: [some user-char | none] pchars: [some path-char | none] digits: [1 5 digit] parse-url: func [ {Return url dataset or cause an error if not a valid URL} url ][ parse/all url url-rules return make object! compose [ scheme: (scheme) username: (user) password: (pass) host: (host) port: (port-id) path: (path) target: (target) tag: (tag) ] ] ]