so... there we go, second snippet :)
Usage: $furl(TEXT) or $furl(TEXT).is
it simply checks TEXT if TEXT is an URL and if so returns TEXT slightly formatted (as light blue and underlined)
if you want change the output format just go to the last two replaces and edit them
also you can use the property .is which will return $true if TEXT is an URL or $false if not
this identifier is not limited to http:// ftp:// and other standard protocols but complys with http://www.ietf.org/rfc/rfc1738.txt
it's not perfect but quite useful for url hotlinking, an url highlighting or whatever you like, you can also easily add more "unsafe" characters to make it work exacter
feel free to use in private scripts but please keep credits if this code is used in public scripts
; $furl Snippet by Nerd on #geeks.chat @ Quakenet, 2006
alias furl {
var %t 2, %tmax $0, %tokens $1
while (%t <= %tmax) {
var %tokens %tokens $+ , $+ [ [ $ $+ [ [ %t ] ] ] ]
inc %t
}
var %store1 %tokens
tokenize 58 %tokens
if (!$2) {
if (www.?*.??* iswm $1) { var %url.hadno $true | var %url.scheme http | var %url.spec // $+ $1 }
else { return $iif($prop == is,$false,%store1) }
}
else { var %url.scheme $lower($1) | var %url.spec $2 }
var %i 1
while (%i <= $len(%url.scheme)) {
if (($mid(%url.scheme,%i,1) != +) && ($mid(%url.scheme,%i,1) != .) && ($mid(%url.scheme,%i,1) != $chr(44)) && ($mid(%url.scheme,%i,1) != -) && ($mid(%url.scheme,%i,1) !isnum 0-9) && ($asc($lower($mid(%url.scheme,%i,1))) !isnum 97-122)) { return $iif($prop == is,$false,%store1) }
inc %i
}
if ($left(%url.spec,2) != //) { return $iif($prop == is,$false,%store1) }
var %i 1
while (%i <= $len(%url.spec)) {
if ($mid(%url.spec,%i,1) == $chr(37)) {
if (($mid(%url.spec,$calc( %i +1),1) !isnum 0-9) && ($asc($upper($mid(%url.spec,$calc( %i +1),1))) !isnum 65-70)) { return $iif($prop == is,$false,%store1) }
if (($mid(%url.spec,$calc( %i +2),1) !isnum 0-9) && ($asc($upper($mid(%url.spec,$calc( %i +2),1))) !isnum 65-70)) { return $iif($prop == is,$false,%store1) }
}
if ($isunsafe($mid(%url.spec,%i,1))) { return $iif($prop == is,$false,%store1) }
inc %i
}
if ($numtok($replace(%url.spec,$chr(35),C#C),35) > 2) { return $iif($prop == is,$false,%store1) }
if (%url.hadno) { return $iif($prop == is,$true,$chr(15) $+ 11 $+ $right(%url.spec,-2)) $+ $chr(15)) }
else { return $iif($prop == is,$true,$chr(15) $+ 11 $+ %url.scheme $+ : $+ %url.spec $+ $chr(15)) }
}
alias -l isunsafe {
if ($1 == ") { return $true }
if ($1 == <) return $true
if ($1 == >) return $true
if (($1 == $chr(123)) || ($1 == $chr(124)) || ($1 == $chr(125)) || ($1 == $chr(126))) return $true
if (($1 == $chr(91)) || ($1 == $chr(92)) || ($1 == $chr(93)) || ($1 == $chr(94)) || ($1 == $chr(96))) return $true
return $false
}
well unsafe characters should be encoded in the url
i guess every browser WILL encode them when you go browse the address
easiest example is \" \" no, urls with spaces are not valid still if you type them into firefox he will go to the url, replacing \" \" with the encoded \"%20\"
still i can\'t go and say \"http://whateveraddress.com/bla bla.htm\" is a valid url when writing an identifier for it
if i type \"google.com\" in my browser it infact WILL connect me to the site and not say this is no valid url
but then you would have to display almost everything with just a \".\" in it as an url in mirc...
whatever the RFC says there are no special characters allowed (like whatever) but you CAN go and get yourself a domain that includes such characters and will redirect to another url...
i can even type a plain \"blah\" in my firefox addressbar and when i hit enter it will direct me to the first search result for \"blah\", still \"blah\" is no url
my mirc is no browser, it can\'t care about all that when trying to find an url in a text...
i could just go and make a hotlink for \"*\" that would perform \"/url -an $1\" i\'m using firefox so 95% of the times i click a word i would come to a homepage... but that\'s not really reasonable, is it?
i had to set priorities and so this snippet was created
and for the registered protocols... it\'s hard to say what\'s registered and what not... of course ftp http gopher mailto https are registered... but as soon as you install mirc \"irc\" will be a registered protocol for you to, same with ATC or teamspeak or whatever... that\'s why i see every protocol that could exist as a protocol that\'s worth highlighting it
test#test is a valid anchor (not 2 anchors, 1 anchor with # in it), it may be considered obsolette by some browsers, but EVEN firefox considers it as a valid anchor (just tested it).
So you are basically saying that whatever protocol is used, it is a valid url (http1://, httpmrc://, bla://) even though they don\'t exist and no browser can display them?
And I just noticed that you consider sites with the ~ in it NOT a valid url. I think you misunderstood http://www.ietf.org/rfc/rfc1738.txt, UNSAFE != INVALID. Here just visit this site as an example http://www.let.uu.nl/~ctl/ I\'m pretty sure that whatever browser you use, it will open the site. And surely the creators of your browser know better of what url is valid and what url is invalid.
you might want to check out this snippet http://hawkee.com/snippet.php?snippet_id=613 for a better solution to handle such problems.