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


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

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


在下文中一共展示了boost::regex_search方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: coefficients

SvmParams::SvmParams(const std::string &filename) throw (IOException) {

    static regex coefficients("betas: ([0-9 .\\-]+)");
    static regex means("means: ([0-9 .\\-]+)");
    static regex sigmas("sigmas: ([0-9 .\\-]+)");
    static regex bias("bias: ([0-9.\\-]+)");

    ifstream file(filename);
    string current_line;
    cmatch matches;

    if (file.is_open()) {
        do {
            getline(file, current_line);

            if (regex_search(current_line.c_str(), matches, coefficients)) {
                this->coefficients = tokenize(matches[1]);
            } else if (regex_search(current_line.c_str(), matches, means)) {
                this->means = tokenize(matches[1]);
            } else if (regex_search(current_line.c_str(), matches, sigmas)) {
                this->sigmas = tokenize(matches[1]);
            } else if (regex_search(current_line.c_str(), matches, bias)) {
                this->bias = stod(matches[1]);
            }
        } while (current_line.length() > 0);
    } else {
        throw IOException("Couldn't open SVM parameters file.");
    }

    file.close();

}
开发者ID:CardioVascular-Research-Group,项目名称:wvtoolscpp,代码行数:32,代码来源:SvmParams.cpp

示例3: CStrRegExprFindInstance

    CStrRegExprFindInstance(const regex * _regEx, const char * _str, size32_t _from, size32_t _len, bool _keep)
        : regEx(_regEx)
    {
        matched = false;
        sample = NULL;
        try
        {
            if (_keep)
            {
                sample = (char *)rtlMalloc(_len + 1);  //required for findstr
                memcpy(sample, _str + _from, _len);
                sample[_len] = (char)NULL;
                matched = regex_search(sample, subs, *regEx);
            }
            else
            {
                matched = regex_search(_str + _from, _str + _len, subs, *regEx);
            }
        }
        catch (const std::runtime_error & e)
        {
            std::string msg = "Error in regex search: ";
            msg += e.what();
#if defined(_USE_BOOST_REGEX)
            msg += "(regex: ";
            msg += regEx->str();
            msg += ")";
#endif
            rtlFail(0, msg.c_str());
        }

    }
开发者ID:GordonSmith,项目名称:HPCC-Platform,代码行数:32,代码来源:eclregex.cpp

示例4: fromStringOrPath

//==============================================================================
bool Uri::fromStringOrPath(const std::string& _input)
{
  // TODO(JS): Need to check if _input is an "absolute" path?

#ifdef _WIN32

  // Assume that any URI begin with pattern [SINGLE_LETTER]:[/ or \\] is an
  // absolute path.
  static regex windowsPathRegex(R"END([a-zA-Z]:[/|\\])END");
  bool isPath = regex_search(_input, windowsPathRegex, match_continuous);

  if (isPath)
    return fromPath(_input);

#else

  // Assume that any URI without a scheme is a path.
  static regex uriSchemeRegex(R"END(^(([^:/?#]+):))END");
  bool noScheme = !regex_search(_input, uriSchemeRegex, match_continuous);

  if (noScheme)
    return fromPath(_input);

#endif

  return fromString(_input);
}
开发者ID:jpgr87,项目名称:dart,代码行数:28,代码来源:Uri.cpp

示例5: handleMessage

std::string MedicManager::handleMessage(Message* message, std::string regexPattern)
{
    // Read the message out of the packet.
    BString tmp;
    message->getStringUnicode16(tmp);

    // If the string has no length the message is ill-formatted, send the
    // proper format to the client.
    if (!tmp.getLength())
        return "";

    // Convert the string to an ansi string for ease with the regex.
    tmp.convert(BSTRType_ANSI);
    std::string input_string(tmp.getAnsi());

    static const regex pattern(regexPattern);
    smatch result;

    regex_search(input_string, result, pattern);

    // Gather the results of the pattern for validation and use.
    std::string messageType(result[1]);
    if (messageType.length() > 0)
    {
        return messageType;
    }
    return "";
}
开发者ID:ELMERzark,项目名称:mmoserver,代码行数:28,代码来源:MedicManager.cpp

示例6: parse_condition_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

示例7: HandleOAuthCallback

void CrowdinClient::HandleOAuthCallback(const std::string& uri)
{
    if (!m_authCallback)
        return;

    const regex re("access_token=([^&]+)&");
    smatch m;
    if (!regex_search(uri, m, re))
        return;

    SaveAndSetToken(m.str(1));

    m_authCallback();
    m_authCallback = nullptr;
}
开发者ID:benpope82,项目名称:poedit,代码行数:15,代码来源:crowdin_client.cpp

示例8: while

// Reads from fin and returns a std::set with all the found authors, using the
// collection of patterns to find the authors in the stream.
template<typename T> set<string, custom_string_cmp>
get_authors(FILE* fin, const T& collection) {
  set<string, custom_string_cmp> authors;
  char buffer[BUFSIZ];
  while (fgets(buffer, sizeof(buffer), fin)) {
    for (const auto& regex_ : collection) {
      cmatch match;
      if (regex_search(buffer, match, regex_)) {
        string author_name = match.str(1);
        authors.emplace(*strip_in_place(&author_name, " \n\r\t."));
        break;  // Go to next line on first match
      }
    }
  }
  return authors;
}
开发者ID:sruffell,项目名称:asterisk-svn-to-git,代码行数:18,代码来源:log-check.cpp

示例9: parse_condition_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

示例10: main

int main(int argc, char** argv)
{
	Configuration configuration = Configuration(argc, argv);
	
	vector<string>* lines = getLines(*configuration.filename);
	
	// run test
	
	string patternString;
	if(configuration.withOrOperator)
	{
		patternString = "\\d+|\\w+\\d+\\.";
	}
	else
	{
		patternString = "\\d+";
	}
	
	regex pattern(patternString);
	
	int countMatches = 0;
	if(configuration.dryRun)
	{
		for(vector<string>::const_iterator iterator = lines->begin(); iterator != lines->end(); iterator++);
	}
	else
	{
		for(vector<string>::const_iterator iterator = lines->begin(); iterator != lines->end(); iterator++)
		{
			if(regex_search(*iterator, pattern))
			{
				countMatches++;
			}
		}
	}
	
	//cout << countMatches << endl;
	
	delete lines;
	
	//cout << "done" << endl;
	return 0;
}
开发者ID:mathias-nyman,项目名称:tehoLab,代码行数:43,代码来源:Regexp3.cpp

示例11: printMatches

void printMatches(const string & textToSearch, const string & regularExpression) {
	using std::endl;
	using std::cout;
	using boost::regex;
	using boost::regex_search;
	using boost::smatch;

	cout << endl << "Looking for " << regularExpression << " in " << textToSearch << endl;

	string::const_iterator start = textToSearch.begin();
	string::const_iterator end = textToSearch.end();
	regex expression(regularExpression);
	smatch result;

	cout << "\tMatched: ";
	while(regex_search(start,end,result,expression)) {
		cout << result << " ";
		start = result[0].second;
	}
	cout << endl;
}
开发者ID:andrewbolster,项目名称:cppqubmarch2013,代码行数:21,代码来源:main.cpp

示例12: isParaviewHere

/**
Is Paraview at this location.
@return TRUE if determined to be present.
*/
bool isParaviewHere(const QString& location)
{
  using boost::regex;
  using boost::regex_search;

  bool found = false;
  if(!location.isEmpty())
  {
    QDirIterator it(location, QDirIterator::NoIteratorFlags);
    while (it.hasNext())
    {
      it.next();
      QString file =it.fileName();
      regex expression("^(paraview.exe)", boost::regex::icase);
      if(regex_search(file.toStdString(), expression) && it.fileInfo().isFile())
      {
        found = true;
        break;
      }
    }
  }
  return found;
}
开发者ID:jkrueger1,项目名称:mantid,代码行数:27,代码来源:SetUpParaview.cpp

示例13: invalid_argument

GncNumeric::GncNumeric(const std::string& str, bool autoround)
{
    static const std::string numer_frag("(-?[0-9]+)");
    static const std::string denom_frag("([0-9]+)");
    static const std::string hex_frag("(0x[a-f0-9]+)");
    static const std::string slash( "[ \\t]*/[ \\t]*");
    /* The llvm standard C++ library refused to recognize the - in the
     * numer_frag patter with the default ECMAScript syntax so we use the awk
     * syntax.
     */
    static const regex numeral(numer_frag);
    static const regex hex(hex_frag);
    static const regex numeral_rational(numer_frag + slash + denom_frag);
    static const regex hex_rational(hex_frag + slash + hex_frag);
    static const regex hex_over_num(hex_frag + slash + denom_frag);
    static const regex num_over_hex(numer_frag + slash + hex_frag);
    static const regex decimal(numer_frag + "[.,]" + denom_frag);
    smatch m;
/* The order of testing the regexes is from the more restrictve to the less
 * restrictive, as less-restrictive ones will match patterns that would also
 * match the more-restrictive and so invoke the wrong construction.
 */
    if (str.empty())
        throw std::invalid_argument("Can't construct a GncNumeric from an empty string.");
    if (regex_search(str, m, hex_rational))
    {
        GncNumeric n(stoll(m[1].str(), nullptr, 16),
                     stoll(m[2].str(), nullptr, 16));
        m_num = n.num();
        m_den = n.denom();
        return;
    }
    if (regex_search(str, m, hex_over_num))
    {
        GncNumeric n(stoll(m[1].str(), nullptr, 16),
                     stoll(m[2].str()));
        m_num = n.num();
        m_den = n.denom();
        return;
    }
    if (regex_search(str, m, num_over_hex))
    {
        GncNumeric n(stoll(m[1].str()),
                     stoll(m[2].str(), nullptr, 16));
        m_num = n.num();
        m_den = n.denom();
        return;
    }
    if (regex_search(str, m, numeral_rational))
    {
        GncNumeric n(stoll(m[1].str()), stoll(m[2].str()));
        m_num = n.num();
        m_den = n.denom();
        return;
    }
    if (regex_search(str, m, decimal))
    {
        GncInt128 high(stoll(m[1].str()));
        GncInt128 low(stoll(m[2].str()));
        int64_t d = powten(m[2].str().length());
        GncInt128 n = high * d + (high > 0 ? low : -low);
        if (!autoround && n.isBig())
        {
            std::ostringstream errmsg;
            errmsg << "Decimal string " << m[1].str() << "." << m[2].str()
                   << "can't be represented in a GncNumeric without rounding.";
            throw std::overflow_error(errmsg.str());
        }
        while (n.isBig() && d > 0)
        {
            n >>= 1;
            d >>= 1;
        }
        if (n.isBig()) //Shouldn't happen, of course
        {
            std::ostringstream errmsg;
            errmsg << "Decimal string " << m[1].str() << "." << m[2].str()
            << " can't be represented in a GncNumeric, even after reducing denom to " << d;
            throw std::overflow_error(errmsg.str());
        }
        GncNumeric gncn(static_cast<int64_t>(n), d);
        m_num = gncn.num();
        m_den = gncn.denom();
        return;
    }
    if (regex_search(str, m, hex))
    {
        GncNumeric n(stoll(m[1].str(), nullptr, 16),INT64_C(1));
        m_num = n.num();
        m_den = n.denom();
        return;
    }
    if (regex_search(str, m, numeral))
    {
        GncNumeric n(stoll(m[1].str()), INT64_C(1));
        m_num = n.num();
        m_den = n.denom();
        return;
    }
    std::ostringstream errmsg;
//.........这里部分代码省略.........
开发者ID:c-holtermann,项目名称:gnucash,代码行数:101,代码来源:gnc-numeric.cpp

示例14: pattern

bool
Filesystem::parse_pattern(const char* pattern_, int framepadding_override,
                          std::string& normalized_pattern,
                          std::string& framespec)
{
    std::string pattern(pattern_);

    // The pattern is either a range (e.g., "1-15#"), a
    // set of hash marks (e.g. "####"), or a printf-style format
    // string (e.g. "%04d").
#define ONERANGE_SPEC "[0-9]+(-[0-9]+((x|y)-?[0-9]+)?)?"
#define MANYRANGE_SPEC ONERANGE_SPEC "(," ONERANGE_SPEC ")*"
#define SEQUENCE_SPEC                                                          \
    "(" MANYRANGE_SPEC ")?"                                                    \
    "((#|@)+|(%[0-9]*d))"
    static regex sequence_re(SEQUENCE_SPEC);
    // std::cout << "pattern >" << (SEQUENCE_SPEC) << "<\n";
    match_results<std::string::const_iterator> range_match;
    if (!regex_search(pattern, range_match, sequence_re)) {
        // Not a range
        static regex all_views_re("%[Vv]");
        if (regex_search(pattern, all_views_re)) {
            normalized_pattern = pattern;
            return true;
        }

        return false;
    }

    // It's a range. Generate the names by iterating through the numbers.
    std::string thematch(range_match[0].first, range_match[0].second);
    std::string thesequence(range_match[1].first, range_match[1].second);
    std::string thehashes(range_match[9].first, range_match[9].second);
    std::string theformat(range_match[11].first, range_match[11].second);
    std::string prefix(range_match.prefix().first, range_match.prefix().second);
    std::string suffix(range_match.suffix().first, range_match.suffix().second);

    // std::cout << "theformat: " << theformat << "\n";

    std::string fmt;
    if (theformat.length() > 0) {
        fmt = theformat;
    } else {
        // Compute the amount of padding desired
        int padding = 0;
        for (int i = (int)thematch.length() - 1; i >= 0; --i) {
            if (thematch[i] == '#')
                padding += 4;
            else if (thematch[i] == '@')
                padding += 1;
        }
        if (framepadding_override > 0)
            padding = framepadding_override;
        fmt = Strutil::sprintf("%%0%dd", padding);
    }

    // std::cout << "Format: '" << fmt << "'\n";

    normalized_pattern = prefix + fmt + suffix;
    framespec          = thesequence;

    return true;
}
开发者ID:OpenImageIO,项目名称:oiio,代码行数:63,代码来源:filesystem.cpp

示例15: regex_search

////////////////////////////////////////////////////////////////////////////////
// 'isAbbreviation' returns true if the string ends on an
// abbreviation, false otherwise.
////////////////////////////////////////////////////////////////////////////////
bool
isAbbreviation(const StringXML& line) {
  const StringXML abbreviations=
  "(\\d+[-\\.:]+(\\d+[-\\.:]+)+$)|"
   "(\\.\\.+$)|"
   "(_\\s*$)|"
   "(\\w+\\.+(\\w+\\.+)+$)|"
   "(A\\.$)|"
   "(Adm\\.$)|"
   "(Ark\\.$)|"
   "(Apr\\.$)|"
   "(Aug\\.$)|"
   "(B\\.$)|"
   "(C\\.$)|"
   "(Calif\\.$)|"
   "(Capt\\.$)|"
   "(Cmdr\\.$)|"
   "(Co\\.$)|"
   "(Conn\\.$)|"
   "(Cpl\\.$)|"
   "(D\\.$)|"
   "(Dec\\.$)|"
   "(Dr\\.$)|"
   "(E\\.$)|"
   "(F\\.$)|"
   "(F\\.W\\.$)|"
   "(Feb\\.$)|"
   "(Fla\\.$)|"
   "(G\\.$)|"
   "(Ga\\.$)|"
   "(Gen\\.$)|"
   "(Gov\\.$)|"
   "(H\\.$)|"
   "(I\\.$)|"
   "(Iraq-U\\.N\\.$)|"
   "(Inc\\.$)|"
   "(J\\.$)|"
   "(Jan\\.$)|"
   "(Jun\\.$)|"
   "(Jul\\.$)|"
   "(Jr\\.$)|"
   "(K\\.$)|"
   "(Ky\\.$)|"
   "(L\\.$)|"
   "(La\\.$)|"
   "(Lt\\.$)|"
   "(Ltd\\.$)|"
   "(m\\.$)|"
   "(M\\.$)|"
   "(Maj\\.$)|"
   "(Mar\\.$)|"
   "(May\\.$)|"
   "(Md\\.$)|"
   "(Mo\\.$)|"
   "(Mr\\.$)|"
   "(Ms\\.$)|"
   "(Mt\\.$)|"
   "(N\\.$)|"
   "(Neb\\.$)|"
   "(Nev\\.$)|"
   "(No\\.$)|"
   "(\\(No\\.$)|"
   "(Nov\\.$)|"
   "(O\\.$)|"
   "(Oct\\.$)|"
   "(Ore\\.$)|"
   "(P\\.$)|"
   "(Pa\\.$)|"
   "(Q\\.$)|"
   "(R\\.$)|"
   "(Rep\\.$)|"
   "(Rev\\.$)|"
   "(R.I\\.$)|"
   "(S\\.$)|"
   "(SA\\.$)|"
   "(Sen\\.$)|"
   "(Sep\\.$)|"
   "(Sgt\\.$)|"
   "(St\\.$)|"
   "(ST\\.$)|"
   "(T\\.$)|"
   "(Tenn\\.$)|"
   "(U\\.$)|"
   "(V\\.$)|"
   "(Va\\.$)|"
   "(vs\\.$)|"
   "(W\\.$)|"
   "(X\\.$)|"
   "(Y\\.$)|"
   "(Z\\.$)";
  static const regex abbrRegex(abbreviations);
  return regex_search(line, abbrRegex);
}
开发者ID:atancasis,项目名称:AFNER,代码行数:97,代码来源:tokeniser.cpp


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