summaryrefslogtreecommitdiff
path: root/noncore/net/mailit/textparser.cpp
Side-by-side diff
Diffstat (limited to 'noncore/net/mailit/textparser.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mailit/textparser.cpp404
1 files changed, 202 insertions, 202 deletions
diff --git a/noncore/net/mailit/textparser.cpp b/noncore/net/mailit/textparser.cpp
index 3fa5f6e..e5c9f7c 100644
--- a/noncore/net/mailit/textparser.cpp
+++ b/noncore/net/mailit/textparser.cpp
@@ -19,286 +19,286 @@
**********************************************************************/
#include "textparser.h"
-TextParser::TextParser(QString in, QString lineBreak)
+TextParser::TextParser(const QString &in, const QString &lineBreak)
{
- data = in;
- lineSep = lineBreak;
-
- init();
- createSeparators();
- split();
+ data = in;
+ lineSep = lineBreak;
+
+ init();
+ createSeparators();
+ split();
}
-TextParser::TextParser(QString in, QString lineBreak, QString sep)
+TextParser::TextParser(const QString &in, const QString &lineBreak, const QString &sep)
{
- data = in;
- lineSep = lineBreak;
-
- init();
- separators = sep;
- split();
+ data = in;
+ lineSep = lineBreak;
+
+ init();
+ separators = sep;
+ split();
}
void TextParser::init()
{
- lineCount = 0;
- linePos = 0;
- totalElmCount = 0;
- separatorPos = -1; //not initialized
- wordPos = -1; //not initialized
- sepAtLine = 0;
- sepAtPosElm = -1; //such that nextSep equals 0
- wordAtLine = 0;
- wordAtPosElm = -1; //such that nextWord equals 0
- atLine = 0;
- atPosElm = 0;
+ lineCount = 0;
+ linePos = 0;
+ totalElmCount = 0;
+ separatorPos = -1; //not initialized
+ wordPos = -1; //not initialized
+ sepAtLine = 0;
+ sepAtPosElm = -1; //such that nextSep equals 0
+ wordAtLine = 0;
+ wordAtPosElm = -1; //such that nextWord equals 0
+ atLine = 0;
+ atPosElm = 0;
}
void TextParser::createSeparators()
{
- separators = " @#,.:;<>*/(){}|'?-+=_";
+ separators = " @#,.:;<>*/(){}|'?-+=_";
}
-/* Returns pos of given search criteria, -1 if not found */
-int TextParser::find(QString target, QChar sep, int pos, bool upperCase)
+/* Returns pos of given search criteria, -1 if not found */
+int TextParser::find(const QString &target, QChar sep, int pos, bool upperCase)
{
-
- t_splitElm parsstr;
- QString pString;
-
- int atLine = 0, atPosElm = 0;
-
- getLineReference(pos,&atLine,&atPosElm);
-
- for (int x = pos; x < totalElmCount; x++)
- {
- parsstr=splitDone[atLine].elm[atPosElm++];
-
- if (upperCase)
- {
- pString=parsstr.str.upper();
- target=target.upper();
- }
- else
- {
- pString=parsstr.str;
- }
- if ((pString == target) && (parsstr.separator == sep))
- {
- return x;
- }
- if (atPosElm >= splitDone[atLine].elmCount)
- { //new Line
- atLine++;
- atPosElm = 0;
- }
- }
- return -1;
+
+ t_splitElm parsstr;
+ QString pString, pTarget;
+ pTarget = target;
+ int atLine = 0, atPosElm = 0;
+
+ getLineReference(pos,&atLine,&atPosElm);
+
+ for (int x = pos; x < totalElmCount; x++)
+ {
+ parsstr=splitDone[atLine].elm[atPosElm++];
+
+ if (upperCase)
+ {
+ pString=parsstr.str.upper();
+ pTarget=pTarget.upper();
+ }
+ else
+ {
+ pString=parsstr.str;
+ }
+ if ((pString == pTarget) && (parsstr.separator == sep))
+ {
+ return x;
+ }
+ if (atPosElm >= splitDone[atLine].elmCount)
+ { //new Line
+ atLine++;
+ atPosElm = 0;
+ }
+ }
+ return -1;
}
int TextParser::elmCount()
{
- return totalElmCount;
+ return totalElmCount;
}
QChar TextParser::separatorAt(int pos)
{
- if (getLineReference(pos, &sepAtLine, &sepAtPosElm) == -1)
- return QChar::null;
-
- separatorPos = pos;
- return splitDone[sepAtLine].elm[sepAtPosElm].separator;
+ if (getLineReference(pos, &sepAtLine, &sepAtPosElm) == -1)
+ return QChar::null;
+
+ separatorPos = pos;
+ return splitDone[sepAtLine].elm[sepAtPosElm].separator;
}
QChar TextParser::nextSeparator()
{
- sepAtPosElm++;
- if (splitDone[sepAtLine].elmCount <= sepAtPosElm) {
- sepAtLine++;
- sepAtPosElm = 0;
- }
-
- separatorPos++;
- return splitDone[sepAtLine].elm[sepAtPosElm].separator;
+ sepAtPosElm++;
+ if (splitDone[sepAtLine].elmCount <= sepAtPosElm) {
+ sepAtLine++;
+ sepAtPosElm = 0;
+ }
+
+ separatorPos++;
+ return splitDone[sepAtLine].elm[sepAtPosElm].separator;
}
bool TextParser::hasNextSeparator()
{
- return ((separatorPos+1) < totalElmCount);
+ return ((separatorPos+1) < totalElmCount);
}
QString TextParser::wordAt(int pos)
{
- if (getLineReference(pos, &wordAtLine, &wordAtPosElm) == -1)
- return NULL;
-
- wordPos = pos;
- return splitDone[wordAtLine].elm[wordAtPosElm].str;
+ if (getLineReference(pos, &wordAtLine, &wordAtPosElm) == -1)
+ return NULL;
+
+ wordPos = pos;
+ return splitDone[wordAtLine].elm[wordAtPosElm].str;
}
QString TextParser::nextWord()
{
- wordAtPosElm++;
- if (splitDone[wordAtLine].elmCount <= wordAtPosElm) {
- wordAtLine++;
- wordAtPosElm = 0;
- }
-
- wordPos++;
- return splitDone[wordAtLine].elm[wordAtPosElm].str;
+ wordAtPosElm++;
+ if (splitDone[wordAtLine].elmCount <= wordAtPosElm) {
+ wordAtLine++;
+ wordAtPosElm = 0;
+ }
+
+ wordPos++;
+ return splitDone[wordAtLine].elm[wordAtPosElm].str;
}
bool TextParser::hasNextWord()
{
- return ((wordPos + 1) < totalElmCount);
+ return ((wordPos + 1) < totalElmCount);
}
QString TextParser::getString(int *pos, QChar stop, bool lineEnd = false)
{
- QString returnStr = wordAt(*pos);
- QChar chr = separatorAt(*pos);
- QString s;
-
- if (returnStr == "")
- return "";
- if (chr == stop)
- return returnStr;
-
- if (!lineEnd) {
- while ((chr != stop) && hasNextWord()) {
- returnStr.append(chr);
- returnStr += nextWord();
- chr = nextSeparator();
- }
- } else { //copy from pos to end of line
- getLineReference(*pos, &atLine, &atPosElm);
- returnStr = "";
- while (atPosElm < splitDone[atLine].elmCount) {
- if (splitDone[atLine].elm[atPosElm].str != "") {
- returnStr += splitDone[atLine].elm[atPosElm].str;
- }
- chr = splitDone[atLine].elm[atPosElm].separator;
- if (!chr.isNull() && (int) chr != 0) {
- returnStr.append(splitDone[atLine].elm[atPosElm].separator);
- }
- atPosElm++;
- }
- }
-
- *pos = wordPos;
- return returnStr;
+ QString returnStr = wordAt(*pos);
+ QChar chr = separatorAt(*pos);
+ QString s;
+
+ if (returnStr == "")
+ return "";
+ if (chr == stop)
+ return returnStr;
+
+ if (!lineEnd) {
+ while ((chr != stop) && hasNextWord()) {
+ returnStr.append(chr);
+ returnStr += nextWord();
+ chr = nextSeparator();
+ }
+ } else { //copy from pos to end of line
+ getLineReference(*pos, &atLine, &atPosElm);
+ returnStr = "";
+ while (atPosElm < splitDone[atLine].elmCount) {
+ if (splitDone[atLine].elm[atPosElm].str != "") {
+ returnStr += splitDone[atLine].elm[atPosElm].str;
+ }
+ chr = splitDone[atLine].elm[atPosElm].separator;
+ if (!chr.isNull() && (int) chr != 0) {
+ returnStr.append(splitDone[atLine].elm[atPosElm].separator);
+ }
+ atPosElm++;
+ }
+ }
+
+ *pos = wordPos;
+ return returnStr;
}
QString TextParser::getNextLine()
{
- atLine++;
- atPosElm = 0;
- if (atLine < lineCount)
- return splitDone[atLine].str;
- return "";
+ atLine++;
+ atPosElm = 0;
+ if (atLine < lineCount)
+ return splitDone[atLine].str;
+ return "";
}
bool TextParser::hasNextLine()
{
- if (atLine+1 < lineCount)
- return TRUE;;
- return FALSE;
+ if (atLine+1 < lineCount)
+ return TRUE;;
+ return FALSE;
}
int TextParser::endLinePos(int pos)
{
- if ( (getLineReference(pos, &atLine, &atPosElm)) == -1)
- return -1;
-
- return (pos + (splitDone[atLine].elmCount - atPosElm) + 1);
+ if ( (getLineReference(pos, &atLine, &atPosElm)) == -1)
+ return -1;
+
+ return (pos + (splitDone[atLine].elmCount - atPosElm) + 1);
}
int TextParser::getLineReference(int pos, int *line, int *inLinePos)
{
- int currentPos = 0;
-
- for (int x = 0; x < lineCount; x++) {
- if ( currentPos + splitDone[x].elmCount > pos) {
- *line = x;
- *inLinePos = pos - currentPos;
- return 0; //pos found okay
- }
- currentPos += splitDone[x].elmCount;
- }
- return -1; //no reference found
+ int currentPos = 0;
+
+ for (int x = 0; x < lineCount; x++) {
+ if ( currentPos + splitDone[x].elmCount > pos) {
+ *line = x;
+ *inLinePos = pos - currentPos;
+ return 0; //pos found okay
+ }
+ currentPos += splitDone[x].elmCount;
+ }
+ return -1; //no reference found
}
void TextParser::split()
{
- t_splitLine newLine;
+ t_splitLine newLine;
- while ((uint) linePos < data.length()) {
- newLine = nextLine();
- splitDone[lineCount] = splitLine(newLine);
- totalElmCount += splitDone[lineCount].elmCount;
- lineCount++;
- }
+ while ((uint) linePos < data.length()) {
+ newLine = nextLine();
+ splitDone[lineCount] = splitLine(newLine);
+ totalElmCount += splitDone[lineCount].elmCount;
+ lineCount++;
+ }
}
t_splitLine TextParser::splitLine(t_splitLine line)
{
- uint pos = 0;
- uint elmCount = 0;
- t_splitLine tempLine = line;
-
- tempLine.str = line.str.simplifyWhiteSpace();
- tempLine.elm[0].str = "";
- while ( pos < line.str.length() ) {
- if ( isSeparator(tempLine.str[pos]) ) {
- tempLine.elm[elmCount].separator = tempLine.str[pos];
- elmCount++;
- pos++;
- while (tempLine.str[pos] == ' ')
- pos++;
- if (pos > line.str.length())
- elmCount--;
- tempLine.elm[elmCount].str = "";
- } else {
- if (!tempLine.str[pos].isNull())
- tempLine.elm[elmCount].str += tempLine.str[pos];
- pos++;
- }
- }
-
- tempLine.elmCount = elmCount + 1;
- return tempLine;
+ uint pos = 0;
+ uint elmCount = 0;
+ t_splitLine tempLine = line;
+
+ tempLine.str = line.str.simplifyWhiteSpace();
+ tempLine.elm[0].str = "";
+ while ( pos < line.str.length() ) {
+ if ( isSeparator(tempLine.str[pos]) ) {
+ tempLine.elm[elmCount].separator = tempLine.str[pos];
+ elmCount++;
+ pos++;
+ while (tempLine.str[pos] == ' ')
+ pos++;
+ if (pos > line.str.length())
+ elmCount--;
+ tempLine.elm[elmCount].str = "";
+ } else {
+ if (!tempLine.str[pos].isNull())
+ tempLine.elm[elmCount].str += tempLine.str[pos];
+ pos++;
+ }
+ }
+
+ tempLine.elmCount = elmCount + 1;
+ return tempLine;
}
bool TextParser::isSeparator(QChar chr)
{
- for (uint x = 0; x < separators.length(); x++) {
- if (chr == separators[x])
- return true;
- }
- return false;
+ for (uint x = 0; x < separators.length(); x++) {
+ if (chr == separators[x])
+ return true;
+ }
+ return false;
}
t_splitLine TextParser::nextLine()
{
- int newLinePos;
- t_splitLine lineType;
-
- newLinePos = data.find(lineSep, linePos);
-
- lineType.lineType = NewLine;
- lineType.str = "";
-
- if (newLinePos == -1) {
- newLinePos = data.length();
- lineType.lineType = LastLine;
- }
-
- for (int x = linePos; x < newLinePos; x++)
- lineType.str += data[x];
-
- linePos = newLinePos;
- if ((uint) linePos < data.length()) //if not EOF, add length of lineSep
- linePos += lineSep.length();
-
- return lineType;
+ int newLinePos;
+ t_splitLine lineType;
+
+ newLinePos = data.find(lineSep, linePos);
+
+ lineType.lineType = NewLine;
+ lineType.str = "";
+
+ if (newLinePos == -1) {
+ newLinePos = data.length();
+ lineType.lineType = LastLine;
+ }
+
+ for (int x = linePos; x < newLinePos; x++)
+ lineType.str += data[x];
+
+ linePos = newLinePos;
+ if ((uint) linePos < data.length()) //if not EOF, add length of lineSep
+ linePos += lineSep.length();
+
+ return lineType;
}