Exemplo n.º 1
0
        public async Task ShouldOmitWhiteCharacters()
        {
            const string data = @"<data> 123 </data>";

            using (Stream source = ResourceFactory.Inline(data))
            {
                XenonReader         reader = new XenonReader(source, "data");
                XenonWhiteCharacter mode   = XenonWhiteCharacter.Omit;

                await reader.Process(document =>
                {
                    Assert.That(document.ToString(mode), Is.EqualTo("123"));
                });
            }
        }
Exemplo n.º 2
0
        public string ToString(XenonWhiteCharacter mode)
        {
            if (id > 0)
            {
                int           length   = hierarchy.GetLength(id);
                int           position = hierarchy.GetPosition(id);
                StringBuilder builder  = new StringBuilder(length);

                if (length < 0)
                {
                    length = -length;
                }

                if (mode == XenonWhiteCharacter.Omit)
                {
                    int next = XenonScanner.SkipWhiteCharactersForward(entry, position);
                    length   = length - (next - position);
                    position = next;
                }

                if (length > 0)
                {
                    int prev = XenonScanner.SkipWhiteCharactersBackward(entry, position + length - 1);
                    length = length - (position + length - 1 - prev);
                }

                while (length > 0)
                {
                    builder.Append(entry.GetCharacterAt(position, out int read));
                    position = position + read;
                    length   = length - read;
                }

                return(builder.ToString());
            }

            return(null);
        }