Ejemplo n.º 1
0
        private XmlToken TokenizeSimple(string text, XmlTokenKind kind, XmlTokenizerMode nextMode)
        {
            XmlToken token = new XmlToken(kind, text.Length);

            position += text.Length;
            mode      = nextMode;
            return(token);
        }
Ejemplo n.º 2
0
        private XmlToken TokenizeEntity()
        {
            Debug.Assert(mode == XmlTokenizerMode.OutsideElement);
            Debug.Assert(input[position] == '&');
            XmlToken token = new XmlToken(XmlTokenKind.Entity, input.IndexOf(';', position) - position);

            position += token.Length;
            return(token);
        }
Ejemplo n.º 3
0
        private XmlToken TokenizeAttributeValue()
        {
            Debug.Assert(mode == XmlTokenizerMode.AfterAttributeEquals);
            int      closePosition = input.IndexOf(input[position], position + 1);
            XmlToken token         = new XmlToken(XmlTokenKind.AttributeValue, closePosition + 1 - position);

            position = closePosition + 1;
            mode     = XmlTokenizerMode.InsideElement;
            return(token);
        }
Ejemplo n.º 4
0
        private XmlToken NextToken()
        {
            if (position >= input.Length)
            {
                return(new XmlToken(XmlTokenKind.EOF, 0));
            }
            XmlToken token;

            switch (mode)
            {
            case XmlTokenizerMode.AfterAttributeEquals:
                token = TokenizeAttributeValue();
                break;

            case XmlTokenizerMode.AfterAttributeName:
                token = TokenizeSimple("=", XmlTokenKind.Equals, XmlTokenizerMode.AfterAttributeEquals);
                break;

            case XmlTokenizerMode.AfterOpen:
                token = TokenizeName(XmlTokenKind.ElementName, XmlTokenizerMode.InsideElement);
                break;

            case XmlTokenizerMode.InsideCData:
                token = TokenizeInsideCData();
                break;

            case XmlTokenizerMode.InsideComment:
                token = TokenizeInsideComment();
                break;

            case XmlTokenizerMode.InsideElement:
                token = TokenizeInsideElement();
                break;

            case XmlTokenizerMode.InsideProcessingInstruction:
                token = TokenizeInsideProcessingInstruction();
                break;

            case XmlTokenizerMode.OutsideElement:
                token = TokenizeOutsideElement();
                break;

            default:
                token = new XmlToken(XmlTokenKind.EOF, 0);
                Debug.Fail("missing case");
                break;
            }
            return(token);
        }
Ejemplo n.º 5
0
        private XmlToken TokenizeElementWhitespace()
        {
            int i;

            for (i = position; i < input.Length; i++)
            {
                if (!char.IsWhiteSpace(input[i]))
                {
                    break;
                }
            }
            XmlToken token = new XmlToken(XmlTokenKind.ElementWhitespace, i - position);

            position = i;
            return(token);
        }
Ejemplo n.º 6
0
        private XmlToken TokenizeInsideCData()
        {
            Debug.Assert(mode == XmlTokenizerMode.InsideCData);
            int tokenend = input.IndexOf("]]>", position);

            if (position == tokenend)
            {
                position += "]]>".Length;
                mode      = XmlTokenizerMode.OutsideElement;
                return(new XmlToken(XmlTokenKind.CDataEnd, "]]>".Length));
            }
            else
            {
                XmlToken token = new XmlToken(XmlTokenKind.TextContent, tokenend - position);
                position = tokenend;
                return(token);
            }
        }
Ejemplo n.º 7
0
        private XmlToken TokenizeInsideProcessingInstruction()
        {
            Debug.Assert(mode == XmlTokenizerMode.InsideProcessingInstruction);
            int tokenend = input.IndexOf("?>", position);

            if (position == tokenend)
            {
                position += "?>".Length;
                mode      = XmlTokenizerMode.OutsideElement;
                return(new XmlToken(XmlTokenKind.CloseProcessingInstruction, "?>".Length));
            }
            else
            {
                XmlToken token = new XmlToken(XmlTokenKind.TextContent, tokenend - position);
                position = tokenend;
                return(token);
            }
        }
Ejemplo n.º 8
0
        private XmlToken TokenizeName(XmlTokenKind kind, XmlTokenizerMode nextMode)
        {
            Debug.Assert(mode == XmlTokenizerMode.AfterOpen || mode == XmlTokenizerMode.InsideElement);
            int i;

            for (i = position; i < input.Length; i++)
            {
                if (!IsNameCharacter(input[i]))
                {
                    break;
                }
            }
            XmlToken token = new XmlToken(kind, i - position);

            mode     = nextMode;
            position = i;
            return(token);
        }
Ejemplo n.º 9
0
        private XmlToken TokenizeInsideComment()
        {
            Debug.Assert(mode == XmlTokenizerMode.InsideComment);
            int tokenend = input.IndexOf("-->", position);

            if (position == tokenend)
            {
                position += "-->".Length;
                mode      = XmlTokenizerMode.OutsideElement;
                return(new XmlToken(XmlTokenKind.CommentEnd, "-->".Length));
            }
            else
            {
                XmlToken token = new XmlToken(XmlTokenKind.CommentText, tokenend - position);
                position = tokenend;
                return(token);
            }
        }
Ejemplo n.º 10
0
 static Color ColorForToken( XmlToken token, string tokenText )
 {
   Color color = Color.FromRgb( 0, 0, 0 );
   switch( token.Kind )
   {
     case XmlTokenKind.Open:
     case XmlTokenKind.OpenClose:
     case XmlTokenKind.Close:
     case XmlTokenKind.SelfClose:
     case XmlTokenKind.CommentBegin:
     case XmlTokenKind.CommentEnd:
     case XmlTokenKind.CDataBegin:
     case XmlTokenKind.CDataEnd:
     case XmlTokenKind.Equals:
     case XmlTokenKind.OpenProcessingInstruction:
     case XmlTokenKind.CloseProcessingInstruction:
     case XmlTokenKind.AttributeValue:
       color = Color.FromRgb( 0, 0, 255 );
       // color = "blue";
       break;
     case XmlTokenKind.ElementName:
       color = Color.FromRgb( 163, 21, 21 );
       // color = "brown";
       break;
     case XmlTokenKind.TextContent:
       // color = "black";
       break;
     case XmlTokenKind.AttributeName:
     case XmlTokenKind.Entity:
       color = Color.FromRgb( 255, 0, 0 );
       // color = "red";
       break;
     case XmlTokenKind.CommentText:
       color = Color.FromRgb( 0, 128, 0 );
       // color = "green";
       break;
   }
   if( token.Kind == XmlTokenKind.ElementWhitespace
       || ( token.Kind == XmlTokenKind.TextContent && tokenText.Trim() == "" ) )
   {
     // color = null;
   }
   return color;
 }
Ejemplo n.º 11
0
        private XmlToken TokenizeText()
        {
            Debug.Assert(input[position] != '<');
            Debug.Assert(input[position] != '&');
            Debug.Assert(mode == XmlTokenizerMode.OutsideElement);
            int i;

            for (i = position; i < input.Length; i++)
            {
                if (input[i] == '<' || input[i] == '&')
                {
                    break;
                }
            }
            XmlToken token = new XmlToken(XmlTokenKind.TextContent, i - position);

            position = i;
            return(token);
        }
Ejemplo n.º 12
0
 private XmlToken NextToken()
 {
   if( position >= input.Length )
     return new XmlToken( XmlTokenKind.EOF, 0 );
   XmlToken token;
   switch( mode )
   {
     case XmlTokenizerMode.AfterAttributeEquals:
       token = TokenizeAttributeValue();
       break;
     case XmlTokenizerMode.AfterAttributeName:
       token = TokenizeSimple( "=", XmlTokenKind.Equals, XmlTokenizerMode.AfterAttributeEquals );
       break;
     case XmlTokenizerMode.AfterOpen:
       token = TokenizeName( XmlTokenKind.ElementName, XmlTokenizerMode.InsideElement );
       break;
     case XmlTokenizerMode.InsideCData:
       token = TokenizeInsideCData();
       break;
     case XmlTokenizerMode.InsideComment:
       token = TokenizeInsideComment();
       break;
     case XmlTokenizerMode.InsideElement:
       token = TokenizeInsideElement();
       break;
     case XmlTokenizerMode.InsideProcessingInstruction:
       token = TokenizeInsideProcessingInstruction();
       break;
     case XmlTokenizerMode.OutsideElement:
       token = TokenizeOutsideElement();
       break;
     default:
       token = new XmlToken( XmlTokenKind.EOF, 0 );
       Debug.Fail( "missing case" );
       break;
   }
   return token;
 }
Ejemplo n.º 13
0
 private XmlToken TokenizeInsideComment()
 {
   Debug.Assert( mode == XmlTokenizerMode.InsideComment );
   int tokenend = input.IndexOf( "-->", position );
   if( position == tokenend )
   {
     position += "-->".Length;
     mode = XmlTokenizerMode.OutsideElement;
     return new XmlToken( XmlTokenKind.CommentEnd, "-->".Length );
   }
   else
   {
     XmlToken token = new XmlToken( XmlTokenKind.CommentText, tokenend - position );
     position = tokenend;
     return token;
   }
 }
Ejemplo n.º 14
0
 private XmlToken TokenizeInsideCData()
 {
   Debug.Assert( mode == XmlTokenizerMode.InsideCData );
   int tokenend = input.IndexOf( "]]>", position );
   if( position == tokenend )
   {
     position += "]]>".Length;
     mode = XmlTokenizerMode.OutsideElement;
     return new XmlToken( XmlTokenKind.CDataEnd, "]]>".Length );
   }
   else
   {
     XmlToken token = new XmlToken( XmlTokenKind.TextContent, tokenend - position );
     position = tokenend;
     return token;
   }
 }
Ejemplo n.º 15
0
 private XmlToken TokenizeInsideProcessingInstruction()
 {
   Debug.Assert( mode == XmlTokenizerMode.InsideProcessingInstruction );
   int tokenend = input.IndexOf( "?>", position );
   if( position == tokenend )
   {
     position += "?>".Length;
     mode = XmlTokenizerMode.OutsideElement;
     return new XmlToken( XmlTokenKind.CloseProcessingInstruction, "?>".Length );
   }
   else
   {
     XmlToken token = new XmlToken( XmlTokenKind.TextContent, tokenend - position );
     position = tokenend;
     return token;
   }
 }
Ejemplo n.º 16
0
 private XmlToken TokenizeEntity()
 {
   Debug.Assert( mode == XmlTokenizerMode.OutsideElement );
   Debug.Assert( input[ position ] == '&' );
   XmlToken token = new XmlToken( XmlTokenKind.Entity, input.IndexOf( ';', position ) - position );
   position += token.Length;
   return token;
 }
Ejemplo n.º 17
0
 private XmlToken TokenizeSimple( string text, XmlTokenKind kind, XmlTokenizerMode nextMode )
 {
   XmlToken token = new XmlToken( kind, text.Length );
   position += text.Length;
   mode = nextMode;
   return token;
 }
Ejemplo n.º 18
0
 private XmlToken TokenizeText()
 {
   Debug.Assert( input[ position ] != '<' );
   Debug.Assert( input[ position ] != '&' );
   Debug.Assert( mode == XmlTokenizerMode.OutsideElement );
   int i;
   for( i = position; i < input.Length; i++ )
     if( input[ i ] == '<' || input[ i ] == '&' )
       break;
   XmlToken token = new XmlToken( XmlTokenKind.TextContent, i - position );
   position = i;
   return token;
 }
Ejemplo n.º 19
0
 private XmlToken TokenizeElementWhitespace()
 {
   int i;
   for( i = position; i < input.Length; i++ )
     if( !char.IsWhiteSpace( input[ i ] ) )
       break;
   XmlToken token = new XmlToken( XmlTokenKind.ElementWhitespace, i - position );
   position = i;
   return token;
 }
Ejemplo n.º 20
0
 private XmlToken TokenizeName( XmlTokenKind kind, XmlTokenizerMode nextMode )
 {
   Debug.Assert( mode == XmlTokenizerMode.AfterOpen || mode == XmlTokenizerMode.InsideElement );
   int i;
   for( i = position; i < input.Length; i++ )
     if( !IsNameCharacter( input[ i ] ) )
       break;
   XmlToken token = new XmlToken( kind, i - position );
   mode = nextMode;
   position = i;
   return token;
 }
Ejemplo n.º 21
0
 private XmlToken TokenizeAttributeValue()
 {
   Debug.Assert( mode == XmlTokenizerMode.AfterAttributeEquals );
   int closePosition = input.IndexOf( input[ position ], position + 1 );
   XmlToken token = new XmlToken( XmlTokenKind.AttributeValue, closePosition + 1 - position );
   position = closePosition + 1;
   mode = XmlTokenizerMode.InsideElement;
   return token;
 }