Newer
Older
#include <math.h>
#define GOV ".gov"
#define COM ".com"
#define EDU ".edu"
#define ORG ".org"
#define NET ".net"
#define MIL ".mil"
#define INT ".int"
private:
string CompleteUrl,
Service,
Host,
Domain,
Path,
AnchorText;
double Score;
// Assumes url points to static text but
// does not check.
char *temp_CompleteUrl,
*temp_Service,
*temp_Host,
*temp_Domain,
*temp_Path,
*temp_AnchorText,
*temp_pathBuffer;
//intialize anchor text to ""
char *null = new char[2];
strcpy( null, string( "" ).c_str( ) );
temp_AnchorText = null;
char *url = new char[input_url.length( ) + 1];
strcpy( url, input_url.c_str( ) );
temp_pathBuffer = new char[strlen( url ) + 1];
char *f, *t;
for ( t = temp_pathBuffer, f = url; ( *t++ = *f++ ); );
const char Colon = ':', Slash = '/', HashTag = '#', Period = '.';
char *p;
for ( p = temp_pathBuffer; *p && *p != Colon; p++ );
if ( *p )
// Mark the end of the Host.
*p++ = 0;
//char * domainBuffer = new char[ 20 ];
//get the domain:
char *i = temp_Host;
for ( ; *i; i++ )
{
if ( *i == Period )
temp_Domain = i;
}
// Whatever remains is the Path. // need to remove fragments
temp_Path = p;
for ( ; *p && *p != HashTag; p++ );
if ( *p )
// Mark the end of the Path, remove fragments.
*p++ = 0;
CompleteUrl = string(temp_CompleteUrl, strlen(temp_CompleteUrl));
Service = string(temp_Service, strlen(temp_Service));
Host = string(temp_Host, strlen(temp_Host));
Domain = string(temp_Domain, strlen(temp_Domain));
Path = string(temp_Path, strlen(temp_Path));
AnchorText = string(temp_AnchorText, strlen(temp_AnchorText));
pathBuffer = temp_pathBuffer;
}
catch (exception e)
{
cerr << "Error constructing a ParsedUrl from string url "<< endl;
cout << "Complete URL: " << CompleteUrl << endl;
cout << "Service: " << Service << endl;
cout << "Host: " << Host << endl;
cout << "Domain: " << Domain << endl;
cout << "Path: " << Path << endl;
cout << "Score: " << Score << endl;
else if ( strcmp ( Domain.c_str() , COM ) )
Score += 2;
else if ( strcmp ( Domain.c_str() , NET ) )
}
}
std::string getDomain ( )
{
return Domain;
}
std::string getService ( )
{
return Service;
double getScore ( )
{
return Score;
}
void updateScore( double time )
{
pathBuffer = 0;