IsAtTagDelimiter() public method

public IsAtTagDelimiter ( ) : bool
return bool
コード例 #1
0
ファイル: NextTokenPeek.cs プロジェクト: Microsoft/RTVS
        public static NextTokenType PeekNextToken(HtmlCharStream cs, int tagEnd, out ITextRange range) {
            NextTokenType tokenType = NextTokenType.Unknown;
            int current = cs.Position;

            if (cs.IsEndOfStream() || cs.Position == tagEnd) {
                range = new TextRange();
                return NextTokenType.None;
            }

            int start = cs.Position;

            while (cs.IsWhiteSpace())
                cs.MoveToNextChar();

            if (cs.IsEndOfStream() || cs.Position == tagEnd) {
                range = TextRange.FromBounds(start, cs.Position);
                return NextTokenType.Unknown;
            }

            if (cs.IsAtTagDelimiter()) {
                tokenType = NextTokenType.Tag;
            } else if (cs.CurrentChar == '=') {
                tokenType = NextTokenType.Equals;
            } else {
                int digits = 0;
                bool firstLetter = false;
                int length = 0;
                int chars = 0;

                if (cs.IsAnsiLetter())
                    firstLetter = true;

                while (!cs.IsEndOfStream() && !cs.IsWhiteSpace() && !cs.IsAtTagDelimiter() && cs.CurrentChar != '=' && cs.Position < tagEnd) {
                    if (cs.IsAnsiLetter() || cs.CurrentChar == '_' || cs.CurrentChar == '-')
                        chars++;
                    else if (cs.IsDecimal() || cs.CurrentChar == '.')
                        digits++;

                    cs.MoveToNextChar();
                    length++;
                }

                if (length > 0) {
                    if (length == digits)
                        tokenType = NextTokenType.Number;
                    else if (length == chars)
                        tokenType = NextTokenType.Letters;
                    else if (firstLetter)
                        tokenType = NextTokenType.Identifier;
                }
            }

            range = TextRange.FromBounds(start, cs.Position);
            cs.Position = current;
            return tokenType;
        }
コード例 #2
0
ファイル: HtmlCharStreamTest.cs プロジェクト: Microsoft/RTVS
        public void HtmlCharStream_IsNameCharTest() {
            var stream = new HtmlCharStream(new TextStream(""));
            Assert.True(stream.IsEndOfStream());
            Assert.Equal(0, stream.Length);

            stream = new HtmlCharStream(new TextStream("<h123"));
            Assert.Equal(0, stream.Position);
            Assert.False(stream.IsEndOfStream());
            stream.Position = 5;
            Assert.True(stream.IsEndOfStream());
            stream.Position = 0;
            Assert.False(stream.IsEndOfStream());

            stream.MoveToNextChar();
            Assert.Equal(1, stream.Position);

            stream.Advance(2);
            Assert.Equal(3, stream.Position);

            stream.Advance(-2);
            Assert.Equal(1, stream.Position);

            stream.Advance(1000);
            Assert.True(stream.IsEndOfStream());

            stream.Position = 0;
            Assert.True(stream.IsAtTagDelimiter());
            Assert.Equal('<', stream.CurrentChar);
            Assert.Equal('h', stream.NextChar);

            stream.Position = 1;
            Assert.False(stream.IsAtTagDelimiter());
            Assert.True(stream.IsNameChar());
            Assert.True(HtmlCharStream.IsNameStartChar(stream.CurrentChar));

            stream.Position = 2;
            Assert.False(stream.IsAtTagDelimiter());
            Assert.True(stream.IsNameChar());
            Assert.False(HtmlCharStream.IsNameStartChar(stream.CurrentChar));
        }
コード例 #3
0
ファイル: CharStreamTest.cs プロジェクト: Microsoft/RTVS
        public void CharStream_BasicTest() {
            string text = "abcd\"foo\"\r\n<a href=";
            HtmlCharStream cs = new HtmlCharStream(text);

            Assert.Equal('a', cs.CurrentChar);

            cs.Advance(2);
            Assert.False(cs.IsEndOfStream());
            Assert.Equal('c', cs.CurrentChar);

            cs.Advance(-1);
            Assert.False(cs.IsEndOfStream());
            Assert.Equal('b', cs.CurrentChar);

            cs.Advance(text.Length);
            Assert.True(cs.IsEndOfStream());
            Assert.Equal(0, cs.CurrentChar);

            cs.Advance(-text.Length);
            Assert.False(cs.IsEndOfStream());
            Assert.Equal('a', cs.CurrentChar);

            Assert.Equal('d', cs.LookAhead(3));
            Assert.Equal('\"', cs.LookAhead(4));

            Assert.Equal(0, cs.LookAhead(text.Length));
            Assert.Equal(0, cs.LookAhead(-1));

            Assert.Equal(text.Length, cs.DistanceFromEnd);
            cs.Advance(1);
            Assert.Equal(text.Length - 1, cs.DistanceFromEnd);

            cs.Position = 4;
            Assert.True(cs.IsAtString());
            cs.Position = 5;
            Assert.False(cs.IsAtString());

            cs.Position = 9;
            Assert.True(cs.IsWhiteSpace());
            cs.MoveToNextChar();
            Assert.True(cs.IsWhiteSpace());

            cs.MoveToNextChar();
            Assert.True(cs.IsAtTagDelimiter());
        }