Example #1
0
        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());
        }