当前位置: 首页>>代码示例>>C++>>正文


C++ boost::regex方法代码示例

本文整理汇总了C++中boost::regex方法的典型用法代码示例。如果您正苦于以下问题:C++ boost::regex方法的具体用法?C++ boost::regex怎么用?C++ boost::regex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在boost的用法示例。


在下文中一共展示了boost::regex方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: dirpath

bool
Filesystem::get_directory_entries(const std::string& dirname,
                                  std::vector<std::string>& filenames,
                                  bool recursive,
                                  const std::string& filter_regex)
{
    filenames.clear();
    if (dirname.size() && !is_directory(dirname))
        return false;
    filesystem::path dirpath(dirname.size() ? u8path(dirname)
                                            : filesystem::path("."));
    regex re;
    try {
        re = regex(filter_regex);
    } catch (...) {
        return false;
    }

    if (recursive) {
        for (filesystem::recursive_directory_iterator s(dirpath);
             s != filesystem::recursive_directory_iterator(); ++s) {
            std::string file = pathstr(s->path());
            if (!filter_regex.size() || regex_search(file, re))
                filenames.push_back(file);
        }
    } else {
        for (filesystem::directory_iterator s(dirpath);
             s != filesystem::directory_iterator(); ++s) {
            std::string file = pathstr(s->path());
            if (!filter_regex.size() || regex_search(file, re))
                filenames.push_back(file);
        }
    }
    return true;
}
开发者ID:OpenImageIO,项目名称:oiio,代码行数:35,代码来源:filesystem.cpp

示例2: acceptor

void
controller::listen_for_command()
{
    LOG(INFO) << "Listening for commands...";
    boost::system::error_code error;
    asio::streambuf buffer;

    try
    {
        uint16_t port = global::config()->get("controller.port", 3103);
        tcp::acceptor acceptor(this->io_service_,
                               tcp::endpoint(tcp::v4(), port));

        while (true)
        {
            acceptor.accept(controll_socket_);
            while (true)
            {
                asio::read_until(controll_socket_, buffer, regex("\n"), error);
                if (error)
                    break;

                std::istream is(&buffer);
                string line;
                std::getline(is, line);
                process_command(line);
            }
            controll_socket_.close();
        }
    }
    catch (std::exception& e)
    {
        LOG(ERROR) << e.what();
    }
}
开发者ID:khoinguyentran,项目名称:hdb-node,代码行数:35,代码来源:controller.cpp

示例3: unitTest

void Replacement::unitTest() {
    using boost::regex;
    using namespace boost::filesystem;

    sqlite3* db;
//    path dbFileName = initial_path<path>()/"unitTest_Replacement.db3";
//    if (exists(dbFileName))
//        boost::filesystem::remove(dbFileName);
//
//    if(sqlite3_open(dbFileName.file_string().c_str(), &db)) {
    if(sqlite3_open(":memory:", &db)) {
        sqlite3_close(db);
        throw std::runtime_error("could not open database file");
    }
    BOOST_REQUIRE(db!=NULL);
    createTables(db);

    Replacement rpAlpha(db);
    rpAlpha.setRegex(regex("A"));
    rpAlpha.setReplacement("X");
    rpAlpha.setGroupId(4711);
    BOOST_CHECK(rpAlpha.getRegex() == regex("A"));
    BOOST_CHECK(rpAlpha.getReplacement() == "X");
    BOOST_CHECK(rpAlpha.getGroupId() == 4711);

    BOOST_CHECK(rpAlpha.replace("ABC") == "XBC");
    BOOST_CHECK(rpAlpha.replace("ABCEFG") == "XBCEFG");
    BOOST_CHECK(rpAlpha.replace("abcABCCBA") == "abcXBCCBX");

    BOOST_CHECK(rpAlpha.replace("abc") != "XBC");

    BOOST_CHECKPOINT("getRowId");
    BOOST_CHECK(rpAlpha.getRowId() == sqlite3_last_insert_rowid(db));

    Replacement rpBeta(db);
    rpBeta.setRegex(regex("\\."));
    rpBeta.setReplacement(" ");
    BOOST_CHECK(rpBeta.replace("Family.Guy.S06E13.PDTV.XviD-LOL.avi") == "Family Guy S06E13 PDTV XviD-LOL avi");

    BOOST_CHECKPOINT("clean up");
    rpAlpha.remove();
    rpBeta.remove();
    BOOST_CHECK_EQUAL(query("SELECT COUNT(*) FROM replacements", db) , "0");

}
开发者ID:arturh85,项目名称:Renamer.NET,代码行数:45,代码来源:replacement.cpp

示例4: select

//////////////////////////////////////////////////////////////////////////////
/// @brief
/// Populates the selection data from the config
///
/// @param config A reference to the config
//////////////////////////////////////////////////////////////////////////////
void Selector::select( const vector<string> & selection_list )
{
    // If selection list is empty, then nothing default to all selected 
    is_all_selected = ( selection_list.size() == 0 );

    // Clear selections
    regex_selections.clear();

    // Get full, and, and signature flags
    Config & config = Config::get_instance();
    is_full_match = config.get_flag_value(Config::Full_match);
    is_and_match = config.get_flag_value(Config::And);
    is_signature_match = config.get_flag_value(Config::Signature_match);

    // Populate regex selection list
    for (unsigned int i = 0; i < selection_list.size(); i++)
    {
        if ( is_full_match )
        {
            regex_selections.push_back( regex( selection_list[i] ) );
        }
        else
        {  
            regex_selections.push_back( regex( ".*" + selection_list[i] + ".*" ) );
        }
    }

#ifdef DEBUGFLAG
    // Verbose for debugging 
    if ( config.get_flag_value(Config::Debug) )
    {
        cerr << "Selected Elements = { ";
        for ( unsigned int i = 0; i < regex_selections.size(); i++ )
        {
            cerr << regex_selections[i] << " ";
        }

        cerr << "}\nSelect: full_match = " << is_full_match
             << "\nSelect: and_match = " << is_and_match
             << "\nSelect: signature_match = " << is_signature_match << "\n";        
    }
#endif

} // End of Selector::select( ... )
开发者ID:mavak,项目名称:trucov,代码行数:50,代码来源:selector.cpp

示例5: regex

bool CForbiddenPro::parse_condition_regex(const string& query, const vector<string>& condition_regex)const {

    for (size_t i = 0; i < condition_regex.size(); i++) {
        boost::regex regex(condition_regex[i].c_str());
        if (regex_search(query, regex)) {
            return true;
        }
    }
    return false;
}
开发者ID:xunyuw,项目名称:iFlyQA,代码行数:10,代码来源:forbidden_pro.cpp

示例6: translate_token

BamConfigEntry::Field BamConfigEntry::translate_token(std::string const& tok) {
    // The point of all the original legacy parsing code was to do something
    // close to the original regular expressions in the perl version of
    // breakdancer. For now, we'll just map hits on those original regexes
    // to standard field names that we define. Ultimately, we want to
    // replace this config file format anyway, so there isn't much use
    // in doing something extremely fancy.
    //
    // Defining a config file format is not really the place to allow this level
    // of flexibility. This code should not be carried forward to any new config
    // format that gets developed.
    using boost::regex;
    static flat_map<regex, Field> tok_map = map_list_of
        (regex("map$", regex::icase), BAM_FILE)
        (regex("lib\\w*$", regex::icase), LIBRARY_NAME)
        (regex("group$", regex::icase), READ_GROUP)
        (regex("mean\\w*$", regex::icase), INSERT_SIZE_MEAN)
        (regex("std\\w*$", regex::icase), INSERT_SIZE_STDDEV)
        (regex("readlen\\w*$", regex::icase), READ_LENGTH)
        (regex("upp\\w*$", regex::icase), INSERT_SIZE_UPPER_CUTOFF)
        (regex("low\\w*$", regex::icase), INSERT_SIZE_LOWER_CUTOFF)
        (regex("map\\w*qual\\w*$", regex::icase), MIN_MAP_QUAL)
        (regex("samp\\w*$", regex::icase), SAMPLE_NAME)
        ;

    typedef flat_map<regex, Field>::const_iterator TIter;
    for (TIter iter = tok_map.begin(); iter != tok_map.end(); ++iter) {
        regex const& re = iter->first;
        boost::smatch match;
        // Note: the original perl version didn't force tokens to begin at
        // any particular point, i.e., they could be prefixed. We will
        // retain that behavior for now
        if (boost::regex_search(tok, match, re))
            return iter->second;
    }

    return UNKNOWN;
}
开发者ID:BIGLabHYU,项目名称:breakdancer,代码行数:38,代码来源:BamConfigEntry.cpp

示例7: regex

bool CForbiddenPro::parse_condition_regex(const string& query, 
        const vector<string>& condition_regex, string& forbidden_word)const {

	std::string tmp_query = query;
	// toUpper
	std::transform(tmp_query.begin(), tmp_query.end(), tmp_query.begin(), ::toupper);

    for (size_t i = 0; i < condition_regex.size(); i++) {
        boost::regex regex(condition_regex[i].c_str());
        if (regex_search(tmp_query, regex)) {
            forbidden_word = condition_regex[i];
            return true;
        }
    }
    return false;
}
开发者ID:xunyuw,项目名称:iFlyQA,代码行数:16,代码来源:forbidden_pro.cpp

示例8: buildFromString

void Persona::buildFromString(std::string const & str) {
    std::vector<std::string> strVec(8);
    split_regex(strVec, str, regex("###"));
    this->buildFromStringVector(strVec);
}
开发者ID:codistmonk,项目名称:burdenofproof,代码行数:5,代码来源:Persona.cpp

示例9: unitTest

void InputRule::unitTest() {
    BOOST_CHECK(true);

    sqlite3* db;

//    // test Ruleset class
//    path dbFileName = initial_path<path>()/"unitTest_InputRule.db3";
//
//    if (exists(dbFileName))
//        boost::filesystem::remove(dbFileName);
//
//    if(sqlite3_open(dbFileName.file_string().c_str(), &db)) {
    if(sqlite3_open(":memory:", &db)) {
        sqlite3_close(db);
        throw std::runtime_error("could not open database file");
    }
    BOOST_REQUIRE(db!=NULL);

    BOOST_CHECKPOINT("create Tables");
    InputRule::createTables(db);
    Replacement::createTables(db);
    Replacements::createTables(db);
    Gem::createTables(db);

    BOOST_CHECKPOINT("InputRule constructor(regex)");
    InputRule ruleAlpha(db, regex("(.*)\\.avi"), -1);
    InputRule ruleBeta(db, regex("(.*)\\.mpg"), -1);
    InputRule ruleGamma(db, regex("(.*)\\.jpg"), -1);
    ruleAlpha.updateGems("$fileName$");
    ruleBeta.updateGems("$fileName$");
    ruleGamma.updateGems("$fileName$");
    BOOST_CHECK(ruleAlpha.getGems().size() == 1);
    BOOST_CHECK(ruleBeta.getGems().size() == 1);
    BOOST_CHECK(ruleGamma.getGems().size() == 1);

    BOOST_CHECKPOINT("get gem");
    BOOST_REQUIRE(ruleAlpha.getGems().size() == 1);
    BOOST_CHECK(ruleAlpha.getGems()[0]->getName() == "fileName");

    BOOST_CHECKPOINT("getRegex(), first time");
    BOOST_CHECK( ruleAlpha.getRegex() == "(.*)\\.avi" );
    BOOST_CHECK( ruleBeta.getRegex() == "(.*)\\.mpg" );
    BOOST_CHECK( ruleGamma.getRegex() == "(.*)\\.jpg" );

    BOOST_CHECKPOINT("getRegex(), second time");
    BOOST_CHECK( ruleAlpha.getRegex() == "(.*)\\.avi" );
    BOOST_CHECK( ruleBeta.getRegex() == "(.*)\\.mpg" );
    BOOST_CHECK( ruleGamma.getRegex() == "(.*)\\.jpg" );


    vector<GemValue> gems;
    BOOST_CHECKPOINT("applyTo()");
    BOOST_CHECK(ruleAlpha.getGems().size() == 1);
    BOOST_CHECK_NO_THROW(ruleAlpha.applyTo("Test.avi", gems, true));
    BOOST_CHECK_NO_THROW(!ruleAlpha.applyTo("Test.mpg", gems, true));
    BOOST_CHECK_NO_THROW(!ruleAlpha.applyTo("Test.jpg", gems, true));

    BOOST_CHECKPOINT("applyTo() 048f97dc");
    BOOST_CHECK(!ruleBeta.applyTo("Test.avi", gems, true));
    BOOST_CHECK(ruleBeta.applyTo("Test.mpg", gems, true));
    BOOST_CHECK(!ruleBeta.applyTo("Test.jpg", gems, true));

    BOOST_CHECKPOINT("applyTo() 092aed5a");
    BOOST_CHECK(!ruleGamma.applyTo("Test.avi", gems, true));
    BOOST_CHECK(!ruleGamma.applyTo("Test.mpg", gems, true));
    BOOST_CHECK(ruleGamma.applyTo("Test.jpg", gems, true));

    BOOST_CHECKPOINT("applyTo() 6d984e20");

    BOOST_CHECK(ruleAlpha.applyTo("Name mit Blank.avi", gems, true));
    BOOST_CHECK(!ruleAlpha.applyTo("Name mit Blank.mpg", gems, true));
    BOOST_CHECK(!ruleAlpha.applyTo("Name mit Blank.jpg", gems, true));

    BOOST_CHECK(!ruleBeta.applyTo("Name mit Blank.avi", gems, true));
    BOOST_CHECK(ruleBeta.applyTo("Name mit Blank.mpg", gems, true));
    BOOST_CHECK(!ruleBeta.applyTo("Name mit Blank.jpg", gems, true));

    BOOST_CHECK(!ruleGamma.applyTo("Name mit Blank.avi", gems, true));
    BOOST_CHECK(!ruleGamma.applyTo("Name mit Blank.mpg", gems, true));
    BOOST_CHECK(ruleGamma.applyTo("Name mit Blank.jpg", gems, true));


    BOOST_CHECKPOINT("setRegex()");
    BOOST_CHECK(ruleAlpha.setRegex("([\\w ]*)\\.avi"));
    BOOST_CHECK(!ruleAlpha.setRegex("([\\w ]*)\\.mpg"));
    BOOST_CHECK(!ruleAlpha.setRegex("Test\\..*"));

    BOOST_CHECK(!ruleBeta.setRegex("([\\w ]*)\\.avi"));
    BOOST_CHECK(ruleBeta.setRegex("([\\w ]*)\\.mpg"));
    BOOST_CHECK(!ruleBeta.setRegex("Test\\..*"));

    BOOST_CHECK(ruleGamma.setRegex("([\\w ]*)\\.jpg"));
    BOOST_CHECK(!ruleGamma.setRegex("([\\w ]*)\\.mpg"));
    BOOST_CHECK(!ruleGamma.setRegex("Test\\..*"));

    BOOST_CHECKPOINT("getRegex(), third time");
    BOOST_CHECK( ruleAlpha.getRegex() == "([\\w ]*)\\.avi" );
    BOOST_CHECK( ruleBeta.getRegex() == "([\\w ]*)\\.mpg" );
    BOOST_CHECK( ruleGamma.getRegex() == "([\\w ]*)\\.jpg" );

//.........这里部分代码省略.........
开发者ID:arturh85,项目名称:Renamer.NET,代码行数:101,代码来源:inputRule.cpp


注:本文中的boost::regex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。