Boost logo

Boost :

Subject: [boost] [xpressive] regex_token_iterator - bug, feature, misunderstanding query?
From: Michael Goldshteyn (mgoldshteyn_at_[hidden])
Date: 2008-12-03 11:50:01


OK, so I want to use the sregex_token_iterator functionality to split a data
string. The data string contains:

/a/b//c/

The delimiter is the forward slash and I do want empty strings. I expect to
get:

{}{a}{b}{}{c}{}

What I actually get is:

{}{a}{b}{}{c}

The empty string after {c}, which I expect because the data string ended in
a forward slash, is missing. What do I have to do to get the empty string
after {c} if the data string ends in a forward slash?

The code is as follows:

---
#include <iostream>
#include <string>
#include <boost/xpressive/xpressive.hpp>
#include <boost/xpressive/regex_token_iterator.hpp>
int main(int argc, char *argv[])
{
  // Split the path
  using namespace boost::xpressive; // For simplicity
  sregex levelSplitter(as_xpr('/'));
  std::string nodePath("/a/b//c/");
  sregex_token_iterator 
begin(nodePath.begin(),nodePath.end(),levelSplitter,-1);
  sregex_token_iterator end;
  for (sregex_token_iterator iCur=begin;iCur!=end;++iCur)
    std::cout << '{' << *iCur << '}';
  std::cout << std::endl;
 return 0;
}
---
Thanks,
Michael Goldshteyn

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk