Ejemplo n.º 1
0
        /// <summary>
        /// Returns true when specified block is contained within this one
        /// </summary>
        public bool Contains(BlockSpan childBlock)
        {
            if (childBlock == null)
            {
                throw new ArgumentNullException("childBlock");
            }

            return((childBlock.AbsoluteCharOffset >= AbsoluteCharOffset) &&
                   (childBlock.AbsoluteCharOffset + childBlock.AbsoluteCharLength <= AbsoluteCharOffset + AbsoluteCharLength));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Called after "&lt;%" has been read to determine what kind of content it is
        /// </summary>
        private void ReactToBeginningOfAspTags()
        {
            if (currentChar == '=')
            {
                outputElementKind   = OutputElementKind.PLAIN;
                withinOutputElement = true;
            }
            if (currentChar == ':')
            {
                outputElementKind   = OutputElementKind.HTML_ESCAPED;
                withinOutputElement = true;
            }
            if (currentChar == '$')
            {
                outputElementKind   = OutputElementKind.EXPRESSION;
                withinOutputElement = true;
            }
            if (currentChar == '#')
            {
                outputElementKind   = OutputElementKind.BIND;
                withinOutputElement = true;
            }
            if (currentChar == '@')
            {
                EndPlainText(-1, 2);

                withinAspDirective  = true;
                withinAspElement    = true;
                withinAspTags       = false;
                withinAttributeName = true;
                attributes          = new List <AttributeInfo>();
                elementName         = null;
                elementPrefix       = null;
                codeBuilder.Length  = 0;
                withinCodeBlock     = false;

                HitStart(ref externalSpan, -1);
            }
            if (withinOutputElement)
            {
                if (withinAttributeValue)
                {
                    backupSpan           = new BlockSpan(externalSpan);
                    backupBuilder.Length = 0;
                    backupBuilder.Append(codeBuilder);
                    codeBuilder.Length = 0;
                }
                if (withinCodeBlock)
                {
                    codeBuilder.Length = 0;
                    withinCodeBlock    = false;
                }
                HitStart(ref internalSpan, 1);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Marks current position as a beginning of a block (creates new if null passed)
        /// </summary>
        private void HitStart(ref BlockSpan span, int correction)
        {
            if (span == null)
            {
                span = new BlockSpan();
            }

            span.StartLine          = currentLine;
            span.StartIndex         = currentIndex + correction;
            span.AbsoluteCharOffset = currentOffset + correction;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Copy constructor
        /// </summary>
        public BlockSpan(BlockSpan copy)
        {
            if (copy == null)
            {
                throw new ArgumentNullException("copy");
            }

            AbsoluteCharLength = copy.AbsoluteCharLength;
            AbsoluteCharOffset = copy.AbsoluteCharOffset;
            StartLine          = copy.StartLine;
            EndLine            = copy.EndLine;
            EndIndex           = copy.EndIndex;
            StartIndex         = copy.StartIndex;
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Marks current position as an end of a block
 /// </summary>
 private void HitEnd(ref BlockSpan span, int correction)
 {
     span.EndLine            = currentLine;
     span.EndIndex           = currentIndex + correction;
     span.AbsoluteCharLength = currentOffset - span.AbsoluteCharOffset + correction;
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Modifies state based on a character within an element
        /// </summary>
        private void ReactToWithinElementChar()
        {
            if (!withinAttributeValue)
            {
                if (currentChar == '"' || currentChar == '\'')   // begining of an attribute
                {
                    withinAttributeValue      = true;
                    quotesChar                = currentChar;
                    currentAttributeBlockSpan = new BlockSpan();
                    currentAttributeBlockSpan.AbsoluteCharOffset = currentOffset - 1;
                    currentAttributeBlockSpan.StartIndex         = currentIndex - 1;
                    currentAttributeBlockSpan.StartLine          = currentLine;
                }
                else if (currentChar == ':')     // tag prefix
                {
                    if (string.IsNullOrEmpty(elementName))
                    {
                        elementPrefix = attributeNameBuilder.ToString().Trim();
                        attributeNameBuilder.Length = 0;
                        return;
                    }
                }
                else
                {
                    if (!withinAttributeName)   // beginning of attribute name, possibly end of tag name
                    {
                        if (currentChar.CanBePartOfIdentifier() && !GetCodeBack(1).CanBePartOfIdentifier())
                        {
                            if (attributeNameBuilder.Length > 0)
                            {
                                if (string.IsNullOrEmpty(elementName))
                                {
                                    elementName = attributeNameBuilder.ToString().Trim();
                                    if (elementName.StartsWith(":"))
                                    {
                                        elementName = elementName.Substring(1);
                                    }
                                }
                                attributeNameBuilder.Length = 0;
                            }
                            withinAttributeName = true;
                        }
                    }
                    else     // end of attribute name
                    {
                        if (!currentChar.CanBePartOfIdentifier() && GetCodeBack(1).CanBePartOfIdentifier())
                        {
                            withinAttributeName = false;
                        }
                    }
                }
            }
            else
            {
                if (currentChar == quotesChar && !withinOutputElement)   // end of attribute value
                {
                    currentAttributeBlockSpan.EndLine            = currentLine;
                    currentAttributeBlockSpan.EndIndex           = currentIndex; // " or '
                    currentAttributeBlockSpan.AbsoluteCharLength = currentOffset - currentAttributeBlockSpan.AbsoluteCharOffset;

                    // add attribute to the element's list
                    AttributeInfo nfo = new AttributeInfo()
                    {
                        Name            = attributeNameBuilder.ToString(),
                        Value           = attributeValueBuilder.ToString().Substring(1), // " or '
                        BlockSpan       = currentAttributeBlockSpan,
                        ContainsAspTags = attributeValueContainsOutput
                    };

                    attributes.Add(nfo);

                    attributeValueContainsOutput = false;
                    currentAttributeBlockSpan    = null;
                    withinAttributeValue         = false;
                    attributeNameBuilder.Length  = 0;
                    attributeValueBuilder.Length = 0;
                }
            }
            if (withinAttributeName)
            {
                attributeNameBuilder.Append(currentChar);
            }
            if (withinAttributeValue)
            {
                attributeValueBuilder.Append(currentChar);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Called after %>, reports the content to the handler
        /// </summary>
        private void ReactToEndOfAspTags()
        {
            if (withinAspElement)   // only expression within attribute value was read
            {
                backupBuilder.Append(codeBuilder);
            }
            if (withinOutputElement)
            {
                handler.OnOutputElement(new OutputElementContext()
                {
                    Kind                    = outputElementKind,
                    InnerText               = codeBuilder.ToString(0, codeBuilder.Length - 2),
                    InnerBlockSpan          = internalSpan,
                    OuterBlockSpan          = externalSpan,
                    WithinClientSideComment = withinClientComment,
                    WithinElementsAttribute = withinAspElement && withinAttributeValue
                });

                if (softStop)
                {
                    hardStop = true;
                }
                withinOutputElement = false;
                internalSpan        = null;
                externalSpan        = null;
                if (withinAttributeValue)
                {
                    attributeValueContainsOutput = true;
                }
                codeBuilder.Length = 0;
            }
            if (withinAspDirective)
            {
                handler.OnPageDirective(new DirectiveContext()
                {
                    Attributes              = attributes,
                    BlockSpan               = externalSpan,
                    DirectiveName           = elementName,
                    WithinClientSideComment = withinClientComment
                });

                if (softStop)
                {
                    hardStop = true;
                }
                externalSpan       = null;
                elementName        = null;
                attributes         = null;
                withinAspDirective = false;
                withinAspElement   = false;
                codeBuilder.Length = 0;
            }
            if (withinCodeBlock)
            {
                handler.OnCodeBlock(new CodeBlockContext()
                {
                    BlockText               = codeBuilder.ToString(0, codeBuilder.Length - 2),
                    InnerBlockSpan          = internalSpan,
                    OuterBlockSpan          = externalSpan,
                    WithinClientSideComment = withinClientComment
                });

                if (softStop)
                {
                    hardStop = true;
                }
                externalSpan       = null;
                internalSpan       = null;
                withinCodeBlock    = false;
                codeBuilder.Length = 0;
            }
            if (withinAspElement)
            {
                externalSpan = new BlockSpan(backupSpan);
                codeBuilder.Append(backupBuilder);
                backupBuilder.Length = 0;
            }
        }