Exemplo n.º 1
0
        /* Function: GetAllHTMLTagProperties
         * If <Type> is <JavadocElementType.HTMLTag>, this generates a dictionary of all the properties in the tag, if any.
         */
        public Dictionary <string, string> GetAllHTMLTagProperties()
        {
            if (type != JavadocElementType.HTMLTag)
            {
                throw new InvalidOperationException();
            }

            Dictionary <string, string> properties = new Dictionary <string, string>();

            Match             match    = HTMLTagRegex.Match(RawText, RawTextIndex, length);
            CaptureCollection captures = match.Groups[2].Captures;

            foreach (Capture capture in captures)
            {
                Match propertyMatch = HTMLTagPropertyRegex.Match(RawText, capture.Index, capture.Length);
                properties.Add(propertyMatch.Groups[1].ToString(),
                               DecodeHTMLPropertyValue(propertyMatch.Groups[2].Index, propertyMatch.Groups[2].Length));
            }

            return(properties);
        }
Exemplo n.º 2
0
        /* Function: HTMLTagProperty
         * If <Type> is <JavadocElementType.HTMLTag>, return the value of the passed property, or null if it doesn't exist.  The property
         * name is case-insensitive.
         */
        public string HTMLTagProperty(string name)
        {
            if (type != JavadocElementType.HTMLTag)
            {
                throw new InvalidOperationException();
            }

            Match             match    = HTMLTagRegex.Match(RawText, RawTextIndex, length);
            CaptureCollection captures = match.Groups[2].Captures;

            foreach (Capture capture in captures)
            {
                Match propertyMatch = HTMLTagPropertyRegex.Match(RawText, capture.Index, capture.Length);

                if (name.Length == propertyMatch.Groups[1].Length &&
                    string.Compare(name, 0, RawText, propertyMatch.Groups[1].Index, name.Length, true) == 0)
                {
                    return(DecodeHTMLPropertyValue(propertyMatch.Groups[2].Index, propertyMatch.Groups[2].Length));
                }
            }

            return(null);
        }
Exemplo n.º 3
0
        // Group: Private Functions
        // __________________________________________________________________________


        /* Function: DetermineElement
         * Determines which <JavadocElementType> the iterator is currently on, setting <type> and <length>.
         */
        private void DetermineElement()
        {
            bool found = false;

            if (tokenIterator == null || !IsInBounds)
            {
                type   = JavadocElementType.OutOfBounds;
                length = 0;
                found  = true;
            }
            // If we're on a new line and either whitespace or a comment token...
            else if ((RawTextIndex == 0 ||
                      Tokenizer.FundamentalTypeOf(RawText[RawTextIndex - 1]) == FundamentalType.LineBreak)
                     &&
                     (tokenIterator.FundamentalType == FundamentalType.Whitespace ||
                      tokenIterator.CommentParsingType == CommentParsingType.CommentSymbol ||
                      tokenIterator.CommentParsingType == CommentParsingType.CommentDecoration))
            {
                type   = JavadocElementType.Indent;
                length = 0;

                TokenIterator lookahead = tokenIterator;

                do
                {
                    length += lookahead.RawTextLength;
                    lookahead.Next();
                }while (lookahead.RawTextIndex < endingRawTextIndex &&
                        (lookahead.FundamentalType == FundamentalType.Whitespace ||
                         lookahead.CommentParsingType == CommentParsingType.CommentSymbol ||
                         lookahead.CommentParsingType == CommentParsingType.CommentDecoration));

                found = true;
            }
            else if (tokenIterator.FundamentalType == FundamentalType.LineBreak)
            {
                type   = JavadocElementType.LineBreak;
                length = tokenIterator.RawTextLength;
                found  = true;
            }
            else if (tokenIterator.MatchesAcrossTokens("<!--"))
            {
                type = JavadocElementType.HTMLComment;

                int endingCommentIndex = RawText.IndexOf("-->", RawTextIndex + 4, endingRawTextIndex - (RawTextIndex + 4));

                if (endingCommentIndex == -1)
                {
                    length = endingRawTextIndex - RawTextIndex;
                }
                else
                {
                    length = (endingCommentIndex + 3) - RawTextIndex;
                }

                found = true;
            }
            else if (tokenIterator.Character == '<')
            {
                int nextBracketIndex = RawText.IndexOfAny(AngleBrackets, RawTextIndex + 1);

                if (nextBracketIndex != -1 && nextBracketIndex < endingRawTextIndex && RawText[nextBracketIndex] == '>')
                {
                    type   = JavadocElementType.HTMLTag;
                    length = nextBracketIndex + 1 - RawTextIndex;

                    Match tagMatch = HTMLTagRegex.Match(RawText, RawTextIndex, length);

                    if (tagMatch.Success)
                    {
                        found   = true;
                        tagType = tagMatch.Groups[1].ToString().ToLower();
                    }
                }
            }
            else if (tokenIterator.MatchesAcrossTokens("{@"))
            {
                int closingBrace = RawText.IndexOf('}', RawTextIndex + 2);

                TokenIterator lookahead = tokenIterator;
                lookahead.NextByCharacters(2);

                if (closingBrace != -1 && closingBrace < endingRawTextIndex &&
                    lookahead.FundamentalType == FundamentalType.Text &&
                    Parsers.Javadoc.InlineTags.Contains(lookahead.String))
                {
                    found   = true;
                    type    = JavadocElementType.JavadocTag;
                    tagType = lookahead.String;
                    length  = (closingBrace + 1) - RawTextIndex;
                }
            }
            else if (tokenIterator.Character == '@')
            {
                TokenIterator lookahead = tokenIterator;
                lookahead.Next();

                if (lookahead.FundamentalType == FundamentalType.Text &&
                    Parsers.Javadoc.BlockTags.Contains(lookahead.String))
                {
                    found   = true;
                    type    = JavadocElementType.JavadocTag;
                    tagType = lookahead.String;
                    length  = tagType.Length + 1;
                }
            }
            else if (tokenIterator.Character == '&')
            {
                int semicolonIndex = RawText.IndexOf(';', RawTextIndex + 1);

                if (semicolonIndex != -1 && semicolonIndex < endingRawTextIndex &&
                    HTMLEntityChars.IsEntityChar(RawText, RawTextIndex, semicolonIndex + 1 - RawTextIndex))
                {
                    type   = JavadocElementType.EntityChar;
                    length = semicolonIndex + 1 - RawTextIndex;
                    found  = true;
                }
            }

            if (!found)
            {
                type = JavadocElementType.Text;

                int nextElementIndex = RawText.IndexOfAny(StartOfElement, RawTextIndex + 1);

                if (nextElementIndex == -1)
                {
                    length = endingRawTextIndex - RawTextIndex;
                }
                else
                {
                    length = nextElementIndex - RawTextIndex;
                }
            }
        }