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

[REBOL] Re: url or file ?

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"] > == ["http://www.rebol.net" "index.html"] > >> url? first test > == false > >> 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] ] ]