使用带有不同参数的 Boost Tokenizer escaped_list_separator
你好,我一直在尝试使用 boost 库 tokenizer 类让 tokenizer 工作。 我在 boost 文档中找到了本教程:
http://www .boost.org/doc/libs/1 _36 _0/libs/tokenizer/escaped _list _separator.htm
问题是我无法获取转义 _list _separator("","",""); 的参数
但如果我修改 boost/tokenizer.hpp 文件,它就可以工作。 但这不是,理想的解决方案是想知道我是否缺少任何东西来将不同的参数放入转义的 _list _separator 中。
我想让它在空格上分割,用 " 和 ' 进行转义,并且在引用的字符串内没有转义字符。
这用于游戏控制台系统中的参数解析系统。
#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 << "\n";
}
}
来自 Visual Studio 2005 的错误是 错误 C2974: 'boost::tokenizer' : 'TokenizerFunc' 的模板参数无效,输入预期的
编辑: 这个问题由费鲁西奥提出,并由彼得·谢克的大家解释。
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 << "\n";
}
}
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试这个:
try this:
您似乎错误地声明了您的分词器类型。
您想要创建一个 boost::tokenizer
boost::tokenizer< boost::escaped_list_separator< 字符> >
带有boost::escaped_list_separator
的类型化对象 char >
分隔符对象作为其 TokenizerFunc。It seems like you're declaring your tokenizer type incorrectly.
You want to make a
boost::tokenizer< boost::escaped_list_separator< char > >
typed object with aboost::escaped_list_separator< char >
separator object as its TokenizerFunc.一个相关但不是答案的问题是,如果用户想在结果中输出双引号,则维基百科 (像这里) 应替换为
(\\\")
字符串,其中\\
表示转义字符,\"
表示引号。 这样输出结果中就会显示引号。以下代码片段是一个示例。
这是典型的输出
A relevant point yet not the answer for this is that if user want to output a double quote in the result, the embedded quote ("") described in the Wikipedia (like here) should be replaced with a string of
(\\\")
, where\\
means a escape char and\"
means the quote mark. In this way, the quote mark will be displayed in the output result.The following code snippet is an example.
This is a typical output for this