根据url提前主机函数

std::string Socket::GetHost(const std::string * url)
{
if (!url) 
return false;


const char* pUrl = url;
if ((pUrl = strstr(pUrl,"http://")) == NULL)
return false;


pUrl += 7;
if (0 == *pUrl)
return false;


const char* host_begin = pUrl;
char* p_host = host;
if ((pUrl = strchr(pUrl,'/')) != NULL)
{
snprintf(p_host,pUrl-host_begin,"%s",host_begin);
p_host[pUrl-host_begin] = 0;
}
else
{
snprintf(p_host,strlen(host_begin),"%s",host_begin);
p_host[strlen(host_begin)] = 0;
}


return true;
}

你可能感兴趣的:(String,socket,null,url)