public static string WrapUOHtmlColors(this string str, Color start, Color end) { if (start == end) { return(WrapUOHtmlColor(str, start)); } var t = new StringBuilder(); var tags = DictionaryPool <int, string> .AcquireObject(); var tago = false; var tagi = 0; for (var i = 0; i < str.Length; i++) { if (str[i] == '<') { tago = true; tagi = i; } else if (tago && str[i] == '>') { tago = false; } if (tago) { if (i > tagi) { t.Append(str[i]); } } else if (t.Length > 0) { tags[tagi] = t.ToString(); t.Clear(); } } t.Clear(); double n, o = 0.0; string tag, s; for (var i = 0; i < str.Length; i++) { tag = tags.GetValue(i); if (tag != null) { t.Append("<" + tag + ">"); } n = i / (double)str.Length; if (n <= 0 || n >= o + 0.05) { o = n; } s = str[i].ToString(); t.Append(o == n ? s.WrapUOHtmlColor(start.Interpolate(end, n), false) : s); } DictionaryPool <int, string> .FreeObject(tags); return(t.ToString()); }
public static string WrapUOHtmlColors(this string str, Color start, Color end) { var t = new StringBuilder(); /*var matches = _HtmlRegex.Matches(str); * * if (matches.Count <= 0) * {*/ double n, o = 0.0; string s; for (var i = 0; i < str.Length; i++) { n = i / (str.Length - 1.0); if (n <= 0 || n >= o + 0.05) { o = n; } s = str[i].ToString(); t.Append(o == n ? s.WrapUOHtmlColor(start.Interpolate(end, n), false) : s); } /*} * else * { * var len = matches.Cast<Match>().Aggregate(0.0, (c, m) => c + m.Groups[1].Length); * var pos = 0; * * GroupCollection g; * * double n, o = 0.0; * string s; * * foreach (Match m in matches) * { * g = m.Groups; * * t.Append(g[0].Value); * * for (var i = 0; i < g[1].Length; i++) * { * n = ++pos / len; * * if (n <= 0 || n >= o + 0.05) * { * o = n; * } * * s = g[1].Value[i].ToString(); * * t.Append(o == n ? s.WrapUOHtmlColor(start.Interpolate(end, n), false) : s); * } * * t.Append(g[2].Value); * } * }*/ return(t.ToString()); }