Boost logo

Boost :

From: CN (cnliou9_at_[hidden])
Date: 2005-11-07 08:47:43


I need to get non-null tokens from std::basic_string deliminated by null
characters. For example, hopefully the following code

string str=string("X;Y\0\0Z\0",7);
typedef tokenizer<boost::escaped_list_separator<char> > Tok;
escaped_list_separator<char> sep(string(),string("\0;",2),string());
Tok tokens(str, sep);
for(Tok::iterator i = tokens.begin();i != tokens.end();++i)
  cout << "<" << *i << ">";

will yield


instead of


An expert told me that changing the tokenizer constructors in BOOST from
char* to std::basic_string should do the job.

The escaped_list_separator is designed to seperated fields for CSV-like
inputs, which allow empty fields. You cannot use this type of separator
here. The default char_separator would do the trick, but the problem is
that it does not allow the null character ('\0') as a separator because
the way the string of separators is passed to its constructor (that is,
const Char*, null-terminated strings). But since the internal
representation is a ::std::basic_string<>, then I wonder why the
type for the constructor is not the same. It would then solve the
//End Quote

Thank you!


-- - Accessible with your email software
                          or over the web

Boost list run by bdawes at, gregod at, cpdaniel at, john at