一些原始代碼做你想要什麼,所以你可以跳過所有的臃腫庫:
var urlJoin:Function = function(base:String, relative:String):String
{
// See if there is already a protocol on this
if (relative.indexOf("://") != -1)
return relative;
// See if this is protocol-relative
if (relative.indexOf("//") == 0)
{
var protocolIndex:int = base.indexOf("://");
return base.substr(0, protocolIndex+1) + relative;
}
// We need to split the domain and the path for the remaining options
var protocolIndexEnd:int = base.indexOf("://") + 3;
if (base.indexOf("/", protocolIndexEnd) == -1) // append slash if passed only http://bla.com
base += "/";
var endDomainIndex:int = base.indexOf("/", protocolIndexEnd);
var domain:String = base.substr(0, endDomainIndex);
var path:String = base.substr(endDomainIndex);
if (path.lastIndexOf("/") != path.length-1) // trim off any ending file name
path = path.substr(0, path.lastIndexOf("/")+1);
// See if this is site-absolute
if (relative.indexOf("/") == 0)
{
return domain + relative;
}
// See if this is document-relative with ../
while (relative.indexOf("../") == 0)
{
relative = relative.substr(3);
if (path.length > 1)
{
var secondToLastSlashIndex:int = path.substr(0, path.length-1).lastIndexOf("/");
path = path.substr(0, secondToLastSlashIndex+1);
}
}
// Finally, slap on whatever ending is left
return domain + path + relative;
};
你可以重寫HTTP://hg.python。 org/cpython/file/2.7/Lib/urlparse.py in AS3;) – Kodiak
您是否正在尋找AS3中的完整python類功能,或者只是描述了基本url和相對url合併的功能? – Mattias
@Mattias我編輯了這個問題。 –