internal void ReadPreservationInfo(string elementStartTag)
        {
            Debug.Assert(elementStartTag.StartsWith("<", StringComparison.Ordinal) && elementStartTag.EndsWith(">", StringComparison.Ordinal), "Expected string containing exactly a single tag");
            WhitespaceTrackingTextReader whitespaceReader = new WhitespaceTrackingTextReader(new StringReader(elementStartTag));

            int lastCharacter = EnumerateAttributes(elementStartTag,
                                                    (int line, int linePosition, string attributeName) =>
            {
                orderedAttributes.Add(attributeName);
                if (whitespaceReader.ReadToPosition(line, linePosition))
                {
                    leadingSpaces.Add(attributeName, whitespaceReader.PrecedingWhitespace);
                }
                else
                {
                    Debug.Fail("Couldn't get leading whitespace for attribute");
                }
            }
                                                    );

            if (whitespaceReader.ReadToPosition(lastCharacter))
            {
                leadingSpaces.Add(String.Empty, whitespaceReader.PrecedingWhitespace);
            }
            else
            {
                Debug.Fail("Couldn't get trailing whitespace for tag");
            }
        }
        internal void ReadPreservationInfo(string elementStartTag) {
            Debug.Assert(elementStartTag.StartsWith("<", StringComparison.Ordinal) && elementStartTag.EndsWith(">", StringComparison.Ordinal), "Expected string containing exactly a single tag");
            WhitespaceTrackingTextReader whitespaceReader = new WhitespaceTrackingTextReader(new StringReader(elementStartTag));

            int lastCharacter = EnumerateAttributes(elementStartTag, 
                (int line, int linePosition, string attributeName) => 
                {
                    orderedAttributes.Add(attributeName);
                    if (whitespaceReader.ReadToPosition(line, linePosition))
                    {
                        leadingSpaces.Add(attributeName, whitespaceReader.PrecedingWhitespace);
                    }
                    else
                    {
                        Debug.Fail("Couldn't get leading whitespace for attribute");
                    }
                }
                );

            if (whitespaceReader.ReadToPosition(lastCharacter)) {
                leadingSpaces.Add(String.Empty, whitespaceReader.PrecedingWhitespace);
            }
            else {
                Debug.Fail("Couldn't get trailing whitespace for tag");
            }
        }
Ejemplo n.º 3
0
        internal void ReadPreservationInfo(string elementStartTag)
        {
            WhitespaceTrackingTextReader whitespaceReader = new WhitespaceTrackingTextReader(new StringReader(elementStartTag));
            int characterPosition = this.EnumerateAttributes(elementStartTag, delegate(int line, int linePosition, string attributeName) {
                this.orderedAttributes.Add(attributeName);
                if (whitespaceReader.ReadToPosition(line, linePosition))
                {
                    this.leadingSpaces.Add(attributeName, whitespaceReader.PrecedingWhitespace);
                }
            });

            if (whitespaceReader.ReadToPosition(characterPosition))
            {
                this.leadingSpaces.Add(string.Empty, whitespaceReader.PrecedingWhitespace);
            }
        }