/// ------------------------------------------------------------------------------------ /// <summary> /// Verifies the pattern is valid. If user wants to use a regex, this validates the /// regular expression. /// </summary> /// <returns><c>true</c> if regular expression is valid or if we don't use regular /// expressions, <c>false</c> if regEx is invalid.</returns> /// ------------------------------------------------------------------------------------ private bool PatternIsValid() { if (chkUseRegularExpressions.Checked) { IMatcher testMatcher = new RegExpMatcher(m_vwPattern); if (!testMatcher.IsValid()) { DisplayInvalidRegExMessage(testMatcher.ErrorMessage()); return false; } } return true; }
private IMatcher GetMatcher(int ws) { IMatcher matcher = null; SetupSearchPattern(ws); if (m_rbtnUseRegExp.Checked) matcher = new RegExpMatcher(m_vwPattern); else if (m_rbtnWholeItem.Checked) { // See whether we can use the MUCH more efficient ExactLiteralMatcher if (!m_vwPattern.UseRegularExpressions && m_vwPattern.MatchDiacritics && m_vwPattern.MatchOldWritingSystem && m_vwPattern.Pattern.RunCount == 1) { string target = m_vwPattern.Pattern.Text; int nVar; int wsMatch = m_vwPattern.Pattern.get_Properties(0).GetIntPropValues((int) FwTextPropType.ktptWs, out nVar); if (m_vwPattern.MatchCase) return new ExactLiteralMatcher(target, wsMatch); return new ExactCaseInsensitiveLiteralMatcher(target, wsMatch); } matcher = new ExactMatcher(m_vwPattern); } else if (m_rbtnAtEnd.Checked) matcher = new EndMatcher(m_vwPattern); else if (m_rbtnAtStart.Checked) matcher = new BeginMatcher(m_vwPattern); else matcher = new AnywhereMatcher(m_vwPattern); if (!matcher.IsValid()) { if (matcher is RegExpMatcher) ShowRegExpMatcherError(matcher); else MessageBox.Show(this, matcher.ErrorMessage(), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error); } return matcher; }
private IMatcher GetRegExpMatcher(int ws) { SetupSearchPattern(ws); IMatcher matcher = new RegExpMatcher(m_vwPattern); if (!matcher.IsValid()) { ShowRegExpMatcherError(matcher); } return matcher; }