Boost logo

Boost Users :

From: Keno.Basedow_at_[hidden]
Date: 2004-12-14 08:18:59


Thanks a lot! Works very fine.

---
Keno Basedow
GEDIS GmbH
Sophienblatt 100
D-24114 Kiel
Fon: +49-431-60051-24 (-0)
Fax: +49-431-60051-11
basedow_at_[hidden]
|---------+----------------------------------->
|         |           "John Maddock"          |
|         |           <john_at_[hidden]>|
|         |           Gesendet von:           |
|         |           boost-users-bounces_at_list|
|         |           s.boost.org             |
|         |                                   |
|         |                                   |
|         |           14.12.2004 13:58        |
|         |           Bitte antworten an      |
|         |           boost-users             |
|         |                                   |
|---------+----------------------------------->
  >------------------------------------------------------------------------------------------------------------------------------|
  |                                                                                                                              |
  |       An:       <boost-users_at_[hidden]>                                                                                |
  |       Kopie:                                                                                                                 |
  |       Thema:    Re: [Boost-users] Using zero characters in regular expessions                                                |
  >------------------------------------------------------------------------------------------------------------------------------|
> i try to use the regex library for binary data.
> I tried this code:
>
>      string h("\x81\x05\x00\x48");
>      regex e2("\x81\x05\x00(.)");
>      smatch m;
>      if (regex_match(h, m, e2))
>      {
>            cout << "0. matched=" << (m[0].matched?"true":"false") <<
endl;
>            cout << "0. match length=" << m[0].str().size() << endl;
>            cout << "0. match character=" << m[0].str() << endl;
>            cout << "1. matched=" << (m[1].matched?"true":"false") <<
endl;
>            cout << "1. match length=" << m[1].str().size() << endl;
>            cout << "1. match character=" << m[1].str() << endl;
>      }
The thing is if you pass a const char* to either basic_string or
boost::regex then it will assume that the string is null-terminated, which
as you have found does the wrong thing in this case.  In both cases use the
constructor that takes a string length as well as a pointer:
      string h("\x81\x05\x00\x48", 4);
      regex e2("\x81\x05\x00(.)", 7, regex::perl);
Hope this helps,
John.
_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net