void MakeText(int start, int end)
        {
            Log.DebugAssert(end > start, "Empty text");
            Log.DebugAssert(end == this.CurrentLocation, "end == current location");

            InternalText text  = new InternalText();
            var          frame = BeginInternalObject(text, start);

            text.Type  = TextType.Other;
            text.Value = GetText(start, end);
            EndInternalObject(frame);
        }
 internal AXmlText(AXmlObject parent, int startOffset, InternalText internalObject)
     : base(parent, startOffset, internalObject)
 {
 }
Ejemplo n.º 3
0
 bool ReadCurrentPosition()
 {
     attributes       = null;
     attributeIndex   = -1;
     inAttributeValue = false;
     while (true)
     {
         var obj = objectIterator.CurrentObject;
         if (obj == null)
         {
             readState       = ReadState.EndOfFile;
             elementNodeType = XmlNodeType.None;
             return(false);
         }
         else if (objectIterator.IsAtElementEnd)
         {
             if (IsEmptyElement)
             {
                 // Don't report EndElement for empty elements
                 nsManager.PopScope();
             }
             else
             {
                 elementNodeType = XmlNodeType.EndElement;
                 return(true);
             }
         }
         else if (obj is InternalElement)
         {
             // element start
             elementNodeType = XmlNodeType.Element;
             InternalTag startTag = ((InternalTag)obj.NestedObjects[0]);
             nsManager.PushScope();
             if (startTag.NestedObjects != null)
             {
                 attributes = startTag.NestedObjects.OfType <InternalAttribute>().ToList();
                 for (int i = 0; i < attributes.Count; i++)
                 {
                     var attr = attributes[i];
                     if (attr.Name.StartsWith("xmlns:", StringComparison.Ordinal))
                     {
                         nsManager.AddNamespace(AXmlObject.GetLocalName(attr.Name), attr.Value);
                     }
                     else if (attr.Name == "xmlns")
                     {
                         nsManager.AddNamespace(string.Empty, attr.Value);
                     }
                 }
             }
             return(true);
         }
         else if (obj is InternalText)
         {
             InternalText text = (InternalText)obj;
             if (text.ContainsOnlyWhitespace)
             {
                 elementNodeType = XmlNodeType.Whitespace;
             }
             else
             {
                 elementNodeType = XmlNodeType.Text;
             }
             return(true);
         }
         else if (obj is InternalTag)
         {
             InternalTag tag = (InternalTag)obj;
             if (tag.IsStartOrEmptyTag || tag.IsEndTag)
             {
                 // start/end tags can be skipped as the parent InternalElement already handles them
             }
             else if (tag.IsComment && !settings.IgnoreComments)
             {
                 elementNodeType = XmlNodeType.Comment;
                 return(true);
             }
             else if (tag.IsProcessingInstruction && !settings.IgnoreProcessingInstructions)
             {
                 if (tag.Name == "xml")
                 {
                     elementNodeType = XmlNodeType.XmlDeclaration;
                     attributes      = tag.NestedObjects.OfType <InternalAttribute>().ToList();
                 }
                 else
                 {
                     elementNodeType = XmlNodeType.ProcessingInstruction;
                 }
                 return(true);
             }
             else if (tag.IsCData)
             {
                 elementNodeType = XmlNodeType.CDATA;
                 return(true);
             }
             else
             {
                 // TODO all other tags
             }
         }
         else
         {
             throw new NotSupportedException();
         }
         objectIterator.MoveInto();
     }
 }
Ejemplo n.º 4
0
		internal AXmlText(AXmlObject parent, int startOffset, InternalText internalObject)
			: base(parent, startOffset, internalObject)
		{
		}
Ejemplo n.º 5
0
		/// <summary>
		/// Reads text.
		/// </summary>
		void ReadText(TextType type)
		{
			var text = new InternalText();
			var frame = BeginInternalObject(text);
			text.Type = type;
			
			int start = this.CurrentLocation;
			int fragmentEnd = inputLength;
			
			// Whitespace would be skipped anyway by any operation
			TryMoveToNonWhiteSpace(fragmentEnd);
			int wsEnd = this.CurrentLocation;
			
			// Try move to the terminator given by the context
			if (type == TextType.WhiteSpace) {
				TryMoveToNonWhiteSpace(fragmentEnd);
			} else if (type == TextType.CharacterData) {
				while(true) {
					if (!TryMoveToAnyOf(new char[] {'<', ']'}, fragmentEnd)) break; // End of fragment
					if (TryPeek('<')) break;
					if (TryPeek(']')) {
						if (TryPeek("]]>")) {
							OnSyntaxError(this.CurrentLocation, this.CurrentLocation + 3, "']]>' is not allowed in text");
						}
						TryMoveNext();
						continue;
					}
					throw new InternalException("Infinite loop");
				}
			} else if (type == TextType.Comment) {
				// Do not report too many errors
				bool errorReported = false;
				while(true) {
					if (!TryMoveTo('-', fragmentEnd)) break; // End of fragment
					if (TryPeek("-->")) break;
					if (TryPeek("--") && !errorReported) {
						OnSyntaxError(this.CurrentLocation, this.CurrentLocation + 2, "'--' is not allowed in comment");
						errorReported = true;
					}
					TryMoveNext();
				}
			} else if (type == TextType.CData) {
				while(true) {
					// We can not use use TryMoveTo("]]>", fragmentEnd) because it may incorectly accept "]" at the end of fragment
					if (!TryMoveTo(']', fragmentEnd)) break; // End of fragment
					if (TryPeek("]]>")) break;
					TryMoveNext();
				}
			} else if (type == TextType.ProcessingInstruction) {
				while(true) {
					if (!TryMoveTo('?', fragmentEnd)) break; // End of fragment
					if (TryPeek("?>")) break;
					TryMoveNext();
				}
			} else if (type == TextType.UnknownBang) {
				TryMoveToAnyOf(new char[] {'<', '>'}, fragmentEnd);
			} else {
				throw new InternalException("Unknown type " + type);
			}
			
			text.ContainsOnlyWhitespace = (wsEnd == this.CurrentLocation);
			
			string escapedValue = GetText(start, this.CurrentLocation);
			if (type == TextType.CharacterData) {
				text.Value = Dereference(escapedValue, start);
			} else {
				text.Value = escapedValue;
			}
			text.Value = GetCachedString(text.Value);
			
			EndInternalObject(frame, storeNewObject: this.CurrentLocation > start);
		}
Ejemplo n.º 6
0
		void MakeText(int start, int end)
		{
			Log.DebugAssert(end > start, "Empty text");
			Log.DebugAssert(end == this.CurrentLocation, "end == current location");
			
			InternalText text = new InternalText();
			var frame = BeginInternalObject(text, start);
			text.Type = TextType.Other;
			text.Value = GetText(start, end);
			EndInternalObject(frame);
		}
        /// <summary>
        /// Reads text.
        /// </summary>
        void ReadText(TextType type)
        {
            var text  = new InternalText();
            var frame = BeginInternalObject(text);

            text.Type = type;

            int start       = this.CurrentLocation;
            int fragmentEnd = inputLength;

            // Whitespace would be skipped anyway by any operation
            TryMoveToNonWhiteSpace(fragmentEnd);
            int wsEnd = this.CurrentLocation;

            // Try move to the terminator given by the context
            if (type == TextType.WhiteSpace)
            {
                TryMoveToNonWhiteSpace(fragmentEnd);
            }
            else if (type == TextType.CharacterData)
            {
                while (true)
                {
                    if (!TryMoveToAnyOf(new char[] { '<', ']' }, fragmentEnd))
                    {
                        break;                                                                          // End of fragment
                    }
                    if (TryPeek('<'))
                    {
                        break;
                    }
                    if (TryPeek(']'))
                    {
                        if (TryPeek("]]>"))
                        {
                            OnSyntaxError(this.CurrentLocation, this.CurrentLocation + 3, "']]>' is not allowed in text");
                        }
                        TryMoveNext();
                        continue;
                    }
                    throw new InternalException("Infinite loop");
                }
            }
            else if (type == TextType.Comment)
            {
                // Do not report too many errors
                bool errorReported = false;
                while (true)
                {
                    if (!TryMoveTo('-', fragmentEnd))
                    {
                        break;                                                   // End of fragment
                    }
                    if (TryPeek("-->"))
                    {
                        break;
                    }
                    if (TryPeek("--") && !errorReported)
                    {
                        OnSyntaxError(this.CurrentLocation, this.CurrentLocation + 2, "'--' is not allowed in comment");
                        errorReported = true;
                    }
                    TryMoveNext();
                }
            }
            else if (type == TextType.CData)
            {
                while (true)
                {
                    // We can not use use TryMoveTo("]]>", fragmentEnd) because it may incorectly accept "]" at the end of fragment
                    if (!TryMoveTo(']', fragmentEnd))
                    {
                        break;                                                   // End of fragment
                    }
                    if (TryPeek("]]>"))
                    {
                        break;
                    }
                    TryMoveNext();
                }
            }
            else if (type == TextType.ProcessingInstruction)
            {
                while (true)
                {
                    if (!TryMoveTo('?', fragmentEnd))
                    {
                        break;                                                   // End of fragment
                    }
                    if (TryPeek("?>"))
                    {
                        break;
                    }
                    TryMoveNext();
                }
            }
            else if (type == TextType.UnknownBang)
            {
                TryMoveToAnyOf(new char[] { '<', '>' }, fragmentEnd);
            }
            else
            {
                throw new InternalException("Unknown type " + type);
            }

            text.ContainsOnlyWhitespace = (wsEnd == this.CurrentLocation);

            string escapedValue = GetText(start, this.CurrentLocation);

            if (type == TextType.CharacterData)
            {
                text.Value = Dereference(escapedValue, start);
            }
            else
            {
                text.Value = escapedValue;
            }
            text.Value = GetCachedString(text.Value);

            EndInternalObject(frame, storeNewObject: this.CurrentLocation > start);
        }