Added parseUri to util, cleaned up.

This commit is contained in:
Guillermo Rauch
2011-11-27 11:30:28 -08:00
parent edc76f322a
commit 7489fa4378

View File

@@ -1,4 +1,10 @@
/**
* engine.io-client
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
* MIT Licensed
*/
/**
* Inheritance.
*
@@ -55,8 +61,6 @@ util.ua.webkit = 'undefined' != typeof navigator &&
util.ua.gecko = 'undefined' != typeof navigator &&
/gecko/i.test(navigator.userAgent);
// end
/**
* XHR request helper.
*
@@ -87,3 +91,29 @@ util.request = function request (xdomain) {
} catch(e) { }
}
};
/**
* Parses an URI
*
* @author Steven Levithan <stevenlevithan.com> (MIT license)
* @api public
*/
var re = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
var parts = [
'source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host'
, 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor'
];
exports.parseUri = function (str) {
var m = re.exec(str || '')
, uri = {}
, i = 14;
while (i--) {
uri[parts[i]] = m[i] || '';
}
return uri;
};