boost正则库

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/INGNIGHT/article/details/78432785

1.代码

std::string slot_name;
    std::string slot_value;
    std::string place_holder;
    // such as "${sys.city}"
    boost::regex rgx("\\$\\{(\\w+\\.{0,1}\\w*)\\}");
    boost::match_results<std::string::const_iterator> result;
    std::string::const_iterator begin = placeholder_str.begin();
    std::string::const_iterator end = placeholder_str.end();
    *str = placeholder_str;
    while (boost::regex_search(begin, end, result, rgx)) {
        slot_name = result[1];
        place_holder = result[0];
        auto ite = map_slot.find(slot_name);
        if (ite != map_slot.end()) {
            const std::vector<std::string>& slot_values = ite->second;
            std::string slot_value = CommonStrategy::join_string(slot_values, " false);
            *str = boost::algorithm::replace_first_copy(*str, place_holder, slot_value);
        } else {
            *str = boost::algorithm::replace_first_copy(*str, place_holder, "");
        }
        begin = result[0].second;
    }


2.编译


1.g++ hh.cpp -std=c++11 -I /usr/local/include/boost/  -L /usr/local/lib -lboost_regex -o ll
2.LD_LIBRARY_PATH="/usr/local/lib" ./ll


猜你喜欢

转载自blog.csdn.net/INGNIGHT/article/details/78432785