Browse Source

Feature Request: Search by abbreviated qualified name when not performing a full name search

pull/1119/head
Rafaat Mir 8 years ago
parent
commit
40cadf0191
  1. 190
      ILSpy/SearchStrategies.cs

190
ILSpy/SearchStrategies.cs

@ -17,6 +17,7 @@ namespace ICSharpCode.ILSpy
protected string[] searchTerm; protected string[] searchTerm;
protected Regex regex; protected Regex regex;
protected bool fullNameSearch; protected bool fullNameSearch;
protected bool allowNonContiguousMatch;
protected AbstractSearchStrategy(params string[] terms) protected AbstractSearchStrategy(params string[] terms)
{ {
@ -114,10 +115,35 @@ namespace ICSharpCode.ILSpy
} }
break; break;
default: default:
if (text.IndexOf(term, StringComparison.OrdinalIgnoreCase) < 0) if (!fullNameSearch && allowNonContiguousMatch) {
return false; if (!IsNonContiguousMatch(text.ToLower(), term.ToLower()))
return false;
} else {
if (text.IndexOf(term, StringComparison.OrdinalIgnoreCase) < 0)
return false;
}
break;
}
}
return true;
}
private bool IsNonContiguousMatch(string text, string searchTerm)
{
if (string.IsNullOrEmpty(text) || string.IsNullOrEmpty(searchTerm)) {
return false;
}
var index = 0;
foreach (char c in searchTerm) {
while (index != text.Length) {
if (text[index] == c) {
index++;
break; break;
}
index++;
} }
if (index == text.Length)
return false;
} }
return true; return true;
} }
@ -227,23 +253,23 @@ namespace ICSharpCode.ILSpy
if (value != null && value.LiteralValue != null) { if (value != null && value.LiteralValue != null) {
TypeCode valueType = Type.GetTypeCode(value.LiteralValue.GetType()); TypeCode valueType = Type.GetTypeCode(value.LiteralValue.GetType());
switch (valueType) { switch (valueType) {
case TypeCode.Byte: case TypeCode.Byte:
case TypeCode.SByte: case TypeCode.SByte:
case TypeCode.Int16: case TypeCode.Int16:
case TypeCode.UInt16: case TypeCode.UInt16:
case TypeCode.Int32: case TypeCode.Int32:
case TypeCode.UInt32: case TypeCode.UInt32:
case TypeCode.Int64: case TypeCode.Int64:
case TypeCode.UInt64: case TypeCode.UInt64:
searchTermLiteralType = TypeCode.Int64; searchTermLiteralType = TypeCode.Int64;
searchTermLiteralValue = CSharpPrimitiveCast.Cast(TypeCode.Int64, value.LiteralValue, false); searchTermLiteralValue = CSharpPrimitiveCast.Cast(TypeCode.Int64, value.LiteralValue, false);
break; break;
case TypeCode.Single: case TypeCode.Single:
case TypeCode.Double: case TypeCode.Double:
case TypeCode.String: case TypeCode.String:
searchTermLiteralType = valueType; searchTermLiteralType = valueType;
searchTermLiteralValue = value.LiteralValue; searchTermLiteralValue = value.LiteralValue;
break; break;
} }
} }
} }
@ -301,74 +327,74 @@ namespace ICSharpCode.ILSpy
long val = (long)searchTermLiteralValue; long val = (long)searchTermLiteralValue;
foreach (var inst in body.Instructions) { foreach (var inst in body.Instructions) {
switch (inst.OpCode.Code) { switch (inst.OpCode.Code) {
case Code.Ldc_I8: case Code.Ldc_I8:
if (val == (long)inst.Operand) if (val == (long)inst.Operand)
return true; return true;
break; break;
case Code.Ldc_I4: case Code.Ldc_I4:
if (val == (int)inst.Operand) if (val == (int)inst.Operand)
return true; return true;
break; break;
case Code.Ldc_I4_S: case Code.Ldc_I4_S:
if (val == (sbyte)inst.Operand) if (val == (sbyte)inst.Operand)
return true; return true;
break; break;
case Code.Ldc_I4_M1: case Code.Ldc_I4_M1:
if (val == -1) if (val == -1)
return true; return true;
break; break;
case Code.Ldc_I4_0: case Code.Ldc_I4_0:
if (val == 0) if (val == 0)
return true; return true;
break; break;
case Code.Ldc_I4_1: case Code.Ldc_I4_1:
if (val == 1) if (val == 1)
return true; return true;
break; break;
case Code.Ldc_I4_2: case Code.Ldc_I4_2:
if (val == 2) if (val == 2)
return true; return true;
break; break;
case Code.Ldc_I4_3: case Code.Ldc_I4_3:
if (val == 3) if (val == 3)
return true; return true;
break; break;
case Code.Ldc_I4_4: case Code.Ldc_I4_4:
if (val == 4) if (val == 4)
return true; return true;
break; break;
case Code.Ldc_I4_5: case Code.Ldc_I4_5:
if (val == 5) if (val == 5)
return true; return true;
break; break;
case Code.Ldc_I4_6: case Code.Ldc_I4_6:
if (val == 6) if (val == 6)
return true; return true;
break; break;
case Code.Ldc_I4_7: case Code.Ldc_I4_7:
if (val == 7) if (val == 7)
return true; return true;
break; break;
case Code.Ldc_I4_8: case Code.Ldc_I4_8:
if (val == 8) if (val == 8)
return true; return true;
break; break;
} }
} }
} else if (searchTermLiteralType != TypeCode.Empty) { } else if (searchTermLiteralType != TypeCode.Empty) {
Code expectedCode; Code expectedCode;
switch (searchTermLiteralType) { switch (searchTermLiteralType) {
case TypeCode.Single: case TypeCode.Single:
expectedCode = Code.Ldc_R4; expectedCode = Code.Ldc_R4;
break; break;
case TypeCode.Double: case TypeCode.Double:
expectedCode = Code.Ldc_R8; expectedCode = Code.Ldc_R8;
break; break;
case TypeCode.String: case TypeCode.String:
expectedCode = Code.Ldstr; expectedCode = Code.Ldstr;
break; break;
default: default:
throw new InvalidOperationException(); throw new InvalidOperationException();
} }
foreach (var inst in body.Instructions) { foreach (var inst in body.Instructions) {
if (inst.OpCode.Code == expectedCode && searchTermLiteralValue.Equals(inst.Operand)) if (inst.OpCode.Code == expectedCode && searchTermLiteralValue.Equals(inst.Operand))

Loading…
Cancel
Save