#include "page.h"
Page::Page() {}
/**
* @brief Page::getString
* @param htmlToPhrased
* @return
*/
QString Page::getString(QString &htmlToParse)
{
makeText(htmlToParse);
return this->text;
}
void Page::makeText(QString &html)
{
int index = 0;
index = html.indexOf("
")
{
temp += "\n"; //new row -> new line
i = stitchText(html, temp, i+4);
if(i == -1) //EOF
break;
}
else if (tableTag == "" || tableTag == " | ")
{
temp += "\t"; // new cell -> tab between data
if (html.mid(i, 6) == " | ');
i = stitchText(html, temp, i+1);
}
else
i = stitchText(html, temp, i+4);
if (i == -1) //EOF
break;
}
else if(tableTag == " | ')
i++;
i = stitchText(html, temp, i+1);
}
else if (html.mid(i,(endofTable).length()) == endofTable) //is end of table
{
break;
}
}
}
this->text = temp;
}
int Page::stitchText(QString &from, QString &to, int index)
{
if (from.at(index) == '<')
{
QString bTag = from.mid(index, 3);
if (bTag != "")
return index-1; //go back one step - for the main function to inc i
index += 3;
}
while (from.at(index) != '<' && index < (int)from.length())
{
if (from[index] == '&')
{
//
QString nbspChr = from.mid(index, 6);
if (nbspChr == " ")
{
index += 5;
from.replace(index,1,' ');
}
}
if (endOfString(index,(int) from.length()))
return -1; //EOF
else if (from.at(index) == '<')
return index - 1; //go back one step - for the main function to inc i
if (from.at(index) != '\n') //check the actuall data before continue
to += from.at(index);
index++;
}
return index-1;
}
bool Page::endOfString(int index, int length)
{
if(index < length)
return false;
return true;
}
|