我有两个字符串,我需要使用 boost::regex
将它们作为一个字符串进行解析。为此,我需要将我的字符串粘附在一些类似 boost::string_ref
的对象中,但不允许进行额外分配。
换句话说,我需要这样的东西。
const char s1[] = "abcd<ht";
const char s2[] = "ml>giuya";
boost::regex e("<[^>]*>");
//this is what i'm looking for
auto glued_string = make_glued_string(s1, sizeof(s1)-1,
s2, sizeof(s2)-1);
boost::regex_iterator<glue_string::iterator>
it(glued_string.begin(), glued_string.end(), e,
boost::match_default | boost::match_partial);
所以问题是有没有合适的库或者我必须自己实现这个?谢谢。
最佳答案
#include <string>
#include <iostream>
#include <boost/range/adaptor/indexed.hpp>
#include <boost/range/join.hpp>
#include <boost/regex.hpp>
const char s1[] = "abcd<ht";
const char s2[] = "ml>giuya";
int main() {
auto glued = boost::range::join(
s1 | boost::adaptors::indexed(0),
s2 | boost::adaptors::indexed(0));
std::cout << "glued: ";
for (auto c : glued)
std::cout << c;
}
关于c++ - 没有第三根弦的胶弦,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25000595/