示例#1
0
 public void Encode(CanonicalEncoder encoder)
 {
     for (int i = 0; i < _count; i++)
     {
         _list[i].Encode(encoder);
     }
 }
 public void Render(CanonicalEncoder encoder)
 {
     for (int i = _namespaceContext.Count - 1; i >= 0; i--)
     {
         NamespaceEntry ne = _namespaceContext[i];
         if (ne == null)
         {
             break;
         }
         else if (ne.Rendered)
         {
             _localNamespacesToRender.Add(ne);
         }
     }
     if (_localNamespacesToRender.Count == 0)
     {
         return;
     }
     _localNamespacesToRender.Sort(NamespaceComparer.Instance);
     for (int i = 0; i < _localNamespacesToRender.Count; i++)
     {
         NamespaceEntry ne = _localNamespacesToRender[i];
         encoder.Encode(" xmlns");
         if (ne.Prefix != null && ne.Prefix.Length > 0)
         {
             encoder.Encode(':');
             encoder.Encode(ne.Prefix);
         }
         encoder.Encode("=\"");
         encoder.EncodeWithTranslation(ne.NamespaceUri, CanonicalEncoder.XmlStringType.AttributeValue);
         encoder.Encode('\"');
     }
     _localNamespacesToRender.Clear();
 }
示例#3
0
 public override void WriteChars(char[] buffer, int index, int count)
 {
     WriteStringCore(buffer, index, count, false, false);
     if (ShouldDelegate)
     {
         CanonicalEncoder.WriteEscapedChars(_bufferingWriter, buffer, index, count);
     }
 }
示例#4
0
 public Engine(bool includeComments, string inclusivePrefixes, bool fullDocumentMode)
 {
     _fullDocumentMode           = fullDocumentMode;
     _includeComments            = includeComments;
     _inclusivePrefixes          = inclusivePrefixes;
     _tokenizedInclusivePrefixes = C14nUtil.TokenizeInclusivePrefixList(inclusivePrefixes);
     _canonicalWriterStream      = new MemoryStream();
     _encoder         = new CanonicalEncoder(_canonicalWriterStream);
     _canonicalWriter = new CanonicalWriter(_encoder, _tokenizedInclusivePrefixes, includeComments, null, 0);
 }
示例#5
0
        public override void WriteString(string s)
        {
            if (s == null)
            {
                throw new ArgumentNullException(nameof(s));
            }

            WriteStringCore(s);
            if (ShouldDelegate)
            {
                CanonicalEncoder.WriteEscapedString(_bufferingWriter, s);
            }
        }
示例#6
0
        public CanonicalWriter(CanonicalEncoder encoder,
                               string[] inclusivePrefixes, bool includeComments, IPrefixGenerator prefixGenerator, int startingDepthForAttributePrefixGeneration)
        {
            _attributesToRender = new CanonicalAttributeManager();
            _encoder            = encoder;
            _includeComments    = includeComments;
            _prefixGenerator    = prefixGenerator;
            _startingDepthForAttributePrefixGeneration = startingDepthForAttributePrefixGeneration;
            _manager           = new ExclusiveCanonicalNamespaceManager();
            _elements          = new ElementEntry[InitialElementStackSize];
            _inclusivePrefixes = inclusivePrefixes;

            Reset();
        }
示例#7
0
        public override void WriteBase64(byte[] buffer, int offset, int count)
        {
            CanonicalEncoder.ValidateBufferBounds(buffer, offset, count);
            int originalOffset = offset;
            int originalCount  = count;

            if (_state == WriteState.Element)
            {
                OnPossibleEndOfStartTag(WriteState.Content);
            }

            // complete previous left overs
            if (_base64RemainderSize > 0)
            {
                int nBytes = Math.Min(3 - _base64RemainderSize, count);
                Buffer.BlockCopy(buffer, offset, _base64Remainder, _base64RemainderSize, nBytes);
                _base64RemainderSize += nBytes;
                offset += nBytes;
                count  -= nBytes;
                if (_base64RemainderSize == 3)
                {
                    WriteBase64Core(_base64Remainder, 0, 3);
                    _base64RemainderSize = 0;
                }
            }

            if (count > 0)
            {
                // save new left over
                _base64RemainderSize = count % 3;
                if (_base64RemainderSize > 0)
                {
                    if (_base64Remainder == null)
                    {
                        _base64Remainder = new byte[3];
                    }

                    Buffer.BlockCopy(buffer, offset + count - _base64RemainderSize, _base64Remainder, 0, _base64RemainderSize);
                    count -= _base64RemainderSize;
                }

                // write the middle
                WriteBase64Core(buffer, offset, count);
            }
            if (ShouldDelegate)
            {
                _bufferingWriter.WriteBase64(buffer, originalOffset, originalCount);
            }
        }
示例#8
0
 public CanonicalWriter(CanonicalEncoder encoder)
     : this(encoder, null, false, null, 0)
 {
 }
示例#9
0
 public void Encode(CanonicalEncoder encoder)
 {
     encoder.EncodeAttribute(prefix, localName, value);
 }