URI Realbasic class

Fork me on GitHub

Download Source(zip) | Documentation | Issue Tracker

This class implements an easy-to-manipulate object for dealing with URIs. URIs are strings like these:

This class ought to work with most of the common variants of the URI scheme. The scheme expected is either:

        SCHEME<://>[USER<:>PASS<@>]HOST[<:>PORT][/PATH/FILE.EXT]<?>[ARG1=1<&>[ARG2=2]][#Fragment]
                                  -OR-
        MAILTO<:>USER<@>HOST<?>[arg1=1<&>[arg2=2]]

HOST is a host name, or IPv4/6 address. IPv6 addresses must be enclosed by square brackets.

mailto: does NOT have a double slash (ie. not mailto://) and is treated as a special case. As you can see, URIs contain a lot of useful information in a fairly elastic format. Not all types of URI accept all the possible formats. mailto: is not technically a URI and is only partly implemented here (the important parts.)

  Dim url As New URI("") 'Pass an empty string for an empty URI
  url.Protocol = "https"
  url.Fragment = "newreports"
  url.FQDN = "crashreports.mycompany.net"
  url.Username = CustomerUserName
  url.Password = CustomerLicenseKey
  url.ServerFile = "/reports/" + reportFile
  url.Arguments.Append("filter=all")
  url.Arguments.Append("hostid=123456789")

The above code might convert back into a string like this:

  https://johncustomer:License1234567@crashreports.mycompany.net/reports/2011.rpt?filter=all&hostid=123456789#newreports

URIs can be manipulated by changing the appropriate property and then converting back to a string:

  Dim URL As New URI("http://www.example.net/foo/bar.bat?Frell=27#Main") 'Create a URI
  URL.FQDN = "www.example.com" 'Change the domain
  URL.Fragment = "" 'Remove the fragment
  ReDim URL.Arguments(-1)  'Remove arguments
  URL.Protocol = "https" 'Change the protocol
  'URL now contains: "https://www.example.com/foo/bar.bat"

This class requires no plugins and doesn't use regular expressions. It should work for all platforms supported by RealStudio.