Пример #1
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Answers the question "Are there any matches?" so that if there aren't,
		/// time is not wasted looking for them. To get all the matches, call GetAllResults() next.
		/// </summary>
		/// <param name="arg">The string to apply the pattern match to.</param>
		/// <returns>true if a match was found</returns>
		/// ------------------------------------------------------------------------------------
		public override bool Matches(ITsString arg)
		{
			m_currentMatchRangePair.Reset();
			try
			{
				m_currentMatchRangePair = FindFirstMatch(arg);
			}
			catch (Exception e)
			{
				System.Diagnostics.Debug.WriteLine(e.Message);
			}
			// see VwPattern.cpp STDMETHODIMP VwPattern::FindIn documentation for *.IchMin >= 0
			return m_currentMatchRangePair.IchMin >= 0;
		}
Пример #2
0
		protected MatchRangePair FindNextMatch()
		{
			int ichStart = 0;
			// if we already have a current match, then reset the starting position
			// NOTE: there seems to be a bug(?) in FindIn that prevents us from using IchMin + 1 to find overlapping matches.
			if (m_currentMatchRangePair.IchMin >= 0)
				ichStart = m_currentMatchRangePair.IchLim;
			int ichMin;
			int ichLim;
			m_pattern.FindIn(m_ts, ichStart, m_tssSource.Length, true, out ichMin, out ichLim, null);
			m_currentMatchRangePair = new MatchRangePair(ichMin, ichLim);
			if (CurrentResultDoesMatch())
			{
				// Don't duplicate items in the result list.  See LT-7041.
				int idxLim = m_results.Count - 1;
				if (idxLim < 0 || m_results[idxLim].IchMin != m_currentMatchRangePair.IchMin ||
					m_results[idxLim].IchLim != m_currentMatchRangePair.IchMin)
				{
					m_results.Add(m_currentMatchRangePair);
				}
			}
			return m_currentMatchRangePair;
		}
Пример #3
0
		/// <summary>
		/// Override this method to match additional conditions not handled at the pattern level.
		/// </summary>
		/// <param name="match">The pattern-matched string segment limits to check against
		/// additional matching criteria.</param>
		/// <returns>true if the additional checks succeeded.</returns>
		abstract protected bool CurrentResultDoesMatch(MatchRangePair match);
Пример #4
0
		/// <summary>
		/// Finds the next match satisfying the pattern.
		/// For some odd cases like looking for "$" in a regular expression,
		/// this will return the same range. The calling code must check.
		/// </summary>
		/// <param name="lastMatch">A match that has been reset to start or the last one found.</param>
		/// <returns>Min and Lim of the segment in the string matching the pattern.</returns>
		protected MatchRangePair FindNextPatternMatch(MatchRangePair lastMatch)
		{
			int ichStart = 0;
			// if we already have a current match, then reset the starting position
			// NOTE: there seems to be a bug(?) in FindIn that prevents us from using IchMin + 1 to find overlapping matches.
			if (lastMatch.IchMin >= 0) // see VwPattern.cpp STDMETHODIMP VwPattern::FindIn documentation
				ichStart = lastMatch.IchLim;
			int ichMin;
			int ichLim;
			m_pattern.FindIn(m_ts, ichStart, m_tssSource.Length, true, out ichMin, out ichLim, null);
			return new MatchRangePair(ichMin, ichLim);
		}
Пример #5
0
		/// <summary>
		/// Finds the first match satisfying the abstract method CurrentResultDoesMatch().
		/// </summary>
		/// <param name="tssSource"></param>
		/// <returns>Min and Lim of the segment in the string matching the pattern
		/// and CurrentResultDoesMatch or {return}.IchMin = -1 if nothing was found.</returns>
		protected MatchRangePair FindFirstMatch(ITsString tssSource)
		{
			var mrp = new MatchRangePair();
			mrp.Reset();
			var mrpLast = new MatchRangePair();
			mrpLast.Reset();
			m_textSourceInit.SetString(tssSource);
			m_tssSource = tssSource;
			bool found = false;
			do
			{   // get first/next match and make sure it is not the same segment of the string
				mrp = FindNextPatternMatch(mrpLast);
				if (mrpLast.Equals(mrp))
					break; // it found the same segment again: Prevent cycles, eg, for Reg Exp "$" (LT-7041).
				mrpLast = mrp;
				found = mrp.IchMin >= 0; // see VwPattern.cpp STDMETHODIMP VwPattern::FindIn documentation
			} while (found && !CurrentResultDoesMatch(mrp)); // must match the overridden condition
			return mrp;
		}
Пример #6
0
		protected override bool CurrentResultDoesMatch(MatchRangePair match)
		{
			return match.IchMin >= 0;
		}
Пример #7
0
		protected override bool CurrentResultDoesMatch(MatchRangePair match)
		{
			return match.IchLim == m_tssSource.Length;
		}