С++,提振:这是解析字符串,如TCP最快的方法:// ADR:端口/成ADRESS字符串和端口都有一个诠释? [英] С++, boost: which is fastest way to parse string like tcp://adr:port/ into adress string and one int for port?
本文介绍了С++,提振:这是解析字符串,如TCP最快的方法:// ADR:端口/成ADRESS字符串和端口都有一个诠释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我们为std :: string A
与 TCP:// ADR:端口/
如何解析到ADRESS的std ::字符串和端口使用一个INT?
解决方案
无效提取物(标准::字符串常量和放大器; IP,标准::字符串&放大器;地址,标准::字符串&安培;服务)
{
提高::正则表达式E(TCP://(+):(\\\\ D +)/);
提高:: SMATCH什么;
如果(的boost :: regex_match(IP,什么,电子,提振:: match_extra))
{
提高:: SMATCH:迭代它= what.begin();
++它; //跳过第一项..
地址= *它;
++它;
服务= *它;
}
}
编辑:原因,服务是这里的字符串是,你需要它作为解析字符串! ;)
so we have std::string A
with tcp://adr:port/
How to parse it into adress std::string and one int for port?
解决方案
void extract(std::string const& ip, std::string& address, std::string& service)
{
boost::regex e("tcp://(.+):(\\d+)/");
boost::smatch what;
if(boost::regex_match(ip, what, e, boost::match_extra))
{
boost::smatch::iterator it = what.begin();
++it; // skip the first entry..
address = *it;
++it;
service = *it;
}
}
EDIT: reason service is a string here is that you'll need it as a string for resolver! ;)
这篇关于С++,提振:这是解析字符串,如TCP最快的方法:// ADR:端口/成ADRESS字符串和端口都有一个诠释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文