private void WriteXmlnsAttribute(ref XmlnsAttribute xmlnsAttribute) { if (xmlnsAttribute.referred) { _writer.WriteXmlnsAttribute(_xmlnsBuffer, xmlnsAttribute.prefixOffset, xmlnsAttribute.prefixLength, _xmlnsBuffer, xmlnsAttribute.nsOffset, xmlnsAttribute.nsLength); } }
private void ResolvePrefix(int prefixOffset, int prefixLength, out int nsOffset, out int nsLength) { int xmlnsAttributeMin = _scopes[_depth - 1].xmlnsAttributeCount; // Lookup the attribute; it has to be there. The decls are in sorted order // so we could do a binary search. int j = _xmlnsAttributeCount - 1; while (!Equals(_elementBuffer, prefixOffset, prefixLength, _xmlnsBuffer, _xmlnsAttributes[j].prefixOffset, _xmlnsAttributes[j].prefixLength)) { j--; } nsOffset = _xmlnsAttributes[j].nsOffset; nsLength = _xmlnsAttributes[j].nsLength; if (j < xmlnsAttributeMin) { // If the xmlns decl isn't at this scope, see if we need to copy it down if (!_xmlnsAttributes[j].referred) { XmlnsAttribute xmlnsAttribute = _xmlnsAttributes[j]; xmlnsAttribute.referred = true; // This inserts the xmlns attribute in sorted order, so j is no longer valid AddXmlnsAttribute(ref xmlnsAttribute); } } else { // Found at this scope, indicate we need to emit it _xmlnsAttributes[j].referred = true; } }
public void WriteStartElement(string prefix, string localName) { if (prefix == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("prefix"); } if (localName == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("localName"); } this.ThrowIfClosed(); bool flag = this.depth == 0; this.StartElement(); this.element.prefixOffset = this.elementWriter.Position + 1; this.element.prefixLength = Encoding.UTF8.GetByteCount(prefix); this.element.localNameOffset = (this.element.prefixOffset + this.element.prefixLength) + ((this.element.prefixLength != 0) ? 1 : 0); this.element.localNameLength = Encoding.UTF8.GetByteCount(localName); this.elementWriter.WriteStartElement(prefix, localName); if (flag && (this.inclusivePrefixes != null)) { for (int i = 0; i < this.scopes[0].xmlnsAttributeCount; i++) { if (this.IsInclusivePrefix(ref this.xmlnsAttributes[i])) { XmlnsAttribute xmlnsAttribute = this.xmlnsAttributes[i]; this.AddXmlnsAttribute(ref xmlnsAttribute); } } } }
public void WriteStartElement(string prefix, string localName) { if (prefix == null) { throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(prefix)); } if (localName == null) { throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(localName)); } ThrowIfClosed(); bool isRootElement = (_depth == 0); StartElement(); _element.prefixOffset = _elementWriter.Position + 1; _element.prefixLength = Encoding.UTF8.GetByteCount(prefix); _element.localNameOffset = _element.prefixOffset + _element.prefixLength + (_element.prefixLength != 0 ? 1 : 0); _element.localNameLength = Encoding.UTF8.GetByteCount(localName); _elementWriter.WriteStartElement(prefix, localName); // If we have a inclusivenamespace prefix list and the namespace declaration is in the // outer context, then Add it to the root element. if (isRootElement && (_inclusivePrefixes != null)) { // Scan through all the namespace declarations in the outer scope. for (int i = 0; i < _scopes[0].xmlnsAttributeCount; ++i) { if (IsInclusivePrefix(ref _xmlnsAttributes[i])) { XmlnsAttribute attribute = _xmlnsAttributes[i]; AddXmlnsAttribute(ref attribute); } } } }
private void ResolvePrefix(int prefixOffset, int prefixLength, out int nsOffset, out int nsLength) { int xmlnsAttributeCount = this.scopes[this.depth - 1].xmlnsAttributeCount; int index = this.xmlnsAttributeCount - 1; while (!this.Equals(this.elementBuffer, prefixOffset, prefixLength, this.xmlnsBuffer, this.xmlnsAttributes[index].prefixOffset, this.xmlnsAttributes[index].prefixLength)) { index--; } nsOffset = this.xmlnsAttributes[index].nsOffset; nsLength = this.xmlnsAttributes[index].nsLength; if (index < xmlnsAttributeCount) { if (!this.xmlnsAttributes[index].referred) { XmlnsAttribute xmlnsAttribute = this.xmlnsAttributes[index]; xmlnsAttribute.referred = true; this.AddXmlnsAttribute(ref xmlnsAttribute); } } else { this.xmlnsAttributes[index].referred = true; } }
private bool IsInclusivePrefix(ref XmlnsAttribute xmlnsAttribute) { for (int i = 0; i < this.inclusivePrefixes.Length; i++) { if ((this.inclusivePrefixes[i].Length == xmlnsAttribute.prefixLength) && (string.Compare(Encoding.UTF8.GetString(this.xmlnsBuffer, xmlnsAttribute.prefixOffset, xmlnsAttribute.prefixLength), this.inclusivePrefixes[i], StringComparison.Ordinal) == 0)) { return(true); } } return(false); }
private void AddXmlnsAttribute(ref XmlnsAttribute xmlnsAttribute) { if (this.xmlnsAttributes == null) { this.xmlnsAttributes = new XmlnsAttribute[4]; } else if (this.xmlnsAttributes.Length == this.xmlnsAttributeCount) { XmlnsAttribute[] destinationArray = new XmlnsAttribute[this.xmlnsAttributeCount * 2]; Array.Copy(this.xmlnsAttributes, destinationArray, this.xmlnsAttributeCount); this.xmlnsAttributes = destinationArray; } if (((this.depth > 0) && (this.inclusivePrefixes != null)) && this.IsInclusivePrefix(ref xmlnsAttribute)) { xmlnsAttribute.referred = true; } if (this.depth == 0) { this.xmlnsAttributes[this.xmlnsAttributeCount++] = xmlnsAttribute; } else { int xmlnsAttributeCount = this.scopes[this.depth - 1].xmlnsAttributeCount; bool flag = true; while (xmlnsAttributeCount < this.xmlnsAttributeCount) { int num2 = this.Compare(ref xmlnsAttribute, ref this.xmlnsAttributes[xmlnsAttributeCount]); if (num2 > 0) { xmlnsAttributeCount++; } else { if (num2 == 0) { this.xmlnsAttributes[xmlnsAttributeCount] = xmlnsAttribute; flag = false; } break; } } if (flag) { Array.Copy(this.xmlnsAttributes, xmlnsAttributeCount, this.xmlnsAttributes, xmlnsAttributeCount + 1, this.xmlnsAttributeCount - xmlnsAttributeCount); this.xmlnsAttributes[xmlnsAttributeCount] = xmlnsAttribute; this.xmlnsAttributeCount++; } } }
private bool IsInclusivePrefix(ref XmlnsAttribute xmlnsAttribute) { for (int i = 0; i < _inclusivePrefixes.Length; ++i) { if (_inclusivePrefixes[i].Length == xmlnsAttribute.prefixLength) { if (String.Compare(Encoding.UTF8.GetString(_xmlnsBuffer, xmlnsAttribute.prefixOffset, xmlnsAttribute.prefixLength), _inclusivePrefixes[i], StringComparison.Ordinal) == 0) { return(true); } } } return(false); }
public void WriteStartElement(byte[] prefixBuffer, int prefixOffset, int prefixLength, byte[] localNameBuffer, int localNameOffset, int localNameLength) { if (prefixBuffer == null) { throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(nameof(prefixBuffer))); } if (prefixOffset < 0) { throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(prefixOffset), SR.ValueMustBeNonNegative)); } if (prefixOffset > prefixBuffer.Length) { throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(prefixOffset), SR.Format(SR.OffsetExceedsBufferSize, prefixBuffer.Length))); } if (prefixLength < 0) { throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(prefixLength), SR.ValueMustBeNonNegative)); } if (prefixLength > prefixBuffer.Length - prefixOffset) { throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(prefixLength), SR.Format(SR.SizeExceedsRemainingBufferSpace, prefixBuffer.Length - prefixOffset))); } if (localNameBuffer == null) { throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(nameof(localNameBuffer))); } if (localNameOffset < 0) { throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(localNameOffset), SR.ValueMustBeNonNegative)); } if (localNameOffset > localNameBuffer.Length) { throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(localNameOffset), SR.Format(SR.OffsetExceedsBufferSize, localNameBuffer.Length))); } if (localNameLength < 0) { throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(localNameLength), SR.ValueMustBeNonNegative)); } if (localNameLength > localNameBuffer.Length - localNameOffset) { throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(localNameLength), SR.Format(SR.SizeExceedsRemainingBufferSpace, localNameBuffer.Length - localNameOffset))); } ThrowIfClosed(); bool isRootElement = (_depth == 0); StartElement(); _element.prefixOffset = _elementWriter.Position + 1; _element.prefixLength = prefixLength; _element.localNameOffset = _element.prefixOffset + prefixLength + (prefixLength != 0 ? 1 : 0); _element.localNameLength = localNameLength; _elementWriter.WriteStartElement(prefixBuffer, prefixOffset, prefixLength, localNameBuffer, localNameOffset, localNameLength); // If we have a inclusivenamespace prefix list and the namespace declaration is in the // outer context, then Add it to the root element. if (isRootElement && (_inclusivePrefixes != null)) { // Scan through all the namespace declarations in the outer scope. for (int i = 0; i < _scopes[0].xmlnsAttributeCount; ++i) { if (IsInclusivePrefix(ref _xmlnsAttributes[i])) { XmlnsAttribute attribute = _xmlnsAttributes[i]; AddXmlnsAttribute(ref attribute); } } } }
private int Compare(ref XmlnsAttribute xmlnsAttribute1, ref XmlnsAttribute xmlnsAttribute2) { return(Compare(_xmlnsBuffer, xmlnsAttribute1.prefixOffset, xmlnsAttribute1.prefixLength, xmlnsAttribute2.prefixOffset, xmlnsAttribute2.prefixLength)); }
private void WriteXmlnsAttribute(ref XmlnsAttribute xmlnsAttribute) { if (xmlnsAttribute.referred) { this.writer.WriteXmlnsAttribute(this.xmlnsBuffer, xmlnsAttribute.prefixOffset, xmlnsAttribute.prefixLength, this.xmlnsBuffer, xmlnsAttribute.nsOffset, xmlnsAttribute.nsLength); } }
private bool IsInclusivePrefix(ref XmlnsAttribute xmlnsAttribute) { for (int i = 0; i < this.inclusivePrefixes.Length; i++) { if ((this.inclusivePrefixes[i].Length == xmlnsAttribute.prefixLength) && (string.Compare(Encoding.UTF8.GetString(this.xmlnsBuffer, xmlnsAttribute.prefixOffset, xmlnsAttribute.prefixLength), this.inclusivePrefixes[i], StringComparison.Ordinal) == 0)) { return true; } } return false; }
void AddXmlnsAttribute(ref XmlnsAttribute xmlnsAttribute) { // Console.WriteLine("{0}={1}", Encoding.UTF8.GetString(xmlnsBuffer, xmlnsAttribute.prefixOffset, xmlnsAttribute.prefixLength), // Encoding.UTF8.GetString(xmlnsBuffer, xmlnsAttribute.nsOffset, xmlnsAttribute.nsLength)); if (xmlnsAttributes == null) { xmlnsAttributes = new XmlnsAttribute[4]; } else if (xmlnsAttributes.Length == xmlnsAttributeCount) { XmlnsAttribute[] newXmlnsAttributes = new XmlnsAttribute[xmlnsAttributeCount * 2]; Array.Copy(xmlnsAttributes, newXmlnsAttributes, xmlnsAttributeCount); xmlnsAttributes = newXmlnsAttributes; } // If the prefix is in the inclusive prefix list, then mark it as // to be rendered. Depth 0 is outer context and those can be ignored // for now. if ((depth > 0) && (this.inclusivePrefixes != null)) { if (IsInclusivePrefix(ref xmlnsAttribute)) { xmlnsAttribute.referred = true; } } if (depth == 0) { // XmlnsAttributes at depth 0 are the outer context. They don't need to be sorted. xmlnsAttributes[xmlnsAttributeCount++] = xmlnsAttribute; } else { // Sort the xmlns xmlnsAttribute int xmlnsAttributeIndex = scopes[depth - 1].xmlnsAttributeCount; bool isNewPrefix = true; while (xmlnsAttributeIndex < xmlnsAttributeCount) { int result = Compare(ref xmlnsAttribute, ref xmlnsAttributes[xmlnsAttributeIndex]); if (result > 0) { xmlnsAttributeIndex++; } else if (result == 0) { // We already have the same prefix at this scope. So let's // just replace the old one with the new. xmlnsAttributes[xmlnsAttributeIndex] = xmlnsAttribute; isNewPrefix = false; break; } else { break; } } if (isNewPrefix) { Array.Copy(xmlnsAttributes, xmlnsAttributeIndex, xmlnsAttributes, xmlnsAttributeIndex + 1, xmlnsAttributeCount - xmlnsAttributeIndex); xmlnsAttributes[xmlnsAttributeIndex] = xmlnsAttribute; xmlnsAttributeCount++; } } }
private void AddXmlnsAttribute(ref XmlnsAttribute xmlnsAttribute) { // Console.WriteLine("{0}={1}", Encoding.UTF8.GetString(xmlnsBuffer, xmlnsAttribute.prefixOffset, xmlnsAttribute.prefixLength), // Encoding.UTF8.GetString(xmlnsBuffer, xmlnsAttribute.nsOffset, xmlnsAttribute.nsLength)); if (_xmlnsAttributes == null) { _xmlnsAttributes = new XmlnsAttribute[4]; } else if (_xmlnsAttributes.Length == _xmlnsAttributeCount) { XmlnsAttribute[] newXmlnsAttributes = new XmlnsAttribute[_xmlnsAttributeCount * 2]; Array.Copy(_xmlnsAttributes, 0, newXmlnsAttributes, 0, _xmlnsAttributeCount); _xmlnsAttributes = newXmlnsAttributes; } // If the prefix is in the inclusive prefix list, then mark it as // to be rendered. Depth 0 is outer context and those can be ignored // for now. if ((_depth > 0) && (_inclusivePrefixes != null)) { if (IsInclusivePrefix(ref xmlnsAttribute)) { xmlnsAttribute.referred = true; } } if (_depth == 0) { // XmlnsAttributes at depth 0 are the outer context. They don't need to be sorted. _xmlnsAttributes[_xmlnsAttributeCount++] = xmlnsAttribute; } else { // Sort the xmlns xmlnsAttribute int xmlnsAttributeIndex = _scopes[_depth - 1].xmlnsAttributeCount; bool isNewPrefix = true; while (xmlnsAttributeIndex < _xmlnsAttributeCount) { int result = Compare(ref xmlnsAttribute, ref _xmlnsAttributes[xmlnsAttributeIndex]); if (result > 0) { xmlnsAttributeIndex++; } else if (result == 0) { // We already have the same prefix at this scope. So let's // just replace the old one with the new. _xmlnsAttributes[xmlnsAttributeIndex] = xmlnsAttribute; isNewPrefix = false; break; } else { break; } } if (isNewPrefix) { Array.Copy(_xmlnsAttributes, xmlnsAttributeIndex, _xmlnsAttributes, xmlnsAttributeIndex + 1, _xmlnsAttributeCount - xmlnsAttributeIndex); _xmlnsAttributes[xmlnsAttributeIndex] = xmlnsAttribute; _xmlnsAttributeCount++; } } }
public void WriteStartElement(byte[] prefixBuffer, int prefixOffset, int prefixLength, byte[] localNameBuffer, int localNameOffset, int localNameLength) { if (prefixBuffer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("prefixBuffer")); } if (prefixOffset < 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("prefixOffset", System.Runtime.Serialization.SR.GetString("ValueMustBeNonNegative"))); } if (prefixOffset > prefixBuffer.Length) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("prefixOffset", System.Runtime.Serialization.SR.GetString("OffsetExceedsBufferSize", new object[] { prefixBuffer.Length }))); } if (prefixLength < 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("prefixLength", System.Runtime.Serialization.SR.GetString("ValueMustBeNonNegative"))); } if (prefixLength > (prefixBuffer.Length - prefixOffset)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("prefixLength", System.Runtime.Serialization.SR.GetString("SizeExceedsRemainingBufferSpace", new object[] { prefixBuffer.Length - prefixOffset }))); } if (localNameBuffer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("localNameBuffer")); } if (localNameOffset < 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("localNameOffset", System.Runtime.Serialization.SR.GetString("ValueMustBeNonNegative"))); } if (localNameOffset > localNameBuffer.Length) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("localNameOffset", System.Runtime.Serialization.SR.GetString("OffsetExceedsBufferSize", new object[] { localNameBuffer.Length }))); } if (localNameLength < 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("localNameLength", System.Runtime.Serialization.SR.GetString("ValueMustBeNonNegative"))); } if (localNameLength > (localNameBuffer.Length - localNameOffset)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("localNameLength", System.Runtime.Serialization.SR.GetString("SizeExceedsRemainingBufferSpace", new object[] { localNameBuffer.Length - localNameOffset }))); } this.ThrowIfClosed(); bool flag = this.depth == 0; this.StartElement(); this.element.prefixOffset = this.elementWriter.Position + 1; this.element.prefixLength = prefixLength; this.element.localNameOffset = (this.element.prefixOffset + prefixLength) + ((prefixLength != 0) ? 1 : 0); this.element.localNameLength = localNameLength; this.elementWriter.WriteStartElement(prefixBuffer, prefixOffset, prefixLength, localNameBuffer, localNameOffset, localNameLength); if (flag && (this.inclusivePrefixes != null)) { for (int i = 0; i < this.scopes[0].xmlnsAttributeCount; i++) { if (this.IsInclusivePrefix(ref this.xmlnsAttributes[i])) { XmlnsAttribute xmlnsAttribute = this.xmlnsAttributes[i]; this.AddXmlnsAttribute(ref xmlnsAttribute); } } } }
int Compare(ref XmlnsAttribute xmlnsAttribute1, ref XmlnsAttribute xmlnsAttribute2) { return Compare(xmlnsBuffer, xmlnsAttribute1.prefixOffset, xmlnsAttribute1.prefixLength, xmlnsAttribute2.prefixOffset, xmlnsAttribute2.prefixLength); }
private int Compare(ref XmlnsAttribute xmlnsAttribute1, ref XmlnsAttribute xmlnsAttribute2) { return this.Compare(this.xmlnsBuffer, xmlnsAttribute1.prefixOffset, xmlnsAttribute1.prefixLength, xmlnsAttribute2.prefixOffset, xmlnsAttribute2.prefixLength); }
void WriteXmlnsAttribute(ref XmlnsAttribute xmlnsAttribute) { if (xmlnsAttribute.referred) { writer.WriteXmlnsAttribute(xmlnsBuffer, xmlnsAttribute.prefixOffset, xmlnsAttribute.prefixLength, xmlnsBuffer, xmlnsAttribute.nsOffset, xmlnsAttribute.nsLength); } }