From 049e2423638b7fa791061f7d6b49d9ed1805e2d9 Mon Sep 17 00:00:00 2001 From: Ronny Klier Date: Fri, 20 Jan 2012 23:27:55 +0100 Subject: [PATCH] Search for multiple string separate by space --- ILSpy/SearchPane.cs | 63 ++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/ILSpy/SearchPane.cs b/ILSpy/SearchPane.cs index 93edf5803..741d10f0c 100644 --- a/ILSpy/SearchPane.cs +++ b/ILSpy/SearchPane.cs @@ -185,7 +185,7 @@ namespace ICSharpCode.ILSpy readonly Dispatcher dispatcher; readonly CancellationTokenSource cts = new CancellationTokenSource(); readonly LoadedAssembly[] assemblies; - readonly string searchTerm; + readonly string[] searchTerm; readonly int searchMode; readonly Language language; public readonly ObservableCollection Results = new ObservableCollection(); @@ -198,7 +198,7 @@ namespace ICSharpCode.ILSpy { this.dispatcher = Dispatcher.CurrentDispatcher; this.assemblies = assemblies; - this.searchTerm = searchTerm; + this.searchTerm = searchTerm.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries); this.language = language; this.searchMode = searchMode; @@ -214,29 +214,32 @@ namespace ICSharpCode.ILSpy { try { if (searchMode == SearchMode_Literal) { - CSharpParser parser = new CSharpParser(); - PrimitiveExpression pe = parser.ParseExpression(new StringReader(searchTerm)) as PrimitiveExpression; - if (pe != null && pe.Value != null) { - TypeCode peValueType = Type.GetTypeCode(pe.Value.GetType()); - switch (peValueType) { - case TypeCode.Byte: - case TypeCode.SByte: - case TypeCode.Int16: - case TypeCode.UInt16: - case TypeCode.Int32: - case TypeCode.UInt32: - case TypeCode.Int64: - case TypeCode.UInt64: - searchTermLiteralType = TypeCode.Int64; - searchTermLiteralValue = CSharpPrimitiveCast.Cast(TypeCode.Int64, pe.Value, false); - break; - case TypeCode.Single: - case TypeCode.Double: - case TypeCode.String: - searchTermLiteralType = peValueType; - searchTermLiteralValue = pe.Value; - break; - } + if (1 == searchTerm.Length) + { + CSharpParser parser = new CSharpParser(); + PrimitiveExpression pe = parser.ParseExpression(new StringReader(searchTerm[0])) as PrimitiveExpression; + if (pe != null && pe.Value != null) { + TypeCode peValueType = Type.GetTypeCode(pe.Value.GetType()); + switch (peValueType) { + case TypeCode.Byte: + case TypeCode.SByte: + case TypeCode.Int16: + case TypeCode.UInt16: + case TypeCode.Int32: + case TypeCode.UInt32: + case TypeCode.Int64: + case TypeCode.UInt64: + searchTermLiteralType = TypeCode.Int64; + searchTermLiteralValue = CSharpPrimitiveCast.Cast(TypeCode.Int64, pe.Value, false); + break; + case TypeCode.Single: + case TypeCode.Double: + case TypeCode.String: + searchTermLiteralType = peValueType; + searchTermLiteralValue = pe.Value; + break; + } + } } } @@ -273,10 +276,12 @@ namespace ICSharpCode.ILSpy bool IsMatch(string text) { - if (text.IndexOf(searchTerm, StringComparison.OrdinalIgnoreCase) >= 0) - return true; - else - return false; + for (int i = 0; i < searchTerm.Length; ++i) { + // How to handle overlapping matches? + if (text.IndexOf(searchTerm[i], StringComparison.OrdinalIgnoreCase) < 0) + return false; + } + return true; } void PerformSearch(TypeDefinition type)