Rejig URL string sniffing to be more robust

* Don't use Apple's URLWithString method, it's flaky
* support for ports in the URL
* support for whitespace in the path (e.g. http://google.com/?q=my search string )
* support for 'localhost' URLs
* Better validation of IP addresses
* Correctly apply the scheme when it doesn't exist in the URL string
* Tidy up the sniffString: method to allow for tests after the URL test (it doesn't necessarily have to be last anymore)

A carry on from the work at #1246