I'm looking for a method to split the following line of text into an array.
Here is some text\r\n"here is another line"\r\nAnd another line
Such that the resultant array is:
Here is some text
\r\n
"
here is another line
"
\r\n
And another line
Note there are essentially two delimeters here, " and \r\n.
I need to do this in C++ and there could be additional delimeters in the future.
Any ideas?
Thanks in advance.
Edit: No, this is not homework.
Here's what I have so far:
const RWCString crLF = "\r\n";
const RWCString doubleQuote = "\"";
RWTValOrderedVector<RWCString> Split(const RWCString &value, const RWCString &specialContent)
{
RWTValOrderedVector<RWCString> result;
unsigned index = 0;
RWCString str = value;
while ( ( index = str.index( specialContent, 0, RWCString::ignoreCase ) ) != RW_NPOS )
{
RWCString line = str(0, index);
result.append(line);
result.append(specialContent);
str = str(index, str.length() - index);
str = str(specialContent.length(), str.length() - specialContent.length());
}
if (str.length() > 0)
{
result.append(str);
}
return result;
}
void replaceSpecialContents(const RWCString &value)
{
RWTValOrderedVector<RWCString> allStrings;
RWTValOrderedVector<RWCString> crLFStrings = Split(value, crLF);
for (unsigned i=0; i<crLFStrings.entries(); i++)
{
RWTValOrderedVector<RWCString> dqStrings = Split(crLFStrings[i], doubleQuote);
if (dqStrings.entries() == 1)
{
allStrings.append(crLFStrings[i]);
}
else
{
for (unsigned j=0; j<dqStrings.entries(); j++)
{
allStrings.append(dqStrings[j]);
}
}
}
}
RWTValOrderedVector: Just wondering, what's unordered vector?RWTValVector<T>which, sadly has restrictions on methods. E.g., there is noappendas the class assumes constant length for the life of the vector. There is areshapeso you can do an append if you work for it.