|
Boost : |
From: James Curran (JamesCurran_at_[hidden])
Date: 2002-06-12 06:37:14
Out of personal need I've written a TokenizerFunction which might be
worth sharing.
It's designed to parse a collection of name/value pairs (with the key
feature for me being that everything after the first delimiter is the second
field, regardless of delimiters it migth contain). It will always return an
even number of tokens. For example, given the input:
Name:James
File:C:\temp\test.txt
Flag:
then the code
name_value_pair nv(':', '\n'); // == to nv()
boost::tokenizer<name_value_pair > tok(input, nv);
boost::tokenizer<name_value_pair > ::iterator iter = tok.begin();
while (iter != tok.end())
{
cout << '[' << *iter << ']' << "/";
++iter;
cout << '[' << *iter << ']' << endl;
++iter;
}
would print
[Name] \ [James]
[File] \ [C:\temp\test.txt]
[Flag] \ []
The code is at:
http://www.noveltheory.com/boost/namevalueiter.h and
http://www.noveltheory.com/boost/NVtest.cpp
(I used the source for offset_separator as a template, so it should be
grossly off boost standards, but so far I haven't tried to meet them either)
-- Truth, James Curran www.NJTheater.com (Professional) www.NovelTheory.com (Personal)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk