Пример #1
0
 private void WriteNumericEntity(Token token, TextWriter writer, NumberStyles styles)
 {
     ushort value;
      if(ushort.TryParse(token.Text, styles, CultureInfo.InvariantCulture, out value))
      {
     writer.Write((char)value);
      }
      else
      {
     // Failed to parse, write it as content
     WriteAsContext(token, writer);
      }
 }
Пример #2
0
 private void WriteTextEntity(Token token, TextWriter writer)
 {
     char c;
      if(_entityToCharMap.TryGetValue(token.Text, out c))
      {
     // We recognize the entity
     writer.Write(c);
      }
      else
      {
     // Do not recognize, treat it as content
     WriteAsContext(token, writer);
      }
 }
Пример #3
0
        public Token? Next()
        {
            _text.Clear();

             int startIndex = _index;

             if(!ParseNext())
            return null;

             Token token = new Token();
             token.Text = _text.ToString();
             token.StartIndex = startIndex + 1;
             token.EndIndex = _index + 1;
             token.Type = _type;

             return token;
        }
Пример #4
0
        private void WriteToken(Token token, TextWriter writer)
        {
            switch(token.Type)
             {
            case TokenType.Content:
               WriteContent(token.Text, writer);
               break;

            case TokenType.TextEntity:
               WriteTextEntity(token, writer);
               break;

            case TokenType.DecimalEntity:
               WriteDecimalEntity(token, writer);
               break;

            case TokenType.HexEntity:
               WriteHexEntity(token, writer);
               break;

             }
        }
Пример #5
0
 private void WriteHexEntity(Token token, TextWriter writer)
 {
     WriteNumericEntity(token, writer, NumberStyles.AllowHexSpecifier);
 }
Пример #6
0
 private void WriteDecimalEntity(Token token, TextWriter writer)
 {
     WriteNumericEntity(token, writer, NumberStyles.Integer);
 }
Пример #7
0
 private void WriteAsContext(Token token, TextWriter writer)
 {
     WriteContent(_html.Substring(token.StartIndex, token.EndIndex - token.StartIndex), writer);
 }