Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. RegExp with a binary data stream [Solved with boost]
Forum Updated to NodeBB v4.3 + New Features

RegExp with a binary data stream [Solved with boost]

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 3.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    koahnig
    wrote on last edited by
    #1

    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?

    Vote the answer(s) that helped you to solve your issue(s)

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      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.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved