public static Reflection GetReflectionsFor(string Input, string ResString) { Reflection Results = new Reflection("", Input, ""); if (Input.Length == 0 || !ResString.Contains(Input)) { return(Results); } //string Pattern = String.Format(@"\W{0}\W", Input.Replace("\\", "\\\\").Replace(".", "\\.").Replace("$", "\\$").Replace("^", "\\^").Replace("*", "\\*").Replace("|", "\\|").Replace("+", "\\+").Replace("?", "\\?").Replace("{", "\\{").Replace("}", "\\}").Replace("[", "\\[").Replace("]", "\\]").Replace("(", "\\(").Replace(")", "\\)")); string Pattern = String.Format(@"\W{0}\W", Regex.Escape(Input)); MatchCollection MatchResults = Regex.Matches(ResString, Pattern, RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace); foreach (Match M in MatchResults) { if (M.Success) { int SubStringStart = M.Index - 20; int SubStringLength = 0; if (SubStringStart < 0) { SubStringStart = 0; SubStringLength = SubStringStart + M.Length + 20; } else { SubStringLength = M.Length + 40; } if (SubStringStart + SubStringLength >= ResString.Length) { Results.Add(ResString.Substring(SubStringStart)); } else { Results.Add(ResString.Substring(SubStringStart, SubStringLength)); } } } return(Results); }
//public static Reflection GetReflections(string Input, Response Res) //{ // List<string> Results = new List<string>(); // string ResString = Res.ToString(); // return GetReflections(Input, ResString); //} public static Reflection GetReflections(string Input, string ResString) { List <string> Variations = new List <string>(); Variations.Add(Input); Variations.Add(Input.ToLower()); Variations.Add(Input.ToUpper()); Variations.Add(Tools.UrlEncode(Input)); Variations.Add(Tools.UrlPathEncode(Input)); Variations.Add(Tools.HtmlEncode(Input)); Variations.Add(Tools.XmlEncode(Input)); Variations.Add(Tools.JsonEncode(Input)); Variations.Add(Tools.RelaxedUrlEncode(Input)); Variations.Add(Tools.UrlUnicodeEncode(Input)); Variations.Add(Input.Replace("\"", "\\\"")); Variations.Add(Input.Replace("'", "\\\'")); Dictionary <string, int> TempDict = new Dictionary <string, int>(); foreach (string V in Variations) { TempDict[V] = 0; } Variations = new List <string>(TempDict.Keys); Reflection Result = new Reflection("", Input, ""); foreach (string V in Variations) { Reflection Ref = GetReflectionsFor(V, ResString); if (Ref.Count > 0) { foreach (string RefStr in Ref.GetReflections()) { //Result.Add(RefStr.Replace(V, string.Format("<i<hlo>>{0}<i</hlo>>", V))); Result.Add(RefStr); } } } return(Result); }
public static Reflection GetReflections(string Input, string ResString) { Reflection Results = new Reflection("", Input, ""); if (Input.Length == 0 || !ResString.Contains(Input)) return Results; string Pattern = String.Format(@"\W{0}\W", Input.Replace("\\", "\\\\").Replace(".", "\\.").Replace("$", "\\$").Replace("^", "\\^").Replace("*", "\\*").Replace("|", "\\|").Replace("+", "\\+").Replace("?", "\\?").Replace("{", "\\{").Replace("}", "\\}").Replace("[", "\\[").Replace("]", "\\]").Replace("(", "\\(").Replace(")", "\\)")); MatchCollection MatchResults = Regex.Matches(ResString, Pattern, RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace); foreach (Match M in MatchResults) { if (M.Success) { int SubStringStart = M.Index - 20; int SubStringLength = 0; if (SubStringStart < 0) { SubStringStart = 0; SubStringLength = SubStringStart + M.Length + 20; } else { SubStringLength = M.Length + 40; } if (SubStringStart + SubStringLength >= ResString.Length) Results.Add(ResString.Substring(SubStringStart)); else Results.Add(ResString.Substring(SubStringStart, SubStringLength)); } } return Results; }