mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
optimize:move getHostBase method to utils
This commit is contained in:
parent
0759259b76
commit
753f07d3fd
|
@ -147,39 +147,6 @@ using std::string;
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
/// Uses some heuristics to chop off the first domain name from the host name,
|
|
||||||
/// but only if it's not too base. Returns the resulting host name.
|
|
||||||
QString getHostBase( QUrl const & url )
|
|
||||||
{
|
|
||||||
QString host = url.host();
|
|
||||||
|
|
||||||
QStringList domains = host.split( '.' );
|
|
||||||
|
|
||||||
int left = domains.size();
|
|
||||||
|
|
||||||
// Skip last <=3-letter domain name
|
|
||||||
if ( left && domains[ left - 1 ].size() <= 3 )
|
|
||||||
--left;
|
|
||||||
|
|
||||||
// Skip another <=3-letter domain name
|
|
||||||
if ( left && domains[ left - 1 ].size() <= 3 )
|
|
||||||
--left;
|
|
||||||
|
|
||||||
if ( left > 1 )
|
|
||||||
{
|
|
||||||
// We've got something like www.foobar.co.uk -- we can chop off the first
|
|
||||||
// domain
|
|
||||||
|
|
||||||
return host.mid( domains[ 0 ].size() + 1 );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return host;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QNetworkReply * ArticleNetworkAccessManager::createRequest( Operation op,
|
QNetworkReply * ArticleNetworkAccessManager::createRequest( Operation op,
|
||||||
QNetworkRequest const & req,
|
QNetworkRequest const & req,
|
||||||
QIODevice * outgoingData )
|
QIODevice * outgoingData )
|
||||||
|
|
32
utils.hh
32
utils.hh
|
@ -148,4 +148,36 @@ inline QString getWordFromUrl( const QUrl & url )
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
/// Uses some heuristics to chop off the first domain name from the host name,
|
||||||
|
/// but only if it's not too base. Returns the resulting host name.
|
||||||
|
inline QString getHostBase( QUrl const & url )
|
||||||
|
{
|
||||||
|
QString host = url.host();
|
||||||
|
|
||||||
|
QStringList domains = host.split( '.' );
|
||||||
|
|
||||||
|
int left = domains.size();
|
||||||
|
|
||||||
|
// Skip last <=3-letter domain name
|
||||||
|
if ( left && domains[ left - 1 ].size() <= 3 )
|
||||||
|
--left;
|
||||||
|
|
||||||
|
// Skip another <=3-letter domain name
|
||||||
|
if ( left && domains[ left - 1 ].size() <= 3 )
|
||||||
|
--left;
|
||||||
|
|
||||||
|
if ( left > 1 )
|
||||||
|
{
|
||||||
|
// We've got something like www.foobar.co.uk -- we can chop off the first
|
||||||
|
// domain
|
||||||
|
|
||||||
|
return host.mid( domains[ 0 ].size() + 1 );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return host;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif // UTILS_HH
|
#endif // UTILS_HH
|
||||||
|
|
Loading…
Reference in a new issue