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


C++ RegularExpression类代码示例

本文整理汇总了C++中RegularExpression的典型用法代码示例。如果您正苦于以下问题:C++ RegularExpression类的具体用法?C++ RegularExpression怎么用?C++ RegularExpression使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: name_sref

bool
lldb_private::NameMatches (const char *name, 
                           NameMatchType match_type, 
                           const char *match)
{
    if (match_type == eNameMatchIgnore)
        return true;

    if (name == match)
        return true;

    if (name && match)
    {
        llvm::StringRef name_sref(name);
        llvm::StringRef match_sref(match);
        switch (match_type)
        {
        case eNameMatchIgnore: // This case cannot occur: tested before
            return true;
        case eNameMatchEquals:      return name_sref == match_sref;
        case eNameMatchContains:    return name_sref.find (match_sref) != llvm::StringRef::npos;
        case eNameMatchStartsWith:  return name_sref.startswith (match_sref);
        case eNameMatchEndsWith:    return name_sref.endswith (match_sref);
        case eNameMatchRegularExpression:
            {
                RegularExpression regex (match);
                return regex.Execute (name);
            }
            break;
        }
    }
    return false;
}
开发者ID:Narupol,项目名称:lldb,代码行数:33,代码来源:lldb.cpp

示例2: Activate

void
AddressSanitizerRuntime::ModulesDidLoad(lldb_private::ModuleList &module_list)
{
    if (IsActive())
        return;
    
    if (m_runtime_module) {
        Activate();
        return;
    }
    
    Mutex::Locker modules_locker(module_list.GetMutex());
    const size_t num_modules = module_list.GetSize();
    for (size_t i = 0; i < num_modules; ++i)
    {
        Module *module_pointer = module_list.GetModulePointerAtIndexUnlocked(i);
        const FileSpec & file_spec = module_pointer->GetFileSpec();
        if (! file_spec)
            continue;
        
        static RegularExpression g_asan_runtime_regex("libclang_rt.asan_(.*)_dynamic\\.dylib");
        if (g_asan_runtime_regex.Execute (file_spec.GetFilename().GetCString()) || module_pointer->IsExecutable())
        {
            if (ModuleContainsASanRuntime(module_pointer))
            {
                m_runtime_module = module_pointer->shared_from_this();
                Activate();
                return;
            }
        }
    }
}
开发者ID:CODECOMMUNITY,项目名称:lldb,代码行数:32,代码来源:AddressSanitizerRuntime.cpp

示例3:

   bool
   StringParser::IsValidEmailAddress(const String &sEmailAddress)
   {
      // Original: [^<>" ][email protected][^<>" ]+\.[^<>" ]+
      // 
      // Rule set:
      // - Don't allow spaces anywhere in the address.
      // - Don't allow < or > or " anywhere.
      //

      // Temp fix for moontear [email protected] hard coded invalid domain issue
      // Less strict requires no suffix for localhost or [email protected] regularExpression = "[^<>\" ][email protected][^<>\" ]+"
      String sValidEmailPattern = IniFileSettings::Instance()->GetValidEmailPattern();
      String regularExpression;

      // Override default pattern if one is defined
      if (sValidEmailPattern.empty())
          regularExpression = "[^<>\" ][email protected][^<>\" ]+\\.[^<>\" ]+";
      else
          regularExpression = sValidEmailPattern;

      RegularExpression regexpEvaluator;
      bool result = regexpEvaluator.TestExactMatch(regularExpression, sEmailAddress);
      return result;
   }
开发者ID:Bill48105,项目名称:hmailserver,代码行数:25,代码来源:StringParser.cpp

示例4: xmlTypeRegExp

bool DOMImplementation::isXMLMIMEType(const String& mimeType)
{
    if (mimeType == "text/xml" || mimeType == "application/xml" || mimeType == "text/xsl")
        return true;
    static const char* validChars = "[0-9a-zA-Z_\\-+~!$\\^{}|.%'`#&*]"; // per RFCs: 3023, 2045
    static RegularExpression xmlTypeRegExp(DeprecatedString("^") + validChars + "+/" + validChars + "+\\+xml$");
    if (xmlTypeRegExp.match(mimeType.deprecatedString()) > -1)
        return true;
    return false;
}
开发者ID:jackiekaon,项目名称:owb-mirror,代码行数:10,代码来源:DOMImplementation.cpp

示例5: GetDemangledName

bool
Mangled::NameMatches (const RegularExpression& regex, lldb::LanguageType language) const
{
    if (m_mangled && regex.Execute (m_mangled.AsCString()))
        return true;

    ConstString demangled = GetDemangledName(language);
    if (demangled && regex.Execute (demangled.AsCString()))
        return true;
    return false;
}
开发者ID:beyond2021,项目名称:swift-lldb,代码行数:11,代码来源:Mangled.cpp

示例6: extension

//------------------------------------------------------------------
/// Returns true if the filespec represents an implementation source
/// file (files with a ".c", ".cpp", ".m", ".mm" (many more)
/// extension).
///
/// @return
///     \b true if the filespec represents an implementation source
///     file, \b false otherwise.
//------------------------------------------------------------------
bool
FileSpec::IsSourceImplementationFile () const
{
    ConstString extension (GetFileNameExtension());
    if (extension)
    {
        static RegularExpression g_source_file_regex ("^(c|m|mm|cpp|c\\+\\+|cxx|cc|cp|s|asm|f|f77|f90|f95|f03|for|ftn|fpp|ada|adb|ads)$",
                llvm::Regex::IgnoreCase);
        return g_source_file_regex.Execute (extension.GetCString());
    }
    return false;
}
开发者ID:carlokok,项目名称:lldb,代码行数:21,代码来源:FileSpec.cpp

示例7: g_basename_regex

bool CPlusPlusLanguage::ExtractContextAndIdentifier(
    const char *name, llvm::StringRef &context, llvm::StringRef &identifier) {
  static RegularExpression g_basename_regex(llvm::StringRef(
      "^(([A-Za-z_][A-Za-z_0-9]*::)*)(~?[A-Za-z_~][A-Za-z_0-9]*)$"));
  RegularExpression::Match match(4);
  if (g_basename_regex.Execute(llvm::StringRef::withNullAsEmpty(name),
                               &match)) {
    match.GetMatchAtIndex(name, 1, context);
    match.GetMatchAtIndex(name, 3, identifier);
    return true;
  }
  return false;
}
开发者ID:CodaFi,项目名称:swift-lldb,代码行数:13,代码来源:CPlusPlusLanguage.cpp

示例8:

   bool
   StringParser::IsValidDomainName(const String &sDomainName)
   {
      // Original: ^(\[([0-9]{1,3}\.){3}[0-9]{1,3}\]|(?=.{1,255}$)((?!-|\.)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9])(|\.(?!-|\.)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]){1,126})$
      // Conversion:
      // 1) Replace \ with \\
      // 2) Replace " with \"

      String regularExpression = "^(\\[([0-9]{1,3}\\.){3}[0-9]{1,3}\\]|(?=.{1,255}$)((?!-|\\.)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9])(|\\.(?!-|\\.)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]){1,126})$";

      RegularExpression regexpEvaluator;
      bool result = regexpEvaluator.TestExactMatch(regularExpression, sDomainName);
      return result;
   }
开发者ID:M0ns1gn0r,项目名称:hmailserver,代码行数:14,代码来源:StringParser.cpp

示例9: IsValidBasename

static bool IsValidBasename(const llvm::StringRef &basename) {
  // Check that the basename matches with the following regular expression or is
  // an operator name:
  // "^~?([A-Za-z_][A-Za-z_0-9]*)(<.*>)?$"
  // We are using a hand written implementation because it is significantly more
  // efficient then
  // using the general purpose regular expression library.
  size_t idx = 0;
  if (basename.size() > 0 && basename[0] == '~')
    idx = 1;

  if (basename.size() <= idx)
    return false; // Empty string or "~"

  if (!std::isalpha(basename[idx]) && basename[idx] != '_')
    return false; // First charater (after removing the possible '~'') isn't in
                  // [A-Za-z_]

  // Read all characters matching [A-Za-z_0-9]
  ++idx;
  while (idx < basename.size()) {
    if (!std::isalnum(basename[idx]) && basename[idx] != '_')
      break;
    ++idx;
  }

  // We processed all characters. It is a vaild basename.
  if (idx == basename.size())
    return true;

  // Check for basename with template arguments
  // TODO: Improve the quality of the validation with validating the template
  // arguments
  if (basename[idx] == '<' && basename.back() == '>')
    return true;

  // Check if the basename is a vaild C++ operator name
  if (!basename.startswith("operator"))
    return false;

  static RegularExpression g_operator_regex(
      llvm::StringRef("^(operator)( "
                      "?)([A-Za-z_][A-Za-z_0-9]*|\\(\\)|"
                      "\\[\\]|[\\^<>=!\\/"
                      "*+-]+)(<.*>)?(\\[\\])?$"));
  std::string basename_str(basename.str());
  return g_operator_regex.Execute(basename_str, nullptr);
}
开发者ID:CodaFi,项目名称:swift-lldb,代码行数:48,代码来源:CPlusPlusLanguage.cpp

示例10: getRegularExpressionMatchesByLines

static Vector<pair<int, String> > getRegularExpressionMatchesByLines(const RegularExpression& regex, const String& text)
{
    Vector<pair<int, String> > result;
    if (text.isEmpty())
        return result;

    int lineNumber = 0;
    unsigned start = 0;
    while (start < text.length()) {
        size_t lineEnd = text.find('\n', start);
        if (lineEnd == notFound)
            lineEnd = text.length();
        else
            lineEnd++;

        String line = text.substring(start, lineEnd - start);
        if (line.endsWith("\r\n"))
            line = line.left(line.length() - 2);
        if (line.endsWith('\n'))
            line = line.left(line.length() - 1);

        int matchLength;
        if (regex.match(line, 0, &matchLength) != -1)
            result.append(pair<int, String>(lineNumber, line));

        start = lineEnd;
        lineNumber++;
    }
    return result;
}
开发者ID:conioh,项目名称:os-design,代码行数:30,代码来源:ContentSearchUtils.cpp

示例11: curr_mod_time

void
SourceManager::File::FindLinesMatchingRegex (RegularExpression& regex, uint32_t start_line, uint32_t end_line, std::vector<uint32_t> &match_lines)
{
    TimeValue curr_mod_time (m_file_spec.GetModificationTime());
    if (m_mod_time != curr_mod_time)
    {
        m_mod_time = curr_mod_time;
        m_data_sp = m_file_spec.ReadFileContents ();
        m_offsets.clear();
    }
    
    match_lines.clear();
    
    if (!LineIsValid(start_line) || (end_line != UINT32_MAX && !LineIsValid(end_line)))
        return;
    if (start_line > end_line)
        return;
        
    for (uint32_t line_no = start_line; line_no < end_line; line_no++)
    {
        std::string buffer;
        if (!GetLine (line_no, buffer))
            break;
        if (regex.Execute(buffer.c_str()))
        {
            match_lines.push_back(line_no);
        }
    }
}
开发者ID:filcab,项目名称:lldb,代码行数:29,代码来源:SourceManager.cpp

示例12:

bool
Variable::NameMatches (const RegularExpression& regex) const
{
    if (regex.Execute (m_name.AsCString()))
        return true;
    return m_mangled.NameMatches (regex);
}
开发者ID:CODECOMMUNITY,项目名称:lldb,代码行数:7,代码来源:Variable.cpp

示例13: g_regex

bool
Socket::DecodeHostAndPort(llvm::StringRef host_and_port,
                          std::string &host_str,
                          std::string &port_str,
                          int32_t& port,
                          Error *error_ptr)
{
    static RegularExpression g_regex ("([^:]+):([0-9]+)");
    RegularExpression::Match regex_match(2);
    if (g_regex.Execute (host_and_port.data(), &regex_match))
    {
        if (regex_match.GetMatchAtIndex (host_and_port.data(), 1, host_str) &&
            regex_match.GetMatchAtIndex (host_and_port.data(), 2, port_str))
        {
            bool ok = false;
            port = StringConvert::ToUInt32 (port_str.c_str(), UINT32_MAX, 10, &ok);
            if (ok && port <= UINT16_MAX)
            {
                if (error_ptr)
                    error_ptr->Clear();
                return true;
            }
            // port is too large
            if (error_ptr)
                error_ptr->SetErrorStringWithFormat("invalid host:port specification: '%s'", host_and_port.data());
            return false;
        }
    }

    // If this was unsuccessful, then check if it's simply a signed 32-bit integer, representing
    // a port with an empty host.
    host_str.clear();
    port_str.clear();
    bool ok = false;
    port = StringConvert::ToUInt32 (host_and_port.data(), UINT32_MAX, 10, &ok);
    if (ok && port < UINT16_MAX)
    {
        port_str = host_and_port;
        if (error_ptr)
            error_ptr->Clear();
        return true;
    }

    if (error_ptr)
        error_ptr->SetErrorStringWithFormat("invalid host:port specification: '%s'", host_and_port.data());
    return false;
}
开发者ID:32bitmicro,项目名称:riscv-lldb,代码行数:47,代码来源:Socket.cpp

示例14: g_regex

bool Socket::DecodeHostAndPort(llvm::StringRef host_and_port,
                               std::string &host_str, std::string &port_str,
                               int32_t &port, Status *error_ptr) {
  static RegularExpression g_regex(
      llvm::StringRef("([^:]+|\\[[0-9a-fA-F:]+.*\\]):([0-9]+)"));
  RegularExpression::Match regex_match(2);
  if (g_regex.Execute(host_and_port, &regex_match)) {
    if (regex_match.GetMatchAtIndex(host_and_port.data(), 1, host_str) &&
        regex_match.GetMatchAtIndex(host_and_port.data(), 2, port_str)) {
      // IPv6 addresses are wrapped in [] when specified with ports
      if (host_str.front() == '[' && host_str.back() == ']')
        host_str = host_str.substr(1, host_str.size() - 2);
      bool ok = false;
      port = StringConvert::ToUInt32(port_str.c_str(), UINT32_MAX, 10, &ok);
      if (ok && port <= UINT16_MAX) {
        if (error_ptr)
          error_ptr->Clear();
        return true;
      }
      // port is too large
      if (error_ptr)
        error_ptr->SetErrorStringWithFormat(
            "invalid host:port specification: '%s'", host_and_port.data());
      return false;
    }
  }

  // If this was unsuccessful, then check if it's simply a signed 32-bit
  // integer, representing a port with an empty host.
  host_str.clear();
  port_str.clear();
  bool ok = false;
  port = StringConvert::ToUInt32(host_and_port.data(), UINT32_MAX, 10, &ok);
  if (ok && port < UINT16_MAX) {
    port_str = host_and_port;
    if (error_ptr)
      error_ptr->Clear();
    return true;
  }

  if (error_ptr)
    error_ptr->SetErrorStringWithFormat("invalid host:port specification: '%s'",
                                        host_and_port.data());
  return false;
}
开发者ID:FreeBSDFoundation,项目名称:freebsd,代码行数:45,代码来源:Socket.cpp

示例15: GetLanguage

bool
Variable::NameMatches (const RegularExpression& regex) const
{
    if (regex.Execute (m_name.AsCString()))
        return true;
    if (m_mangled)
        return m_mangled.NameMatches (regex, GetLanguage());
    return false;
}
开发者ID:faxue-msft,项目名称:lldb,代码行数:9,代码来源:Variable.cpp


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