| 1 | #include <cassert>
|
|---|
| 2 | #include <cstring> // strlen
|
|---|
| 3 | #include <string>
|
|---|
| 4 | #include <boost/regex.hpp>
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 | int main()
|
|---|
| 8 | {
|
|---|
| 9 | static boost::regex re("^\\s*(\\S+)"); // My RE
|
|---|
| 10 | boost::smatch match;
|
|---|
| 11 | std::string comm = "abcd"; // the input string
|
|---|
| 12 |
|
|---|
| 13 | if(boost::regex_search(comm, match, re)) {
|
|---|
| 14 | comm = match.suffix(); // eat the matched word
|
|---|
| 15 | std::string word(match.str(1)); // get the matched word
|
|---|
| 16 | assert(strlen(word.c_str()) > 0); // ASSERTION FAILS!!!
|
|---|
| 17 | // "word" should be "abcd", gdb output:
|
|---|
| 18 | // (gdb) p word
|
|---|
| 19 | // $1 = "\000bcd"
|
|---|
| 20 | }
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|