public void TestWordStart2() { var matcher = StringMatcher.GetMatcher("Abc", true); var match = matcher.GetMatch("AbAbc"); CompareMatch(match, "--***"); }
public void TestGetMatchWithunderscoreWord() { var matcher = StringMatcher.GetMatcher("myhtmser", true); var match = matcher.GetMatch("my_html_Service"); CompareMatch(match, "**-***--***----"); }
public override Task <ISearchDataSource> GetResults(SearchPopupSearchPattern searchPattern, int resultsCount, CancellationToken token) { return(Task.Factory.StartNew(delegate { if (searchPattern.Tag != null && !validTags.Contains(searchPattern.Tag)) { return null; } try { var newResult = new WorkerResult(widget); newResult.pattern = searchPattern.Pattern; newResult.IncludeFiles = true; newResult.IncludeTypes = true; newResult.IncludeMembers = true; string toMatch = searchPattern.Pattern; newResult.matcher = StringMatcher.GetMatcher(toMatch, false); newResult.FullSearch = true; AllResults(lastResult, newResult, token); newResult.results.SortUpToN(new DataItemComparer(token), resultsCount); lastResult = newResult; return (ISearchDataSource)newResult.results; } catch { token.ThrowIfCancellationRequested(); throw; } }, token)); }
protected static string HighlightMatch(string text, string toMatch, bool selected) { var lane = StringMatcher.GetMatcher(toMatch, true).GetMatch(text); var matchHexColor = selected ? selectedResultMatchTextColor : resultMatchTextColor; var result = StringBuilderCache.Allocate(); if (lane != null) { int lastPos = 0; for (int n = 0; n < lane.Length; n++) { int pos = lane[n]; if (pos - lastPos > 0) { MarkupUtilities.AppendEscapedString(result, text, lastPos, pos - lastPos); } result.Append("<span foreground=\""); result.Append(matchHexColor); result.Append("\" font_weight=\"bold\">"); MarkupUtilities.AppendEscapedString(result, text, pos, 1); result.Append("</span>"); lastPos = pos + 1; } if (lastPos < text.Length) { MarkupUtilities.AppendEscapedString(result, text, lastPos, text.Length - lastPos); } } else { MarkupUtilities.AppendEscapedString(result, text, 0, text.Length); } return(StringBuilderCache.ReturnAndFree(result)); }
protected static string HighlightMatch(Widget widget, string text, string toMatch) { var lane = StringMatcher.GetMatcher(toMatch, false).GetMatch(text); StringBuilder result = new StringBuilder(); if (lane != null) { int lastPos = 0; for (int n = 0; n < lane.Length; n++) { int pos = lane[n]; if (pos - lastPos > 0) { MarkupUtilities.AppendEscapedString(result, text.Substring(lastPos, pos - lastPos)); } result.Append("<span foreground=\""); var color = Mono.TextEditor.HslColor.GenerateHighlightColors(widget.Style.Base(StateType.Normal), widget.Style.Text(StateType.Normal), 3)[2]; result.Append(color.ToPangoString()); result.Append("\">"); MarkupUtilities.AppendEscapedString(result, text[pos].ToString()); result.Append("</span>"); lastPos = pos + 1; } if (lastPos < text.Length) { MarkupUtilities.AppendEscapedString(result, text.Substring(lastPos, text.Length - lastPos)); } } else { MarkupUtilities.AppendEscapedString(result, text); } return(result.ToString()); }
public override Task GetResults(ISearchResultCallback searchResultCallback, SearchPopupSearchPattern pattern, CancellationToken token) { var files = AllFiles.ToList(); return(Task.Run(delegate { var matcher = StringMatcher.GetMatcher(pattern.Pattern, false); savedMatches = new Dictionary <string, MatchResult> (); foreach (ProjectFile file in files) { if (token.IsCancellationRequested) { break; } int rank; string matchString = System.IO.Path.GetFileName(file.FilePath); if (MatchName(matcher, matchString, out rank)) { searchResultCallback.ReportResult(new FileSearchResult(pattern.Pattern, matchString, rank, file, true)); } matchString = FileSearchResult.GetRelProjectPath(file); if (MatchName(matcher, matchString, out rank)) { searchResultCallback.ReportResult(new FileSearchResult(pattern.Pattern, matchString, rank, file, true)); } } savedMatches = null; })); }
public override Task <ISearchDataSource> GetResults(SearchPopupSearchPattern searchPattern, int resultsCount, CancellationToken token) { // NOTE: This is run on the UI thread as checking whether or not a command is enabled is not thread-safe return(Task.Factory.StartNew(delegate { try { if (searchPattern.Tag != null && !validTags.Contains(searchPattern.Tag) || searchPattern.HasLineNumber) { return null; } WorkerResult newResult = new WorkerResult(widget); newResult.pattern = searchPattern.Pattern; newResult.matcher = StringMatcher.GetMatcher(searchPattern.Pattern, false); newResult.FullSearch = true; AllResults(lastResult, newResult, token); newResult.results.SortUpToN(new DataItemComparer(token), resultsCount); lastResult = newResult; return (ISearchDataSource)newResult.results; } catch { token.ThrowIfCancellationRequested(); throw; } }, token, TaskCreationOptions.None, Xwt.Application.UITaskScheduler)); }
protected static string HighlightMatch(string text, string toMatch) { var lane = StringMatcher.GetMatcher(toMatch, true).GetMatch(text); StringBuilder result = new StringBuilder(); if (lane != null) { int lastPos = 0; for (int n = 0; n < lane.Length; n++) { int pos = lane[n]; if (pos - lastPos > 0) { MarkupUtilities.AppendEscapedString(result, text.Substring(lastPos, pos - lastPos)); } result.Append("<span foreground=\"#4d4d4d\" font_weight=\"bold\">"); MarkupUtilities.AppendEscapedString(result, text[pos].ToString()); result.Append("</span>"); lastPos = pos + 1; } if (lastPos < text.Length) { MarkupUtilities.AppendEscapedString(result, text.Substring(lastPos, text.Length - lastPos)); } } else { MarkupUtilities.AppendEscapedString(result, text); } return(result.ToString()); }
public void TestBug7659() { var matcher = StringMatcher.GetMatcher("MoDr.add", true); int rank; Assert.IsTrue(matcher.CalcMatchRank("MonoDevelop.MonoDroid.addin.xml", out rank)); }
public override Task GetResults(ISearchResultCallback searchResultCallback, SearchPopupSearchPattern pattern, CancellationToken token) { return(Task.Run(delegate { try { if (pattern.HasLineNumber) { return; } CommandTargetRoute route = new CommandTargetRoute(MainToolbar.LastCommandTarget); var matcher = StringMatcher.GetMatcher(pattern.Pattern, false); foreach (var cmdTuple in allCommands) { if (token.IsCancellationRequested) { break; } var cmd = cmdTuple.Item1; var matchString = cmdTuple.Item2; int rank; if (matcher.CalcMatchRank(matchString, out rank)) { searchResultCallback.ReportResult(new CommandResult(cmd, null, route, pattern.Pattern, matchString, rank)); } } } catch (OperationCanceledException) { } }, token)); }
public void TestDigit() { var matcher = StringMatcher.GetMatcher("my12", true); var match = matcher.GetMatch("my_html_Service_123"); CompareMatch(match, "**--------------**-"); }
public void TestPunctuation() { var matcher = StringMatcher.GetMatcher("foo:b", true); var match = matcher.GetMatch("foo:bar"); CompareMatch(match, "*****--"); }
public void TestUnderscoreAtEnd() { var matcher = StringMatcher.GetMatcher("FB", true); var match = matcher.GetMatch("foo_"); Assert.AreEqual(null, match); }
public void TestWordStart() { var matcher = StringMatcher.GetMatcher("A", true); var match = matcher.GetMatch("aaa0"); CompareMatch(match, "*---"); }
public void TestGetMatchWithUpperCaseWordCase2() { var matcher = StringMatcher.GetMatcher("myhmser", true); var match = matcher.GetMatch("MyFunnyHTMLMasterService"); CompareMatch(match, "**-----*---*-----***----"); }
public void TestGetMatch() { var matcher = StringMatcher.GetMatcher("typese", true); var match = matcher.GetMatch("TypeSystemService"); CompareMatch(match, "****------**-----"); }
public override Task GetResults(ISearchResultCallback searchResultCallback, SearchPopupSearchPattern pattern, CancellationToken token) { if (pattern.HasLineNumber) { return(Task.CompletedTask); } var route = new CommandTargetRoute(IdeApp.CommandService.LastCommandTarget); var matcher = StringMatcher.GetMatcher(pattern.Pattern, false); foreach (var cmd in GetAllCommands()) { if (token.IsCancellationRequested) { break; } var matchString = cmd.DisplayName; if (matcher.CalcMatchRank(matchString, out var rank)) { if ((cmd as ActionCommand)?.RuntimeAddin == currentRuntimeAddin) { rank += 1; // we prefer commands comming from the addin } searchResultCallback.ReportResult(new CommandResult(cmd, null, route, pattern.Pattern, matchString, rank)); } } return(Task.CompletedTask); }
protected static string HighlightMatch(string text, string toMatch, bool selected) { var lane = StringMatcher.GetMatcher(toMatch, true).GetMatch(text); StringBuilder result = new StringBuilder(); if (lane != null) { int lastPos = 0; for (int n = 0; n < lane.Length; n++) { int pos = lane[n]; if (pos - lastPos > 0) { MarkupUtilities.AppendEscapedString(result, text.Substring(lastPos, pos - lastPos)); } var matchColor = selected ? Styles.GlobalSearch.SelectedResultMatchTextColor : Styles.GlobalSearch.ResultMatchTextColor; result.Append("<span foreground=\"" + Styles.ColorGetHex(matchColor) + "\" font_weight=\"bold\">"); MarkupUtilities.AppendEscapedString(result, text[pos].ToString()); result.Append("</span>"); lastPos = pos + 1; } if (lastPos < text.Length) { MarkupUtilities.AppendEscapedString(result, text.Substring(lastPos, text.Length - lastPos)); } } else { MarkupUtilities.AppendEscapedString(result, text); } return(result.ToString()); }
public override Task GetResults(ISearchResultCallback searchResultCallback, SearchPopupSearchPattern pattern, CancellationToken token) { return(Task.Run(async delegate { List <Tuple <string, string, ProjectFile> > files; //This lock is here in case user quickly types 5 letters which triggers 5 threads //we don't want to use all CPU doing same thing, instead 1st one will create cache, others will wait here //and then all will use cached version... bool locked = false; try { locked = await allFilesLock.WaitAsync(System.Threading.Timeout.Infinite, token).ConfigureAwait(false); files = allFilesCache = allFilesCache ?? GenerateAllFiles(); if (token.IsCancellationRequested) { return; } } finally { if (locked) { allFilesLock.Release(); } } var matcher = StringMatcher.GetMatcher(pattern.Pattern, false); var savedMatches = new Dictionary <string, MatchResult> (files.Count * 2); foreach (var file in files) { if (token.IsCancellationRequested) { break; } int rank1; int rank2; var match1 = MatchName(savedMatches, matcher, file.Item1, out rank1); var match2 = MatchName(savedMatches, matcher, file.Item2, out rank2); if (match1 && match2) { if (rank1 > rank2 || (rank1 == rank2 && String.CompareOrdinal(file.Item1, file.Item2) > 0)) { searchResultCallback.ReportResult(new FileSearchResult(pattern.Pattern, file.Item1, rank1, file.Item3)); } else { searchResultCallback.ReportResult(new FileSearchResult(pattern.Pattern, file.Item2, rank2, file.Item3)); } } else if (match1) { searchResultCallback.ReportResult(new FileSearchResult(pattern.Pattern, file.Item1, rank1, file.Item3)); } else if (match2) { searchResultCallback.ReportResult(new FileSearchResult(pattern.Pattern, file.Item2, rank2, file.Item3)); } } }, token)); }
public SearchIdleRunner(AssemblyBrowserWidget assemblyBrowserWidget, string pattern, CancellationToken token) { this.assemblyBrowserWidget = assemblyBrowserWidget; this.publicOnly = assemblyBrowserWidget.PublicApiOnly; this.token = token; this.pattern = pattern; this.definitions = assemblyBrowserWidget.definitions; this.searchMode = assemblyBrowserWidget.searchMode; matcher = StringMatcher.GetMatcher(pattern, true); }
public void TestBacktrackBug() { var matcher = StringMatcher.GetMatcher("dlli", true); var match = matcher.GetMatch("DllList"); CompareMatch(match, "**-**--"); matcher = StringMatcher.GetMatcher("dLli", true); match = matcher.GetMatch("DllList"); Assert.IsNull(match, "match found"); }
public override Task GetResults(ISearchResultCallback searchResultCallback, SearchPopupSearchPattern searchPattern, CancellationToken token) { return(Task.Run(async delegate { if (searchPattern.Tag != null && !(typeTags.Contains(searchPattern.Tag) || memberTags.Contains(searchPattern.Tag)) || searchPattern.HasLineNumber) { return; } try { if (SymbolInfoTask == null) { SymbolInfoTask = Task.FromResult(default(SymbolCache)).ContinueWith(t => GetSymbolInfos(token)); } var cache = await SymbolInfoTask.ConfigureAwait(false); if (token.IsCancellationRequested) { return; } string toMatch = searchPattern.Pattern; var newResult = new WorkerResult(); newResult.pattern = searchPattern.Pattern; newResult.Tag = searchPattern.Tag; newResult.matcher = StringMatcher.GetMatcher(toMatch, false); newResult.FullSearch = toMatch.IndexOf('.') > 0; var oldLastResult = lastResult; if (newResult.FullSearch && oldLastResult != null && !oldLastResult.FullSearch) { oldLastResult = new WorkerResult(); } if (token.IsCancellationRequested) { return; } IReadOnlyList <DeclaredSymbolInfo> allTypes = null; if (!IsSameFilterStart(oldLastResult, newResult)) { allTypes = cache.GetAllTypes(searchPattern.Tag, token); } // var now = DateTime.Now; AllResults(searchResultCallback, newResult, allTypes ?? lastResult.filteredSymbols, token); //newResult.results.SortUpToN (new DataItemComparer (token), resultsCount); lastResult = newResult; // Console.WriteLine ((now - DateTime.Now).TotalMilliseconds); } catch { token.ThrowIfCancellationRequested(); throw; } }, token)); }
public void SetFilter(string filter) { if (!string.IsNullOrEmpty(filter)) { stringMatcher = StringMatcher.GetMatcher(filter, false); } else { stringMatcher = null; } Reset(); }
public void SetFilter(string filter) { if (!string.IsNullOrEmpty(filter)) { stringMatcher = StringMatcher.GetMatcher(filter, false); } else { stringMatcher = null; } PopulateListView(); }
void SearchWorker(object sender, DoWorkEventArgs e) { BackgroundWorker worker = (BackgroundWorker)sender; var arg = (KeyValuePair <string, WorkerResult>)e.Argument; WorkerResult lastResult = arg.Value; WorkerResult newResult = new WorkerResult(this); newResult.pattern = arg.Key; newResult.IncludeFiles = (NavigateToType & NavigateToType.Files) == NavigateToType.Files; newResult.IncludeTypes = (NavigateToType & NavigateToType.Types) == NavigateToType.Types; newResult.IncludeMembers = (NavigateToType & NavigateToType.Members) == NavigateToType.Members; string toMatch = arg.Key; int i = toMatch.IndexOf(':'); if (i != -1) { toMatch = toMatch.Substring(0, i); newResult.isGotoFilePattern = true; } newResult.matcher = StringMatcher.GetMatcher(toMatch, false); newResult.FullSearch = useFullSearch; foreach (SearchResult result in AllResults(worker, lastResult, newResult)) { if (worker.CancellationPending) { break; } newResult.results.AddResult(result); } if (worker.CancellationPending) { e.Cancel = true; return; } newResult.results.Sort(new DataItemComparer()); e.Result = newResult; }
public override Task GetResults(ISearchResultCallback searchResultCallback, SearchPopupSearchPattern searchPattern, CancellationToken token) { return(Task.Run(async delegate { if (searchPattern.Tag != null && !(typeTags.Contains(searchPattern.Tag) || memberTags.Contains(searchPattern.Tag)) || searchPattern.HasLineNumber) { return null; } try { var newResult = new WorkerResult(widget); newResult.pattern = searchPattern.Pattern; newResult.Tag = searchPattern.Tag; List <DeclaredSymbolInfo> allTypes; if (SymbolInfoTask == null) { SymbolInfoTask = Task.FromResult(GetSymbolInfos(token)); } var cache = await SymbolInfoTask.ConfigureAwait(false); allTypes = cache.AllTypes; string toMatch = searchPattern.Pattern; newResult.matcher = StringMatcher.GetMatcher(toMatch, false); newResult.FullSearch = toMatch.IndexOf('.') > 0; var oldLastResult = lastResult; if (newResult.FullSearch && oldLastResult != null && !oldLastResult.FullSearch) { oldLastResult = new WorkerResult(widget); } // var now = DateTime.Now; AllResults(searchResultCallback, oldLastResult, newResult, allTypes, token); //newResult.results.SortUpToN (new DataItemComparer (token), resultsCount); lastResult = newResult; // Console.WriteLine ((now - DateTime.Now).TotalMilliseconds); return (ISearchDataSource)newResult.results; } catch { token.ThrowIfCancellationRequested(); throw; } }, token)); }
public override Task <ISearchDataSource> GetResults(SearchPopupSearchPattern searchPattern, int resultsCount, CancellationToken token) { return(Task.Factory.StartNew(delegate { if (searchPattern.Tag != null && !(typeTags.Contains(searchPattern.Tag) || memberTags.Contains(searchPattern.Tag)) || searchPattern.HasLineNumber) { return null; } try { var newResult = new WorkerResult(widget); newResult.pattern = searchPattern.Pattern; newResult.IncludeFiles = true; newResult.Tag = searchPattern.Tag; newResult.IncludeTypes = searchPattern.Tag == null || typeTags.Contains(searchPattern.Tag); newResult.IncludeMembers = searchPattern.Tag == null || memberTags.Contains(searchPattern.Tag); var firstType = types.FirstOrDefault(); newResult.ambience = firstType != null ? AmbienceService.GetAmbienceForFile(firstType.Region.FileName) : AmbienceService.DefaultAmbience; string toMatch = searchPattern.Pattern; newResult.matcher = StringMatcher.GetMatcher(toMatch, false); newResult.FullSearch = toMatch.IndexOf('.') > 0; var oldLastResult = lastResult; if (newResult.FullSearch && oldLastResult != null && !oldLastResult.FullSearch) { oldLastResult = new WorkerResult(widget); } // var now = DateTime.Now; AllResults(oldLastResult, newResult, token); newResult.results.SortUpToN(new DataItemComparer(token), resultsCount); lastResult = newResult; // Console.WriteLine ((now - DateTime.Now).TotalMilliseconds); return (ISearchDataSource)newResult.results; } catch { token.ThrowIfCancellationRequested(); throw; } }, token)); }
public override Task GetResults(ISearchResultCallback searchResultCallback, SearchPopupSearchPattern pattern, CancellationToken token) { return(Task.Run(delegate { var files = allFilesCache = allFilesCache ?? GenerateAllFiles(); var matcher = StringMatcher.GetMatcher(pattern.Pattern, false); var savedMatches = new Dictionary <string, MatchResult> (); foreach (var file in files) { if (token.IsCancellationRequested) { break; } int rank1; int rank2; var match1 = MatchName(savedMatches, matcher, file.Item1, out rank1); var match2 = MatchName(savedMatches, matcher, file.Item2, out rank2); if (match1 && match2) { if (rank1 > rank2 || (rank1 == rank2 && String.CompareOrdinal(file.Item1, file.Item2) > 0)) { searchResultCallback.ReportResult(new FileSearchResult(pattern.Pattern, file.Item1, rank1, file.Item3)); } else { searchResultCallback.ReportResult(new FileSearchResult(pattern.Pattern, file.Item2, rank2, file.Item3)); } } else if (match1) { searchResultCallback.ReportResult(new FileSearchResult(pattern.Pattern, file.Item1, rank1, file.Item3)); } else if (match2) { searchResultCallback.ReportResult(new FileSearchResult(pattern.Pattern, file.Item2, rank2, file.Item3)); } } }, token)); }
public void TestStringMatcher() { var matcher = StringMatcher.GetMatcher("typese", true); Assert.IsTrue(matcher.IsMatch("TypeSystemService")); }
public static StringMatcher CreateCompletionMatcher(string filterText) { return(StringMatcher.GetMatcher(filterText, true)); }