本文整理汇总了C++中MatchResult::IsMatched方法的典型用法代码示例。如果您正苦于以下问题:C++ MatchResult::IsMatched方法的具体用法?C++ MatchResult::IsMatched怎么用?C++ MatchResult::IsMatched使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MatchResult
的用法示例。
在下文中一共展示了MatchResult::IsMatched方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SearchKeysInFile
// 仅用来搜索关键字,结果保存在char* resultFile中
void SearchKeysInFile(const char* file,const char * keys,const char * resultFile)
{
// text
//char * text = "12.5, a1.1, 0.123, 178";
// declare
//static CRegexpT <char> regexp("\\b\\d+\\.\\d+");
//char * key=m_Keyword.GetBuffer();
static CRegexpT <char> regexp(keys);
CContext * pContext;
//读文件,分块查找
std::ifstream ifs;
ifs.open(file,ifstream::binary);
ifs.seekg(0,ifstream::beg);
std::ofstream ofs;
ofs.open(resultFile,ofstream::binary);
ofs.clear();
//ofs.seekg(0,ofstream::beg);
char * pBuffer=new char[BLOCK_SIZE];
while(!ifs.eof())
{
ifs.read(pBuffer,BLOCK_SIZE);
//////////////////////////////////////////////////////////////////////////
//分块查找
// prepare
pContext= regexp.PrepareMatch(pBuffer);
// loop
MatchResult result = regexp.Match(pContext);
while( result.IsMatched() )
{
// 写入结果文件
// printf("%.*s\n", result.GetEnd() - result.GetStart(), pBuffer + result.GetStart());
// 先转换,再写入
ofs.write(pBuffer + result.GetStart(),result.GetEnd() - result.GetStart());
ofs<<endl;
ofs<<"——————————————————————"<<endl;
// get next
result = regexp.Match(pContext);
}
}
// 搜索成功结束
ifs.close();
ofs.close();
// release
regexp.ReleaseContext(pContext);
delete[] pBuffer;
}
示例2: test_all_number
int test_all_number( const char *string )
{
//declare
static CRegexpT <char> regexp("\\d+");
//test
MatchResult result = regexp.MatchExact( string );
//matched or not
return result.IsMatched();
}
示例3:
bool Foam::regExp::match(const std::string& str) const
{
bool isExactMatch = false;
if (preg_ && !str.empty())
{
const MatchResult result = preg_->MatchExact(str.c_str());
isExactMatch = (0 < result.IsMatched());
}
return isExactMatch;
}
示例4: regexp
CString CCommands::XApplicationEvents::ReplaceRegexpData( IN CString Data, IN LPCTSTR lpRegexp, IN DWORD dwRegexpType, IN LPCTSTR lpRegexpReplace )
{
CRegexpT <TCHAR> regexp(lpRegexp, dwRegexpType);
CString strRetData;
MatchResult result = regexp.Match(Data);
if (result.IsMatched())
{
TCHAR * cReplace = regexp.Replace(Data, lpRegexpReplace);
strRetData = cReplace;
regexp.ReleaseString(cReplace);
}
return strRetData;
}
示例5: main
int main(int argc, char * argv[])
{
std::ifstream fs("C:\\Lookup\\112.127.141.86.html");
std::string in;
load_file(in, fs);
fs.close();
//static CRegexpT <char> regexp1("\\d+");
static CRegexpT <char> regexp1("target=\\\"_blank\\\"\\>(.+?)\\</a\\>\\</td\\>");
// loop
MatchResult result1 = regexp1.Match(in.c_str());
while( result1.IsMatched() )
{
//GetEnd匹配成功后,获取所匹配到的子字符串的结束位置。如果匹配失败,则返回负值。
//GetStart匹配成功后,获取所匹配到的子字符串的开始位置。如果匹配失败,则返回负值。
printf("%.*s\n", result1.GetEnd() - result1.GetStart(), in.c_str() + result1.GetStart());
// get next
result1 = regexp1.Match(in.c_str(), result1.GetEnd()); //返回匹配结果 MatchResult 对象。
// 通过 MatchResult 对象,可以得知是否匹配成功。如果成功,通过 MatchResult 对象可以获取捕获信息。
}
// text
char * text = "http://www.cppprog.com/2009/0112/48.html";
// declare
static CRegexpT <char> regexp("\\d+");
// loop
MatchResult result = regexp.Match(text);
//IsMatched返回非零值表示匹配成功,返回 0 表示匹配失败。
while( result.IsMatched() )
{
//GetEnd匹配成功后,获取所匹配到的子字符串的结束位置。如果匹配失败,则返回负值。
//GetStart匹配成功后,获取所匹配到的子字符串的开始位置。如果匹配失败,则返回负值。
printf("%.*s\n", result.GetEnd() - result.GetStart(), text + result.GetStart());
// get next
result = regexp.Match(text, result.GetEnd()); //返回匹配结果 MatchResult 对象。
// 通过 MatchResult 对象,可以得知是否匹配成功。如果成功,通过 MatchResult 对象可以获取捕获信息。
}
return 0;
}
示例6: Str_RegExMatch
int Str_RegExMatch( LPCTSTR pPattern, LPCTSTR pText, TCHAR * lastError )
{
try
{
CRegexp expressionformatch(pPattern, NO_FLAG);
MatchResult result = expressionformatch.Match(pText);
if( result.IsMatched() )
return 1;
return 0;
}
catch (std::bad_alloc e)
{
strcpylen(lastError,e.what(),SCRIPT_MAX_LINE_LEN);
CurrentProfileData.Count(PROFILE_STAT_FAULTS, 1);
return -1;
}
catch ( ... )
{
strcpylen(lastError,"Unknown",SCRIPT_MAX_LINE_LEN);
CurrentProfileData.Count(PROFILE_STAT_FAULTS, 1);
return -1;
}
}
示例7: fetcher
pfc::string8 provider_darklyrics::lookup_one(unsigned p_index, const metadb_handle_ptr & p_meta, threaded_process_status & p_status, abort_callback & p_abort)
{
TRACK_CALL_TEXT("provider_darklyrics::lookup_one");
const float threshold = 0.8f;
const pfc::string8 site = "darklyrics.com";
// Regular Expression Class
CRegexpT<char> regexp;
MatchResult match;
// Buffer
pfc::string8 buff;
try
{
// Init fetcher
curl_wrapper_simple fetcher(&m_config_item);
const metadb_handle_ptr & p = p_meta;
if (p.is_empty())
{
return "";
}
pfc::string8_fast artist, title, album, keywords;
file_info_impl info;
p->get_info(info);
// Get count of artists
t_size count = info.meta_get_count_by_name("album");
if (count == 0)
return "";
// Get Album
album = info.meta_get("album", 0);
count = info.meta_get_count_by_name("title");
if (count == 0)
return "";
// Get TITLE
title = info.meta_get("title", 0);
count = info.meta_get_count_by_name("artist");
// Iterate through all artists listed
for (int j = 0; j < count; j++)
{
// Get Artist
artist = info.meta_get("artist", j); //Fetching from HTTP
keywords = artist;
keywords += "+";
keywords += album;
keywords.replace_char(' ', '+');
// Get it now
try
{
fetcher.fetch_googleluck(site, keywords, buff);
}
catch (pfc::exception & e)
{
console_error(e.what());
continue;
}
catch (...)
{
continue;
}
const char * regex_ahref = "<a\\shref=\"#(?P<no>\\d+)\">(?P<text>.+?)</a>";
// expression for extract lyrics
regexp.Compile(regex_ahref, IGNORECASE);
// match
MatchResult result = regexp.Match(buff.get_ptr());
int noGroup = regexp.GetNamedGroupNumber("no");
int textGroup = regexp.GetNamedGroupNumber("text");
int jump_to = 0;
pfc::string8_fast compare = title;
compare.insert_chars(0, ". ");
float good;
float best = 0.0f;
while (result.IsMatched())
{
int gStart = result.GetGroupStart(noGroup);
int gEnd = result.GetGroupEnd(noGroup);
pfc::string8_fast temp(buff.get_ptr() + gStart, gEnd - gStart);
//.........这里部分代码省略.........