Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
224 views
in Technique[技术] by (71.8m points)

c++ - Using Boost Tokenizer escaped_list_separator with different parameters

Hello i been trying to get a tokenizer to work using the boost library tokenizer class. I found this tutorial on the boost documentation:

http://www.boost.org/doc/libs/1 _36 _0/libs/tokenizer/escaped _list _separator.htm

problem is i cant get the argument's to escaped _list _separator("","","");

but if i modify the boost/tokenizer.hpp file it work's. but that's not and ideal solution was wondering if there's anything i am missing to get diferent arguments into the escaped _list _separator.

i want to make it split on spaces with " and ' for escaping and with no escape character inside the quoted string.

this is used for a argument parsing system in a ingame console system.


include <iostream>
include <boost/tokenizer.hpp>
include <string>

int main()
{
    using namespace std;
    using namespace boost;
    string s = "exec script1 "script argument number one"";
    string separator1("");//dont let quoted arguments escape themselves
    string separator2(" ");//split on spaces
    string separator3(""'");//let it have quoted arguments
    tokenizer<escaped_list_separator<char>(separator1,separator2,separator3)> tok(s);
    for(tokenizer<escaped_list_separator<char>(separator1,separator2,separator3)>::iterator beg=tok.begin(); beg!=tok.end();++beg)
    {
    cout << *beg << "
";
    }
}
the error from visual studio 2005 is error C2974: 'boost::tokenizer' : invalid template argument for 'TokenizerFunc', type expected

EDIT: This question was awnsered by ferrucio and explained by peter thank's everybody.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

try this:

#include <iostream>
#include <boost/tokenizer.hpp>
#include <string>

int main()
{
    using namespace std;
    using namespace boost;
    string s = "exec script1 "script argument number one"";
    string separator1("");//dont let quoted arguments escape themselves
    string separator2(" ");//split on spaces
    string separator3(""'");//let it have quoted arguments

    escaped_list_separator<char> els(separator1,separator2,separator3);
    tokenizer<escaped_list_separator<char>> tok(s, els);

    for(tokenizer<escaped_list_separator<char>>::iterator beg=tok.begin(); beg!=tok.end();++beg)
    {
        cout << *beg << "
";
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...