private int FormatRichText(ref RichTextBox targetObject, string Text, bool IndividualLines) { int ret = 0; string Raw; int CountSinceLastPair = 0; bool StartCounting = false; targetObject.Font = new Font(targetObject.Font.FontFamily, FontSize); targetObject.Clear(); //ensure we only got single spaces Raw = Text.Replace(" ", " "); List <string> Tokens = new List <string>(); //split tokens Tokens.AddRange(Raw.Split(' ').ToList()); // int Max = Tokens.Count(); int cnt = 0; //TODO apply formatting foreach (string Tok in Tokens) { //Check VS ling bool Bold = false; cnt++; System.Drawing.Color DaColor = Color.Black; string TokCopy = Tok; if (StartCounting) { CountSinceLastPair++; } //we replace incoming \r\ns anyway... TokCopy = Tok.Replace("\r\n", ""); TokCopy = TokCopy.Replace("\r", ""); TokCopy = TokCopy.Replace("\n", ""); //global keywork replacements DaColor = ApplyFormatting(ref TokCopy, DockerSyntax, IndividualLines); //Check if uppercase : //CHeck for substring ,in token sply by an equall List <string> SubTokens = new List <string>(); List <string> splitters = new List <string>(); char[] spearator = { '=', ',' }; string workCopy = TokCopy; int dk = 0; SubTokens = TokCopy.Split(spearator).ToList(); // SubTokens.AddRange(Tok.Split('=').ToList()); //append to the box if (SubTokens.Count > 1) { int daC = -1; foreach (string s in SubTokens) { dk++; if (dk == SubTokens.Count) { break; // last one no separator } workCopy = workCopy.Substring(s.Length, workCopy.Length - s.Length); string sep = workCopy.Substring(0, 1); splitters.Add(sep); //remove the separator workCopy = workCopy.Substring(1, workCopy.Length - 1); } //we have all the sub tokens and we have the separators foreach (string s in SubTokens) { daC++; string s_copy = s; DaColor = ApplyFormatting(ref s_copy, DockerSyntax, IndividualLines); targetObject.AppendText(s_copy, DaColor); if (daC < splitters.Count) // LAst case { targetObject.AppendText(splitters[daC], System.Drawing.Color.Brown); } } } else { //jsut the one token targetObject.AppendText(TokCopy, DaColor); } //Carraige returns if (IndividualLines) { if (TokCopy.Length > 2) { if (TokCopy.Substring(0, 2) == "--") { StartCounting = true; } } } if (cnt != Max) { targetObject.AppendText(" "); if (IndividualLines) { if (CountSinceLastPair == 1) { CountSinceLastPair = 0; StartCounting = false; targetObject.AppendText("\r\n"); } } } } return(ret); }