private SortedDictionary <int, Tuple <int, IMacro, string[]> > FindMacros(StringBuilder s) { SortedDictionary <int, Tuple <int, IMacro, string[]> > replace = new SortedDictionary <int, Tuple <int, IMacro, string[]> >(ReverseComparer <int> .Default); StringBuilder stringBuilder = new StringBuilder(); int i = 0; bool inQuotes = false; while (i < s.Length) { if (s[i] == '"') { inQuotes = !inQuotes; ++i; } else if (inQuotes || DefineCollectionOptimized.IsValidCharacter(s[i])) { stringBuilder.Append(s[i]); ++i; } else if (stringBuilder.Length > 0) { this.GetMacroData(s, replace, ref i, stringBuilder.ToString()); stringBuilder.Clear(); } else { ++i; } } int length = s.Length; this.GetMacroData(s, replace, ref length, stringBuilder.ToString()); return(replace); }
private SortedDictionary <int, Tuple <int, IMacro, string[]> > FindMacros(StringBuilder s) { var replace = new SortedDictionary <int, Tuple <int, IMacro, string[]> >( ReverseComparer <int> .Default ); StringBuilder macroName = new StringBuilder(); for (int i = 0; i < s.Length;) { if (DefineCollectionOptimized.IsValidCharacter(s[i])) { macroName.Append(s[i]); i++; } else { if (macroName.Length > 0) { GetMacroData(s, replace, ref i, macroName.ToString()); macroName.Clear(); } else { i++; } } } int last = s.Length; GetMacroData(s, replace, ref last, macroName.ToString()); return(replace); }
private void FindString(string s, IDictionary <int, string> containedOriginals, string toFind) { int index = s.IndexOf(toFind); while (index >= 0)// && index + original.Length < s.Length && s[index - 1] { bool can1; if (index > 0) { char c = s[index - 1]; can1 = !DefineCollectionOptimized.IsValidCharacter(c); } else { can1 = true; //in the beginning of the line } bool can2; if (index + toFind.Length < s.Length) { char c = s[index + toFind.Length]; can2 = !DefineCollectionOptimized.IsValidCharacter(c); } else { can2 = true; //in the end of the line } if (can1 && can2 && !containedOriginals.ContainsKey(index)) { containedOriginals[index] = toFind; break; } index = s.IndexOf(toFind, index + 1); } }
private void FindString(string s, IDictionary <int, string> containedOriginals, string toFind) { for (int key = s.IndexOf(toFind); key >= 0; key = s.IndexOf(toFind, key + 1)) { if ((key <= 0 || !DefineCollectionOptimized.IsValidCharacter(s[key - 1])) && (key + toFind.Length >= s.Length || !DefineCollectionOptimized.IsValidCharacter(s[key + toFind.Length])) && !containedOriginals.ContainsKey(key)) { containedOriginals[key] = toFind; break; } } }