本文整理汇总了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;
}
示例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;
}
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
}
}
示例12:
bool
Variable::NameMatches (const RegularExpression& regex) const
{
if (regex.Execute (m_name.AsCString()))
return true;
return m_mangled.NameMatches (regex);
}
示例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(), ®ex_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;
}
示例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, ®ex_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;
}
示例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;
}