RegExp with a binary data stream [Solved with boost]
-
Within a binary data stream I like to find a regular expression.
@
QByteArray ba = is.readAll ();cout << ba.size() << endl; QRegExp reg ( "\r\n[0-9a-fA-F]{1,2}\r\n" ); QString str = ba; int pos = reg.indexIn ( ba, 100 ); int posalt = 0; cout << str.length() << endl; while ( pos >= 0 ) { QString str = ba.mid ( pos + 2, 2 ); cout << setw ( 6 ) << pos << " " << str.toStdString() << " " << pos - posalt << " " << ba.length() << endl; pos = reg.indexIn ( ba, pos + reg.matchedLength() ); }
@
The pattern is with a carriage return and a linefeed. At next there is a hex number concluded by carriage return and linefeed.
The file read has about 250k and the first pattern is found easily. The next pattern is not found anymore. There is a null character in the stream. The conversion from QByteArray to QString is copying only up to this null character. One can use also the QByteArray in the indexIn call. However, it does a conversion to QString and the result is same. The search is stopping after the first occassion of the pattern.What is the best way to convinence QString to hold the complete 250k and allow the continued search of the pattern?
-
I have switched to boost::regex for that task.
Even so I am not enjoying the complicated interface of the boost::regex implementation, it solved my problem.