/// <summary>
 /// Handles the filters for closing html tags
 /// </summary>
 private void CloseTag(FilterBuffer b, int i, FilterTags Filters)
 {
     i = b.SkipWhiteSpace(i, true);
     b.Write(i);
     b.Write(Filters.Content.HTML);
     b.Seek(i);
 }
 /// <summary>
 /// Checks the located tag for a match, and does the required operation if found.
 /// Returns the next position to check.
 /// </summary>
 private int HandleTag(FilterBuffer b, int i, int j, string tag, ArrayList FilterList)
 {
     foreach (FilterTags Filter in FilterList)
     {
         if (String.Compare(tag, 1, Filter.Tag, 0, Filter.Tag.Length, true) == 0)
         {
             if (!Filter.Multiple)
             {
                 FilterList.Remove(Filter);
             }
             if (tag[1] != '/')
             {
                 OpenTag(b, i, j, tag, Filter);
                 j = b.offset;
             }
             else
             {
                 CloseTag(b, i, Filter);
             }
             if (FilterList.Count == 0)
             {
                 return(b.Last);
             }
             break;
         }
     }
     return(j + 1);
 }
        /// <summary>
        /// This is the actual Response filter.
        /// </summary>
        /// <param name="b"></param>
        public void DoFilter(FilterBuffer b)
        {
            int j;

            foreach (object o in BkupList)
            {
                FwdList.Add(o);
            }
            if (FwdList.Count > 0)
            {
                int i = b.IndexOf('<');
                //TODO: Add backup.
                //TODO: handle multiple calls.
                while (i < b.Last)
                {
                    j = b.IndexOf('>', i);
                    while (InComment(b, i, j))
                    {
                        j = b.IndexOf('>', j + 1);
                    }
                    if (i < j)
                    {
                        i = b.IndexOf('<', HandleTag(b, i, j, b.ToString(i, j), FwdList));
                    }
                }
            }
            b.Write();
        }
 /// <summary>
 /// Returns true if position in b at i starts a comment that isn't completed
 /// by the close carot at j.
 /// </summary>
 private bool InComment(FilterBuffer b, int i, int j)
 {
     if (j < i + 7 || b.ToString(i, i + 3) != "<!--")
     {
         return(false);
     }
     return(b.ToString(j - 2, j) != "-->" && j < b.Last);
 }
 /// <summary>
 /// Handles the filters for opening html tags
 /// </summary>
 private void OpenTag(FilterBuffer b, int i, int j, string tag, FilterTags Filters)
 {
     b.Write(i);
     if (Filters.Replace != null)
     {
         tag = Filters.Replace.HTML;
     }
     foreach (FilterTag F in Filters.Attributes)
     {
         F.Substitute(ref tag);
     }
     b.Write(tag);
     if (Filters.Content != null)
     {
         b.Write(Filters.Content.HTML);
     }
     b.Seek(j + 1);
 }