public RTFBuilder ColorArg(string arg) { if (arg.StartsWith("\"") || arg.StartsWith("\'")) { bool colon = arg.EndsWith(arg[0].ToString() + ":"); if (arg.Length == 1 || (!arg.EndsWith(arg[0].ToString()) && !colon)) { return(RTFBuilder.Colored(RTFBuilder.WavyUnderline(RTFBuilder.For(arg)), ColorTable.PINK)); } RTFBuilder res = new RTFBuilder(); res.Append(RTFBuilder.Colored(RTFBuilder.For(arg[0].ToString()), ColorTable.DARK_CYAN)); res.Append(RTFBuilder.Colored(ColorArg(arg.Substring(1, arg.Length - (colon ? 3 : 2))), ColorTable.DARK_CYAN)); res.Append(RTFBuilder.Colored(RTFBuilder.For(arg[0].ToString()), ColorTable.DARK_CYAN)); if (colon) { res.Append(RTFBuilder.For(":")); } return(res); } RTFBuilder built = new RTFBuilder(); StringBuilder sb = new StringBuilder(); int deep = 0; for (int i = 0; i < arg.Length; i++) { if (arg[i] == '<') { if (deep == 0) { built.Append(RTFBuilder.For(sb.ToString())); sb.Clear(); } deep++; } else if (deep > 0 && arg[i] == '>') { deep--; if (deep == 0) { built.Append(RTFBuilder.BackColored(RTFBuilder.Colored(RTFBuilder.For("<"), ColorTable.DARK_GRAY), ColorTable.LIGHT_GRAY)); if (sb.Length > 1) { built.Append(RTFBuilder.BackColored(RTFBuilder.Colored(ColorInsideTag(sb.ToString().Substring(1, sb.Length - 1)), ColorTable.DARK_GRAY), ColorTable.LIGHT_GRAY)); } built.Append(RTFBuilder.BackColored(RTFBuilder.Colored(RTFBuilder.For(">"), ColorTable.DARK_GRAY), ColorTable.LIGHT_GRAY)); sb.Clear(); continue; } } sb.Append(arg[i]); } built.Append(RTFBuilder.For(sb.ToString())); return(built); }
public RTFBuilder ColorInsideTag(string arg) { RTFBuilder built = new RTFBuilder(); StringBuilder sb = new StringBuilder(); int deep = 0; for (int i = 0; i < arg.Length; i++) { if (arg[i] == '[') { if (deep == 0) { built.Append(RTFBuilder.For(sb.ToString())); sb.Clear(); } deep++; } else if (deep > 0 && arg[i] == ']') { deep--; if (deep == 0) { built.Append(RTFBuilder.BackColored(RTFBuilder.Colored(RTFBuilder.For("["), ColorTable.LIGHT_GRAY), ColorTable.DARK_GRAY)); if (sb.Length > 1) { built.Append(RTFBuilder.BackColored(RTFBuilder.Colored(ColorArg(sb.ToString().Substring(1, sb.Length - 1)), ColorTable.LIGHT_GRAY), ColorTable.DARK_GRAY)); } built.Append(RTFBuilder.BackColored(RTFBuilder.Colored(RTFBuilder.For("]"), ColorTable.LIGHT_GRAY), ColorTable.DARK_GRAY)); sb.Clear(); continue; } } sb.Append(arg[i]); } built.Append(RTFBuilder.For(sb.ToString())); return(built); }