context: //---------------------------------------------------------------------------
  // 
  // File: HtmlSchema.cs
  //
  // Copyright (C) Microsoft Corporation.  All rights reserved.
  //
  // Description: Static information about HTML structure
  //
  //---------------------------------------------------------------------------
  
  using System.Collections;
  using System.Diagnostics;
  
  namespace CalendarSyncPlus.Presentation.Controls.HtmlXamlConversion
  {
      /// <summary>
      ///     <see cref="HtmlSchema" /> class maintains <see langword="static" />
      ///     information about HTML structure can be used by <see cref="HtmlParser" />
      ///     to check conditions under which an element starts or ends, etc.
      /// </summary>
      internal class HtmlSchema
      {
          // ---------------------------------------------------------------------
          //
          // Constructors
          //
          // ---------------------------------------------------------------------
  
          #region Constructors
  
          /// <summary>
          ///     <see langword="static" /> constructor, initializes the ArrayLists
          ///     that hold the elements in various sub-components of the schema e.g
          ///     _htmlEmptyElements, etc.
          /// </summary>
          static HtmlSchema()
          {
              // initializes the list of all html elements
              InitializeInlineElements();
  
              InitializeBlockElements();
  
              InitializeOtherOpenableElements();
  
              // initialize empty elements list
              InitializeEmptyElements();
  
              // initialize list of elements closing on the outer element end
              InitializeElementsClosingOnParentElementEnd();
  
              // initalize list of elements that close when a new element starts
              InitializeElementsClosingOnNewElementStart();
  
              // Initialize character entities
              InitializeHtmlCharacterEntities();
          }
  
          #endregion Constructors;
  
          // ---------------------------------------------------------------------
          //
          // Internal Methods
          //
          // ---------------------------------------------------------------------
  
          #region Internal Methods
  
          /// <summary>
          ///     returns <see langword="true" /> when
          ///     <paramref name="xmlElementName" /> corresponds to empty element
          /// </summary>
          /// <param name="xmlElementName">
          ///     string representing name to test
          /// </param>
          internal static bool IsEmptyElement(string xmlElementName)
          {
              // convert to lowercase before we check
              // because element names are not case sensitive
              return _htmlEmptyElements.Contains(xmlElementName.ToLower());
          }
  
          /// <summary>
          ///     returns <see langword="true" /> if <paramref name="xmlElementName" />
          ///     represents a block formattinng element. It used in an algorithm of
          ///     transferring inline elements over block elements in
          ///     <see cref="HtmlParser" />
          /// </summary>
          /// <param name="xmlElementName"></param>
          /// <returns>
          /// </returns>
          internal static bool IsBlockElement(string xmlElementName)
          {
              return _htmlBlockElements.Contains(xmlElementName);
          }
  
          /// <summary>
          ///     returns <see langword="true" /> if the
          ///     <paramref name="xmlElementName" /> represents an inline formatting
          ///     element
          /// </summary>
          /// <param name="xmlElementName"></param>
          /// <returns>
          /// </returns>
          internal static bool IsInlineElement(string xmlElementName)
          {
              return _htmlInlineElements.Contains(xmlElementName);
          }
  
          /// <summary>
          ///     It is a list of known html elements which we want to allow to
          ///     produce bt HTML parser, but don'tt want to act as inline, block or
          ///     no-scope. Presence in this list will allow to open elements during
          ///     html parsing, and adding the to a tree produced by html parser.
          /// </summary>
          internal static bool IsKnownOpenableElement(string xmlElementName)
          {
              return _htmlOtherOpenableElements.Contains(xmlElementName);
          }
  
          /// <summary>
          ///     returns <see langword="true" /> when
          ///     <paramref name="xmlElementName" /> closes when the outer element
          ///     closes this is <see langword="true" /> of elements with optional
          ///     start tags
          /// </summary>
          /// <param name="xmlElementName">
          ///     string representing name to test
          /// </param>
          internal static bool ClosesOnParentElementEnd(string xmlElementName)
          {
              // convert to lowercase when testing
              return _htmlElementsClosingOnParentElementEnd.Contains(xmlElementName.ToLower());
          }
  
          /// <summary>
          ///     returns <see langword="true" /> if the current element closes when
          ///     the new element, whose name has just been read, starts
          /// </summary>
          /// <param name="currentElementName">
          ///     string representing current element name
          /// </param>
          /// <param name="elementName"></param>
          internal static bool ClosesOnNextElementStart(string currentElementName, string nextElementName)
          {
              Debug.Assert(currentElementName == currentElementName.ToLower());
              switch (currentElementName)
              {
                  case "colgroup":
                      return _htmlElementsClosingColgroup.Contains(nextElementName) && IsBlockElement(nextElementName);
                  case "dd":
                      return _htmlElementsClosingDD.Contains(nextElementName) && IsBlockElement(nextElementName);
                  case "dt":
                      return _htmlElementsClosingDT.Contains(nextElementName) && IsBlockElement(nextElementName);
                  case "li":
                      return _htmlElementsClosingLI.Contains(nextElementName);
                  case "p":
                      return IsBlockElement(nextElementName);
                  case "tbody":
                      return _htmlElementsClosingTbody.Contains(nextElementName);
                  case "tfoot":
                      return _htmlElementsClosingTfoot.Contains(nextElementName);
                  case "thead":
                      return _htmlElementsClosingThead.Contains(nextElementName);
                  case "tr":
                      return _htmlElementsClosingTR.Contains(nextElementName);
                  case "td":
                      return _htmlElementsClosingTD.Contains(nextElementName);
                  case "th":
                      return _htmlElementsClosingTH.Contains(nextElementName);
              }
              return false;
          }
  
          /// <summary>
          ///     returns <see langword="true" /> if the string passed as argument is
          ///     an Html entity name
          /// </summary>
          /// <param name="entityName">
          ///     string to be tested for Html entity name
          /// </param>
          internal static bool IsEntity(string entityName)
          {
              // we do not convert entity strings to lowercase because these names are case-sensitive
              if (_htmlCharacterEntities.Contains(entityName))
              {
                  return true;
              }
              return false;
          }
  
          /// <summary>
          ///     returns the character represented by the entity name string which is
          ///     passed as an argument, if the string is an entity name as specified
          ///     in _htmlCharacterEntities, returns the character value of 0
          ///     otherwise
          /// </summary>
          /// <param name="entityName">
          ///     string representing entity name whose character value is desired
          /// </param>
          internal static char EntityCharacterValue(string entityName)
          {
              if (_htmlCharacterEntities.Contains(entityName))
              {
                  return (char) _htmlCharacterEntities[entityName];
              }
              return (char) 0;
          }
  
          #endregion Internal Methods
  
          // ---------------------------------------------------------------------
          //
          //  Internal Properties
          //
          // ---------------------------------------------------------------------
  
          #region Internal Properties
  
          #endregion Internal Indexers
  
          // ---------------------------------------------------------------------
          //
          // Private Methods
          //
          // ---------------------------------------------------------------------
  
          #region Private Methods
  
          private static void InitializeInlineElements()
          {
              _htmlInlineElements = new ArrayList();
              _htmlInlineElements.Add("a");
              _htmlInlineElements.Add("abbr");
              _htmlInlineElements.Add("acronym");
              _htmlInlineElements.Add("address");
              _htmlInlineElements.Add("b");
              _htmlInlineElements.Add("bdo"); // ???
              _htmlInlineElements.Add("big");
              _htmlInlineElements.Add("button");
              _htmlInlineElements.Add("code");
              _htmlInlineElements.Add("del"); // deleted text
              _htmlInlineElements.Add("dfn");
              _htmlInlineElements.Add("em");
              _htmlInlineElements.Add("font");
              _htmlInlineElements.Add("i");
              _htmlInlineElements.Add("ins"); // inserted text
              _htmlInlineElements.Add("kbd"); // text to entered by a user
              _htmlInlineElements.Add("label");
              _htmlInlineElements.Add("legend"); // ???
              _htmlInlineElements.Add("q"); // short inline quotation
              _htmlInlineElements.Add("s"); // strike-through text style
              _htmlInlineElements.Add("samp"); // Specifies a code sample
              _htmlInlineElements.Add("small");
              _htmlInlineElements.Add("span");
              _htmlInlineElements.Add("strike");
              _htmlInlineElements.Add("strong");
              _htmlInlineElements.Add("sub");
              _htmlInlineElements.Add("sup");
              _htmlInlineElements.Add("u");
              _htmlInlineElements.Add("var"); // indicates an instance of a program variable
          }
  
          private static void InitializeBlockElements()
          {
  
gt:             _htmlBlockElements = new ArrayList();