protected string KeywordColor(string line, string color) { int i; string newstr; string[] keywords = GetKeywords(); IStringMatcher matcher = GetMatcher(); StringBuilder sb = new StringBuilder(line); foreach (string key in keywords) { i = 0; while (0 <= (i = matcher.IndexOf(key, sb, i, sb.Length - i))) { if ((i == 0 || IsKosher(sb[i - 1])) && (key.Length + i == sb.Length || IsKosher(sb[key.Length + i]))) { newstr = "<b><font color=\"" + color + "\">" + key + "</font></b>"; sb = sb.Replace(key, newstr, i, key.Length); i += newstr.Length - 1; } else { i += key.Length; } } } return(sb.ToString()); }
public ErrorFilter(Type exceptionType, IStringMatcher messageMatcher = null, IStringMatcher sourceMatcher = null, bool recurseInnerExceptions=false) : base(messageMatcher,sourceMatcher) { if(exceptionType!=null && !exceptionType.Implements<Exception>()) throw new ArgumentException("The type must be an exception. It was: " + exceptionType, "exceptionType"); _exceptionType = exceptionType; _recurseInnerExceptions = recurseInnerExceptions; }
public void TestParse__NullArgument() { Assert.Throws <ArgumentNullException>(delegate { IStringMatcher matcher = StringMatcher.Parse(null); }); }
public void EmptyPatternMatchTest() { IStringMatcher stringMatcher = CreateStringMatcher(""); Assert.IsTrue(stringMatcher.MatchTo("1")); Assert.IsTrue(stringMatcher.MatchTo(" ")); Assert.IsTrue(stringMatcher.MatchTo("test")); }
/// <summary> /// Matches Int32 values that must not start with '0' ('0' is valid but '0d', where d is any digit, is not). /// A signed integer starts with a '-'. '-0' is valid but '-0d' (where d is any digit) is not. /// If the value is too big for an Int32, it fails. /// </summary> /// <param name="this">This <see cref="IStringMatcher"/>.</param> /// <param name="i">The result integer. 0 on failure.</param> /// <param name="minValue">Optional minimal value.</param> /// <param name="maxValue">Optional maximal value.</param> /// <returns><c>true</c> when matched, <c>false</c> otherwise.</returns> public static bool MatchInt32(this IStringMatcher @this, out int i, int minValue = int.MinValue, int maxValue = int.MaxValue) { i = 0; long savedIndex = @this.StartIndex; long value = 0; bool signed; if (@this.IsEnd) { return(@this.SetError()); } if ((signed = @this.TryMatchChar('-')) && @this.IsEnd) { return(@this.BackwardAddError(savedIndex)); } char c; if (@this.TryMatchChar('0')) { if ([email protected] && (c = @this.Head) >= '0' && c <= '9') { return(@this.BackwardAddError(savedIndex, "0...9")); } return(@this.ClearError()); } unchecked { long iMax = Int32.MaxValue; if (signed) { iMax = iMax + 1; } while ([email protected] && (c = @this.Head) >= '0' && c <= '9') { value = value * 10 + (c - '0'); if (value > iMax) { break; } @this.UncheckedMove(1); } } if (@this.StartIndex > savedIndex) { if (signed) { value = -value; } if (value < minValue || value > maxValue) { return(@this.BackwardAddError(savedIndex, String.Format(CultureInfo.InvariantCulture, "value between {0} and {1}", minValue, maxValue))); } i = (int)value; return(@this.ClearError()); } return(@this.SetError()); }
/// <summary> /// Adds new matcher to the list of contained matchers. /// </summary> /// <param name="matcher">New matcher to add to the list.</param> /// <exception cref="System.ArgumentNullException"><paramref name="matcher" /> is null.</exception> public void Add(IStringMatcher matcher) { if (matcher == null) { throw new ArgumentNullException("Cannot add null reference string matcher."); } _matchers.Add(matcher); }
/// <summary> /// Skips any white spaces or JS comments (//... or /* ... */) and always returns true. /// </summary> /// <param name="this">This <see cref="IStringMatcher"/>.</param> /// <returns>Always true to ease composition.</returns> public static bool SkipWhiteSpacesAndJSComments(this IStringMatcher @this) { @this.MatchWhiteSpaces(0); while (@this.TryMatchJSComment()) { @this.MatchWhiteSpaces(0); } return(true); }
/// <summary> /// TBD /// </summary> /// <param name="exceptionType">TBD</param> /// <param name="messageMatcher">TBD</param> /// <param name="sourceMatcher">TBD</param> /// <param name="recurseInnerExceptions">TBD</param> /// <exception cref="ArgumentException"> /// This exception is thrown when the specified <paramref name="exceptionType"/> does not implement <see cref="Exception"/>. /// </exception> public ErrorFilter(Type exceptionType, IStringMatcher messageMatcher = null, IStringMatcher sourceMatcher = null, bool recurseInnerExceptions = false) : base(messageMatcher, sourceMatcher) { if (exceptionType != null && !exceptionType.Implements <Exception>()) { throw new ArgumentException($"The type must be an exception. It was: {exceptionType}", nameof(exceptionType)); } _exceptionType = exceptionType; _recurseInnerExceptions = recurseInnerExceptions; }
public void EmptyTextMatchTest() { IStringMatcher stringMatcher = CreateStringMatcher("1"); Assert.IsFalse(stringMatcher.MatchTo("")); stringMatcher = CreateStringMatcher(" "); Assert.IsFalse(stringMatcher.MatchTo("")); stringMatcher = CreateStringMatcher("test"); Assert.IsFalse(stringMatcher.MatchTo("")); }
// Main entry point for our application protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Create the speech object to use for speech recognition speech = new Speech(10); this.context = this; // Initialize the command matcher and application matcher to use to parse the user's input commandMatcher = new CommandStringMatcher(this.Assets.Open("dictionary.txt")); // Initialize suggestion manager with default commands suggestionManager = new SuggestionManager(this, commandMatcher.Dictionary); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // get the resources from the layout recordBtn = FindViewById <Button>(Resource.Id.recordBtn); textBox = FindViewById <EditText>(Resource.Id.outputTxt); enterBtn = FindViewById <Button>(Resource.Id.enterBtn); commandHeaderText = FindViewById <TextView>(Resource.Id.cmdPrompt); commandList = FindViewById <ListView>(Resource.Id.cmdList); // Create a button click event for the recordBtn : Nathan recordBtn.Click += delegate { // create the intent and start the activity var voiceIntent = speech.setUpIntent(new Intent()); StartActivityForResult(voiceIntent, 10); }; // coded by Julien enterBtn.Click += delegate { textCommand = textBox.Text; string arguments = commandMatcher.process(textCommand); if (!commandMatcher.KeyWord.Equals("")) { IAction action = Implementations.Action.createAction(context, commandMatcher.KeyWord); action.setArguments(arguments); action.run(); } else { this.ErrorMessage("No commands recognised."); var commands = suggestionManager.pullSpecificCommands(textCommand); this.CommandList(commands); } commandMatcher.KeyWord = ""; }; }
public LineReader(IStringReader StringReader, IStringMatcher DiscardMatcher) { if (DiscardMatcher == null) { throw new ArgumentNullException("DiscardMatcher"); } if (StringReader == null) { throw new ArgumentNullException("StringReader"); } this.discardMatcher = DiscardMatcher; this.stringReader = StringReader; }
public RegexTitleQuickFilterWindow(string title, TreeModel <string> model, IStringMatcher stringMatcher = null) { InitializeComponent(); this.Model = model; SearchTermsComboBox.ItemsSource = SearchTerms; SearchTermsComboBox.SelectedIndex = 0; PostTitleTextBox.Text = title; this.StringMatcher = stringMatcher; FilterTextOrRegex.Loaded += RegexTitleQuickFilterWindow_Loaded; }
public void TestParse__Match__ToString(string matchString, string testSting, bool result) { IStringMatcher matcher = StringMatcher.Parse(matchString); Assert.Equal(result, matcher.Match(testSting)); Assert.Throws <ArgumentNullException>(delegate { matcher.Match(null); }); string otherString = matcher.ToString(); IStringMatcher matcher2 = StringMatcher.Parse(otherString); Assert.Equal(result, matcher2.Match(testSting)); }
public ModuleMatcher(ConfigNode identifierNode) { this.identifierNode = identifierNode ?? throw new ArgumentNullException(nameof(identifierNode)); string moduleNameStr = identifierNode.GetValue("name"); if (moduleNameStr == null) { throw new ArgumentException("node has no name", nameof(identifierNode)); } if (moduleNameStr == "") { throw new ArgumentException("node has empty name", nameof(identifierNode)); } moduleName = StringMatcher.Parse(moduleNameStr); }
private static MatcherModel Map([CanBeNull] IMatcher matcher) { if (matcher == null) { return(null); } IStringMatcher stringMatcher = matcher as IStringMatcher; string[] patterns = stringMatcher != null?stringMatcher.GetPatterns() : new string[0]; return(new MatcherModel { Name = matcher.GetName(), Pattern = patterns.Length == 1 ? patterns.First() : null, Patterns = patterns.Length > 1 ? patterns : null }); }
public LogReader(ILineReader LineReader, IStringMatcher LogPrefixMatcher, IStringMatcher DiscardLogMatcher) { if (LogPrefixMatcher == null) { throw new ArgumentNullException("LogPrefixMatcher"); } if (LineReader == null) { throw new ArgumentNullException("LineReader"); } if (DiscardLogMatcher == null) { throw new ArgumentNullException("DiscardLogMatcher"); } this.lineReader = LineReader; this.logPrefixMatcher = LogPrefixMatcher; this.discardLogMatcher = DiscardLogMatcher; }
/// <summary> /// Matches hexadecimal values: between 1 and 16 0-9, A-F or a-f digits. /// </summary> /// <param name="this">This <see cref="IStringMatcher"/>.</param> /// <param name="value">Resulting value on success.</param> /// <param name="minDigit">Minimal digit count. Must be between 1 and 16 and smaller or equal to <paramref name="maxDigit"/>.</param> /// <param name="maxDigit">Maximal digit count. Must be between 1 and 16.</param> /// <returns><c>true</c> when matched, <c>false</c> otherwise.</returns> public static bool TryMatchHexNumber(this IStringMatcher @this, out ulong value, int minDigit = 1, int maxDigit = 16) { if (minDigit <= 0) { throw new ArgumentException("Must be at least 1 digit.", nameof(minDigit)); } if (maxDigit > 16) { throw new ArgumentException("Must be at most 16 digits.", nameof(maxDigit)); } if (minDigit > maxDigit) { throw new ArgumentException("Must be smaller than maxDigit.", nameof(minDigit)); } value = 0; if (@this.IsEnd) { return(false); } long i = @this.StartIndex; long len = @this.Length; while (--maxDigit >= 0 && --len >= 0) { int cN = ReadHexDigit(@this.Head); if (cN < 0 || cN > 15) { break; } @this.UncheckedMove(1); value <<= 4; value |= (uint)cN; } if ((@this.StartIndex - i) >= minDigit) { return(true); } @this.UncheckedMove(i - @this.StartIndex); return(false); }
/// <summary> /// Tries to match a //.... or /* ... */ comment. /// Proper termination of comment (by a new line or the closing */) is not required: /// a ending /*... is considered valid. /// </summary> /// <param name="this">This <see cref="IStringMatcher"/>.</param> /// <returns>True on success, false if the <see cref="IStringMatcher.Head"/> is not on a /.</returns> public static bool TryMatchJSComment(this IStringMatcher @this) { if ([email protected]('/')) { return(false); } if (@this.TryMatchChar('/')) { while ([email protected] && @this.Head != '\n') { @this.UncheckedMove(1); } if ([email protected]) { @this.UncheckedMove(1); } return(true); } else if (@this.TryMatchChar('*')) { while ([email protected]) { if (@this.Head == '*') { @this.UncheckedMove(1); if (@this.IsEnd || @this.TryMatchChar('/')) { return(true); } } @this.UncheckedMove(1); } return(true); } @this.UncheckedMove(-1); return(false); }
/// <summary> /// TBD /// </summary> /// <param name="messageMatcher">TBD</param> /// <param name="sourceMatcher">TBD</param> public ErrorFilter(IStringMatcher messageMatcher = null, IStringMatcher sourceMatcher = null) : this(null, messageMatcher, sourceMatcher, false) { }
public Action(IStringMatcher commandMatcher, IStringMatcher applicationMatcher, MainActivity activity) { this.commandMatcher = commandMatcher; this.applicationMatcher = applicationMatcher; this.activity = activity; }
private IEventFilterApplier Exception(Type exceptionType, IStringMatcher messageMatcher, IStringMatcher sourceMatcher, bool checkInnerExceptions) { var filter = new ErrorFilter(exceptionType, messageMatcher, sourceMatcher, checkInnerExceptions); return(CreateApplier(filter, _system)); }
public static bool FindText( DataView dataView, IStringMatcher matcher, ref int rowIndex, ref int columnIndex) { var found = false; var dataTable = dataView.Table; var dataRows = dataTable.Rows; var rowCount = dataView.Count; var columnCount = dataTable.Columns.Count; var currentValueObject = dataTable.DefaultView[rowIndex][columnIndex]; string currentValue; if (currentValueObject is StringField) { var stringField = currentValueObject as StringField; currentValue = stringField.Value; } else { currentValue = currentValueObject.ToString(); } if (matcher.IsMatch(currentValue)) { if (columnIndex < columnCount - 1) { columnIndex++; } else if (rowIndex < rowCount - 1) { rowIndex++; } } if (rowIndex == 0) { for (var i = columnIndex + 1; i < dataTable.Columns.Count; i++) { var dataColumn = dataTable.Columns[i]; found = matcher.IsMatch(dataColumn.ColumnName); if (found) { columnIndex = i; break; } } } if (!found) { var dataRow = dataTable.DefaultView[rowIndex].Row; while (true) { found = matcher.IsMatch(dataRow[columnIndex].ToString()); if (found) { //cell.DataGridView.Rows[row].Cells[col].Selected = true; // TODO // cell.RowIndex = row; // cell.ColumnIndex = col; break; } if ((columnIndex + 1)%columnCount != 0) { columnIndex++; } else { rowIndex++; columnIndex = 0; if (rowIndex < rowCount) { dataRow = dataTable.DefaultView[rowIndex].Row; } else { break; } } } } return found; }
/// <summary> /// TBD /// </summary> /// <param name="messageMatcher">TBD</param> /// <param name="sourceMatcher">TBD</param> /// <param name="isMatch">TBD</param> public DeadLettersFilter(IStringMatcher messageMatcher, IStringMatcher sourceMatcher, Predicate <DeadLetter> isMatch = null) : base(messageMatcher, sourceMatcher) { _isMatch = isMatch; }
/// <summary> /// TBD /// </summary> /// <param name="messageMatcher">TBD</param> /// <param name="sourceMatcher">TBD</param> protected EventFilterBase(IStringMatcher messageMatcher, IStringMatcher sourceMatcher) { _messageMatcher = messageMatcher ?? MatchesAll.Instance; _sourceMatcher = sourceMatcher ?? MatchesAll.Instance; }
public OpenAction(Context context, IStringMatcher applicationMatcher) { this.applicationMatcher = applicationMatcher; this.context = context; }
public ErrorFilter(IStringMatcher messageMatcher = null, IStringMatcher sourceMatcher = null) : this(null,messageMatcher,sourceMatcher, false) { }
/// <summary> /// Constructor which initializes list of contained string matchers. /// </summary> /// <param name="matchers">Array of matchers that should be added to this matcher.</param> /// <exception cref="System.ArgumentNullException"><paramref name="matchers" /> is null or contains null reference.</exception> public CombinedStringMatcher(IStringMatcher[] matchers) : this() { AddRange(matchers); }
/// <summary> /// Adds multiple matchers to the set of contained matchers. /// </summary> /// <param name="matchers">Array of matchers that should be added.</param> /// <exception cref="System.ArgumentNullException"><paramref name="matchers" /> is null or contains null reference.</exception> public void AddRange(IStringMatcher[] matchers) { if (matchers == null) { throw new ArgumentNullException("Array of matchers cannot be null."); } for (var i = 0; i < matchers.Length; i++) { Add(matchers[i]); // May throw new System.ArgumentNullException } }
public FileCrawler(IFilesFinder filesFinder, IParser parser, IStringMatcher matcher) { _filesFinder = filesFinder; _parser = parser; _matcher = matcher; }
public void AddMatcher(IStringMatcher matcher) { matchers.Add(matcher); }
public InfoFilter(IStringMatcher messageMatcher = null, IStringMatcher sourceMatcher = null) : base(messageMatcher, sourceMatcher) { }
public void MatchTest5() { IStringMatcher stringMatcher = CreateStringMatcher("y"); Assert.IsFalse(stringMatcher.MatchTo("other input string")); }
public StringMatcherBuilder addMatcher(IStringMatcher matcher) { _matchers.AddMatcher(matcher); return(this); }
public DeadLettersFilter(IStringMatcher messageMatcher, IStringMatcher sourceMatcher, Predicate<DeadLetter> isMatch = null) : base(messageMatcher, sourceMatcher) { _isMatch = isMatch; }
public SparseArrayLuncher(IMainUserInterface userInterface, IStringsCollector stringsCollector, IStringMatcher stringMatcher) { _userInterface = userInterface; _stringsCollector = stringsCollector; _stringMatcher = stringMatcher; }
/// <summary> /// TBD /// </summary> /// <param name="messageMatcher">TBD</param> /// <param name="sourceMatcher">TBD</param> public WarningFilter(IStringMatcher messageMatcher = null, IStringMatcher sourceMatcher = null) : base(messageMatcher, sourceMatcher) { }
protected EventFilterBase(IStringMatcher messageMatcher, IStringMatcher sourceMatcher) { _messageMatcher = messageMatcher ?? MatchesAll.Instance; _sourceMatcher = sourceMatcher ?? MatchesAll.Instance; }