static public Cache_Entry <Expression> For <Expression>(MatchCase match_case, Expression x, Expression y, Rational k, Expression result) { Contract.Requires((object)k != null); Contract.Requires(match_case != MatchCase.NotLinear); return(new Cache_Entry <Expression>(match_case, x, y, k, result)); }
public override int GetHashCode() { var hash = 23; hash = hash * 31 + MatchCase.GetHashCode(); hash = hash * 31 + MatchWholeWord.GetHashCode(); hash = hash * 31 + IsRegex.GetHashCode(); hash = hash * 31 + UseExcludeSettingsAndIgnoreFiles.GetHashCode(); if (Query != null) { hash = hash * 31 + Query.GetHashCode(); } if (WorkingDirectory != null) { hash = hash * 31 + WorkingDirectory.GetHashCode(); } if (Include != null) { hash = hash * 31 + Include.GetHashCode(); } if (Exclude != null) { hash = hash * 31 + Exclude.GetHashCode(); } return(hash); }
private void MatchCaseButton_Click(object sender, EventArgs e) { MatchCase CallMatchCase = new MatchCase(SelectedFileType); CallMatchCase.ShowDialog(); CallMatchCase.Close(); if (CallMatchCase.RegexFinal != null && CallMatchCase.EnteredUserNameFormat != null && CallMatchCase.RegexFinal.Length > 0 && CallMatchCase.EnteredUserNameFormat.Length > 0) { if (RegexTextBox.Text.Length > 0 && FileNameTB.Text.Length > 0) { DialogResult ReplaceMatch = MessageBox.Show("Do you really want to replace the existing File Name Regex and File Name Format expressions?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (ReplaceMatch == DialogResult.Yes) { RegexTextBox.Text = CallMatchCase.RegexFinal; FileNameTB.Text = CallMatchCase.EnteredUserNameFormat; } } else { RegexTextBox.Text = CallMatchCase.RegexFinal; FileNameTB.Text = CallMatchCase.EnteredUserNameFormat; } } }
/// <summary> /// Generates the text for a MatchCase builder. /// </summary> /// <param name="item">The MatchCase builder to generate the text for.</param> protected internal override void VisitMatchCase(MatchCase item) { if (!item.Branches.Any()) { throw new SQLGenerationException(Resources.EmptyCaseExpression); } writer.Write("CASE "); item.Item.Accept(forSubCommand()); writer.Write(" "); foreach (MatchCaseBranch branch in item.Branches) { writer.Write("WHEN "); branch.Option.Accept(forSubCommand()); writer.Write(" THEN "); branch.Value.Accept(forSubCommand()); writer.Write(" "); } if (item.Default != null) { writer.Write("ELSE "); item.Default.Accept(forSubCommand()); writer.Write(" "); } writer.Write("END"); }
public override int GetHashCode() { unchecked { var hashCode = base.GetHashCode(); hashCode = (hashCode * 397) ^ (InField != null ? InField.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Index != null ? Index.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Characters != null ? Characters.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Direction != null ? Direction.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Result != null ? Result.GetHashCode() : 0); hashCode = (hashCode * 397) ^ MatchCase.GetHashCode(); hashCode = (hashCode * 397) ^ (StartIndex != null ? StartIndex.GetHashCode() : 0); return(hashCode); } }
public override int GetHashCode() { unchecked { var hashCode = base.GetHashCode(); hashCode = (hashCode * 397) ^ (FieldsToSearch != null ? FieldsToSearch.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Result != null ? Result.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (StartIndex != null ? StartIndex.GetHashCode() : 0); hashCode = (hashCode * 397) ^ MatchCase.GetHashCode(); hashCode = (hashCode * 397) ^ RequireAllTrue.GetHashCode(); hashCode = (hashCode * 397) ^ RequireAllFieldsToMatch.GetHashCode(); hashCode = (hashCode * 397) ^ (ResultsCollection != null ? ResultsCollection.GetHashCode() : 0); return(hashCode); } }
public override IEnumerable <StateVariable> GetState() { return(new[] { new StateVariable { Name = "StartIndex", Type = StateVariable.StateType.Input, Value = StartIndex }, new StateVariable { Name = "MatchCase", Type = StateVariable.StateType.Input, Value = MatchCase.ToString() }, new StateVariable { Name = "Direction", Type = StateVariable.StateType.Input, Value = Direction }, new StateVariable { Name = "Characters", Type = StateVariable.StateType.Input, Value = Characters }, new StateVariable { Name = "Index", Type = StateVariable.StateType.Input, Value = Index }, new StateVariable { Name = "InField", Type = StateVariable.StateType.Input, Value = InField }, new StateVariable { Name = "Result", Type = StateVariable.StateType.Output, Value = Result }, }); }
public void PrintMatchCaseArgument(MatchCase mc) { if (mc.Arguments != null) { if (mc.Arguments.Count != 0) { string sep = "("; foreach (BoundVar bv in mc.Arguments) { wr.Write("{0}{1}", sep, bv.DisplayName); string typeName = bv.Type.TypeName(null, true); if (bv.Type is NonProxyType && !typeName.StartsWith("_")) { wr.Write(": {0}", typeName); } sep = ", "; } wr.Write(")"); } } else { Contract.Assert(mc.CasePatterns != null); if (mc.CasePatterns.Count != 0) { string sep = "("; foreach (var cp in mc.CasePatterns) { wr.Write(sep); PrintCasePattern(cp); sep = ", "; } wr.Write(")"); } } }
/// <summary> /// filter the comic book list based on criteria /// </summary> /// <param name="comicBookList"> /// List of ComicBook objects /// <param name="searchOption"> /// search criteria based on comic book property /// </param> /// <param name="sortOrder"> /// Order in which the items should be sorted /// </param> /// <returns></returns> public static List <ComicBook> Filter(List <ComicBook> comicBookList, string searchVal, SearchComicOption searchOption, MatchCase matchCase = MatchCase.No, SortOrder sortOrder = SortOrder.Ascending) { if (comicBookList.Count() == 0) { return(comicBookList); } switch (searchOption) { case SearchComicOption.Title: if (matchCase == MatchCase.No) { comicBookList = comicBookList.Where(cb => cb.ComicTitle.ToLower().Contains(searchVal.ToLower())).ToList(); } else { comicBookList = comicBookList.Where(cb => cb.ComicTitle == searchVal).ToList(); } break; case SearchComicOption.Subtitle: if (matchCase == MatchCase.No) { comicBookList = comicBookList.Where(cb => cb.ComicSubTitle.ToLower().Contains(searchVal.ToLower())).ToList(); } else { comicBookList = comicBookList.Where(cb => cb.ComicSubTitle == searchVal).ToList(); } break; case SearchComicOption.Issue: if (matchCase == MatchCase.No) { comicBookList = comicBookList.Where(cb => cb.ComicIssue.ToLower().Contains(searchVal.ToLower())).ToList(); } else { comicBookList = comicBookList.Where(cb => cb.ComicIssue == searchVal).ToList(); } break; case SearchComicOption.Author: if (matchCase == MatchCase.No) { comicBookList = comicBookList.Where(comicBook => comicBook.ComicAuthors != null) .Where(comicBook => string.Join("", comicBook.ComicAuthors).ToLower().Contains(searchVal.ToLower())) .ToList(); } else { comicBookList = comicBookList.Where(comicBook => comicBook.ComicAuthors != null) .Where(comicBook => comicBook.ComicAuthors.Any(author => author == searchVal)) .ToList(); } break; case SearchComicOption.Genre: if (matchCase == MatchCase.No) { comicBookList = comicBookList.Where(comicBook => comicBook.ComicGenres != null) .Where(comicBook => string.Join("", comicBook.ComicGenres).ToLower().Contains(searchVal.ToLower())) .ToList(); } else { comicBookList = comicBookList.Where(comicBook => comicBook.ComicGenres != null) .Where(comicBook => comicBook.ComicGenres.Any(author => author == searchVal)) .ToList(); } break; case SearchComicOption.Publisher: if (matchCase == MatchCase.No) { comicBookList = comicBookList.Where(cb => cb.Publisher.ToLower().Contains(searchVal.ToLower())).ToList(); } else { comicBookList = comicBookList.Where(cb => cb.Publisher == searchVal).ToList(); } break; default: throw new InvalidSearchOptionException("Provided search option is invalid."); } switch (sortOrder) { case SortOrder.Ascending: break; case SortOrder.Descending: comicBookList.Reverse(); break; default: throw new InvalidSortOptionException("Provided sort order is invalid."); } return(comicBookList); }
public (Value success, Value cost, Value result) CompileMatchCase(Value matchWith, MatchCase matchCase) { LabelTarget failLabel = Expression.Label("fail"); LabelTarget finishLabel = Expression.Label("finish"); var successVar = Expression.Parameter(typeof(bool), "success"); var costVar = Expression.Parameter(typeof(int), "cost"); var compiler = new FunctionCompiler(scope); var matcher = new Matcher( compiler, implicitVariables: matchCase.ImplicitVariables ); var instr = new List <Expression>(); instr.Add(matcher.CompileMatch(matchWith, matchCase.MatchedValue, failLabel, MatchKind.exact)); foreach (var variable in matchCase.ImplicitVariables) { if (matcher.implicitVars[variable.name] == null) { throw new Exception($"{variable.name} was not instantiated at {matchCase.Location}"); } var value = matcher.implicitVars[variable.name]; if (variable.type.IsSome()) { var coerceResult = compiler.CompileCoerce(value, CompileExpr(variable.type.Get())); // TODO: this should always succeed due to type constraints instr.Add(Expression.IfThenElse( coerceResult.success.Expression, Expression.Block( Expression.AddAssign(costVar, coerceResult.cost.Expression), scope.CreateVariable(variable.name, coerceResult.value)), Expression.Goto(failLabel))); } else { instr.Add(scope.CreateVariable(variable.name, value)); } } instr.Add(Expression.Assign(successVar, Expression.Constant(true))); instr.Add(Expression.Goto(finishLabel)); instr.Add(Expression.Label(failLabel)); instr.Add(Expression.Assign(successVar, Expression.Constant(false))); instr.Add(Expression.Label(finishLabel)); return(Value.Seq(instr, Value.Dynamic(successVar)), Value.Dynamic(costVar), compiler.CompileExpr(matchCase.Body)); }