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

url or file ?

 [1/7] from: patrick:philipot:laposte at: 4-Oct-2003 18:08


Hi List, I already know how to test url and file.
>> url? http://www.rebol.net
== true
>> file? %index.html
== true But what if these came as strings
>> test: ["http://www.rebol.net" "index.html"]
== ["http://www.rebol.net" "index.html"]
>> url? first test
== false
>> file? second test
== false In my case, I have to decide between url and file. How can i do? Regards Patrick

 [2/7] from: greggirwin:mindspring at: 4-Oct-2003 10:48


Hi Patrick, p> But what if these came as strings
>>> test: ["http://www.rebol.net" "index.html"]
p> == ["http://www.rebol.net" "index.html"]
>>> url? first test
p> == false
>>> file? second test
p> == false p> In my case, I have to decide between url and file. How can i do? How about this?
>> url? load "http://www.rebol.net"
== true
>> url? load "index.html"
== false OK, so this gives you a choice of URL or not-URL, but it still might work. :) -- Gregg

 [3/7] from: patrick:philipot:laposte at: 4-Oct-2003 20:39


Thanks Gregg, I came to the same solution but ... load fails with some value:
>> s: "recipes/0001.html"
== "recipes/0001.html"
>> s
== "recipes/0001.html"
>> load s
** Syntax Error: Invalid decimal -- 0001.html ** Near: (line 1) recipes/0001.html And I have no idea how to workaround this easily. Regards Patrick

 [4/7] from: SunandaDH:aol at: 4-Oct-2003 14:40


Patrick:
> I came to the same solution but ... load fails with some value:
...
> And I have no idea how to workaround this easily.
Load is not good if the values do not translate into REBOL words or datatypes. You may need to surround it with an error/try: s: "recipes/0001.html" loaded-s: form s error? try [loaded-s: load s] loaded-s is either now the original as a string, or the loaded values. Also, load can be dangerous if the string is untrusted. Try this: load "rebol [quit]" It'll exit your console. So you probably really need to use load/all. That returns a block, so your original code may need to become: s: "recipes/0001.html" loaded-s: form s error? try [loaded-s: first load/all s] Sunanda.

 [5/7] from: ingo::2b1::de at: 4-Oct-2003 21:18


Hi Patrick, how are you? patrick wrote:
> Hi List, > I already know how to test url and file.
<<quoted lines omitted: 4>>
> But what if these came as strings >>>test: ["http://www.rebol.net" "index.html"]
The problem here (apart from the 'load problems already discussed), is that rebol won't understand a file that is written in non Rebol format (that is, without the leading % sign). A function that will do the trick, as long as you are certain there will only be urls and files in your data, is this: string-to-url-or-file: func [s [string!] /local uf][ either url? uf: attempt[load s ] [uf][to file! s]] ] When your data is a url, load should always succeed, so attempt returns either a url, or somthing else, or none (e.g., if load failed) in the latter cases we just convert it to a file.
>> test: ["http://www.rebol.net" "index.html"]
== ["http://www.rebol.net" "index.html"]
>> repeat d test [ print [ f d " " type? f d ]]
http://www.rebol.net url index.html file Kind regards, Ingo

 [6/7] from: AJMartin:orcon at: 24-Dec-2003 22:38


Patrick wrote:
> But what if these came as strings > >> test: ["http://www.rebol.net" "index.html"]
<<quoted lines omitted: 3>>
> >> file? second test > == false
Then it's best to use my url and file patterns:
>> test: ["http://www.rebol.net" "index.html"]
== ["http://www.rebol.net" "index.html"]
>> parse test/1 [url^ end]
== true
>> parse test/2 [url^ end]
== false
>> parse test/2 [file^ end]
== true
>> parse test/2 [url^ end]
== false Caution: 'file^ has only been tested on Windows and some internet file names! Andrew J Martin Grail Jedi ICQ: 26227169 http://www.rebol.it/Valley/ http://valley.orcon.net.nz/ http://Valley.150m.com/ -><- [ Rebol [ Name: 'Patterns Title: "Patterns" File: %"Patterns.r" Author: "A J Martin" Owner: "Aztecnology" Rights: "Copyright © 2003 A J Martin, Aztecnology." eMail: [Rebol--orcon--net--nz] Web: http://www.rebol.it/Valley/ Needs: [%Map.r] Tabs: 4 Language: 'English Date: 14/August/2003 Version: 1.1.0 ] Fail^: [to end skip] ; A rule that always fails. Succeed^: [] ; A rule that always succeeds. Octet: charset [#"^(00)" - #"^(FF)"] Digit: charset "0123456789" Digits: [some Digit] Upper: charset [#"A" - #"Z"] Lower: charset [#"a" - #"z"] Alpha: union Upper Lower Alphas: [some Alpha] AlphaDigit: union Alpha Digit AlphaDigits: [some AlphaDigit] Control: charset [#"^(00)" - #"^(1F)" #"^(7F)"] Hex: union Digit charset [#"A" - #"F" #"a" - #"f"] HT: #"^-" SP: #" " LWS: charset reduce [SP HT #"^(A0)"] LWS*: [some LWS] LWS?: [any LWS] LF: #"^(0A)" WS: charset reduce [SP HT newline CR LF] WS*: [some WS] WS?: [any WS] Sign^: [#"+" | #"-"] Integer^: [opt Sign^ Digits] Decimal^: [opt Sign^ Digits #"." Digits] Tuple^: [1 3 Digit some [#"." 1 3 Digit]] Graphic: charset [ #"^(21)" - #"^(7E)" #"^(80)" #"^(82)" - #"^(8C)" #"^(8E)" #"^(91)" - #"^(9C)" #"^(9E)" - #"^(9F)" #"^(A1)" - #"^(FF)" ] Printable: union Graphic charset reduce [SP #"^(A0)"] Integer^: Digits Decimal^: [Digits #"." Digits] Pair^: [Digits #"x" Digits] Money^: [0 3 Alpha #"$" Digits #"." 2 Digit] Tag^: [#"<" thru #">"] ; A Windows file name cannot contain any of these characters: Forbidden: charset {\/:*?"<>|} Line_End: [newline | end] Blank_Line: [LWS? newline] Blank_Lines: [any Blank_Line] make object! [ Zone: [Sign^ 1 2 Digit #":" 2 Digit] set 'Time^ [1 2 Digit #":" 1 2 Digit opt [#":" 1 2 Digit]] Long-Months: remove map Rebol/locale/Months func [Month [string!]] [ reduce ['| copy Month] ] Short-Months: remove map Rebol/locale/Months func [Month [string!]] [ reduce ['| copy/part Month 3] ] Month: [1 2 Digit | Long-Months | Short-Months] Separator: charset "/-" Day: [1 2 Digit] set 'Date^ [ [ [Day Separator Month Separator [4 Digit | 2 Digit]] | [4 Digit Separator Month Separator Day] ] opt [#"/" [Time^ opt Zone]] ] ] make object! [ Permitted: exclude Printable Forbidden Filename: [some Permitted] Folder: [Filename #"/"] Relative_Path: [some Folder] Absolute_Path: [#"/" any Relative_Path] set 'File^ [ [Absolute_Path opt Filename] | [Relative_Path opt Filename] | Filename ] ] make object! [ Permitted: exclude Printable Forbidden Drive^: [Alpha #":"] Filename^: [some Permitted] Folder^: [Filename^ #"\"] Relative_Path^: [some Folder^] Absolute_Path^: [#"\" any Relative_Path^] set 'Local_File^ [Drive^ Absolute_Path^ opt Filename^] ] make object! [ Char: union AlphaDigit charset "-_~+*'" Escape: [#"%" Hex Hex] Chars: [some [Char | Escape]] User: [some [Char | Escape | #"."]] Domain-Label: Chars Domain: [Domain-Label any [#"." Domain-Label]] IP-Address: [Digits #"." Digits #"." Digits #"." Digits] Host: [Domain | IP-Address] set 'eMail^ [User #"@" Host] Pass: Chars Port: [1 4 Digit] User-Pass-Host-Port: [ [User #":" Pass #"@" Host #":" Port] | [User #":" Pass #"@" Host] | [User #":" Host] | [Host #":" Port] | [Host] ] Fragment: [#"#" Chars] Query: [ #"?" [ any [opt #"&" Chars #"=" [Chars | Absolute-Folder] | Chars | Absolute-Folder opt [#":" Port]] ] ] Fragment_Or_Query: [Fragment | Query] Extension: [#"." 1 4 Char] File: Chars Folder: [some ["../" | "./" | [File opt [#"." Chars] #"/"]]] set 'URI_Relative-Folder Relative-Folder: [ Folder opt File opt Extension opt Fragment_Or_Query | opt Folder File opt Extension opt Fragment_Or_Query | opt Folder opt File Extension opt Fragment_Or_Query | opt Folder opt File opt Extension Fragment_Or_Query ] set 'URI_Absolute-Folder Absolute-Folder: [#"/" opt Relative-Folder] Net-Folder: ["//" User-Pass-Host-Port opt [Absolute-Folder]] Scheme: [Alpha some Char] set 'URL^ [Scheme #":" Net-Folder] Local-File: [#"%" [Absolute-Folder | Relative-Folder]] set 'URI^ [eMail^ | URL^ | Local-File] ] ]

 [7/7] from: nitsch-lists:netcologne at: 5-Oct-2003 0:43


is-url?: parse string[ thru "://" to end] the basic idea is: is-url?: parse string[ copy protocol thru "://" copy where-there to end] for specific protocols do without 'thru : is-http:? parse string[ "http://" to end] eventually /all is not needed, but i always mess that up. -Volker Am Samstag, 4. Oktober 2003 20:40 schrieb [SunandaDH--aol--com]:

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