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


C++ MatchResult::GetGroupEnd方法代码示例

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


在下文中一共展示了MatchResult::GetGroupEnd方法的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;
}
开发者ID:daiybh,项目名称:UpdateVersion,代码行数:37,代码来源:Commands.cpp

示例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;
}
开发者ID:kempj,项目名称:OpenFOAM-win,代码行数:40,代码来源:regExp.C

示例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 "";
}
开发者ID:LWain83,项目名称:lyricsgrabber2,代码行数:101,代码来源:builtin_providers.cpp


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