deano
13th September 2009, 11:29
Hi,
I have the situation where I need a user to be able to set a (some) characters to either separate fields or end a line in an input interpreter. Once I have a set of RegExp matches (QStringList), I then write them out. I have added options for the user to set how they want the fields separated and then the lines ended, the code to do it looks something like;
QByteArray result;
if(-1 != regExpMatcher.indexIn(regExpBuffer.constData()))
{
regExpBuffer.clear();
QStringList captures = regExpMatcher.capturedTexts();
int numberOfCaps = captures.size();
if(numberOfCaps > 1)
{
for(int i=1; i < numberOfCaps; i++)
{
result.append(captures.at(i));
if(i != (numberOfCaps-1))
result.append(seperator.toAscii());
}
}
else
result.append(captures.at(0));
result.append(lineEnd.toAscii());
}
My problem is, if a user wants to enter a TAB as the seperator '\t' or some variant of a newline '\r\n'. How do I easily parse their input? What I would LOVE is something similar to the way the RegExps are done, some one character escapes for the common ones \0x00 (or \0xxx) for others. Of course I could write a parser, but surely there is an easy 'QT way' for this?
Any ideas?
I have the situation where I need a user to be able to set a (some) characters to either separate fields or end a line in an input interpreter. Once I have a set of RegExp matches (QStringList), I then write them out. I have added options for the user to set how they want the fields separated and then the lines ended, the code to do it looks something like;
QByteArray result;
if(-1 != regExpMatcher.indexIn(regExpBuffer.constData()))
{
regExpBuffer.clear();
QStringList captures = regExpMatcher.capturedTexts();
int numberOfCaps = captures.size();
if(numberOfCaps > 1)
{
for(int i=1; i < numberOfCaps; i++)
{
result.append(captures.at(i));
if(i != (numberOfCaps-1))
result.append(seperator.toAscii());
}
}
else
result.append(captures.at(0));
result.append(lineEnd.toAscii());
}
My problem is, if a user wants to enter a TAB as the seperator '\t' or some variant of a newline '\r\n'. How do I easily parse their input? What I would LOVE is something similar to the way the RegExps are done, some one character escapes for the common ones \0x00 (or \0xxx) for others. Of course I could write a parser, but surely there is an easy 'QT way' for this?
Any ideas?