Native(!) URL Parser

By Spoofing on Jul 27, 2010

This is native URL parser :p
without regex, com objects - as always, because written by me. ;>

So... I long time tested it, and all works fine, i think.

var %url =

//echo -a $urlinf(%url).scheme = http
//echo -a $urlinf(%url).ssl = $true (because http port is 443, also ssl always return $true if first right symbols in scheme is "s", like: https ftps ircs)
//echo -a $urlinf(%url).user = username
//echo -a $urlinf(%url).pass = password
//echo -a $urlinf(%url).host =
//echo -a $urlinf(%url).port = 443
//echo -a $urlinf(%url).domain = (for "Host" HTTP header, if non-default 80 port that returns "host:port")
//echo -a $urlinf(%url).path = /page
//echo -a $urlinf(%url).query = ?query
//echo -a $urlinf(%url).fragment = #fragment
//echo -a $urlinf(%url).request (for GET /page?query HTTP header, contains .path and (if it needed) .query props)

By default .query returns ? and .fragment returns #

Also, snippet contains some protect from 'idiots' :), like: - url without /page, but .request returns /?query and .path returns just /. works fine ;)

Also, example, if (irc.* iswm .scheme returns irc. great? yep)..


alias urlinf {
  var %scheme, %ssl = $false, %user, %pass, %address = $1, %port = 0, %request = /, %path = /, %query = ?, %fragment = $(#,)
  if ($pos(%address,://)) {
    var %:// = $v1, %address = $mid(%address,$calc(%:// + 3))
    if (%:// > 1) {
      var %scheme = $gettok($1,1,58)
      if (*s iswm %scheme) var %scheme = $mid(%scheme,1,-1), %ssl = $true
  if ($pos(%address,$(#,))) var %fragment = $mid(%address,$v1), %address = $gettok(%address,1,35)
  if ($pos(%address,/)) {
    var %request = $mid(%address,$v1), %path = %request, %address = $gettok(%address,1,47)
    if ($pos(%path,?)) var %query = $mid(%path,$v1), %path = $gettok(%path,1,63)
  elseif ($pos(%address,?)) var %query = $mid(%address,$v1), %request = $+(/,%query), %address = $gettok(%address,1,63)
  if (*?:?*@* iswm %address) var %user = $gettok(%address,1,58), %pass = $gettok($gettok(%address,1,64),2,58)
  if ($pos(%address,@)) var %address = $gettok(%address,2,64)
  var %host = $gettok(%address,1,58), %port = $gettok(%address,2,58)
  if (www.* iswm %host) var %scheme = http
  elseif (ftp.* iswm %host) var %scheme = ftp
  elseif (irc.* iswm %host) var %scheme = irc
  if (%scheme == http) {
    var %domain = %host
    if (%port == 443) var %ssl = $true
    if (%port == 80) var %domain = %host
    elseif (%port isnum 1-65536) var %domain = $+(%host,:,%port)
  return % [ $+ [ $prop ] ]


Sign in to comment.
Jethro   -  Jul 29, 2010

Firstmate, if my post appears to be ignorant or disparaging (at least to you), I apologize. But my main aim is to tell people to like regex. For your info, I'm still learning about regex, and I know I won't be good at mastering it. Learning is a long, winding road that it's never enough. Again, I'm not trying to get people withdrawn from using other methods, identifiers, or commands made available to simulate regex. They're also good for scripting purposes but will come in a limitation as Hawkee suggested, hence not universal.

Firstmate   -  Jul 29, 2010

Jethro, that's a very ignorant statement. For one, you seem to think everyone will like RegEx. Can't it be possible that he has learned and understood it, but would rather use a different scripting method?

Granted, RegEx is a powerful tool, there's no need to belittle those that don't wish to use it.

Jethro   -  Jul 28, 2010

I concur with Hawkee wholeheartedly. Regex is universal in just about every programming language known to date. By using tokens (other than the ones made solely for certain programming languages) that will only work for MSL and nothing else.

Aucun50, you don't like using regex is because you don't want or bother to understand how it works. Once you get some understanding of it, you'll find yourself fancying it more than you think.

Hawkee   -  Jul 27, 2010

I think it's a good idea to use regex where you can just to become more familiar with it. It's fairly universal across most programming platforms, so it's something you can take from mIRC scripting when it's time to move on.

Aucun50   -  Jul 27, 2010

I personaly don't like using regex if I can use tokens or something else, sometimes it does come in handy.

Jethro   -  Jul 27, 2010

without regexRegex can come in very handy and make a code a lot shorter than it is. It's a nice addition Khaled ever introduced to mIRC.

Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.