Пример #1
0
 public XmlParserTagInfo(XmlParserCursor cursor, string name)
 {
     this.cursor         = cursor.Clone();
     this.Name           = name;
     IsEmptyElement      = false;
     IsElementClosingTag = false;
     IsBoundaryElement   = false;
 }
Пример #2
0
 public AttributesParser(string tagString, IAttributeValueReader[] prependedValueReaders)
 {
     this.tagString = tagString;
     nameCursor     = new XmlParserCursor();
     valueCursor    = new XmlParserCursor();
     valueReader    = new CacadedValueReaders(prependedValueReaders);
     Reset();
 }
Пример #3
0
        public XmlParserCursor Clone()
        {
            XmlParserCursor clone = new XmlParserCursor();

            clone.startPosition = startPosition;
            clone.endPosition   = endPosition;
            return(clone);
        }
Пример #4
0
        public override bool Equals(object obj)
        {
            XmlParserCursor other = obj as XmlParserCursor;

            if (obj == null)
            {
                return(false);
            }

            return((startPosition == other.startPosition) && (endPosition == other.endPosition));
        }
Пример #5
0
        /// <summary>
        /// Finds the end of the tag pointed to by the cursor, and updates the cursor's
        /// end position to point to the end of the tag.
        /// </summary>
        /// <param name="cursor">A cursor initialized so its start position is at the beginning of a tag.</param>
        /// <returns>Method returns true if the tag's end was found, false otherwise.</returns>
        public bool FindEndOfTag(string xml, XmlParserCursor cursor)
        {
            Debug.Assert(xml[cursor.StartPosition] == '<', "The cursor is not positioned on the beginning of tag.");
            int endPosition = xml.IndexOf('>', cursor.StartPosition);

            if (endPosition < 0)
            {
                return(false);
            }
            cursor.EndPosition = endPosition + 1;
            return(true);
        }
Пример #6
0
        public bool GetValueExtents(string tagString, int valueStartPosition, ref XmlParserCursor cursor)
        {
            foreach (var reader in cascadedReaders)
            {
                if (reader.GetValueExtents(tagString, valueStartPosition, ref cursor))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #7
0
        public bool GetValueExtents(string tagString, int valueStartPosition, ref XmlParserCursor cursor)
        {
            if (ValueLength == 0)
            {
                return(false);
            }

            // The values are assumed to be quoted, so start position is valueStartPosition + 1.
            cursor.StartPosition = valueStartPosition + 1;
            cursor.Span          = ValueLength;
            ValueLength          = 0;
            return(true);
        }
Пример #8
0
        public bool GetValueExtents(string tagString, int valueStartPosition, ref XmlParserCursor cursor)
        {
            cursor = null;

            int valueEndPos = tagString.IndexOfAny(XmlParserConstants.WhitespaceChars, valueStartPosition + 1);

            if (valueEndPos == -1)
            {
                return(false);
            }

            cursor = new XmlParserCursor();
            cursor.StartPosition = valueStartPosition;
            cursor.EndPosition   = valueEndPos;
            return(true);
        }
Пример #9
0
        public bool GetValueExtents(string tagString, int valueStartPosition, ref XmlParserCursor cursor)
        {
            if (tagString[valueStartPosition] != '"')
            {
                cursor.Invalidate();
            }
            else
            {
                // Skip the opening quote.
                cursor.StartPosition = valueStartPosition + 1;

                // The attribute value starts with '"'. The returned string will be unquoted.
                int valueEndPos = FindExpectedChar(tagString, '"', cursor.StartPosition + 1);

                while (valueEndPos != -1)
                {
                    bool isEscaped = false;
                    int  testChar  = valueEndPos - 1;
                    while (testChar >= 0 && tagString[testChar] == '\\')
                    {
                        isEscaped = !isEscaped;
                        testChar--;
                    }
                    // If the quote is escaped with '\\', keep on searching for an non-escaped quote.
                    if (isEscaped)
                    {
                        valueEndPos = FindExpectedChar(tagString, '"', valueEndPos + 1);
                    }
                    else
                    {
                        break;
                    }
                }
                if (valueEndPos == -1)
                {
                    cursor.Invalidate();
                }
                else
                {
                    cursor.EndPosition = valueEndPos;
                }
            }

            return(cursor.IsValid);
        }
Пример #10
0
        /// <summary>
        /// Puts an XmlParserCursor information into a string, so that the cursor's position can be
        /// viewed in debug watch list.
        /// </summary>
        /// <param name="original">The original string, to which the cursors apply.</param>
        /// <param name="cursors">A set of cursors applied on the list.</param>
        /// <returns></returns>
        public static string AddCursorsInfo(string original, params XmlParserCursor[] cursors)
        {
#if !PocketPC
            List <XmlParserCursor> cursorSet = new List <XmlParserCursor>(cursors);
            cursorSet.Sort(new CursorComparer());
            StringBuilder   result     = new StringBuilder();
            XmlParserCursor lastCursor = new XmlParserCursor();
            foreach (var cursor in cursorSet)
            {
                if (cursor.IsValid)
                {
                    result.Append(original.Substring(lastCursor.StartPosition, cursor.StartPosition - lastCursor.StartPosition));
                    result.AppendFormat("|-{{{0}}}-|", cursor);
                    lastCursor = cursor;
                }
            }
            result.Append(original.Substring(lastCursor.StartPosition, original.Length - lastCursor.StartPosition));
            return(result.ToString());
#else
            return(original);
#endif
        }
Пример #11
0
 public ReadOnlyCursor(XmlParserCursor cursor)
 {
     this.cursor = cursor;
 }