Browse Source

Merge pull request #311 from RKlier/search

Search for multiple strings separate by space
pull/310/merge
Daniel Grunwald 14 years ago
parent
commit
2370f8c61f
  1. 63
      ILSpy/SearchPane.cs

63
ILSpy/SearchPane.cs

@ -185,7 +185,7 @@ namespace ICSharpCode.ILSpy
readonly Dispatcher dispatcher; readonly Dispatcher dispatcher;
readonly CancellationTokenSource cts = new CancellationTokenSource(); readonly CancellationTokenSource cts = new CancellationTokenSource();
readonly LoadedAssembly[] assemblies; readonly LoadedAssembly[] assemblies;
readonly string searchTerm; readonly string[] searchTerm;
readonly int searchMode; readonly int searchMode;
readonly Language language; readonly Language language;
public readonly ObservableCollection<SearchResult> Results = new ObservableCollection<SearchResult>(); public readonly ObservableCollection<SearchResult> Results = new ObservableCollection<SearchResult>();
@ -198,7 +198,7 @@ namespace ICSharpCode.ILSpy
{ {
this.dispatcher = Dispatcher.CurrentDispatcher; this.dispatcher = Dispatcher.CurrentDispatcher;
this.assemblies = assemblies; this.assemblies = assemblies;
this.searchTerm = searchTerm; this.searchTerm = searchTerm.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);
this.language = language; this.language = language;
this.searchMode = searchMode; this.searchMode = searchMode;
@ -214,29 +214,32 @@ namespace ICSharpCode.ILSpy
{ {
try { try {
if (searchMode == SearchMode_Literal) { if (searchMode == SearchMode_Literal) {
CSharpParser parser = new CSharpParser(); if (1 == searchTerm.Length)
PrimitiveExpression pe = parser.ParseExpression(new StringReader(searchTerm)) as PrimitiveExpression; {
if (pe != null && pe.Value != null) { CSharpParser parser = new CSharpParser();
TypeCode peValueType = Type.GetTypeCode(pe.Value.GetType()); PrimitiveExpression pe = parser.ParseExpression(new StringReader(searchTerm[0])) as PrimitiveExpression;
switch (peValueType) { if (pe != null && pe.Value != null) {
case TypeCode.Byte: TypeCode peValueType = Type.GetTypeCode(pe.Value.GetType());
case TypeCode.SByte: switch (peValueType) {
case TypeCode.Int16: case TypeCode.Byte:
case TypeCode.UInt16: case TypeCode.SByte:
case TypeCode.Int32: case TypeCode.Int16:
case TypeCode.UInt32: case TypeCode.UInt16:
case TypeCode.Int64: case TypeCode.Int32:
case TypeCode.UInt64: case TypeCode.UInt32:
searchTermLiteralType = TypeCode.Int64; case TypeCode.Int64:
searchTermLiteralValue = CSharpPrimitiveCast.Cast(TypeCode.Int64, pe.Value, false); case TypeCode.UInt64:
break; searchTermLiteralType = TypeCode.Int64;
case TypeCode.Single: searchTermLiteralValue = CSharpPrimitiveCast.Cast(TypeCode.Int64, pe.Value, false);
case TypeCode.Double: break;
case TypeCode.String: case TypeCode.Single:
searchTermLiteralType = peValueType; case TypeCode.Double:
searchTermLiteralValue = pe.Value; case TypeCode.String:
break; searchTermLiteralType = peValueType;
} searchTermLiteralValue = pe.Value;
break;
}
}
} }
} }
@ -273,10 +276,12 @@ namespace ICSharpCode.ILSpy
bool IsMatch(string text) bool IsMatch(string text)
{ {
if (text.IndexOf(searchTerm, StringComparison.OrdinalIgnoreCase) >= 0) for (int i = 0; i < searchTerm.Length; ++i) {
return true; // How to handle overlapping matches?
else if (text.IndexOf(searchTerm[i], StringComparison.OrdinalIgnoreCase) < 0)
return false; return false;
}
return true;
} }
void PerformSearch(TypeDefinition type) void PerformSearch(TypeDefinition type)

Loading…
Cancel
Save