本文整理汇总了C++中MatchResult::GetGroupStart方法的典型用法代码示例。如果您正苦于以下问题:C++ MatchResult::GetGroupStart方法的具体用法?C++ MatchResult::GetGroupStart怎么用?C++ MatchResult::GetGroupStart使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MatchResult
的用法示例。
在下文中一共展示了MatchResult::GetGroupStart方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: regexp
CString CCommands::XApplicationEvents::GetRegexpData( IN CString Data, IN LPCTSTR lpRegexp, IN DWORD dwRegexpType, LPCTSTR sNamedGroup /*= NULL*/ )
{
CRegexpT <TCHAR> regexp(lpRegexp, dwRegexpType);
CString strRetData;
MatchResult result = regexp.Match(Data);
if (result.IsMatched())
{
int iStart, iEnd;
if (sNamedGroup == NULL)
{
iStart = result.GetGroupStart(1); //得到 捕获组\1
iEnd = result.GetGroupEnd(1);
if (iStart < 0 || iEnd < 0)
{
return "";
}
strRetData = Data.Mid(iStart, iEnd - iStart);
}
else
{
int iIndex;
iIndex = regexp.GetNamedGroupNumber(sNamedGroup);
if (iIndex < 0)
{
return "";
}
iStart = result.GetGroupStart(iIndex);
iEnd = result.GetGroupEnd(iIndex);
strRetData = Data.Mid(iStart, iEnd - iStart);
}
}
return strRetData;
}
示例2:
bool Foam::regExp::match(const string& str, List<string>& groups) const
{
bool isMatch = false;
if (preg_ && !str.empty())
{
const MatchResult results = preg_->MatchExact(str.c_str());
isMatch = (0 < results.IsMatched());
if (isMatch)
{
int const notFound = -1;
int start, end;
const int groupsCount = results.MaxGroupNumber();
groups.setSize(groupsCount);
for (int i = 0; groupsCount > i; ++i)
{
start = results.GetGroupStart(i);
end = results.GetGroupEnd(i);
if ((notFound < start) && (notFound < end))
{
groups[i] = str.substr(start, end - start);
}
else
{
groups[i].clear();
}
}
}
}
if (!isMatch)
{
groups.clear();
}
return isMatch;
}
示例3: fetcher
//.........这里部分代码省略.........
pfc::string8_fast url("http://search.azlyrics.com/search.php?q=");
url += fetcher.quote(artist);
url += "+";
url += fetcher.quote(title);
// Get it now
try
{
fetcher.fetch(url, buff);
}
catch (pfc::exception & e)
{
console_error(e.what());
continue;
}
catch (...)
{
continue;
}
if (buff.get_length() == 0)
continue;
int resultStart = buff.find_first("<b>1.</b>");
int startUrl = buff.find_first("<a href=\"", resultStart) + 9;
int endUrl = buff.find_first("\"", startUrl);
url = pfc::string8_fast(buff.get_ptr()+startUrl, endUrl - startUrl);
// Get it now
try
{
fetcher.fetch(url, buff);
}
catch (pfc::exception & e)
{
console_error(e.what());
continue;
}
catch (...)
{
continue;
}
if (buff.get_length() == 0)
continue;
const char * regex_lyrics = "<!-- END OF RINGTONE 1 -->\\s*?<b>\"(?P<title>.*?)\"</b><br>\\s*?<br>\\s\\s(?P<lyrics>.*?)\\s<br>";
// expression for extract lyrics
regexp.Compile(regex_lyrics, IGNORECASE | SINGLELINE);
int noGroup = regexp.GetNamedGroupNumber("lyrics");
int noTitle = regexp.GetNamedGroupNumber("title");
MatchResult result = regexp.Match(buff.get_ptr());
if (result.IsMatched())
{
int nStart = result.GetGroupStart(noTitle);
int nEnd = result.GetGroupEnd(noTitle);
pfc::string8_fast songTitle(buff.get_ptr() +nStart, nEnd - nStart);
int levDist = LD(title, title.get_length(), songTitle, songTitle.get_length());
float good = 1.0f - ((float)levDist / title.get_length());
if (good < threshold)
return "";
nStart = result.GetGroupStart(noGroup);
nEnd = result.GetGroupEnd(noGroup);
pfc::string8 lyric(buff.get_ptr() + nStart, nEnd - nStart);
convert_html_to_plain(lyric);
if (lyric.get_length() > 0)
{
string_helper::remove_end_linebreaks(lyric);
return lyric;
}
}
}
}
catch (pfc::exception & e)
{
console_error(e.what());
return "";
}
catch (...)
{
return "";
}
return "";
}