c++ - 没有第三根弦的胶弦

标签 c++ regex string boost

我有两个字符串,我需要使用 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/

相关文章:

c++ - 只调用其他类成员的类成员?

javascript - Coderbyte 上的字母计数 I JavaScript 挑战

c++ - openAL c++ 库比较两个音频文件

android - NDK 构建错误

java - 我如何使用 Java Regex 将土耳其语字符转换为 UTF-8

regex - 文件系统正则表达式搜索工具

c++ - 将 char * 转换为 LPWSTR

带有 utf-16 代理项对的 javascript 和字符串操作

python - 正则表达式:匹配单词中未知数量字母的更好方法

c++ - 为了在测试中调用析构函数(用于测试),将基类静态转换为派生类有多可怕?