rendered paste bodyvoid CleanStopwords(string& line, vector<string>& stopwords)
{
long a = 0;
long b = line.find(' ');
string t;
string cleaned;
while(a != -1)
{
if(b != -1)
t = line.substr(a, b-a);
else
t = line.substr(a);
if(!VectorContainsWord(stopwords, t))
{
cleaned += t;
if(b != -1)
cleaned += ' ';
}
if(b == -1)
a = -1;
else
{
a = b+1;
b = line.find(' ', a);
}
}
line = cleaned;
}
bool VectorContainsWord(vector<string>& v, string& s)
{
unsigned long low = 0;
unsigned long high = v.size()-1;
unsigned long pos = (high+low)/2;
long c;
bool bFound = false;
while(low < high-1 && !bFound)
{
c = v[pos].compare(s);
if(c < 0)
{
low = pos;
}
else if(c > 0)
{
high = pos;
}
else
{
bFound = true;
}
pos = (high + low)/2;
}
if(low == high && v[low].compare(s) == 0)
{
bFound = true;
}
else if(low == high-1)
{
if(v[low].compare(s) == 0)
{
bFound = true;
}
else if(v[high].compare(s) == 0)
{
bFound = true;
}
}
return bFound;
}