* Prefix protected fields with underscore for the internal XmlRawWriter and its descendant classes
{
internal class HtmlEncodedRawTextWriter : XmlEncodedRawTextWriter
{
- protected ByteStack elementScope;
- protected ElementProperties currentElementProperties;
+ protected ByteStack _elementScope;
+ protected ElementProperties _currentElementProperties;
private AttributeProperties _currentAttributeProperties;
private bool _endsWithAmpersand;
private string _mediaType;
private bool _doNotEscapeUriAttributes;
- protected static TernaryTreeReadOnly elementPropertySearch;
- protected static TernaryTreeReadOnly attributePropertySearch;
+ protected static TernaryTreeReadOnly _elementPropertySearch;
+ protected static TernaryTreeReadOnly _attributePropertySearch;
private const int StackIncrement = 10;
{
Debug.Assert(name != null && name.Length > 0);
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
RawText("<!DOCTYPE ");
RawText("\" \"");
RawText(sysid);
}
- bufChars[bufPos++] = (char)'"';
+ _bufChars[_bufPos++] = (char)'"';
}
else if (sysid != null)
{
RawText(" SYSTEM \"");
RawText(sysid);
- bufChars[bufPos++] = (char)'"';
+ _bufChars[_bufPos++] = (char)'"';
}
else
{
- bufChars[bufPos++] = (char)' ';
+ _bufChars[_bufPos++] = (char)' ';
}
if (subset != null)
{
- bufChars[bufPos++] = (char)'[';
+ _bufChars[_bufPos++] = (char)'[';
RawText(subset);
- bufChars[bufPos++] = (char)']';
+ _bufChars[_bufPos++] = (char)']';
}
- bufChars[bufPos++] = (char)'>';
+ _bufChars[_bufPos++] = (char)'>';
}
// For the HTML element, it should call this method with ns and prefix as String.Empty
{
Debug.Assert(localName != null && localName.Length != 0 && prefix != null && ns != null);
- elementScope.Push((byte)currentElementProperties);
+ _elementScope.Push((byte)_currentElementProperties);
if (ns.Length == 0)
{
Debug.Assert(prefix.Length == 0);
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
- currentElementProperties = (ElementProperties)elementPropertySearch.FindCaseInsensitiveString(localName);
- base.bufChars[bufPos++] = (char)'<';
+ _currentElementProperties = (ElementProperties)_elementPropertySearch.FindCaseInsensitiveString(localName);
+ base._bufChars[_bufPos++] = (char)'<';
base.RawText(localName);
- base.attrEndPos = bufPos;
+ base._attrEndPos = _bufPos;
}
else
{
// Since the HAS_NS has no impact to the ElementTextBlock behavior,
// we don't need to push it into the stack.
- currentElementProperties = ElementProperties.HAS_NS;
+ _currentElementProperties = ElementProperties.HAS_NS;
base.WriteStartElement(prefix, localName, ns);
}
}
// Output >. For HTML needs to output META info
internal override void StartElementContent()
{
- base.bufChars[base.bufPos++] = (char)'>';
+ base._bufChars[base._bufPos++] = (char)'>';
// Detect whether content is output
- contentPos = bufPos;
+ _contentPos = _bufPos;
- if ((currentElementProperties & ElementProperties.HEAD) != 0)
+ if ((_currentElementProperties & ElementProperties.HEAD) != 0)
{
WriteMetaElement();
}
{
Debug.Assert(prefix.Length == 0);
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
- if ((currentElementProperties & ElementProperties.EMPTY) == 0)
+ if ((_currentElementProperties & ElementProperties.EMPTY) == 0)
{
- bufChars[base.bufPos++] = (char)'<';
- bufChars[base.bufPos++] = (char)'/';
+ _bufChars[base._bufPos++] = (char)'<';
+ _bufChars[base._bufPos++] = (char)'/';
base.RawText(localName);
- bufChars[base.bufPos++] = (char)'>';
+ _bufChars[base._bufPos++] = (char)'>';
}
}
else
base.WriteEndElement(prefix, localName, ns);
}
- currentElementProperties = (ElementProperties)elementScope.Pop();
+ _currentElementProperties = (ElementProperties)_elementScope.Pop();
}
internal override void WriteFullEndElement(string prefix, string localName, string ns)
{
Debug.Assert(prefix.Length == 0);
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
- if ((currentElementProperties & ElementProperties.EMPTY) == 0)
+ if ((_currentElementProperties & ElementProperties.EMPTY) == 0)
{
- bufChars[base.bufPos++] = (char)'<';
- bufChars[base.bufPos++] = (char)'/';
+ _bufChars[base._bufPos++] = (char)'<';
+ _bufChars[base._bufPos++] = (char)'/';
base.RawText(localName);
- bufChars[base.bufPos++] = (char)'>';
+ _bufChars[base._bufPos++] = (char)'>';
}
}
else
base.WriteFullEndElement(prefix, localName, ns);
}
- currentElementProperties = (ElementProperties)elementScope.Pop();
+ _currentElementProperties = (ElementProperties)_elementScope.Pop();
}
// 1. How the outputBooleanAttribute(fBOOL) and outputHtmlUriText(fURI) being set?
{
Debug.Assert(prefix.Length == 0);
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
- if (base.attrEndPos == bufPos)
+ if (base._attrEndPos == _bufPos)
{
- base.bufChars[bufPos++] = (char)' ';
+ base._bufChars[_bufPos++] = (char)' ';
}
base.RawText(localName);
- if ((currentElementProperties & (ElementProperties.BOOL_PARENT | ElementProperties.URI_PARENT | ElementProperties.NAME_PARENT)) != 0)
+ if ((_currentElementProperties & (ElementProperties.BOOL_PARENT | ElementProperties.URI_PARENT | ElementProperties.NAME_PARENT)) != 0)
{
- _currentAttributeProperties = (AttributeProperties)attributePropertySearch.FindCaseInsensitiveString(localName) &
- (AttributeProperties)currentElementProperties;
+ _currentAttributeProperties = (AttributeProperties)_attributePropertySearch.FindCaseInsensitiveString(localName) &
+ (AttributeProperties)_currentElementProperties;
if ((_currentAttributeProperties & AttributeProperties.BOOLEAN) != 0)
{
- base.inAttributeValue = true;
+ base._inAttributeValue = true;
return;
}
}
_currentAttributeProperties = AttributeProperties.DEFAULT;
}
- base.bufChars[bufPos++] = (char)'=';
- base.bufChars[bufPos++] = (char)'"';
+ base._bufChars[_bufPos++] = (char)'=';
+ base._bufChars[_bufPos++] = (char)'"';
}
else
{
_currentAttributeProperties = AttributeProperties.DEFAULT;
}
- base.inAttributeValue = true;
+ base._inAttributeValue = true;
}
// Output the amp; at end of EndAttribute
{
if ((_currentAttributeProperties & AttributeProperties.BOOLEAN) != 0)
{
- base.attrEndPos = bufPos;
+ base._attrEndPos = _bufPos;
}
else
{
_endsWithAmpersand = false;
}
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
- base.bufChars[bufPos++] = (char)'"';
+ base._bufChars[_bufPos++] = (char)'"';
}
- base.inAttributeValue = false;
- base.attrEndPos = bufPos;
+ base._inAttributeValue = false;
+ base._attrEndPos = _bufPos;
}
// HTML PI's use ">" to terminate rather than "?>".
{
Debug.Assert(target != null && target.Length != 0 && text != null);
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
- bufChars[base.bufPos++] = (char)'<';
- bufChars[base.bufPos++] = (char)'?';
+ _bufChars[base._bufPos++] = (char)'<';
+ _bufChars[base._bufPos++] = (char)'?';
base.RawText(target);
- bufChars[base.bufPos++] = (char)' ';
+ _bufChars[base._bufPos++] = (char)' ';
base.WriteCommentOrPi(text, '?');
- base.bufChars[base.bufPos++] = (char)'>';
+ base._bufChars[base._bufPos++] = (char)'>';
- if (base.bufPos > base.bufLen)
+ if (base._bufPos > base._bufLen)
{
FlushBuffer();
}
{
Debug.Assert(text != null);
- if (trackTextContent && inTextContent != true) { ChangeTextContentMark(true); }
+ if (_trackTextContent && _inTextContent != true) { ChangeTextContentMark(true); }
fixed (char* pSrc = text)
{
char* pSrcEnd = pSrc + text.Length;
- if (base.inAttributeValue)
+ if (base._inAttributeValue)
{
WriteHtmlAttributeTextBlock(pSrc, pSrcEnd);
}
Debug.Assert(index >= 0);
Debug.Assert(count >= 0 && index + count <= buffer.Length);
- if (trackTextContent && inTextContent != true) { ChangeTextContentMark(true); }
+ if (_trackTextContent && _inTextContent != true) { ChangeTextContentMark(true); }
fixed (char* pSrcBegin = &buffer[index])
{
- if (inAttributeValue)
+ if (_inAttributeValue)
{
WriteAttributeTextBlock(pSrcBegin, pSrcBegin + count);
}
Debug.Assert((int)ElementProperties.BOOL_PARENT == (int)AttributeProperties.BOOLEAN);
Debug.Assert((int)ElementProperties.NAME_PARENT == (int)AttributeProperties.NAME);
- if (elementPropertySearch == null)
+ if (_elementPropertySearch == null)
{
- //elementPropertySearch should be init last for the mutli thread safe situation.
- attributePropertySearch = new TernaryTreeReadOnly(HtmlTernaryTree.htmlAttributes);
- elementPropertySearch = new TernaryTreeReadOnly(HtmlTernaryTree.htmlElements);
+ //_elementPropertySearch should be init last for the mutli thread safe situation.
+ _attributePropertySearch = new TernaryTreeReadOnly(HtmlTernaryTree.htmlAttributes);
+ _elementPropertySearch = new TernaryTreeReadOnly(HtmlTernaryTree.htmlElements);
}
- elementScope = new ByteStack(StackIncrement);
+ _elementScope = new ByteStack(StackIncrement);
_uriEscapingBuffer = new byte[5];
- currentElementProperties = ElementProperties.DEFAULT;
+ _currentElementProperties = ElementProperties.DEFAULT;
_mediaType = settings.MediaType;
_doNotEscapeUriAttributes = settings.DoNotEscapeUriAttributes;
base.RawText(" content=\"");
base.RawText(_mediaType);
base.RawText("; charset=");
- base.RawText(base.encoding.WebName);
+ base.RawText(base._encoding.WebName);
base.RawText("\">");
}
// only the top of the stack is the real E1 element properties.
protected unsafe void WriteHtmlElementTextBlock(char* pSrc, char* pSrcEnd)
{
- if ((currentElementProperties & ElementProperties.NO_ENTITIES) != 0)
+ if ((_currentElementProperties & ElementProperties.NO_ENTITIES) != 0)
{
base.RawText(pSrc, pSrcEnd);
}
WriteHtmlAttributeText(pSrc, pSrcEnd);
}
}
- else if ((currentElementProperties & ElementProperties.HAS_NS) != 0)
+ else if ((_currentElementProperties & ElementProperties.HAS_NS) != 0)
{
base.WriteAttributeTextBlock(pSrc, pSrcEnd);
}
_endsWithAmpersand = false;
}
- fixed (char* pDstBegin = bufChars)
+ fixed (char* pDstBegin = _bufChars)
{
- char* pDst = pDstBegin + bufPos;
+ char* pDst = pDstBegin + _bufPos;
char ch = (char)0;
while (true)
{
char* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
- while (pDst < pDstEnd && xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)))
+ while (pDst < pDstEnd && _xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)))
{
*pDst++ = (char)ch;
pSrc++;
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
FlushBuffer();
pDst = pDstBegin + 1;
continue;
}
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
}
}
_endsWithAmpersand = false;
}
- fixed (char* pDstBegin = bufChars)
+ fixed (char* pDstBegin = _bufChars)
{
- char* pDst = pDstBegin + bufPos;
+ char* pDst = pDstBegin + _bufPos;
char ch = (char)0;
while (true)
{
char* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
- while (pDst < pDstEnd && (xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch < 0x80))
+ while (pDst < pDstEnd && (_xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch < 0x80))
{
*pDst++ = (char)ch;
pSrc++;
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
FlushBuffer();
pDst = pDstBegin + 1;
continue;
}
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
}
}
// For handling &{ in Html text field. If & is not followed by {, it still needs to be escaped.
private void OutputRestAmps()
{
- base.bufChars[bufPos++] = (char)'a';
- base.bufChars[bufPos++] = (char)'m';
- base.bufChars[bufPos++] = (char)'p';
- base.bufChars[bufPos++] = (char)';';
+ base._bufChars[_bufPos++] = (char)'a';
+ base._bufChars[_bufPos++] = (char)'m';
+ base._bufChars[_bufPos++] = (char)'p';
+ base._bufChars[_bufPos++] = (char)';';
}
}
base.WriteDocType(name, pubid, sysid, subset);
// Allow indentation after DocTypeDecl
- _endBlockPos = base.bufPos;
+ _endBlockPos = base._bufPos;
}
public override void WriteStartElement(string prefix, string localName, string ns)
{
Debug.Assert(localName != null && localName.Length != 0 && prefix != null && ns != null);
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
- base.elementScope.Push((byte)base.currentElementProperties);
+ base._elementScope.Push((byte)base._currentElementProperties);
if (ns.Length == 0)
{
Debug.Assert(prefix.Length == 0);
- base.currentElementProperties = (ElementProperties)elementPropertySearch.FindCaseInsensitiveString(localName);
+ base._currentElementProperties = (ElementProperties)_elementPropertySearch.FindCaseInsensitiveString(localName);
- if (_endBlockPos == base.bufPos && (base.currentElementProperties & ElementProperties.BLOCK_WS) != 0)
+ if (_endBlockPos == base._bufPos && (base._currentElementProperties & ElementProperties.BLOCK_WS) != 0)
{
WriteIndent();
}
_indentLevel++;
- base.bufChars[bufPos++] = (char)'<';
+ base._bufChars[_bufPos++] = (char)'<';
}
else
{
- base.currentElementProperties = ElementProperties.HAS_NS | ElementProperties.BLOCK_WS;
+ base._currentElementProperties = ElementProperties.HAS_NS | ElementProperties.BLOCK_WS;
- if (_endBlockPos == base.bufPos)
+ if (_endBlockPos == base._bufPos)
{
WriteIndent();
}
_indentLevel++;
- base.bufChars[base.bufPos++] = (char)'<';
+ base._bufChars[base._bufPos++] = (char)'<';
if (prefix.Length != 0)
{
base.RawText(prefix);
- base.bufChars[base.bufPos++] = (char)':';
+ base._bufChars[base._bufPos++] = (char)':';
}
}
base.RawText(localName);
- base.attrEndPos = bufPos;
+ base._attrEndPos = _bufPos;
}
internal override void StartElementContent()
{
- base.bufChars[base.bufPos++] = (char)'>';
+ base._bufChars[base._bufPos++] = (char)'>';
// Detect whether content is output
- base.contentPos = base.bufPos;
+ base._contentPos = base._bufPos;
- if ((currentElementProperties & ElementProperties.HEAD) != 0)
+ if ((_currentElementProperties & ElementProperties.HEAD) != 0)
{
WriteIndent();
WriteMetaElement();
- _endBlockPos = base.bufPos;
+ _endBlockPos = base._bufPos;
}
- else if ((base.currentElementProperties & ElementProperties.BLOCK_WS) != 0)
+ else if ((base._currentElementProperties & ElementProperties.BLOCK_WS) != 0)
{
// store the element block position
- _endBlockPos = base.bufPos;
+ _endBlockPos = base._bufPos;
}
}
_indentLevel--;
// If this element has block whitespace properties,
- isBlockWs = (base.currentElementProperties & ElementProperties.BLOCK_WS) != 0;
+ isBlockWs = (base._currentElementProperties & ElementProperties.BLOCK_WS) != 0;
if (isBlockWs)
{
// And if the last node to be output had block whitespace properties,
// And if content was output within this element,
- if (_endBlockPos == base.bufPos && base.contentPos != base.bufPos)
+ if (_endBlockPos == base._bufPos && base._contentPos != base._bufPos)
{
// Then indent
WriteIndent();
base.WriteEndElement(prefix, localName, ns);
// Reset contentPos in case of empty elements
- base.contentPos = 0;
+ base._contentPos = 0;
// Mark end of element in buffer for element's with block whitespace properties
if (isBlockWs)
{
- _endBlockPos = base.bufPos;
+ _endBlockPos = base._bufPos;
}
}
{
if (_newLineOnAttributes)
{
- RawText(base.newLineChars);
+ RawText(base._newLineChars);
_indentLevel++;
WriteIndent();
_indentLevel--;
protected override void FlushBuffer()
{
// Make sure the buffer will reset the block position
- _endBlockPos = (_endBlockPos == base.bufPos) ? 1 : 0;
+ _endBlockPos = (_endBlockPos == base._bufPos) ? 1 : 0;
base.FlushBuffer();
}
// <inline><?PI?> -- suppress ws betw <inline> and PI
// <inline><!-- --> -- suppress ws betw <inline> and comment
- RawText(base.newLineChars);
+ RawText(base._newLineChars);
for (int i = _indentLevel; i > 0; i--)
{
RawText(_indentChars);
{
internal class <#= ClassName #> : <#= BaseClassName #>
{
- protected ByteStack elementScope;
- protected ElementProperties currentElementProperties;
+ protected ByteStack _elementScope;
+ protected ElementProperties _currentElementProperties;
private AttributeProperties _currentAttributeProperties;
private bool _endsWithAmpersand;
private string _mediaType;
private bool _doNotEscapeUriAttributes;
- protected static TernaryTreeReadOnly elementPropertySearch;
- protected static TernaryTreeReadOnly attributePropertySearch;
+ protected static TernaryTreeReadOnly _elementPropertySearch;
+ protected static TernaryTreeReadOnly _attributePropertySearch;
private const int StackIncrement = 10;
<# if (WriterType == RawTextWriterType.Encoded) { #>
{
Debug.Assert(localName != null && localName.Length != 0 && prefix != null && ns != null);
- elementScope.Push((byte)currentElementProperties);
+ _elementScope.Push((byte)_currentElementProperties);
if (ns.Length == 0)
{
#><#= SetTextContentMark(4, false) #>
- currentElementProperties = (ElementProperties)elementPropertySearch.FindCaseInsensitiveString(localName);
+ _currentElementProperties = (ElementProperties)_elementPropertySearch.FindCaseInsensitiveString(localName);
base.<#= BufferName #>[bufPos++] = (<#= BufferType #>)'<';
base.RawText(localName);
base.attrEndPos = bufPos;
{
// Since the HAS_NS has no impact to the ElementTextBlock behavior,
// we don't need to push it into the stack.
- currentElementProperties = ElementProperties.HAS_NS;
+ _currentElementProperties = ElementProperties.HAS_NS;
base.WriteStartElement(prefix, localName, ns);
}
}
// Detect whether content is output
contentPos = bufPos;
- if ((currentElementProperties & ElementProperties.HEAD) != 0)
+ if ((_currentElementProperties & ElementProperties.HEAD) != 0)
{
WriteMetaElement();
}
#><#= SetTextContentMark(4, false) #>
- if ((currentElementProperties & ElementProperties.EMPTY) == 0)
+ if ((_currentElementProperties & ElementProperties.EMPTY) == 0)
{
<#= BufferName #>[base.bufPos++] = (<#= BufferType #>)'<';
<#= BufferName #>[base.bufPos++] = (<#= BufferType #>)'/';
base.WriteEndElement(prefix, localName, ns);
}
- currentElementProperties = (ElementProperties)elementScope.Pop();
+ _currentElementProperties = (ElementProperties)_elementScope.Pop();
}
internal override void WriteFullEndElement(string prefix, string localName, string ns)
#><#= SetTextContentMark(4, false) #>
- if ((currentElementProperties & ElementProperties.EMPTY) == 0)
+ if ((_currentElementProperties & ElementProperties.EMPTY) == 0)
{
<#= BufferName #>[base.bufPos++] = (<#= BufferType #>)'<';
<#= BufferName #>[base.bufPos++] = (<#= BufferType #>)'/';
base.WriteFullEndElement(prefix, localName, ns);
}
- currentElementProperties = (ElementProperties)elementScope.Pop();
+ _currentElementProperties = (ElementProperties)_elementScope.Pop();
}
// 1. How the outputBooleanAttribute(fBOOL) and outputHtmlUriText(fURI) being set?
}
base.RawText(localName);
- if ((currentElementProperties & (ElementProperties.BOOL_PARENT | ElementProperties.URI_PARENT | ElementProperties.NAME_PARENT)) != 0)
+ if ((_currentElementProperties & (ElementProperties.BOOL_PARENT | ElementProperties.URI_PARENT | ElementProperties.NAME_PARENT)) != 0)
{
- _currentAttributeProperties = (AttributeProperties)attributePropertySearch.FindCaseInsensitiveString(localName) &
- (AttributeProperties)currentElementProperties;
+ _currentAttributeProperties = (AttributeProperties)_attributePropertySearch.FindCaseInsensitiveString(localName) &
+ (AttributeProperties)_currentElementProperties;
if ((_currentAttributeProperties & AttributeProperties.BOOLEAN) != 0)
{
Debug.Assert((int)ElementProperties.BOOL_PARENT == (int)AttributeProperties.BOOLEAN);
Debug.Assert((int)ElementProperties.NAME_PARENT == (int)AttributeProperties.NAME);
- if (elementPropertySearch == null)
+ if (_elementPropertySearch == null)
{
- //elementPropertySearch should be init last for the mutli thread safe situation.
- attributePropertySearch = new TernaryTreeReadOnly(HtmlTernaryTree.htmlAttributes);
- elementPropertySearch = new TernaryTreeReadOnly(HtmlTernaryTree.htmlElements);
+ //_elementPropertySearch should be init last for the mutli thread safe situation.
+ _attributePropertySearch = new TernaryTreeReadOnly(HtmlTernaryTree.htmlAttributes);
+ _elementPropertySearch = new TernaryTreeReadOnly(HtmlTernaryTree.htmlElements);
}
- elementScope = new ByteStack(StackIncrement);
+ _elementScope = new ByteStack(StackIncrement);
_uriEscapingBuffer = new byte[5];
- currentElementProperties = ElementProperties.DEFAULT;
+ _currentElementProperties = ElementProperties.DEFAULT;
_mediaType = settings.MediaType;
_doNotEscapeUriAttributes = settings.DoNotEscapeUriAttributes;
// only the top of the stack is the real E1 element properties.
protected unsafe void WriteHtmlElementTextBlock(char* pSrc, char* pSrcEnd)
{
- if ((currentElementProperties & ElementProperties.NO_ENTITIES) != 0)
+ if ((_currentElementProperties & ElementProperties.NO_ENTITIES) != 0)
{
base.RawText(pSrc, pSrcEnd);
}
WriteHtmlAttributeText(pSrc, pSrcEnd);
}
}
- else if ((currentElementProperties & ElementProperties.HAS_NS) != 0)
+ else if ((_currentElementProperties & ElementProperties.HAS_NS) != 0)
{
base.WriteAttributeTextBlock(pSrc, pSrcEnd);
}
#><#= SetTextContentMark(3, false) #>
- base.elementScope.Push((byte)base.currentElementProperties);
+ base._elementScope.Push((byte)base._currentElementProperties);
if (ns.Length == 0)
{
Debug.Assert(prefix.Length == 0);
- base.currentElementProperties = (ElementProperties)elementPropertySearch.FindCaseInsensitiveString(localName);
+ base._currentElementProperties = (ElementProperties)_elementPropertySearch.FindCaseInsensitiveString(localName);
- if (_endBlockPos == base.bufPos && (base.currentElementProperties & ElementProperties.BLOCK_WS) != 0)
+ if (_endBlockPos == base.bufPos && (base._currentElementProperties & ElementProperties.BLOCK_WS) != 0)
{
WriteIndent();
}
}
else
{
- base.currentElementProperties = ElementProperties.HAS_NS | ElementProperties.BLOCK_WS;
+ base._currentElementProperties = ElementProperties.HAS_NS | ElementProperties.BLOCK_WS;
if (_endBlockPos == base.bufPos)
{
// Detect whether content is output
base.contentPos = base.bufPos;
- if ((currentElementProperties & ElementProperties.HEAD) != 0)
+ if ((_currentElementProperties & ElementProperties.HEAD) != 0)
{
WriteIndent();
WriteMetaElement();
_endBlockPos = base.bufPos;
}
- else if ((base.currentElementProperties & ElementProperties.BLOCK_WS) != 0)
+ else if ((base._currentElementProperties & ElementProperties.BLOCK_WS) != 0)
{
// store the element block position
_endBlockPos = base.bufPos;
_indentLevel--;
// If this element has block whitespace properties,
- isBlockWs = (base.currentElementProperties & ElementProperties.BLOCK_WS) != 0;
+ isBlockWs = (base._currentElementProperties & ElementProperties.BLOCK_WS) != 0;
if (isBlockWs)
{
// And if the last node to be output had block whitespace properties,
{
internal class HtmlUtf8RawTextWriter : XmlUtf8RawTextWriter
{
- protected ByteStack elementScope;
- protected ElementProperties currentElementProperties;
+ protected ByteStack _elementScope;
+ protected ElementProperties _currentElementProperties;
private AttributeProperties _currentAttributeProperties;
private bool _endsWithAmpersand;
private string _mediaType;
private bool _doNotEscapeUriAttributes;
- protected static TernaryTreeReadOnly elementPropertySearch;
- protected static TernaryTreeReadOnly attributePropertySearch;
+ protected static TernaryTreeReadOnly _elementPropertySearch;
+ protected static TernaryTreeReadOnly _attributePropertySearch;
private const int StackIncrement = 10;
RawText("\" \"");
RawText(sysid);
}
- bufBytes[bufPos++] = (byte)'"';
+ _bufBytes[_bufPos++] = (byte)'"';
}
else if (sysid != null)
{
RawText(" SYSTEM \"");
RawText(sysid);
- bufBytes[bufPos++] = (byte)'"';
+ _bufBytes[_bufPos++] = (byte)'"';
}
else
{
- bufBytes[bufPos++] = (byte)' ';
+ _bufBytes[_bufPos++] = (byte)' ';
}
if (subset != null)
{
- bufBytes[bufPos++] = (byte)'[';
+ _bufBytes[_bufPos++] = (byte)'[';
RawText(subset);
- bufBytes[bufPos++] = (byte)']';
+ _bufBytes[_bufPos++] = (byte)']';
}
- bufBytes[bufPos++] = (byte)'>';
+ _bufBytes[_bufPos++] = (byte)'>';
}
// For the HTML element, it should call this method with ns and prefix as String.Empty
{
Debug.Assert(localName != null && localName.Length != 0 && prefix != null && ns != null);
- elementScope.Push((byte)currentElementProperties);
+ _elementScope.Push((byte)_currentElementProperties);
if (ns.Length == 0)
{
Debug.Assert(prefix.Length == 0);
- currentElementProperties = (ElementProperties)elementPropertySearch.FindCaseInsensitiveString(localName);
- base.bufBytes[bufPos++] = (byte)'<';
+ _currentElementProperties = (ElementProperties)_elementPropertySearch.FindCaseInsensitiveString(localName);
+ base._bufBytes[_bufPos++] = (byte)'<';
base.RawText(localName);
- base.attrEndPos = bufPos;
+ base._attrEndPos = _bufPos;
}
else
{
// Since the HAS_NS has no impact to the ElementTextBlock behavior,
// we don't need to push it into the stack.
- currentElementProperties = ElementProperties.HAS_NS;
+ _currentElementProperties = ElementProperties.HAS_NS;
base.WriteStartElement(prefix, localName, ns);
}
}
// Output >. For HTML needs to output META info
internal override void StartElementContent()
{
- base.bufBytes[base.bufPos++] = (byte)'>';
+ base._bufBytes[base._bufPos++] = (byte)'>';
// Detect whether content is output
- contentPos = bufPos;
+ _contentPos = _bufPos;
- if ((currentElementProperties & ElementProperties.HEAD) != 0)
+ if ((_currentElementProperties & ElementProperties.HEAD) != 0)
{
WriteMetaElement();
}
{
Debug.Assert(prefix.Length == 0);
- if ((currentElementProperties & ElementProperties.EMPTY) == 0)
+ if ((_currentElementProperties & ElementProperties.EMPTY) == 0)
{
- bufBytes[base.bufPos++] = (byte)'<';
- bufBytes[base.bufPos++] = (byte)'/';
+ _bufBytes[base._bufPos++] = (byte)'<';
+ _bufBytes[base._bufPos++] = (byte)'/';
base.RawText(localName);
- bufBytes[base.bufPos++] = (byte)'>';
+ _bufBytes[base._bufPos++] = (byte)'>';
}
}
else
base.WriteEndElement(prefix, localName, ns);
}
- currentElementProperties = (ElementProperties)elementScope.Pop();
+ _currentElementProperties = (ElementProperties)_elementScope.Pop();
}
internal override void WriteFullEndElement(string prefix, string localName, string ns)
{
Debug.Assert(prefix.Length == 0);
- if ((currentElementProperties & ElementProperties.EMPTY) == 0)
+ if ((_currentElementProperties & ElementProperties.EMPTY) == 0)
{
- bufBytes[base.bufPos++] = (byte)'<';
- bufBytes[base.bufPos++] = (byte)'/';
+ _bufBytes[base._bufPos++] = (byte)'<';
+ _bufBytes[base._bufPos++] = (byte)'/';
base.RawText(localName);
- bufBytes[base.bufPos++] = (byte)'>';
+ _bufBytes[base._bufPos++] = (byte)'>';
}
}
else
base.WriteFullEndElement(prefix, localName, ns);
}
- currentElementProperties = (ElementProperties)elementScope.Pop();
+ _currentElementProperties = (ElementProperties)_elementScope.Pop();
}
// 1. How the outputBooleanAttribute(fBOOL) and outputHtmlUriText(fURI) being set?
{
Debug.Assert(prefix.Length == 0);
- if (base.attrEndPos == bufPos)
+ if (base._attrEndPos == _bufPos)
{
- base.bufBytes[bufPos++] = (byte)' ';
+ base._bufBytes[_bufPos++] = (byte)' ';
}
base.RawText(localName);
- if ((currentElementProperties & (ElementProperties.BOOL_PARENT | ElementProperties.URI_PARENT | ElementProperties.NAME_PARENT)) != 0)
+ if ((_currentElementProperties & (ElementProperties.BOOL_PARENT | ElementProperties.URI_PARENT | ElementProperties.NAME_PARENT)) != 0)
{
- _currentAttributeProperties = (AttributeProperties)attributePropertySearch.FindCaseInsensitiveString(localName) &
- (AttributeProperties)currentElementProperties;
+ _currentAttributeProperties = (AttributeProperties)_attributePropertySearch.FindCaseInsensitiveString(localName) &
+ (AttributeProperties)_currentElementProperties;
if ((_currentAttributeProperties & AttributeProperties.BOOLEAN) != 0)
{
- base.inAttributeValue = true;
+ base._inAttributeValue = true;
return;
}
}
_currentAttributeProperties = AttributeProperties.DEFAULT;
}
- base.bufBytes[bufPos++] = (byte)'=';
- base.bufBytes[bufPos++] = (byte)'"';
+ base._bufBytes[_bufPos++] = (byte)'=';
+ base._bufBytes[_bufPos++] = (byte)'"';
}
else
{
_currentAttributeProperties = AttributeProperties.DEFAULT;
}
- base.inAttributeValue = true;
+ base._inAttributeValue = true;
}
// Output the amp; at end of EndAttribute
{
if ((_currentAttributeProperties & AttributeProperties.BOOLEAN) != 0)
{
- base.attrEndPos = bufPos;
+ base._attrEndPos = _bufPos;
}
else
{
_endsWithAmpersand = false;
}
- base.bufBytes[bufPos++] = (byte)'"';
+ base._bufBytes[_bufPos++] = (byte)'"';
}
- base.inAttributeValue = false;
- base.attrEndPos = bufPos;
+ base._inAttributeValue = false;
+ base._attrEndPos = _bufPos;
}
// HTML PI's use ">" to terminate rather than "?>".
{
Debug.Assert(target != null && target.Length != 0 && text != null);
- bufBytes[base.bufPos++] = (byte)'<';
- bufBytes[base.bufPos++] = (byte)'?';
+ _bufBytes[base._bufPos++] = (byte)'<';
+ _bufBytes[base._bufPos++] = (byte)'?';
base.RawText(target);
- bufBytes[base.bufPos++] = (byte)' ';
+ _bufBytes[base._bufPos++] = (byte)' ';
base.WriteCommentOrPi(text, '?');
- base.bufBytes[base.bufPos++] = (byte)'>';
+ base._bufBytes[base._bufPos++] = (byte)'>';
- if (base.bufPos > base.bufLen)
+ if (base._bufPos > base._bufLen)
{
FlushBuffer();
}
fixed (char* pSrc = text)
{
char* pSrcEnd = pSrc + text.Length;
- if (base.inAttributeValue)
+ if (base._inAttributeValue)
{
WriteHtmlAttributeTextBlock(pSrc, pSrcEnd);
}
fixed (char* pSrcBegin = &buffer[index])
{
- if (inAttributeValue)
+ if (_inAttributeValue)
{
WriteAttributeTextBlock(pSrcBegin, pSrcBegin + count);
}
Debug.Assert((int)ElementProperties.BOOL_PARENT == (int)AttributeProperties.BOOLEAN);
Debug.Assert((int)ElementProperties.NAME_PARENT == (int)AttributeProperties.NAME);
- if (elementPropertySearch == null)
+ if (_elementPropertySearch == null)
{
//elementPropertySearch should be init last for the mutli thread safe situation.
- attributePropertySearch = new TernaryTreeReadOnly(HtmlTernaryTree.htmlAttributes);
- elementPropertySearch = new TernaryTreeReadOnly(HtmlTernaryTree.htmlElements);
+ _attributePropertySearch = new TernaryTreeReadOnly(HtmlTernaryTree.htmlAttributes);
+ _elementPropertySearch = new TernaryTreeReadOnly(HtmlTernaryTree.htmlElements);
}
- elementScope = new ByteStack(StackIncrement);
+ _elementScope = new ByteStack(StackIncrement);
_uriEscapingBuffer = new byte[5];
- currentElementProperties = ElementProperties.DEFAULT;
+ _currentElementProperties = ElementProperties.DEFAULT;
_mediaType = settings.MediaType;
_doNotEscapeUriAttributes = settings.DoNotEscapeUriAttributes;
base.RawText(" content=\"");
base.RawText(_mediaType);
base.RawText("; charset=");
- base.RawText(base.encoding.WebName);
+ base.RawText(base._encoding.WebName);
base.RawText("\">");
}
// only the top of the stack is the real E1 element properties.
protected unsafe void WriteHtmlElementTextBlock(char* pSrc, char* pSrcEnd)
{
- if ((currentElementProperties & ElementProperties.NO_ENTITIES) != 0)
+ if ((_currentElementProperties & ElementProperties.NO_ENTITIES) != 0)
{
base.RawText(pSrc, pSrcEnd);
}
WriteHtmlAttributeText(pSrc, pSrcEnd);
}
}
- else if ((currentElementProperties & ElementProperties.HAS_NS) != 0)
+ else if ((_currentElementProperties & ElementProperties.HAS_NS) != 0)
{
base.WriteAttributeTextBlock(pSrc, pSrcEnd);
}
_endsWithAmpersand = false;
}
- fixed (byte* pDstBegin = bufBytes)
+ fixed (byte* pDstBegin = _bufBytes)
{
- byte* pDst = pDstBegin + bufPos;
+ byte* pDst = pDstBegin + _bufPos;
char ch = (char)0;
while (true)
{
byte* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
- while (pDst < pDstEnd && (xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch <= 0x7F))
+ while (pDst < pDstEnd && (_xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch <= 0x7F))
{
*pDst++ = (byte)ch;
pSrc++;
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
FlushBuffer();
pDst = pDstBegin + 1;
continue;
}
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
}
}
_endsWithAmpersand = false;
}
- fixed (byte* pDstBegin = bufBytes)
+ fixed (byte* pDstBegin = _bufBytes)
{
- byte* pDst = pDstBegin + bufPos;
+ byte* pDst = pDstBegin + _bufPos;
char ch = (char)0;
while (true)
{
byte* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
- while (pDst < pDstEnd && (xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch < 0x80))
+ while (pDst < pDstEnd && (_xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch < 0x80))
{
*pDst++ = (byte)ch;
pSrc++;
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
FlushBuffer();
pDst = pDstBegin + 1;
continue;
}
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
}
}
// For handling &{ in Html text field. If & is not followed by {, it still needs to be escaped.
private void OutputRestAmps()
{
- base.bufBytes[bufPos++] = (byte)'a';
- base.bufBytes[bufPos++] = (byte)'m';
- base.bufBytes[bufPos++] = (byte)'p';
- base.bufBytes[bufPos++] = (byte)';';
+ base._bufBytes[_bufPos++] = (byte)'a';
+ base._bufBytes[_bufPos++] = (byte)'m';
+ base._bufBytes[_bufPos++] = (byte)'p';
+ base._bufBytes[_bufPos++] = (byte)';';
}
}
base.WriteDocType(name, pubid, sysid, subset);
// Allow indentation after DocTypeDecl
- _endBlockPos = base.bufPos;
+ _endBlockPos = base._bufPos;
}
public override void WriteStartElement(string prefix, string localName, string ns)
{
Debug.Assert(localName != null && localName.Length != 0 && prefix != null && ns != null);
- base.elementScope.Push((byte)base.currentElementProperties);
+ base._elementScope.Push((byte)base._currentElementProperties);
if (ns.Length == 0)
{
Debug.Assert(prefix.Length == 0);
- base.currentElementProperties = (ElementProperties)elementPropertySearch.FindCaseInsensitiveString(localName);
+ base._currentElementProperties = (ElementProperties)_elementPropertySearch.FindCaseInsensitiveString(localName);
- if (_endBlockPos == base.bufPos && (base.currentElementProperties & ElementProperties.BLOCK_WS) != 0)
+ if (_endBlockPos == base._bufPos && (base._currentElementProperties & ElementProperties.BLOCK_WS) != 0)
{
WriteIndent();
}
_indentLevel++;
- base.bufBytes[bufPos++] = (byte)'<';
+ base._bufBytes[_bufPos++] = (byte)'<';
}
else
{
- base.currentElementProperties = ElementProperties.HAS_NS | ElementProperties.BLOCK_WS;
+ base._currentElementProperties = ElementProperties.HAS_NS | ElementProperties.BLOCK_WS;
- if (_endBlockPos == base.bufPos)
+ if (_endBlockPos == base._bufPos)
{
WriteIndent();
}
_indentLevel++;
- base.bufBytes[base.bufPos++] = (byte)'<';
+ base._bufBytes[base._bufPos++] = (byte)'<';
if (prefix.Length != 0)
{
base.RawText(prefix);
- base.bufBytes[base.bufPos++] = (byte)':';
+ base._bufBytes[base._bufPos++] = (byte)':';
}
}
base.RawText(localName);
- base.attrEndPos = bufPos;
+ base._attrEndPos = _bufPos;
}
internal override void StartElementContent()
{
- base.bufBytes[base.bufPos++] = (byte)'>';
+ base._bufBytes[base._bufPos++] = (byte)'>';
// Detect whether content is output
- base.contentPos = base.bufPos;
+ base._contentPos = base._bufPos;
- if ((currentElementProperties & ElementProperties.HEAD) != 0)
+ if ((_currentElementProperties & ElementProperties.HEAD) != 0)
{
WriteIndent();
WriteMetaElement();
- _endBlockPos = base.bufPos;
+ _endBlockPos = base._bufPos;
}
- else if ((base.currentElementProperties & ElementProperties.BLOCK_WS) != 0)
+ else if ((base._currentElementProperties & ElementProperties.BLOCK_WS) != 0)
{
// store the element block position
- _endBlockPos = base.bufPos;
+ _endBlockPos = base._bufPos;
}
}
_indentLevel--;
// If this element has block whitespace properties,
- isBlockWs = (base.currentElementProperties & ElementProperties.BLOCK_WS) != 0;
+ isBlockWs = (base._currentElementProperties & ElementProperties.BLOCK_WS) != 0;
if (isBlockWs)
{
// And if the last node to be output had block whitespace properties,
// And if content was output within this element,
- if (_endBlockPos == base.bufPos && base.contentPos != base.bufPos)
+ if (_endBlockPos == base._bufPos && base._contentPos != base._bufPos)
{
// Then indent
WriteIndent();
base.WriteEndElement(prefix, localName, ns);
// Reset contentPos in case of empty elements
- base.contentPos = 0;
+ base._contentPos = 0;
// Mark end of element in buffer for element's with block whitespace properties
if (isBlockWs)
{
- _endBlockPos = base.bufPos;
+ _endBlockPos = base._bufPos;
}
}
{
if (_newLineOnAttributes)
{
- RawText(base.newLineChars);
+ RawText(base._newLineChars);
_indentLevel++;
WriteIndent();
_indentLevel--;
protected override void FlushBuffer()
{
// Make sure the buffer will reset the block position
- _endBlockPos = (_endBlockPos == base.bufPos) ? 1 : 0;
+ _endBlockPos = (_endBlockPos == base._bufPos) ? 1 : 0;
base.FlushBuffer();
}
// <inline><?PI?> -- suppress ws betw <inline> and PI
// <inline><!-- --> -- suppress ws betw <inline> and comment
- RawText(base.newLineChars);
+ RawText(base._newLineChars);
for (int i = _indentLevel; i > 0; i--)
{
RawText(_indentChars);
{
get
{
- return this.resolver;
+ return this._resolver;
}
set
{
- this.resolver = value;
+ this._resolver = value;
_wrapped.NamespaceResolver = value;
}
}
WriterType = RawTextWriterType.Encoded;
ClassName = "XmlEncodedRawTextWriter";
ClassNameIndent = "XmlEncodedRawTextWriterIndent";
- BufferName = "bufChars";
+ BufferName = "_bufChars";
BufferType = "char";
EncodeCharBody = @"/* Surrogate character */
if (XmlCharType.IsSurrogate(ch))
// Ignore attributes
public override void WriteStartAttribute(string prefix, string localName, string ns)
{
- base.inAttributeValue = true;
+ base._inAttributeValue = true;
}
public override void WriteEndAttribute()
{
- base.inAttributeValue = false;
+ base._inAttributeValue = false;
}
// Ignore namespace declarations
// Output text content without any escaping; ignore attribute values
public override void WriteWhitespace(string ws)
{
- if (!base.inAttributeValue)
+ if (!base._inAttributeValue)
{
base.WriteRaw(ws);
}
// Output text content without any escaping; ignore attribute values
public override void WriteString(string textBlock)
{
- if (!base.inAttributeValue)
+ if (!base._inAttributeValue)
{
base.WriteRaw(textBlock);
}
// Output text content without any escaping; ignore attribute values
public override void WriteChars(char[] buffer, int index, int count)
{
- if (!base.inAttributeValue)
+ if (!base._inAttributeValue)
{
base.WriteRaw(buffer, index, count);
}
// Output text content without any escaping; ignore attribute values
public override void WriteRaw(char[] buffer, int index, int count)
{
- if (!base.inAttributeValue)
+ if (!base._inAttributeValue)
{
base.WriteRaw(buffer, index, count);
}
// Output text content without any escaping; ignore attribute values
public override void WriteRaw(string data)
{
- if (!base.inAttributeValue)
+ if (!base._inAttributeValue)
{
base.WriteRaw(data);
}
// Ignore attributes
public override void WriteStartAttribute(string prefix, string localName, string ns)
{
- base.inAttributeValue = true;
+ base._inAttributeValue = true;
}
public override void WriteEndAttribute()
{
- base.inAttributeValue = false;
+ base._inAttributeValue = false;
}
// Ignore namespace declarations
// Output text content without any escaping; ignore attribute values
public override void WriteWhitespace(string ws)
{
- if (!base.inAttributeValue)
+ if (!base._inAttributeValue)
{
base.WriteRaw(ws);
}
// Output text content without any escaping; ignore attribute values
public override void WriteString(string textBlock)
{
- if (!base.inAttributeValue)
+ if (!base._inAttributeValue)
{
base.WriteRaw(textBlock);
}
// Output text content without any escaping; ignore attribute values
public override void WriteChars(char[] buffer, int index, int count)
{
- if (!base.inAttributeValue)
+ if (!base._inAttributeValue)
{
base.WriteRaw(buffer, index, count);
}
// Output text content without any escaping; ignore attribute values
public override void WriteRaw(char[] buffer, int index, int count)
{
- if (!base.inAttributeValue)
+ if (!base._inAttributeValue)
{
base.WriteRaw(buffer, index, count);
}
// Output text content without any escaping; ignore attribute values
public override void WriteRaw(string data)
{
- if (!base.inAttributeValue)
+ if (!base._inAttributeValue)
{
base.WriteRaw(data);
}
{
get
{
- return this.resolver;
+ return this._resolver;
}
set
{
- this.resolver = value;
+ this._resolver = value;
if (_wrapped == null)
_eventCache.NamespaceResolver = value;
private readonly bool _useAsync;
// main buffer
- protected byte[] bufBytes;
+ protected byte[] _bufBytes;
// output stream
- protected Stream stream;
+ protected Stream _stream;
// encoding of the stream or text writer
- protected Encoding encoding;
+ protected Encoding _encoding;
// char type tables
- protected XmlCharType xmlCharType = XmlCharType.Instance;
+ protected XmlCharType _xmlCharType = XmlCharType.Instance;
// buffer positions
- protected int bufPos = 1; // buffer position starts at 1, because we need to be able to safely step back -1 in case we need to
- // close an empty element or in CDATA section detection of double ]; bufChars[0] will always be 0
- protected int textPos = 1; // text end position; don't indent first element, pi, or comment
- protected int contentPos; // element content end position
- protected int cdataPos; // cdata end position
- protected int attrEndPos; // end of the last attribute
- protected int bufLen = BUFSIZE;
+ protected int _bufPos = 1; // buffer position starts at 1, because we need to be able to safely step back -1 in case we need to
+ // close an empty element or in CDATA section detection of double ]; bufChars[0] will always be 0
+ protected int _textPos = 1; // text end position; don't indent first element, pi, or comment
+ protected int _contentPos; // element content end position
+ protected int _cdataPos; // cdata end position
+ protected int _attrEndPos; // end of the last attribute
+ protected int _bufLen = BUFSIZE;
// flags
- protected bool writeToNull;
- protected bool hadDoubleBracket;
- protected bool inAttributeValue;
+ protected bool _writeToNull;
+ protected bool _hadDoubleBracket;
+ protected bool _inAttributeValue;
- protected int bufBytesUsed;
- protected char[] bufChars;
+ protected int _bufBytesUsed;
+ protected char[] _bufChars;
// encoder for encoding chars in specified encoding when writing to stream
- protected Encoder encoder;
+ protected Encoder _encoder;
// output text writer
- protected TextWriter writer;
+ protected TextWriter _writer;
// escaping of characters invalid in the output encoding
- protected bool trackTextContent;
- protected bool inTextContent;
+ protected bool _trackTextContent;
+ protected bool _inTextContent;
private int _lastMarkPos;
private int[] _textContentMarks; // even indices contain text content start positions
// odd indices contain markup start positions
private readonly CharEntityEncoderFallback _charEntityFallback;
// writer settings
- protected NewLineHandling newLineHandling;
- protected bool closeOutput;
- protected bool omitXmlDeclaration;
- protected string newLineChars;
- protected bool checkCharacters;
+ protected NewLineHandling _newLineHandling;
+ protected bool _closeOutput;
+ protected bool _omitXmlDeclaration;
+ protected string _newLineChars;
+ protected bool _checkCharacters;
- protected XmlStandalone standalone;
- protected XmlOutputMethod outputMethod;
+ protected XmlStandalone _standalone;
+ protected XmlOutputMethod _outputMethod;
- protected bool autoXmlDeclaration;
- protected bool mergeCDataSections;
+ protected bool _autoXmlDeclaration;
+ protected bool _mergeCDataSections;
//
// Constants
_useAsync = settings.Async;
// copy settings
- newLineHandling = settings.NewLineHandling;
- omitXmlDeclaration = settings.OmitXmlDeclaration;
- newLineChars = settings.NewLineChars;
- checkCharacters = settings.CheckCharacters;
- closeOutput = settings.CloseOutput;
+ _newLineHandling = settings.NewLineHandling;
+ _omitXmlDeclaration = settings.OmitXmlDeclaration;
+ _newLineChars = settings.NewLineChars;
+ _checkCharacters = settings.CheckCharacters;
+ _closeOutput = settings.CloseOutput;
- standalone = settings.Standalone;
- outputMethod = settings.OutputMethod;
- mergeCDataSections = settings.MergeCDataSections;
+ _standalone = settings.Standalone;
+ _outputMethod = settings.OutputMethod;
+ _mergeCDataSections = settings.MergeCDataSections;
- if (checkCharacters && newLineHandling == NewLineHandling.Replace)
+ if (_checkCharacters && _newLineHandling == NewLineHandling.Replace)
{
- ValidateContentChars(newLineChars, "NewLineChars", false);
+ ValidateContentChars(_newLineChars, "NewLineChars", false);
}
}
{
Debug.Assert(writer != null && settings != null);
- this.writer = writer;
- this.encoding = writer.Encoding;
+ this._writer = writer;
+ this._encoding = writer.Encoding;
// the buffer is allocated will OVERFLOW in order to reduce checks when writing out constant size markup
if (settings.Async)
{
- bufLen = ASYNCBUFSIZE;
+ _bufLen = ASYNCBUFSIZE;
}
- this.bufChars = new char[bufLen + OVERFLOW];
+ this._bufChars = new char[_bufLen + OVERFLOW];
// Write the xml declaration
if (settings.AutoXmlDeclaration)
{
- WriteXmlDeclaration(standalone);
- autoXmlDeclaration = true;
+ WriteXmlDeclaration(_standalone);
+ _autoXmlDeclaration = true;
}
}
{
Debug.Assert(stream != null && settings != null);
- this.stream = stream;
- this.encoding = settings.Encoding;
+ this._stream = stream;
+ this._encoding = settings.Encoding;
// the buffer is allocated will OVERFLOW in order to reduce checks when writing out constant size markup
if (settings.Async)
{
- bufLen = ASYNCBUFSIZE;
+ _bufLen = ASYNCBUFSIZE;
}
- bufChars = new char[bufLen + OVERFLOW];
- bufBytes = new byte[bufChars.Length];
- bufBytesUsed = 0;
+ _bufChars = new char[_bufLen + OVERFLOW];
+ _bufBytes = new byte[_bufChars.Length];
+ _bufBytesUsed = 0;
// Init escaping of characters not fitting into the target encoding
- trackTextContent = true;
- inTextContent = false;
+ _trackTextContent = true;
+ _inTextContent = false;
_lastMarkPos = 0;
_textContentMarks = new int[INIT_MARKS_COUNT];
_textContentMarks[0] = 1;
_charEntityFallback = new CharEntityEncoderFallback();
// grab bom before possibly changing encoding settings
- ReadOnlySpan<byte> bom = encoding.Preamble;
+ ReadOnlySpan<byte> bom = _encoding.Preamble;
// the encoding instance this creates can differ from the one passed in
- this.encoding = Encoding.GetEncoding(
+ this._encoding = Encoding.GetEncoding(
settings.Encoding.CodePage,
_charEntityFallback,
settings.Encoding.DecoderFallback);
- encoder = encoding.GetEncoder();
+ _encoder = _encoding.GetEncoder();
if (!stream.CanSeek || stream.Position == 0)
{
if (bom.Length != 0)
{
- this.stream.Write(bom);
+ this._stream.Write(bom);
}
}
// Write the xml declaration
if (settings.AutoXmlDeclaration)
{
- WriteXmlDeclaration(standalone);
- autoXmlDeclaration = true;
+ WriteXmlDeclaration(_standalone);
+ _autoXmlDeclaration = true;
}
}
{
XmlWriterSettings settings = new XmlWriterSettings();
- settings.Encoding = encoding;
- settings.OmitXmlDeclaration = omitXmlDeclaration;
- settings.NewLineHandling = newLineHandling;
- settings.NewLineChars = newLineChars;
- settings.CloseOutput = closeOutput;
+ settings.Encoding = _encoding;
+ settings.OmitXmlDeclaration = _omitXmlDeclaration;
+ settings.NewLineHandling = _newLineHandling;
+ settings.NewLineChars = _newLineChars;
+ settings.CloseOutput = _closeOutput;
settings.ConformanceLevel = ConformanceLevel.Auto;
- settings.CheckCharacters = checkCharacters;
+ settings.CheckCharacters = _checkCharacters;
- settings.AutoXmlDeclaration = autoXmlDeclaration;
- settings.Standalone = standalone;
- settings.OutputMethod = outputMethod;
+ settings.AutoXmlDeclaration = _autoXmlDeclaration;
+ settings.Standalone = _standalone;
+ settings.OutputMethod = _outputMethod;
settings.ReadOnly = true;
return settings;
internal override void WriteXmlDeclaration(XmlStandalone standalone)
{
// Output xml declaration only if user allows it and it was not already output
- if (!omitXmlDeclaration && !autoXmlDeclaration)
+ if (!_omitXmlDeclaration && !_autoXmlDeclaration)
{
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
RawText("<?xml version=\"");
RawText("1.0");
// Encoding
- if (encoding != null)
+ if (_encoding != null)
{
RawText("\" encoding=\"");
- RawText(encoding.WebName);
+ RawText(_encoding.WebName);
}
// Standalone
internal override void WriteXmlDeclaration(string xmldecl)
{
// Output xml declaration only if user allows it and it was not already output
- if (!omitXmlDeclaration && !autoXmlDeclaration)
+ if (!_omitXmlDeclaration && !_autoXmlDeclaration)
{
WriteProcessingInstruction("xml", xmldecl);
}
{
Debug.Assert(name != null && name.Length > 0);
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
RawText("<!DOCTYPE ");
RawText(name);
{
RawText(sysid);
}
- bufChars[bufPos++] = (char)'"';
+ _bufChars[_bufPos++] = (char)'"';
}
else if (sysid != null)
{
RawText(" SYSTEM \"");
RawText(sysid);
- bufChars[bufPos++] = (char)'"';
+ _bufChars[_bufPos++] = (char)'"';
}
else
{
- bufChars[bufPos++] = (char)' ';
+ _bufChars[_bufPos++] = (char)' ';
}
if (subset != null)
{
- bufChars[bufPos++] = (char)'[';
+ _bufChars[_bufPos++] = (char)'[';
RawText(subset);
- bufChars[bufPos++] = (char)']';
+ _bufChars[_bufPos++] = (char)']';
}
- bufChars[bufPos++] = (char)'>';
+ _bufChars[_bufPos++] = (char)'>';
}
// Serialize the beginning of an element start tag: "<prefix:localName"
Debug.Assert(localName != null && localName.Length > 0);
Debug.Assert(prefix != null);
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
- bufChars[bufPos++] = (char)'<';
+ _bufChars[_bufPos++] = (char)'<';
if (prefix != null && prefix.Length != 0)
{
RawText(prefix);
- bufChars[bufPos++] = (char)':';
+ _bufChars[_bufPos++] = (char)':';
}
RawText(localName);
- attrEndPos = bufPos;
+ _attrEndPos = _bufPos;
}
// Serialize the end of an element start tag in preparation for content serialization: ">"
internal override void StartElementContent()
{
- bufChars[bufPos++] = (char)'>';
+ _bufChars[_bufPos++] = (char)'>';
// StartElementContent is always called; therefore, in order to allow shortcut syntax, we save the
// position of the '>' character. If WriteEndElement is called and no other characters have been
// output, then the '>' character can be overwritten with the shortcut syntax " />".
- contentPos = bufPos;
+ _contentPos = _bufPos;
}
// Serialize an element end tag: "</prefix:localName>", if content was output. Otherwise, serialize
Debug.Assert(localName != null && localName.Length > 0);
Debug.Assert(prefix != null);
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
- if (contentPos != bufPos)
+ if (_contentPos != _bufPos)
{
// Content has been output, so can't use shortcut syntax
- bufChars[bufPos++] = (char)'<';
- bufChars[bufPos++] = (char)'/';
+ _bufChars[_bufPos++] = (char)'<';
+ _bufChars[_bufPos++] = (char)'/';
if (prefix != null && prefix.Length != 0)
{
RawText(prefix);
- bufChars[bufPos++] = (char)':';
+ _bufChars[_bufPos++] = (char)':';
}
RawText(localName);
- bufChars[bufPos++] = (char)'>';
+ _bufChars[_bufPos++] = (char)'>';
}
else
{
// Use shortcut syntax; overwrite the already output '>' character
- bufPos--;
- bufChars[bufPos++] = (char)' ';
- bufChars[bufPos++] = (char)'/';
- bufChars[bufPos++] = (char)'>';
+ _bufPos--;
+ _bufChars[_bufPos++] = (char)' ';
+ _bufChars[_bufPos++] = (char)'/';
+ _bufChars[_bufPos++] = (char)'>';
}
}
Debug.Assert(localName != null && localName.Length > 0);
Debug.Assert(prefix != null);
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
- bufChars[bufPos++] = (char)'<';
- bufChars[bufPos++] = (char)'/';
+ _bufChars[_bufPos++] = (char)'<';
+ _bufChars[_bufPos++] = (char)'/';
if (prefix != null && prefix.Length != 0)
{
RawText(prefix);
- bufChars[bufPos++] = (char)':';
+ _bufChars[_bufPos++] = (char)':';
}
RawText(localName);
- bufChars[bufPos++] = (char)'>';
+ _bufChars[_bufPos++] = (char)'>';
}
// Serialize an attribute tag using double quotes around the attribute value: 'prefix:localName="'
Debug.Assert(localName != null && localName.Length > 0);
Debug.Assert(prefix != null);
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
- if (attrEndPos == bufPos)
+ if (_attrEndPos == _bufPos)
{
- bufChars[bufPos++] = (char)' ';
+ _bufChars[_bufPos++] = (char)' ';
}
if (prefix != null && prefix.Length > 0)
{
RawText(prefix);
- bufChars[bufPos++] = (char)':';
+ _bufChars[_bufPos++] = (char)':';
}
RawText(localName);
- bufChars[bufPos++] = (char)'=';
- bufChars[bufPos++] = (char)'"';
+ _bufChars[_bufPos++] = (char)'=';
+ _bufChars[_bufPos++] = (char)'"';
- inAttributeValue = true;
+ _inAttributeValue = true;
}
// Serialize the end of an attribute value using double quotes: '"'
public override void WriteEndAttribute()
{
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
- bufChars[bufPos++] = (char)'"';
- inAttributeValue = false;
- attrEndPos = bufPos;
+ _bufChars[_bufPos++] = (char)'"';
+ _inAttributeValue = false;
+ _attrEndPos = _bufPos;
}
internal override void WriteNamespaceDeclaration(string prefix, string namespaceName)
{
Debug.Assert(prefix != null);
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
if (prefix.Length == 0)
{
{
RawText(" xmlns:");
RawText(prefix);
- bufChars[bufPos++] = (char)'=';
- bufChars[bufPos++] = (char)'"';
+ _bufChars[_bufPos++] = (char)'=';
+ _bufChars[_bufPos++] = (char)'"';
}
- inAttributeValue = true;
+ _inAttributeValue = true;
- if (trackTextContent && inTextContent != true) { ChangeTextContentMark(true); }
+ if (_trackTextContent && _inTextContent != true) { ChangeTextContentMark(true); }
}
internal override void WriteEndNamespaceDeclaration()
{
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
- inAttributeValue = false;
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
+ _inAttributeValue = false;
- bufChars[bufPos++] = (char)'"';
- attrEndPos = bufPos;
+ _bufChars[_bufPos++] = (char)'"';
+ _attrEndPos = _bufPos;
}
// Serialize a CData section. If the "]]>" pattern is found within
{
Debug.Assert(text != null);
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
- if (mergeCDataSections && bufPos == cdataPos)
+ if (_mergeCDataSections && _bufPos == _cdataPos)
{
// Merge adjacent cdata sections - overwrite the "]]>" characters
- Debug.Assert(bufPos >= 4);
- bufPos -= 3;
+ Debug.Assert(_bufPos >= 4);
+ _bufPos -= 3;
}
else
{
// Start a new cdata section
- bufChars[bufPos++] = (char)'<';
- bufChars[bufPos++] = (char)'!';
- bufChars[bufPos++] = (char)'[';
- bufChars[bufPos++] = (char)'C';
- bufChars[bufPos++] = (char)'D';
- bufChars[bufPos++] = (char)'A';
- bufChars[bufPos++] = (char)'T';
- bufChars[bufPos++] = (char)'A';
- bufChars[bufPos++] = (char)'[';
+ _bufChars[_bufPos++] = (char)'<';
+ _bufChars[_bufPos++] = (char)'!';
+ _bufChars[_bufPos++] = (char)'[';
+ _bufChars[_bufPos++] = (char)'C';
+ _bufChars[_bufPos++] = (char)'D';
+ _bufChars[_bufPos++] = (char)'A';
+ _bufChars[_bufPos++] = (char)'T';
+ _bufChars[_bufPos++] = (char)'A';
+ _bufChars[_bufPos++] = (char)'[';
}
WriteCDataSection(text);
- bufChars[bufPos++] = (char)']';
- bufChars[bufPos++] = (char)']';
- bufChars[bufPos++] = (char)'>';
+ _bufChars[_bufPos++] = (char)']';
+ _bufChars[_bufPos++] = (char)']';
+ _bufChars[_bufPos++] = (char)'>';
- textPos = bufPos;
- cdataPos = bufPos;
+ _textPos = _bufPos;
+ _cdataPos = _bufPos;
}
// Serialize a comment.
{
Debug.Assert(text != null);
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
- bufChars[bufPos++] = (char)'<';
- bufChars[bufPos++] = (char)'!';
- bufChars[bufPos++] = (char)'-';
- bufChars[bufPos++] = (char)'-';
+ _bufChars[_bufPos++] = (char)'<';
+ _bufChars[_bufPos++] = (char)'!';
+ _bufChars[_bufPos++] = (char)'-';
+ _bufChars[_bufPos++] = (char)'-';
WriteCommentOrPi(text, '-');
- bufChars[bufPos++] = (char)'-';
- bufChars[bufPos++] = (char)'-';
- bufChars[bufPos++] = (char)'>';
+ _bufChars[_bufPos++] = (char)'-';
+ _bufChars[_bufPos++] = (char)'-';
+ _bufChars[_bufPos++] = (char)'>';
}
// Serialize a processing instruction.
Debug.Assert(name != null && name.Length > 0);
Debug.Assert(text != null);
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
- bufChars[bufPos++] = (char)'<';
- bufChars[bufPos++] = (char)'?';
+ _bufChars[_bufPos++] = (char)'<';
+ _bufChars[_bufPos++] = (char)'?';
RawText(name);
if (text.Length > 0)
{
- bufChars[bufPos++] = (char)' ';
+ _bufChars[_bufPos++] = (char)' ';
WriteCommentOrPi(text, '?');
}
- bufChars[bufPos++] = (char)'?';
- bufChars[bufPos++] = (char)'>';
+ _bufChars[_bufPos++] = (char)'?';
+ _bufChars[_bufPos++] = (char)'>';
}
// Serialize an entity reference.
{
Debug.Assert(name != null && name.Length > 0);
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
- bufChars[bufPos++] = (char)'&';
+ _bufChars[_bufPos++] = (char)'&';
RawText(name);
- bufChars[bufPos++] = (char)';';
+ _bufChars[_bufPos++] = (char)';';
- if (bufPos > bufLen)
+ if (_bufPos > _bufLen)
{
FlushBuffer();
}
- textPos = bufPos;
+ _textPos = _bufPos;
}
// Serialize a character entity reference.
{
string strVal = ((int)ch).ToString("X", NumberFormatInfo.InvariantInfo);
- if (checkCharacters && !xmlCharType.IsCharData(ch))
+ if (_checkCharacters && !_xmlCharType.IsCharData(ch))
{
// we just have a single char, not a surrogate, therefore we have to pass in '\0' for the second char
throw XmlConvert.CreateInvalidCharException(ch, '\0');
}
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
- bufChars[bufPos++] = (char)'&';
- bufChars[bufPos++] = (char)'#';
- bufChars[bufPos++] = (char)'x';
+ _bufChars[_bufPos++] = (char)'&';
+ _bufChars[_bufPos++] = (char)'#';
+ _bufChars[_bufPos++] = (char)'x';
RawText(strVal);
- bufChars[bufPos++] = (char)';';
+ _bufChars[_bufPos++] = (char)';';
- if (bufPos > bufLen)
+ if (_bufPos > _bufLen)
{
FlushBuffer();
}
- textPos = bufPos;
+ _textPos = _bufPos;
}
// Serialize a whitespace node.
{
Debug.Assert(ws != null);
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
fixed (char* pSrc = ws)
{
char* pSrcEnd = pSrc + ws.Length;
- if (inAttributeValue)
+ if (_inAttributeValue)
{
WriteAttributeTextBlock(pSrc, pSrcEnd);
}
{
Debug.Assert(text != null);
- if (trackTextContent && inTextContent != true) { ChangeTextContentMark(true); }
+ if (_trackTextContent && _inTextContent != true) { ChangeTextContentMark(true); }
fixed (char* pSrc = text)
{
char* pSrcEnd = pSrc + text.Length;
- if (inAttributeValue)
+ if (_inAttributeValue)
{
WriteAttributeTextBlock(pSrc, pSrcEnd);
}
// Serialize surrogate character entity.
public override void WriteSurrogateCharEntity(char lowChar, char highChar)
{
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
int surrogateChar = XmlCharType.CombineSurrogateChar(lowChar, highChar);
- bufChars[bufPos++] = (char)'&';
- bufChars[bufPos++] = (char)'#';
- bufChars[bufPos++] = (char)'x';
+ _bufChars[_bufPos++] = (char)'&';
+ _bufChars[_bufPos++] = (char)'#';
+ _bufChars[_bufPos++] = (char)'x';
RawText(surrogateChar.ToString("X", NumberFormatInfo.InvariantInfo));
- bufChars[bufPos++] = (char)';';
- textPos = bufPos;
+ _bufChars[_bufPos++] = (char)';';
+ _textPos = _bufPos;
}
// Serialize either attribute or element text using XML rules.
Debug.Assert(index >= 0);
Debug.Assert(count >= 0 && index + count <= buffer.Length);
- if (trackTextContent && inTextContent != true) { ChangeTextContentMark(true); }
+ if (_trackTextContent && _inTextContent != true) { ChangeTextContentMark(true); }
fixed (char* pSrcBegin = &buffer[index])
{
- if (inAttributeValue)
+ if (_inAttributeValue)
{
WriteAttributeTextBlock(pSrcBegin, pSrcBegin + count);
}
Debug.Assert(index >= 0);
Debug.Assert(count >= 0 && index + count <= buffer.Length);
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
fixed (char* pSrcBegin = &buffer[index])
{
WriteRawWithCharChecking(pSrcBegin, pSrcBegin + count);
}
- textPos = bufPos;
+ _textPos = _bufPos;
}
// Serialize raw data.
{
Debug.Assert(data != null);
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
fixed (char* pSrcBegin = data)
{
WriteRawWithCharChecking(pSrcBegin, pSrcBegin + data.Length);
}
- textPos = bufPos;
+ _textPos = _bufPos;
}
// Flush all bytes in the buffer to output and close the output stream or writer.
finally
{
// Future calls to Close or Flush shouldn't write to Stream or Writer
- writeToNull = true;
+ _writeToNull = true;
- if (stream != null)
+ if (_stream != null)
{
try
{
- stream.Flush();
+ _stream.Flush();
}
finally
{
try
{
- if (closeOutput)
+ if (_closeOutput)
{
- stream.Dispose();
+ _stream.Dispose();
}
}
finally
{
- stream = null;
+ _stream = null;
}
}
}
- else if (writer != null)
+ else if (_writer != null)
{
try
{
- writer.Flush();
+ _writer.Flush();
}
finally
{
try
{
- if (closeOutput)
+ if (_closeOutput)
{
- writer.Dispose();
+ _writer.Dispose();
}
}
finally
{
- writer = null;
+ _writer = null;
}
}
}
{
FlushBuffer();
FlushEncoder();
- if (stream != null)
+ if (_stream != null)
{
- stream.Flush();
+ _stream.Flush();
}
- else if (writer != null)
+ else if (_writer != null)
{
- writer.Flush();
+ _writer.Flush();
}
}
try
{
// Output all characters (except for previous characters stored at beginning of buffer)
- if (!writeToNull)
+ if (!_writeToNull)
{
- Debug.Assert(stream != null || writer != null);
+ Debug.Assert(_stream != null || _writer != null);
- if (stream != null)
+ if (_stream != null)
{
- if (trackTextContent)
+ if (_trackTextContent)
{
_charEntityFallback.Reset(_textContentMarks, _lastMarkPos);
// reset text content tracking
}
Debug.Assert(_textContentMarks[0] == 1);
}
- EncodeChars(1, bufPos, true);
+ EncodeChars(1, _bufPos, true);
}
else
{
- if (bufPos - 1 > 0)
+ if (_bufPos - 1 > 0)
{
// Write text to TextWriter
- writer.Write(bufChars, 1, bufPos - 1);
+ _writer.Write(_bufChars, 1, _bufPos - 1);
}
}
}
catch
{
// Future calls to flush (i.e. when Close() is called) don't attempt to write to stream
- writeToNull = true;
+ _writeToNull = true;
throw;
}
finally
{
// Move last buffer character to the beginning of the buffer (so that previous character can always be determined)
- bufChars[0] = bufChars[bufPos - 1];
+ _bufChars[0] = _bufChars[_bufPos - 1];
// Reset buffer position
- textPos = (textPos == bufPos) ? 1 : 0;
- attrEndPos = (attrEndPos == bufPos) ? 1 : 0;
- contentPos = 0; // Needs to be zero, since overwriting '>' character is no longer possible
- cdataPos = 0; // Needs to be zero, since overwriting ']]>' characters is no longer possible
- bufPos = 1; // Buffer position starts at 1, because we need to be able to safely step back -1 in case we need to
+ _textPos = (_textPos == _bufPos) ? 1 : 0;
+ _attrEndPos = (_attrEndPos == _bufPos) ? 1 : 0;
+ _contentPos = 0; // Needs to be zero, since overwriting '>' character is no longer possible
+ _cdataPos = 0; // Needs to be zero, since overwriting ']]>' characters is no longer possible
+ _bufPos = 1; // Buffer position starts at 1, because we need to be able to safely step back -1 in case we need to
// close an empty element or in CDATA section detection of double ]; bufChars[0] will always be 0
}
}
{
_charEntityFallback.StartOffset = startOffset;
}
- encoder.Convert(bufChars, startOffset, endOffset - startOffset, bufBytes, bufBytesUsed, bufBytes.Length - bufBytesUsed, false, out chEnc, out bEnc, out completed);
+ _encoder.Convert(_bufChars, startOffset, endOffset - startOffset, _bufBytes, _bufBytesUsed, _bufBytes.Length - _bufBytesUsed, false, out chEnc, out bEnc, out completed);
startOffset += chEnc;
- bufBytesUsed += bEnc;
- if (bufBytesUsed >= (bufBytes.Length - 16))
+ _bufBytesUsed += bEnc;
+ if (_bufBytesUsed >= (_bufBytes.Length - 16))
{
- stream.Write(bufBytes, 0, bufBytesUsed);
- bufBytesUsed = 0;
+ _stream.Write(_bufBytes, 0, _bufBytesUsed);
+ _bufBytesUsed = 0;
}
}
- if (writeAllToStream && bufBytesUsed > 0)
+ if (writeAllToStream && _bufBytesUsed > 0)
{
- stream.Write(bufBytes, 0, bufBytesUsed);
- bufBytesUsed = 0;
+ _stream.Write(_bufBytes, 0, _bufBytesUsed);
+ _bufBytesUsed = 0;
}
}
private void FlushEncoder()
{
- Debug.Assert(bufPos == 1);
- if (stream != null)
+ Debug.Assert(_bufPos == 1);
+ if (_stream != null)
{
int chEnc;
int bEnc;
bool completed;
// decode no chars, just flush
- encoder.Convert(bufChars, 1, 0, bufBytes, 0, bufBytes.Length, true, out chEnc, out bEnc, out completed);
+ _encoder.Convert(_bufChars, 1, 0, _bufBytes, 0, _bufBytes.Length, true, out chEnc, out bEnc, out completed);
if (bEnc != 0)
{
- stream.Write(bufBytes, 0, bEnc);
+ _stream.Write(_bufBytes, 0, bEnc);
}
}
}
// are entitized.
protected unsafe void WriteAttributeTextBlock(char* pSrc, char* pSrcEnd)
{
- fixed (char* pDstBegin = bufChars)
+ fixed (char* pDstBegin = _bufChars)
{
- char* pDst = pDstBegin + bufPos;
+ char* pDst = pDstBegin + _bufPos;
int ch = 0;
while (true)
{
char* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
- while (pDst < pDstEnd && xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)))
+ while (pDst < pDstEnd && _xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)))
{
*pDst = (char)ch;
pDst++;
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
FlushBuffer();
pDst = pDstBegin + 1;
continue;
pDst++;
break;
case (char)0x9:
- if (newLineHandling == NewLineHandling.None)
+ if (_newLineHandling == NewLineHandling.None)
{
*pDst = (char)ch;
pDst++;
}
break;
case (char)0xD:
- if (newLineHandling == NewLineHandling.None)
+ if (_newLineHandling == NewLineHandling.None)
{
*pDst = (char)ch;
pDst++;
}
break;
case (char)0xA:
- if (newLineHandling == NewLineHandling.None)
+ if (_newLineHandling == NewLineHandling.None)
{
*pDst = (char)ch;
pDst++;
}
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
}
}
// are entitized.
protected unsafe void WriteElementTextBlock(char* pSrc, char* pSrcEnd)
{
- fixed (char* pDstBegin = bufChars)
+ fixed (char* pDstBegin = _bufChars)
{
- char* pDst = pDstBegin + bufPos;
+ char* pDst = pDstBegin + _bufPos;
int ch = 0;
while (true)
{
char* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
- while (pDst < pDstEnd && xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)))
+ while (pDst < pDstEnd && _xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)))
{
*pDst = (char)ch;
pDst++;
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
FlushBuffer();
pDst = pDstBegin + 1;
continue;
pDst++;
break;
case (char)0xA:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
pDst = WriteNewLine(pDst);
}
}
break;
case (char)0xD:
- switch (newLineHandling)
+ switch (_newLineHandling)
{
case NewLineHandling.Replace:
// Replace "\r\n", or "\r" with NewLineChars
}
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
- textPos = bufPos;
- contentPos = 0;
+ _bufPos = (int)(pDst - pDstBegin);
+ _textPos = _bufPos;
+ _contentPos = 0;
}
}
protected unsafe void RawText(char* pSrcBegin, char* pSrcEnd)
{
- fixed (char* pDstBegin = bufChars)
+ fixed (char* pDstBegin = _bufChars)
{
- char* pDst = pDstBegin + bufPos;
+ char* pDst = pDstBegin + _bufPos;
char* pSrc = pSrcBegin;
int ch = 0;
while (true)
{
char* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
while (pDst < pDstEnd && ((ch = *pSrc) < XmlCharType.SurHighStart))
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
FlushBuffer();
pDst = pDstBegin + 1;
continue;
}
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
}
}
protected unsafe void WriteRawWithCharChecking(char* pSrcBegin, char* pSrcEnd)
{
- fixed (char* pDstBegin = bufChars)
+ fixed (char* pDstBegin = _bufChars)
{
char* pSrc = pSrcBegin;
- char* pDst = pDstBegin + bufPos;
+ char* pDst = pDstBegin + _bufPos;
int ch = 0;
while (true)
{
char* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
- while (pDst < pDstEnd && xmlCharType.IsTextChar((char)(ch = *pSrc)))
+ while (pDst < pDstEnd && _xmlCharType.IsTextChar((char)(ch = *pSrc)))
{
*pDst = (char)ch;
pDst++;
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
FlushBuffer();
pDst = pDstBegin + 1;
continue;
pDst++;
break;
case (char)0xD:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
// Normalize "\r\n", or "\r" to NewLineChars
if (pSrc + 1 < pSrcEnd && pSrc[1] == '\n')
}
break;
case (char)0xA:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
pDst = WriteNewLine(pDst);
}
}
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
}
}
{
if (text.Length == 0)
{
- if (bufPos >= bufLen)
+ if (_bufPos >= _bufLen)
{
FlushBuffer();
}
// write text
fixed (char* pSrcBegin = text)
- fixed (char* pDstBegin = bufChars)
+ fixed (char* pDstBegin = _bufChars)
{
char* pSrc = pSrcBegin;
char* pSrcEnd = pSrcBegin + text.Length;
- char* pDst = pDstBegin + bufPos;
+ char* pDst = pDstBegin + _bufPos;
int ch = 0;
while (true)
{
char* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
- while (pDst < pDstEnd && (xmlCharType.IsTextChar((char)(ch = *pSrc)) && ch != stopChar))
+ while (pDst < pDstEnd && (_xmlCharType.IsTextChar((char)(ch = *pSrc)) && ch != stopChar))
{
*pDst = (char)ch;
pDst++;
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
FlushBuffer();
pDst = pDstBegin + 1;
continue;
pDst++;
break;
case (char)0xD:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
// Normalize "\r\n", or "\r" to NewLineChars
if (pSrc + 1 < pSrcEnd && pSrc[1] == '\n')
}
break;
case (char)0xA:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
pDst = WriteNewLine(pDst);
}
}
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
}
}
{
if (text.Length == 0)
{
- if (bufPos >= bufLen)
+ if (_bufPos >= _bufLen)
{
FlushBuffer();
}
fixed (char* pSrcBegin = text)
- fixed (char* pDstBegin = bufChars)
+ fixed (char* pDstBegin = _bufChars)
{
char* pSrc = pSrcBegin;
char* pSrcEnd = pSrcBegin + text.Length;
- char* pDst = pDstBegin + bufPos;
+ char* pDst = pDstBegin + _bufPos;
int ch = 0;
while (true)
{
char* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
- while (pDst < pDstEnd && (xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch != ']'))
+ while (pDst < pDstEnd && (_xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch != ']'))
{
*pDst = (char)ch;
pDst++;
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
FlushBuffer();
pDst = pDstBegin + 1;
continue;
switch (ch)
{
case '>':
- if (hadDoubleBracket && pDst[-1] == (char)']')
+ if (_hadDoubleBracket && pDst[-1] == (char)']')
{ // pDst[-1] will always correct - there is a padding character at bufChars[0]
// The characters "]]>" were found within the CData text
pDst = RawEndCData(pDst);
case ']':
if (pDst[-1] == (char)']')
{ // pDst[-1] will always correct - there is a padding character at bufChars[0]
- hadDoubleBracket = true;
+ _hadDoubleBracket = true;
}
else
{
- hadDoubleBracket = false;
+ _hadDoubleBracket = false;
}
*pDst = (char)']';
pDst++;
break;
case (char)0xD:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
// Normalize "\r\n", or "\r" to NewLineChars
if (pSrc + 1 < pSrcEnd && pSrc[1] == '\n')
}
break;
case (char)0xA:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
pDst = WriteNewLine(pDst);
}
}
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
}
}
private unsafe char* InvalidXmlChar(int ch, char* pDst, bool entitize)
{
- Debug.Assert(!xmlCharType.IsWhiteSpace((char)ch));
- Debug.Assert(!xmlCharType.IsAttributeValueChar((char)ch));
+ Debug.Assert(!_xmlCharType.IsWhiteSpace((char)ch));
+ Debug.Assert(!_xmlCharType.IsAttributeValueChar((char)ch));
- if (checkCharacters)
+ if (_checkCharacters)
{
// This method will never be called on surrogates, so it is ok to pass in '\0' to the CreateInvalidCharException
throw XmlConvert.CreateInvalidCharException((char)ch, '\0');
protected void ChangeTextContentMark(bool value)
{
- Debug.Assert(inTextContent != value);
- Debug.Assert(inTextContent || ((_lastMarkPos & 1) == 0));
- inTextContent = value;
+ Debug.Assert(_inTextContent != value);
+ Debug.Assert(_inTextContent || ((_lastMarkPos & 1) == 0));
+ _inTextContent = value;
if (_lastMarkPos + 1 == _textContentMarks.Length)
{
GrowTextContentMarks();
}
- _textContentMarks[++_lastMarkPos] = bufPos;
+ _textContentMarks[++_lastMarkPos] = _bufPos;
}
private void GrowTextContentMarks()
// Write NewLineChars to the specified buffer position and return an updated position.
protected unsafe char* WriteNewLine(char* pDst)
{
- fixed (char* pDstBegin = bufChars)
+ fixed (char* pDstBegin = _bufChars)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
// Let RawText do the real work
- RawText(newLineChars);
- return pDstBegin + bufPos;
+ RawText(_newLineChars);
+ return pDstBegin + _bufPos;
}
}
{
if (allowOnlyWhitespace)
{
- if (!xmlCharType.IsOnlyWhitespace(chars))
+ if (!_xmlCharType.IsOnlyWhitespace(chars))
{
throw new ArgumentException(SR.Format(SR.Xml_IndentCharsNotWhitespace, propertyName));
}
string error = null;
for (int i = 0; i < chars.Length; i++)
{
- if (!xmlCharType.IsTextChar(chars[i]))
+ if (!_xmlCharType.IsTextChar(chars[i]))
{
switch (chars[i])
{
//
// Fields
//
- protected int indentLevel;
- protected bool newLineOnAttributes;
- protected string indentChars;
+ protected int _indentLevel;
+ protected bool _newLineOnAttributes;
+ protected string _indentChars;
- protected bool mixedContent;
+ protected bool _mixedContent;
private BitStack _mixedContentStack;
- protected ConformanceLevel conformanceLevel = ConformanceLevel.Auto;
+ protected ConformanceLevel _conformanceLevel = ConformanceLevel.Auto;
//
// Constructors
settings.ReadOnly = false;
settings.Indent = true;
- settings.IndentChars = indentChars;
- settings.NewLineOnAttributes = newLineOnAttributes;
+ settings.IndentChars = _indentChars;
+ settings.NewLineOnAttributes = _newLineOnAttributes;
settings.ReadOnly = true;
return settings;
public override void WriteDocType(string name, string pubid, string sysid, string subset)
{
// Add indentation
- if (!mixedContent && base.textPos != base.bufPos)
+ if (!_mixedContent && base._textPos != base._bufPos)
{
WriteIndent();
}
Debug.Assert(localName != null && localName.Length != 0 && prefix != null && ns != null);
// Add indentation
- if (!mixedContent && base.textPos != base.bufPos)
+ if (!_mixedContent && base._textPos != base._bufPos)
{
WriteIndent();
}
- indentLevel++;
- _mixedContentStack.PushBit(mixedContent);
+ _indentLevel++;
+ _mixedContentStack.PushBit(_mixedContent);
base.WriteStartElement(prefix, localName, ns);
}
internal override void StartElementContent()
{
// If this is the root element and we're writing a document
- // do not inherit the mixedContent flag into the root element.
+ // do not inherit the _mixedContent flag into the root element.
// This is to allow for whitespace nodes on root level
// without disabling indentation for the whole document.
- if (indentLevel == 1 && conformanceLevel == ConformanceLevel.Document)
+ if (_indentLevel == 1 && _conformanceLevel == ConformanceLevel.Document)
{
- mixedContent = false;
+ _mixedContent = false;
}
else
{
- mixedContent = _mixedContentStack.PeekBit();
+ _mixedContent = _mixedContentStack.PeekBit();
}
base.StartElementContent();
}
internal override void OnRootElement(ConformanceLevel currentConformanceLevel)
{
// Just remember the current conformance level
- conformanceLevel = currentConformanceLevel;
+ _conformanceLevel = currentConformanceLevel;
}
internal override void WriteEndElement(string prefix, string localName, string ns)
{
// Add indentation
- indentLevel--;
- if (!mixedContent && base.contentPos != base.bufPos)
+ _indentLevel--;
+ if (!_mixedContent && base._contentPos != base._bufPos)
{
// There was content, so try to indent
- if (base.textPos != base.bufPos)
+ if (base._textPos != base._bufPos)
{
WriteIndent();
}
}
- mixedContent = _mixedContentStack.PopBit();
+ _mixedContent = _mixedContentStack.PopBit();
base.WriteEndElement(prefix, localName, ns);
}
internal override void WriteFullEndElement(string prefix, string localName, string ns)
{
// Add indentation
- indentLevel--;
- if (!mixedContent && base.contentPos != base.bufPos)
+ _indentLevel--;
+ if (!_mixedContent && base._contentPos != base._bufPos)
{
// There was content, so try to indent
- if (base.textPos != base.bufPos)
+ if (base._textPos != base._bufPos)
{
WriteIndent();
}
}
- mixedContent = _mixedContentStack.PopBit();
+ _mixedContent = _mixedContentStack.PopBit();
base.WriteFullEndElement(prefix, localName, ns);
}
public override void WriteStartAttribute(string prefix, string localName, string ns)
{
// Add indentation
- if (newLineOnAttributes)
+ if (_newLineOnAttributes)
{
WriteIndent();
}
public override void WriteCData(string text)
{
- mixedContent = true;
+ _mixedContent = true;
base.WriteCData(text);
}
public override void WriteComment(string text)
{
- if (!mixedContent && base.textPos != base.bufPos)
+ if (!_mixedContent && base._textPos != base._bufPos)
{
WriteIndent();
}
public override void WriteProcessingInstruction(string target, string text)
{
- if (!mixedContent && base.textPos != base.bufPos)
+ if (!_mixedContent && base._textPos != base._bufPos)
{
WriteIndent();
}
public override void WriteEntityRef(string name)
{
- mixedContent = true;
+ _mixedContent = true;
base.WriteEntityRef(name);
}
public override void WriteCharEntity(char ch)
{
- mixedContent = true;
+ _mixedContent = true;
base.WriteCharEntity(ch);
}
public override void WriteSurrogateCharEntity(char lowChar, char highChar)
{
- mixedContent = true;
+ _mixedContent = true;
base.WriteSurrogateCharEntity(lowChar, highChar);
}
public override void WriteWhitespace(string ws)
{
- mixedContent = true;
+ _mixedContent = true;
base.WriteWhitespace(ws);
}
public override void WriteString(string text)
{
- mixedContent = true;
+ _mixedContent = true;
base.WriteString(text);
}
public override void WriteChars(char[] buffer, int index, int count)
{
- mixedContent = true;
+ _mixedContent = true;
base.WriteChars(buffer, index, count);
}
public override void WriteRaw(char[] buffer, int index, int count)
{
- mixedContent = true;
+ _mixedContent = true;
base.WriteRaw(buffer, index, count);
}
public override void WriteRaw(string data)
{
- mixedContent = true;
+ _mixedContent = true;
base.WriteRaw(data);
}
public override void WriteBase64(byte[] buffer, int index, int count)
{
- mixedContent = true;
+ _mixedContent = true;
base.WriteBase64(buffer, index, count);
}
//
private void Init(XmlWriterSettings settings)
{
- indentLevel = 0;
- indentChars = settings.IndentChars;
- newLineOnAttributes = settings.NewLineOnAttributes;
+ _indentLevel = 0;
+ _indentChars = settings.IndentChars;
+ _newLineOnAttributes = settings.NewLineOnAttributes;
_mixedContentStack = new BitStack();
// check indent characters that they are valid XML characters
- if (base.checkCharacters)
+ if (base._checkCharacters)
{
- if (newLineOnAttributes)
+ if (_newLineOnAttributes)
{
- base.ValidateContentChars(indentChars, "IndentChars", true);
- base.ValidateContentChars(newLineChars, "NewLineChars", true);
+ base.ValidateContentChars(_indentChars, "IndentChars", true);
+ base.ValidateContentChars(_newLineChars, "NewLineChars", true);
}
else
{
- base.ValidateContentChars(indentChars, "IndentChars", false);
- if (base.newLineHandling != NewLineHandling.Replace)
+ base.ValidateContentChars(_indentChars, "IndentChars", false);
+ if (base._newLineHandling != NewLineHandling.Replace)
{
- base.ValidateContentChars(newLineChars, "NewLineChars", false);
+ base.ValidateContentChars(_newLineChars, "NewLineChars", false);
}
}
}
// Add indentation to output. Write newline and then repeat IndentChars for each indent level.
private void WriteIndent()
{
- RawText(base.newLineChars);
- for (int i = indentLevel; i > 0; i--)
+ RawText(base._newLineChars);
+ for (int i = _indentLevel; i > 0; i--)
{
- RawText(indentChars);
+ RawText(_indentChars);
}
}
}
{
CheckAsyncCall();
// Output xml declaration only if user allows it and it was not already output
- if (!omitXmlDeclaration && !autoXmlDeclaration)
+ if (!_omitXmlDeclaration && !_autoXmlDeclaration)
{
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
await RawTextAsync("<?xml version=\"").ConfigureAwait(false);
// Version
await RawTextAsync("1.0").ConfigureAwait(false);
// Encoding
- if (encoding != null)
+ if (_encoding != null)
{
await RawTextAsync("\" encoding=\"").ConfigureAwait(false);
- await RawTextAsync(encoding.WebName).ConfigureAwait(false);
+ await RawTextAsync(_encoding.WebName).ConfigureAwait(false);
}
// Standalone
{
CheckAsyncCall();
// Output xml declaration only if user allows it and it was not already output
- if (!omitXmlDeclaration && !autoXmlDeclaration)
+ if (!_omitXmlDeclaration && !_autoXmlDeclaration)
{
return WriteProcessingInstructionAsync("xml", xmldecl);
}
finally
{
// Future calls to Close or Flush shouldn't write to Stream or Writer
- writeToNull = true;
+ _writeToNull = true;
- if (stream != null)
+ if (_stream != null)
{
try
{
- await stream.FlushAsync().ConfigureAwait(false);
+ await _stream.FlushAsync().ConfigureAwait(false);
}
finally
{
try
{
- if (closeOutput)
+ if (_closeOutput)
{
- await stream.DisposeAsync().ConfigureAwait(false);
+ await _stream.DisposeAsync().ConfigureAwait(false);
}
}
finally
{
- stream = null;
+ _stream = null;
}
}
}
- else if (writer != null)
+ else if (_writer != null)
{
try
{
- await writer.FlushAsync().ConfigureAwait(false);
+ await _writer.FlushAsync().ConfigureAwait(false);
}
finally
{
try
{
- if (closeOutput)
+ if (_closeOutput)
{
- await writer.DisposeAsync().ConfigureAwait(false);
+ await _writer.DisposeAsync().ConfigureAwait(false);
}
}
finally
{
- writer = null;
+ _writer = null;
}
}
}
CheckAsyncCall();
Debug.Assert(name != null && name.Length > 0);
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
await RawTextAsync("<!DOCTYPE ").ConfigureAwait(false);
await RawTextAsync(name).ConfigureAwait(false);
{
await RawTextAsync(sysid).ConfigureAwait(false);
}
- bufChars[bufPos++] = (char)'"';
+ _bufChars[_bufPos++] = (char)'"';
}
else if (sysid != null)
{
await RawTextAsync(" SYSTEM \"").ConfigureAwait(false);
await RawTextAsync(sysid).ConfigureAwait(false);
- bufChars[bufPos++] = (char)'"';
+ _bufChars[_bufPos++] = (char)'"';
}
else
{
- bufChars[bufPos++] = (char)' ';
+ _bufChars[_bufPos++] = (char)' ';
}
if (subset != null)
{
- bufChars[bufPos++] = (char)'[';
+ _bufChars[_bufPos++] = (char)'[';
await RawTextAsync(subset).ConfigureAwait(false);
- bufChars[bufPos++] = (char)']';
+ _bufChars[_bufPos++] = (char)']';
}
- bufChars[bufPos++] = (char)'>';
+ _bufChars[_bufPos++] = (char)'>';
}
// Serialize the beginning of an element start tag: "<prefix:localName"
Debug.Assert(localName != null && localName.Length > 0);
Debug.Assert(prefix != null);
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
Task task;
- bufChars[bufPos++] = (char)'<';
+ _bufChars[_bufPos++] = (char)'<';
if (prefix != null && prefix.Length != 0)
{
task = RawTextAsync(prefix, ":", localName);
private void WriteStartElementAsync_SetAttEndPos()
{
- attrEndPos = bufPos;
+ _attrEndPos = _bufPos;
}
// Serialize an element end tag: "</prefix:localName>", if content was output. Otherwise, serialize
Debug.Assert(localName != null && localName.Length > 0);
Debug.Assert(prefix != null);
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
- if (contentPos != bufPos)
+ if (_contentPos != _bufPos)
{
// Content has been output, so can't use shortcut syntax
- bufChars[bufPos++] = (char)'<';
- bufChars[bufPos++] = (char)'/';
+ _bufChars[_bufPos++] = (char)'<';
+ _bufChars[_bufPos++] = (char)'/';
if (prefix != null && prefix.Length != 0)
{
else
{
// Use shortcut syntax; overwrite the already output '>' character
- bufPos--;
- bufChars[bufPos++] = (char)' ';
- bufChars[bufPos++] = (char)'/';
- bufChars[bufPos++] = (char)'>';
+ _bufPos--;
+ _bufChars[_bufPos++] = (char)' ';
+ _bufChars[_bufPos++] = (char)'/';
+ _bufChars[_bufPos++] = (char)'>';
}
return Task.CompletedTask;
}
Debug.Assert(localName != null && localName.Length > 0);
Debug.Assert(prefix != null);
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
- bufChars[bufPos++] = (char)'<';
- bufChars[bufPos++] = (char)'/';
+ _bufChars[_bufPos++] = (char)'<';
+ _bufChars[_bufPos++] = (char)'/';
if (prefix != null && prefix.Length != 0)
{
Debug.Assert(localName != null && localName.Length > 0);
Debug.Assert(prefix != null);
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
- if (attrEndPos == bufPos)
+ if (_attrEndPos == _bufPos)
{
- bufChars[bufPos++] = (char)' ';
+ _bufChars[_bufPos++] = (char)' ';
}
Task task;
if (prefix != null && prefix.Length > 0)
private void WriteStartAttribute_SetInAttribute()
{
- bufChars[bufPos++] = (char)'=';
- bufChars[bufPos++] = (char)'"';
- inAttributeValue = true;
+ _bufChars[_bufPos++] = (char)'=';
+ _bufChars[_bufPos++] = (char)'"';
+ _inAttributeValue = true;
}
// Serialize the end of an attribute value using double quotes: '"'
{
CheckAsyncCall();
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
- bufChars[bufPos++] = (char)'"';
- inAttributeValue = false;
- attrEndPos = bufPos;
+ _bufChars[_bufPos++] = (char)'"';
+ _inAttributeValue = false;
+ _attrEndPos = _bufPos;
return Task.CompletedTask;
}
CheckAsyncCall();
Debug.Assert(prefix != null);
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
if (prefix.Length == 0)
{
{
await RawTextAsync(" xmlns:").ConfigureAwait(false);
await RawTextAsync(prefix).ConfigureAwait(false);
- bufChars[bufPos++] = (char)'=';
- bufChars[bufPos++] = (char)'"';
+ _bufChars[_bufPos++] = (char)'=';
+ _bufChars[_bufPos++] = (char)'"';
}
- inAttributeValue = true;
+ _inAttributeValue = true;
- if (trackTextContent && inTextContent != true) { ChangeTextContentMark(true); }
+ if (_trackTextContent && _inTextContent != true) { ChangeTextContentMark(true); }
}
internal override Task WriteEndNamespaceDeclarationAsync()
{
CheckAsyncCall();
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
- inAttributeValue = false;
+ _inAttributeValue = false;
- bufChars[bufPos++] = (char)'"';
- attrEndPos = bufPos;
+ _bufChars[_bufPos++] = (char)'"';
+ _attrEndPos = _bufPos;
return Task.CompletedTask;
}
CheckAsyncCall();
Debug.Assert(text != null);
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
- if (mergeCDataSections && bufPos == cdataPos)
+ if (_mergeCDataSections && _bufPos == _cdataPos)
{
// Merge adjacent cdata sections - overwrite the "]]>" characters
- Debug.Assert(bufPos >= 4);
- bufPos -= 3;
+ Debug.Assert(_bufPos >= 4);
+ _bufPos -= 3;
}
else
{
// Start a new cdata section
- bufChars[bufPos++] = (char)'<';
- bufChars[bufPos++] = (char)'!';
- bufChars[bufPos++] = (char)'[';
- bufChars[bufPos++] = (char)'C';
- bufChars[bufPos++] = (char)'D';
- bufChars[bufPos++] = (char)'A';
- bufChars[bufPos++] = (char)'T';
- bufChars[bufPos++] = (char)'A';
- bufChars[bufPos++] = (char)'[';
+ _bufChars[_bufPos++] = (char)'<';
+ _bufChars[_bufPos++] = (char)'!';
+ _bufChars[_bufPos++] = (char)'[';
+ _bufChars[_bufPos++] = (char)'C';
+ _bufChars[_bufPos++] = (char)'D';
+ _bufChars[_bufPos++] = (char)'A';
+ _bufChars[_bufPos++] = (char)'T';
+ _bufChars[_bufPos++] = (char)'A';
+ _bufChars[_bufPos++] = (char)'[';
}
await WriteCDataSectionAsync(text).ConfigureAwait(false);
- bufChars[bufPos++] = (char)']';
- bufChars[bufPos++] = (char)']';
- bufChars[bufPos++] = (char)'>';
+ _bufChars[_bufPos++] = (char)']';
+ _bufChars[_bufPos++] = (char)']';
+ _bufChars[_bufPos++] = (char)'>';
- textPos = bufPos;
- cdataPos = bufPos;
+ _textPos = _bufPos;
+ _cdataPos = _bufPos;
}
// Serialize a comment.
CheckAsyncCall();
Debug.Assert(text != null);
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
- bufChars[bufPos++] = (char)'<';
- bufChars[bufPos++] = (char)'!';
- bufChars[bufPos++] = (char)'-';
- bufChars[bufPos++] = (char)'-';
+ _bufChars[_bufPos++] = (char)'<';
+ _bufChars[_bufPos++] = (char)'!';
+ _bufChars[_bufPos++] = (char)'-';
+ _bufChars[_bufPos++] = (char)'-';
await WriteCommentOrPiAsync(text, '-').ConfigureAwait(false);
- bufChars[bufPos++] = (char)'-';
- bufChars[bufPos++] = (char)'-';
- bufChars[bufPos++] = (char)'>';
+ _bufChars[_bufPos++] = (char)'-';
+ _bufChars[_bufPos++] = (char)'-';
+ _bufChars[_bufPos++] = (char)'>';
}
// Serialize a processing instruction.
Debug.Assert(name != null && name.Length > 0);
Debug.Assert(text != null);
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
- bufChars[bufPos++] = (char)'<';
- bufChars[bufPos++] = (char)'?';
+ _bufChars[_bufPos++] = (char)'<';
+ _bufChars[_bufPos++] = (char)'?';
await RawTextAsync(name).ConfigureAwait(false);
if (text.Length > 0)
{
- bufChars[bufPos++] = (char)' ';
+ _bufChars[_bufPos++] = (char)' ';
await WriteCommentOrPiAsync(text, '?').ConfigureAwait(false);
}
- bufChars[bufPos++] = (char)'?';
- bufChars[bufPos++] = (char)'>';
+ _bufChars[_bufPos++] = (char)'?';
+ _bufChars[_bufPos++] = (char)'>';
}
// Serialize an entity reference.
CheckAsyncCall();
Debug.Assert(name != null && name.Length > 0);
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
- bufChars[bufPos++] = (char)'&';
+ _bufChars[_bufPos++] = (char)'&';
await RawTextAsync(name).ConfigureAwait(false);
- bufChars[bufPos++] = (char)';';
+ _bufChars[_bufPos++] = (char)';';
- if (bufPos > bufLen)
+ if (_bufPos > _bufLen)
{
await FlushBufferAsync().ConfigureAwait(false);
}
- textPos = bufPos;
+ _textPos = _bufPos;
}
// Serialize a character entity reference.
CheckAsyncCall();
string strVal = ((int)ch).ToString("X", NumberFormatInfo.InvariantInfo);
- if (checkCharacters && !xmlCharType.IsCharData(ch))
+ if (_checkCharacters && !_xmlCharType.IsCharData(ch))
{
// we just have a single char, not a surrogate, therefore we have to pass in '\0' for the second char
throw XmlConvert.CreateInvalidCharException(ch, '\0');
}
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
- bufChars[bufPos++] = (char)'&';
- bufChars[bufPos++] = (char)'#';
- bufChars[bufPos++] = (char)'x';
+ _bufChars[_bufPos++] = (char)'&';
+ _bufChars[_bufPos++] = (char)'#';
+ _bufChars[_bufPos++] = (char)'x';
await RawTextAsync(strVal).ConfigureAwait(false);
- bufChars[bufPos++] = (char)';';
+ _bufChars[_bufPos++] = (char)';';
- if (bufPos > bufLen)
+ if (_bufPos > _bufLen)
{
await FlushBufferAsync().ConfigureAwait(false);
}
- textPos = bufPos;
+ _textPos = _bufPos;
}
// Serialize a whitespace node.
CheckAsyncCall();
Debug.Assert(ws != null);
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
- if (inAttributeValue)
+ if (_inAttributeValue)
{
return WriteAttributeTextBlockAsync(ws);
}
CheckAsyncCall();
Debug.Assert(text != null);
- if (trackTextContent && inTextContent != true) { ChangeTextContentMark(true); }
+ if (_trackTextContent && _inTextContent != true) { ChangeTextContentMark(true); }
- if (inAttributeValue)
+ if (_inAttributeValue)
{
return WriteAttributeTextBlockAsync(text);
}
{
CheckAsyncCall();
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
int surrogateChar = XmlCharType.CombineSurrogateChar(lowChar, highChar);
- bufChars[bufPos++] = (char)'&';
- bufChars[bufPos++] = (char)'#';
- bufChars[bufPos++] = (char)'x';
+ _bufChars[_bufPos++] = (char)'&';
+ _bufChars[_bufPos++] = (char)'#';
+ _bufChars[_bufPos++] = (char)'x';
await RawTextAsync(surrogateChar.ToString("X", NumberFormatInfo.InvariantInfo)).ConfigureAwait(false);
- bufChars[bufPos++] = (char)';';
- textPos = bufPos;
+ _bufChars[_bufPos++] = (char)';';
+ _textPos = _bufPos;
}
// Serialize either attribute or element text using XML rules.
Debug.Assert(index >= 0);
Debug.Assert(count >= 0 && index + count <= buffer.Length);
- if (trackTextContent && inTextContent != true) { ChangeTextContentMark(true); }
+ if (_trackTextContent && _inTextContent != true) { ChangeTextContentMark(true); }
- if (inAttributeValue)
+ if (_inAttributeValue)
{
return WriteAttributeTextBlockAsync(buffer, index, count);
}
Debug.Assert(index >= 0);
Debug.Assert(count >= 0 && index + count <= buffer.Length);
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
await WriteRawWithCharCheckingAsync(buffer, index, count).ConfigureAwait(false);
- textPos = bufPos;
+ _textPos = _bufPos;
}
// Serialize raw data.
CheckAsyncCall();
Debug.Assert(data != null);
- if (trackTextContent && inTextContent != false) { ChangeTextContentMark(false); }
+ if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }
await WriteRawWithCharCheckingAsync(data).ConfigureAwait(false);
- textPos = bufPos;
+ _textPos = _bufPos;
}
// Flush all characters in the buffer to output and call Flush() on the output object.
await FlushBufferAsync().ConfigureAwait(false);
await FlushEncoderAsync().ConfigureAwait(false);
- if (stream != null)
+ if (_stream != null)
{
- await stream.FlushAsync().ConfigureAwait(false);
+ await _stream.FlushAsync().ConfigureAwait(false);
}
- else if (writer != null)
+ else if (_writer != null)
{
- await writer.FlushAsync().ConfigureAwait(false);
+ await _writer.FlushAsync().ConfigureAwait(false);
}
}
try
{
// Output all characters (except for previous characters stored at beginning of buffer)
- if (!writeToNull)
+ if (!_writeToNull)
{
- Debug.Assert(stream != null || writer != null);
+ Debug.Assert(_stream != null || _writer != null);
- if (stream != null)
+ if (_stream != null)
{
- if (trackTextContent)
+ if (_trackTextContent)
{
_charEntityFallback.Reset(_textContentMarks, _lastMarkPos);
// reset text content tracking
}
Debug.Assert(_textContentMarks[0] == 1);
}
- await EncodeCharsAsync(1, bufPos, true).ConfigureAwait(false);
+ await EncodeCharsAsync(1, _bufPos, true).ConfigureAwait(false);
}
else
{
- if (bufPos - 1 > 0)
+ if (_bufPos - 1 > 0)
{
// Write text to TextWriter
- await writer.WriteAsync(bufChars.AsMemory(1, bufPos - 1)).ConfigureAwait(false);
+ await _writer.WriteAsync(_bufChars.AsMemory(1, _bufPos - 1)).ConfigureAwait(false);
}
}
}
catch
{
// Future calls to flush (i.e. when Close() is called) don't attempt to write to stream
- writeToNull = true;
+ _writeToNull = true;
throw;
}
finally
{
// Move last buffer character to the beginning of the buffer (so that previous character can always be determined)
- bufChars[0] = bufChars[bufPos - 1];
+ _bufChars[0] = _bufChars[_bufPos - 1];
// Reset buffer position
- textPos = (textPos == bufPos) ? 1 : 0;
- attrEndPos = (attrEndPos == bufPos) ? 1 : 0;
- contentPos = 0; // Needs to be zero, since overwriting '>' character is no longer possible
- cdataPos = 0; // Needs to be zero, since overwriting ']]>' characters is no longer possible
- bufPos = 1; // Buffer position starts at 1, because we need to be able to safely step back -1 in case we need to
+ _textPos = (_textPos == _bufPos) ? 1 : 0;
+ _attrEndPos = (_attrEndPos == _bufPos) ? 1 : 0;
+ _contentPos = 0; // Needs to be zero, since overwriting '>' character is no longer possible
+ _cdataPos = 0; // Needs to be zero, since overwriting ']]>' characters is no longer possible
+ _bufPos = 1; // Buffer position starts at 1, because we need to be able to safely step back -1 in case we need to
// close an empty element or in CDATA section detection of double ]; _BUFFER[0] will always be 0
}
}
{
_charEntityFallback.StartOffset = startOffset;
}
- encoder.Convert(bufChars, startOffset, endOffset - startOffset, bufBytes, bufBytesUsed, bufBytes.Length - bufBytesUsed, false, out chEnc, out bEnc, out completed);
+ _encoder.Convert(_bufChars, startOffset, endOffset - startOffset, _bufBytes, _bufBytesUsed, _bufBytes.Length - _bufBytesUsed, false, out chEnc, out bEnc, out completed);
startOffset += chEnc;
- bufBytesUsed += bEnc;
- if (bufBytesUsed >= (bufBytes.Length - 16))
+ _bufBytesUsed += bEnc;
+ if (_bufBytesUsed >= (_bufBytes.Length - 16))
{
- await stream.WriteAsync(bufBytes.AsMemory(0, bufBytesUsed)).ConfigureAwait(false);
- bufBytesUsed = 0;
+ await _stream.WriteAsync(_bufBytes.AsMemory(0, _bufBytesUsed)).ConfigureAwait(false);
+ _bufBytesUsed = 0;
}
}
- if (writeAllToStream && bufBytesUsed > 0)
+ if (writeAllToStream && _bufBytesUsed > 0)
{
- await stream.WriteAsync(bufBytes.AsMemory(0, bufBytesUsed)).ConfigureAwait(false);
- bufBytesUsed = 0;
+ await _stream.WriteAsync(_bufBytes.AsMemory(0, _bufBytesUsed)).ConfigureAwait(false);
+ _bufBytesUsed = 0;
}
}
private Task FlushEncoderAsync()
{
- Debug.Assert(bufPos == 1);
- if (stream != null)
+ Debug.Assert(_bufPos == 1);
+ if (_stream != null)
{
int chEnc;
int bEnc;
bool completed;
// decode no chars, just flush
- encoder.Convert(bufChars, 1, 0, bufBytes, 0, bufBytes.Length, true, out chEnc, out bEnc, out completed);
+ _encoder.Convert(_bufChars, 1, 0, _bufBytes, 0, _bufBytes.Length, true, out chEnc, out bEnc, out completed);
if (bEnc != 0)
{
- return stream.WriteAsync(bufBytes, 0, bEnc);
+ return _stream.WriteAsync(_bufBytes, 0, bEnc);
}
}
{
char* pRaw = pSrc;
- fixed (char* pDstBegin = bufChars)
+ fixed (char* pDstBegin = _bufChars)
{
- char* pDst = pDstBegin + bufPos;
+ char* pDst = pDstBegin + _bufPos;
int ch = 0;
while (true)
{
char* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
- while (pDst < pDstEnd && xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)))
+ while (pDst < pDstEnd && _xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)))
{
*pDst = (char)ch;
pDst++;
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
return (int)(pSrc - pRaw);
}
pDst++;
break;
case (char)0x9:
- if (newLineHandling == NewLineHandling.None)
+ if (_newLineHandling == NewLineHandling.None)
{
*pDst = (char)ch;
pDst++;
}
break;
case (char)0xD:
- if (newLineHandling == NewLineHandling.None)
+ if (_newLineHandling == NewLineHandling.None)
{
*pDst = (char)ch;
pDst++;
}
break;
case (char)0xA:
- if (newLineHandling == NewLineHandling.None)
+ if (_newLineHandling == NewLineHandling.None)
{
*pDst = (char)ch;
pDst++;
}
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
}
return -1;
needWriteNewLine = false;
char* pRaw = pSrc;
- fixed (char* pDstBegin = bufChars)
+ fixed (char* pDstBegin = _bufChars)
{
- char* pDst = pDstBegin + bufPos;
+ char* pDst = pDstBegin + _bufPos;
int ch = 0;
while (true)
{
char* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
- while (pDst < pDstEnd && xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)))
+ while (pDst < pDstEnd && _xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)))
{
*pDst = (char)ch;
pDst++;
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
return (int)(pSrc - pRaw);
}
pDst++;
break;
case (char)0xA:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
needWriteNewLine = true;
return (int)(pSrc - pRaw);
}
}
break;
case (char)0xD:
- switch (newLineHandling)
+ switch (_newLineHandling)
{
case NewLineHandling.Replace:
// Replace "\r\n", or "\r" with NewLineChars
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
needWriteNewLine = true;
return (int)(pSrc - pRaw);
}
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
- textPos = bufPos;
- contentPos = 0;
+ _bufPos = (int)(pDst - pDstBegin);
+ _textPos = _bufPos;
+ _contentPos = 0;
}
return -1;
needWriteNewLine = false;
if (count == 0)
{
- contentPos = 0;
+ _contentPos = 0;
return -1;
}
fixed (char* pSrc = &chars[index])
needWriteNewLine = false;
if (count == 0)
{
- contentPos = 0;
+ _contentPos = 0;
return -1;
}
fixed (char* pSrc = text)
if (needWriteNewLine)
{
//hit WriteNewLine
- await RawTextAsync(newLineChars).ConfigureAwait(false);
+ await RawTextAsync(_newLineChars).ConfigureAwait(false);
curIndex++;
leftCount--;
}
if (newLine)
{
- await RawTextAsync(newLineChars).ConfigureAwait(false);
+ await RawTextAsync(_newLineChars).ConfigureAwait(false);
curIndex++;
leftCount--;
}
if (needWriteNewLine)
{
//hit WriteNewLine
- await RawTextAsync(newLineChars).ConfigureAwait(false);
+ await RawTextAsync(_newLineChars).ConfigureAwait(false);
curIndex++;
leftCount--;
}
{
char* pRaw = pSrcBegin;
- fixed (char* pDstBegin = bufChars)
+ fixed (char* pDstBegin = _bufChars)
{
- char* pDst = pDstBegin + bufPos;
+ char* pDst = pDstBegin + _bufPos;
char* pSrc = pSrcBegin;
int ch = 0;
while (true)
{
char* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
while (pDst < pDstEnd && ((ch = *pSrc) < XmlCharType.SurHighStart))
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
return (int)(pSrc - pRaw);
}
}
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
}
return -1;
needWriteNewLine = false;
char* pRaw = pSrcBegin;
- fixed (char* pDstBegin = bufChars)
+ fixed (char* pDstBegin = _bufChars)
{
char* pSrc = pSrcBegin;
- char* pDst = pDstBegin + bufPos;
+ char* pDst = pDstBegin + _bufPos;
int ch = 0;
while (true)
{
char* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
- while (pDst < pDstEnd && xmlCharType.IsTextChar((char)(ch = *pSrc)))
+ while (pDst < pDstEnd && _xmlCharType.IsTextChar((char)(ch = *pSrc)))
{
*pDst = (char)ch;
pDst++;
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
return (int)(pSrc - pRaw);
}
pDst++;
break;
case (char)0xD:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
// Normalize "\r\n", or "\r" to NewLineChars
if (pSrc + 1 < pSrcEnd && pSrc[1] == '\n')
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
needWriteNewLine = true;
return (int)(pSrc - pRaw);
}
}
break;
case (char)0xA:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
needWriteNewLine = true;
return (int)(pSrc - pRaw);
}
}
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
}
return -1;
leftCount -= writeLen;
if (needWriteNewLine)
{
- await RawTextAsync(newLineChars).ConfigureAwait(false);
+ await RawTextAsync(_newLineChars).ConfigureAwait(false);
curIndex++;
leftCount--;
}
leftCount -= writeLen;
if (needWriteNewLine)
{
- await RawTextAsync(newLineChars).ConfigureAwait(false);
+ await RawTextAsync(_newLineChars).ConfigureAwait(false);
curIndex++;
leftCount--;
}
{
char* pSrcBegin = pSrcText + index;
- fixed (char* pDstBegin = bufChars)
+ fixed (char* pDstBegin = _bufChars)
{
char* pSrc = pSrcBegin;
char* pSrcEnd = pSrcBegin + count;
- char* pDst = pDstBegin + bufPos;
+ char* pDst = pDstBegin + _bufPos;
int ch = 0;
while (true)
{
char* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
- while (pDst < pDstEnd && (xmlCharType.IsTextChar((char)(ch = *pSrc)) && ch != stopChar))
+ while (pDst < pDstEnd && (_xmlCharType.IsTextChar((char)(ch = *pSrc)) && ch != stopChar))
{
*pDst = (char)ch;
pDst++;
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
return (int)(pSrc - pRaw);
}
pDst++;
break;
case (char)0xD:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
// Normalize "\r\n", or "\r" to NewLineChars
if (pSrc + 1 < pSrcEnd && pSrc[1] == '\n')
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
needWriteNewLine = true;
return (int)(pSrc - pRaw);
}
}
break;
case (char)0xA:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
needWriteNewLine = true;
return (int)(pSrc - pRaw);
}
}
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
}
return -1;
{
if (text.Length == 0)
{
- if (bufPos >= bufLen)
+ if (_bufPos >= _bufLen)
{
await FlushBufferAsync().ConfigureAwait(false);
}
leftCount -= writeLen;
if (needWriteNewLine)
{
- await RawTextAsync(newLineChars).ConfigureAwait(false);
+ await RawTextAsync(_newLineChars).ConfigureAwait(false);
curIndex++;
leftCount--;
}
{
char* pSrcBegin = pSrcText + index;
- fixed (char* pDstBegin = bufChars)
+ fixed (char* pDstBegin = _bufChars)
{
char* pSrc = pSrcBegin;
char* pRaw = pSrc;
- char* pDst = pDstBegin + bufPos;
+ char* pDst = pDstBegin + _bufPos;
int ch = 0;
while (true)
{
char* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
- while (pDst < pDstEnd && (xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch != ']'))
+ while (pDst < pDstEnd && (_xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch != ']'))
{
*pDst = (char)ch;
pDst++;
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
return (int)(pSrc - pRaw);
}
switch (ch)
{
case '>':
- if (hadDoubleBracket && pDst[-1] == (char)']')
+ if (_hadDoubleBracket && pDst[-1] == (char)']')
{ // pDst[-1] will always correct - there is a padding character at _BUFFER[0]
// The characters "]]>" were found within the CData text
pDst = RawEndCData(pDst);
case ']':
if (pDst[-1] == (char)']')
{ // pDst[-1] will always correct - there is a padding character at _BUFFER[0]
- hadDoubleBracket = true;
+ _hadDoubleBracket = true;
}
else
{
- hadDoubleBracket = false;
+ _hadDoubleBracket = false;
}
*pDst = (char)']';
pDst++;
break;
case (char)0xD:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
// Normalize "\r\n", or "\r" to NewLineChars
if (pSrc + 1 < pSrcEnd && pSrc[1] == '\n')
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
needWriteNewLine = true;
return (int)(pSrc - pRaw);
}
}
break;
case (char)0xA:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
needWriteNewLine = true;
return (int)(pSrc - pRaw);
}
}
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
}
return -1;
{
if (text.Length == 0)
{
- if (bufPos >= bufLen)
+ if (_bufPos >= _bufLen)
{
await FlushBufferAsync().ConfigureAwait(false);
}
leftCount -= writeLen;
if (needWriteNewLine)
{
- await RawTextAsync(newLineChars).ConfigureAwait(false);
+ await RawTextAsync(_newLineChars).ConfigureAwait(false);
curIndex++;
leftCount--;
}
{
CheckAsyncCall();
// Add indentation
- if (!mixedContent && base.textPos != base.bufPos)
+ if (!_mixedContent && base._textPos != base._bufPos)
{
await WriteIndentAsync().ConfigureAwait(false);
}
Debug.Assert(localName != null && localName.Length != 0 && prefix != null && ns != null);
// Add indentation
- if (!mixedContent && base.textPos != base.bufPos)
+ if (!_mixedContent && base._textPos != base._bufPos)
{
await WriteIndentAsync().ConfigureAwait(false);
}
- indentLevel++;
- _mixedContentStack.PushBit(mixedContent);
+ _indentLevel++;
+ _mixedContentStack.PushBit(_mixedContent);
await base.WriteStartElementAsync(prefix, localName, ns).ConfigureAwait(false);
}
{
CheckAsyncCall();
// Add indentation
- indentLevel--;
- if (!mixedContent && base.contentPos != base.bufPos)
+ _indentLevel--;
+ if (!_mixedContent && base._contentPos != base._bufPos)
{
// There was content, so try to indent
- if (base.textPos != base.bufPos)
+ if (base._textPos != base._bufPos)
{
await WriteIndentAsync().ConfigureAwait(false);
}
}
- mixedContent = _mixedContentStack.PopBit();
+ _mixedContent = _mixedContentStack.PopBit();
await base.WriteEndElementAsync(prefix, localName, ns).ConfigureAwait(false);
}
{
CheckAsyncCall();
// Add indentation
- indentLevel--;
- if (!mixedContent && base.contentPos != base.bufPos)
+ _indentLevel--;
+ if (!_mixedContent && base._contentPos != base._bufPos)
{
// There was content, so try to indent
- if (base.textPos != base.bufPos)
+ if (base._textPos != base._bufPos)
{
await WriteIndentAsync().ConfigureAwait(false);
}
}
- mixedContent = _mixedContentStack.PopBit();
+ _mixedContent = _mixedContentStack.PopBit();
await base.WriteFullEndElementAsync(prefix, localName, ns).ConfigureAwait(false);
}
{
CheckAsyncCall();
// Add indentation
- if (newLineOnAttributes)
+ if (_newLineOnAttributes)
{
await WriteIndentAsync().ConfigureAwait(false);
}
public override Task WriteCDataAsync(string text)
{
CheckAsyncCall();
- mixedContent = true;
+ _mixedContent = true;
return base.WriteCDataAsync(text);
}
public override async Task WriteCommentAsync(string text)
{
CheckAsyncCall();
- if (!mixedContent && base.textPos != base.bufPos)
+ if (!_mixedContent && base._textPos != base._bufPos)
{
await WriteIndentAsync().ConfigureAwait(false);
}
public override async Task WriteProcessingInstructionAsync(string target, string text)
{
CheckAsyncCall();
- if (!mixedContent && base.textPos != base.bufPos)
+ if (!_mixedContent && base._textPos != base._bufPos)
{
await WriteIndentAsync().ConfigureAwait(false);
}
public override Task WriteEntityRefAsync(string name)
{
CheckAsyncCall();
- mixedContent = true;
+ _mixedContent = true;
return base.WriteEntityRefAsync(name);
}
public override Task WriteCharEntityAsync(char ch)
{
CheckAsyncCall();
- mixedContent = true;
+ _mixedContent = true;
return base.WriteCharEntityAsync(ch);
}
public override Task WriteSurrogateCharEntityAsync(char lowChar, char highChar)
{
CheckAsyncCall();
- mixedContent = true;
+ _mixedContent = true;
return base.WriteSurrogateCharEntityAsync(lowChar, highChar);
}
public override Task WriteWhitespaceAsync(string ws)
{
CheckAsyncCall();
- mixedContent = true;
+ _mixedContent = true;
return base.WriteWhitespaceAsync(ws);
}
public override Task WriteStringAsync(string text)
{
CheckAsyncCall();
- mixedContent = true;
+ _mixedContent = true;
return base.WriteStringAsync(text);
}
public override Task WriteCharsAsync(char[] buffer, int index, int count)
{
CheckAsyncCall();
- mixedContent = true;
+ _mixedContent = true;
return base.WriteCharsAsync(buffer, index, count);
}
public override Task WriteRawAsync(char[] buffer, int index, int count)
{
CheckAsyncCall();
- mixedContent = true;
+ _mixedContent = true;
return base.WriteRawAsync(buffer, index, count);
}
public override Task WriteRawAsync(string data)
{
CheckAsyncCall();
- mixedContent = true;
+ _mixedContent = true;
return base.WriteRawAsync(data);
}
public override Task WriteBase64Async(byte[] buffer, int index, int count)
{
CheckAsyncCall();
- mixedContent = true;
+ _mixedContent = true;
return base.WriteBase64Async(buffer, index, count);
}
private async Task WriteIndentAsync()
{
CheckAsyncCall();
- await RawTextAsync(base.newLineChars).ConfigureAwait(false);
- for (int i = indentLevel; i > 0; i--)
+ await RawTextAsync(base._newLineChars).ConfigureAwait(false);
+ for (int i = _indentLevel; i > 0; i--)
{
- await RawTextAsync(indentChars).ConfigureAwait(false);
+ await RawTextAsync(_indentChars).ConfigureAwait(false);
}
}
}
/// </summary>
public override void WriteValue(object value)
{
- WriteString(XmlUntypedConverter.Untyped.ToString(value, this.resolver));
+ WriteString(XmlUntypedConverter.Untyped.ToString(value, this._resolver));
}
public override void WriteValue(string value)
private readonly bool _useAsync;
// main buffer
- protected byte[] bufBytes;
+ protected byte[] _bufBytes;
// output stream
- protected Stream stream;
+ protected Stream _stream;
// encoding of the stream or text writer
- protected Encoding encoding;
+ protected Encoding _encoding;
// char type tables
- protected XmlCharType xmlCharType = XmlCharType.Instance;
+ protected XmlCharType _xmlCharType = XmlCharType.Instance;
// buffer positions
- protected int bufPos = 1; // buffer position starts at 1, because we need to be able to safely step back -1 in case we need to
- // close an empty element or in CDATA section detection of double ]; <#= BufferName #>[0] will always be 0
- protected int textPos = 1; // text end position; don't indent first element, pi, or comment
- protected int contentPos; // element content end position
- protected int cdataPos; // cdata end position
- protected int attrEndPos; // end of the last attribute
- protected int bufLen = BUFSIZE;
+ protected int _bufPos = 1; // buffer position starts at 1, because we need to be able to safely step back -1 in case we need to
+ // close an empty element or in CDATA section detection of double ]; <#= BufferName #>[0] will always be 0
+ protected int _textPos = 1; // text end position; don't indent first element, pi, or comment
+ protected int _contentPos; // element content end position
+ protected int _cdataPos; // cdata end position
+ protected int _attrEndPos; // end of the last attribute
+ protected int _bufLen = BUFSIZE;
// flags
- protected bool writeToNull;
- protected bool hadDoubleBracket;
- protected bool inAttributeValue;
+ protected bool _writeToNull;
+ protected bool _hadDoubleBracket;
+ protected bool _inAttributeValue;
<# if (WriterType == RawTextWriterType.Encoded) { #>
- protected int bufBytesUsed;
- protected char[] bufChars;
+ protected int _bufBytesUsed;
+ protected char[] _bufChars;
// encoder for encoding chars in specified encoding when writing to stream
- protected Encoder encoder;
+ protected Encoder _encoder;
// output text writer
- protected TextWriter writer;
+ protected TextWriter _writer;
// escaping of characters invalid in the output encoding
- protected bool trackTextContent;
- protected bool inTextContent;
+ protected bool _trackTextContent;
+ protected bool _inTextContent;
private int _lastMarkPos;
private int[] _textContentMarks; // even indices contain text content start positions
// odd indices contain markup start positions
<# } #>
// writer settings
- protected NewLineHandling newLineHandling;
- protected bool closeOutput;
- protected bool omitXmlDeclaration;
- protected string newLineChars;
- protected bool checkCharacters;
+ protected NewLineHandling _newLineHandling;
+ protected bool _closeOutput;
+ protected bool _omitXmlDeclaration;
+ protected string _newLineChars;
+ protected bool _checkCharacters;
- protected XmlStandalone standalone;
- protected XmlOutputMethod outputMethod;
+ protected XmlStandalone _standalone;
+ protected XmlOutputMethod _outputMethod;
- protected bool autoXmlDeclaration;
- protected bool mergeCDataSections;
+ protected bool _autoXmlDeclaration;
+ protected bool _mergeCDataSections;
//
// Constants
_useAsync = settings.Async;
// copy settings
- newLineHandling = settings.NewLineHandling;
- omitXmlDeclaration = settings.OmitXmlDeclaration;
- newLineChars = settings.NewLineChars;
- checkCharacters = settings.CheckCharacters;
- closeOutput = settings.CloseOutput;
+ _newLineHandling = settings.NewLineHandling;
+ _omitXmlDeclaration = settings.OmitXmlDeclaration;
+ _newLineChars = settings.NewLineChars;
+ _checkCharacters = settings.CheckCharacters;
+ _closeOutput = settings.CloseOutput;
- standalone = settings.Standalone;
- outputMethod = settings.OutputMethod;
- mergeCDataSections = settings.MergeCDataSections;
+ _standalone = settings.Standalone;
+ _outputMethod = settings.OutputMethod;
+ _mergeCDataSections = settings.MergeCDataSections;
- if (checkCharacters && newLineHandling == NewLineHandling.Replace)
+ if (_checkCharacters && _newLineHandling == NewLineHandling.Replace)
{
- ValidateContentChars(newLineChars, "NewLineChars", false);
+ ValidateContentChars(_newLineChars, "NewLineChars", false);
}
}
<# if (WriterType == RawTextWriterType.Encoded) { #>
{
Debug.Assert(writer != null && settings != null);
- this.writer = writer;
- this.encoding = writer.Encoding;
+ this._writer = writer;
+ this._encoding = writer.Encoding;
// the buffer is allocated will OVERFLOW in order to reduce checks when writing out constant size markup
if (settings.Async)
{
- bufLen = ASYNCBUFSIZE;
+ _bufLen = ASYNCBUFSIZE;
}
- this.bufChars = new <#= BufferType #>[bufLen + OVERFLOW];
+ this._bufChars = new <#= BufferType #>[_bufLen + OVERFLOW];
// Write the xml declaration
if (settings.AutoXmlDeclaration)
{
- WriteXmlDeclaration(standalone);
- autoXmlDeclaration = true;
+ WriteXmlDeclaration(_standalone);
+ _autoXmlDeclaration = true;
}
}
<# } #>
{
Debug.Assert(stream != null && settings != null);
- this.stream = stream;
- this.encoding = settings.Encoding;
+ this._stream = stream;
+ this._encoding = settings.Encoding;
// the buffer is allocated will OVERFLOW in order to reduce checks when writing out constant size markup
if (settings.Async)
{
- bufLen = ASYNCBUFSIZE;
+ _bufLen = ASYNCBUFSIZE;
}
- <#= BufferName #> = new <#= BufferType #>[bufLen + OVERFLOW];
+ <#= BufferName #> = new <#= BufferType #>[_bufLen + OVERFLOW];
<# if (WriterType == RawTextWriterType.Utf8) { #>
// Output UTF-8 byte order mark if Encoding object wants it
if (!stream.CanSeek || stream.Position == 0)
{
- ReadOnlySpan<byte> bom = encoding.Preamble;
+ ReadOnlySpan<byte> bom = _encoding.Preamble;
if (bom.Length != 0)
{
- bom.CopyTo(new Span<byte>(bufBytes).Slice(1));
- bufPos += bom.Length;
- textPos += bom.Length;
+ bom.CopyTo(new Span<byte>(_bufBytes).Slice(1));
+ _bufPos += bom.Length;
+ _textPos += bom.Length;
}
}
<# } else { #>
- bufBytes = new byte[bufChars.Length];
- bufBytesUsed = 0;
+ _bufBytes = new byte[_bufChars.Length];
+ _bufBytesUsed = 0;
// Init escaping of characters not fitting into the target encoding
- trackTextContent = true;
- inTextContent = false;
+ _trackTextContent = true;
+ _inTextContent = false;
_lastMarkPos = 0;
_textContentMarks = new int[INIT_MARKS_COUNT];
_textContentMarks[0] = 1;
_charEntityFallback = new CharEntityEncoderFallback();
// grab bom before possibly changing encoding settings
- ReadOnlySpan<byte> bom = encoding.Preamble;
+ ReadOnlySpan<byte> bom = _encoding.Preamble;
// the encoding instance this creates can differ from the one passed in
- this.encoding = Encoding.GetEncoding(
+ this._encoding = Encoding.GetEncoding(
settings.Encoding.CodePage,
_charEntityFallback,
settings.Encoding.DecoderFallback);
- encoder = encoding.GetEncoder();
+ _encoder = _encoding.GetEncoder();
- if (!stream.CanSeek || stream.Position == 0)
+ if (!_stream.CanSeek || _stream.Position == 0)
{
if (bom.Length != 0)
{
- this.stream.Write(bom);
+ this._stream.Write(bom);
}
}
<# } #>
// Write the xml declaration
if (settings.AutoXmlDeclaration)
{
- WriteXmlDeclaration(standalone);
- autoXmlDeclaration = true;
+ WriteXmlDeclaration(_standalone);
+ _autoXmlDeclaration = true;
}
}
{
XmlWriterSettings settings = new XmlWriterSettings();
- settings.Encoding = encoding;
- settings.OmitXmlDeclaration = omitXmlDeclaration;
- settings.NewLineHandling = newLineHandling;
- settings.NewLineChars = newLineChars;
- settings.CloseOutput = closeOutput;
+ settings.Encoding = _encoding;
+ settings.OmitXmlDeclaration = _omitXmlDeclaration;
+ settings.NewLineHandling = _newLineHandling;
+ settings.NewLineChars = _newLineChars;
+ settings.CloseOutput = _closeOutput;
settings.ConformanceLevel = ConformanceLevel.Auto;
- settings.CheckCharacters = checkCharacters;
+ settings.CheckCharacters = _checkCharacters;
- settings.AutoXmlDeclaration = autoXmlDeclaration;
- settings.Standalone = standalone;
- settings.OutputMethod = outputMethod;
+ settings.AutoXmlDeclaration = _autoXmlDeclaration;
+ settings.Standalone = _standalone;
+ settings.OutputMethod = _outputMethod;
settings.ReadOnly = true;
return settings;
internal override void WriteXmlDeclaration(XmlStandalone standalone)
{
// Output xml declaration only if user allows it and it was not already output
- if (!omitXmlDeclaration && !autoXmlDeclaration)
+ if (!_omitXmlDeclaration && !_autoXmlDeclaration)
{<# /* Code block is to squash extra line. */
#><#= SetTextContentMark(4, 1, false) #>
RawText("<?xml version=\"");
RawText("1.0");
// Encoding
- if (encoding != null)
+ if (_encoding != null)
{
RawText("\" encoding=\"");
- RawText(encoding.WebName);
+ RawText(_encoding.WebName);
}
// Standalone
internal override void WriteXmlDeclaration(string xmldecl)
{
// Output xml declaration only if user allows it and it was not already output
- if (!omitXmlDeclaration && !autoXmlDeclaration)
+ if (!_omitXmlDeclaration && !_autoXmlDeclaration)
{
WriteProcessingInstruction("xml", xmldecl);
}
{
RawText(sysid);
}
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'"';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'"';
}
else if (sysid != null)
{
RawText(" SYSTEM \"");
RawText(sysid);
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'"';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'"';
}
else
{
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)' ';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)' ';
}
if (subset != null)
{
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'[';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'[';
RawText(subset);
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)']';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)']';
}
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'>';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'>';
}
// Serialize the beginning of an element start tag: "<prefix:localName"
#><#= SetTextContentMark(3, false) #>
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'<';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'<';
if (prefix != null && prefix.Length != 0)
{
RawText(prefix);
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)':';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)':';
}
RawText(localName);
- attrEndPos = bufPos;
+ _attrEndPos = _bufPos;
}
// Serialize the end of an element start tag in preparation for content serialization: ">"
internal override void StartElementContent()
{
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'>';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'>';
// StartElementContent is always called; therefore, in order to allow shortcut syntax, we save the
// position of the '>' character. If WriteEndElement is called and no other characters have been
// output, then the '>' character can be overwritten with the shortcut syntax " />".
- contentPos = bufPos;
+ _contentPos = _bufPos;
}
// Serialize an element end tag: "</prefix:localName>", if content was output. Otherwise, serialize
#><#= SetTextContentMark(3, false) #>
- if (contentPos != bufPos)
+ if (_contentPos != _bufPos)
{
// Content has been output, so can't use shortcut syntax
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'<';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'/';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'<';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'/';
if (prefix != null && prefix.Length != 0)
{
RawText(prefix);
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)':';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)':';
}
RawText(localName);
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'>';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'>';
}
else
{
// Use shortcut syntax; overwrite the already output '>' character
- bufPos--;
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)' ';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'/';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'>';
+ _bufPos--;
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)' ';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'/';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'>';
}
}
#><#= SetTextContentMark(3, false) #>
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'<';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'/';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'<';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'/';
if (prefix != null && prefix.Length != 0)
{
RawText(prefix);
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)':';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)':';
}
RawText(localName);
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'>';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'>';
}
// Serialize an attribute tag using double quotes around the attribute value: 'prefix:localName="'
#><#= SetTextContentMark(3, false) #>
- if (attrEndPos == bufPos)
+ if (_attrEndPos == _bufPos)
{
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)' ';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)' ';
}
if (prefix != null && prefix.Length > 0)
{
RawText(prefix);
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)':';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)':';
}
RawText(localName);
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'=';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'"';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'=';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'"';
- inAttributeValue = true;
+ _inAttributeValue = true;
}
// Serialize the end of an attribute value using double quotes: '"'
{<#
#><#= SetTextContentMark(3, 1, false) #>
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'"';
- inAttributeValue = false;
- attrEndPos = bufPos;
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'"';
+ _inAttributeValue = false;
+ _attrEndPos = _bufPos;
}
internal override void WriteNamespaceDeclaration(string prefix, string namespaceName)
{
RawText(" xmlns:");
RawText(prefix);
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'=';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'"';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'=';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'"';
}
- inAttributeValue = true;<#
+ _inAttributeValue = true;<#
#><#= SetTextContentMark(3, true) #>
}
internal override void WriteEndNamespaceDeclaration()
{<#
#><#= SetTextContentMark(3, 1, false) #>
- inAttributeValue = false;
+ _inAttributeValue = false;
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'"';
- attrEndPos = bufPos;
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'"';
+ _attrEndPos = _bufPos;
}
// Serialize a CData section. If the "]]>" pattern is found within
#><#= SetTextContentMark(3, false) #>
- if (mergeCDataSections && bufPos == cdataPos)
+ if (_mergeCDataSections && _bufPos == _cdataPos)
{
// Merge adjacent cdata sections - overwrite the "]]>" characters
- Debug.Assert(bufPos >= 4);
- bufPos -= 3;
+ Debug.Assert(_bufPos >= 4);
+ _bufPos -= 3;
}
else
{
// Start a new cdata section
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'<';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'!';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'[';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'C';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'D';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'A';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'T';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'A';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'[';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'<';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'!';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'[';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'C';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'D';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'A';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'T';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'A';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'[';
}
WriteCDataSection(text);
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)']';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)']';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'>';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)']';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)']';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'>';
- textPos = bufPos;
- cdataPos = bufPos;
+ _textPos = _bufPos;
+ _cdataPos = _bufPos;
}
// Serialize a comment.
#><#= SetTextContentMark(3, false) #>
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'<';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'!';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'-';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'-';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'<';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'!';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'-';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'-';
WriteCommentOrPi(text, '-');
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'-';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'-';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'>';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'-';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'-';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'>';
}
// Serialize a processing instruction.
#><#= SetTextContentMark(3, false) #>
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'<';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'?';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'<';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'?';
RawText(name);
if (text.Length > 0)
{
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)' ';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)' ';
WriteCommentOrPi(text, '?');
}
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'?';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'>';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'?';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'>';
}
// Serialize an entity reference.
#><#= SetTextContentMark(3, false) #>
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'&';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'&';
RawText(name);
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)';';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)';';
- if (bufPos > bufLen)
+ if (_bufPos > _bufLen)
{
FlushBuffer();
}
- textPos = bufPos;
+ _textPos = _bufPos;
}
// Serialize a character entity reference.
{
string strVal = ((int)ch).ToString("X", NumberFormatInfo.InvariantInfo);
- if (checkCharacters && !xmlCharType.IsCharData(ch))
+ if (_checkCharacters && !_xmlCharType.IsCharData(ch))
{
// we just have a single char, not a surrogate, therefore we have to pass in '\0' for the second char
throw XmlConvert.CreateInvalidCharException(ch, '\0');
#><#= SetTextContentMark(3, false) #>
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'&';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'#';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'x';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'&';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'#';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'x';
RawText(strVal);
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)';';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)';';
- if (bufPos > bufLen)
+ if (_bufPos > _bufLen)
{
FlushBuffer();
}
- textPos = bufPos;
+ _textPos = _bufPos;
}
// Serialize a whitespace node.
fixed (char* pSrc = ws)
{
char* pSrcEnd = pSrc + ws.Length;
- if (inAttributeValue)
+ if (_inAttributeValue)
{
WriteAttributeTextBlock(pSrc, pSrcEnd);
}
fixed (char* pSrc = text)
{
char* pSrcEnd = pSrc + text.Length;
- if (inAttributeValue)
+ if (_inAttributeValue)
{
WriteAttributeTextBlock(pSrc, pSrcEnd);
}
#><#= SetTextContentMark(3, 1, false) #>
int surrogateChar = XmlCharType.CombineSurrogateChar(lowChar, highChar);
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'&';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'#';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'x';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'&';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'#';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'x';
RawText(surrogateChar.ToString("X", NumberFormatInfo.InvariantInfo));
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)';';
- textPos = bufPos;
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)';';
+ _textPos = _bufPos;
}
// Serialize either attribute or element text using XML rules.
fixed (char* pSrcBegin = &buffer[index])
{
- if (inAttributeValue)
+ if (_inAttributeValue)
{
WriteAttributeTextBlock(pSrcBegin, pSrcBegin + count);
}
WriteRawWithCharChecking(pSrcBegin, pSrcBegin + count);
}
- textPos = bufPos;
+ _textPos = _bufPos;
}
// Serialize raw data.
WriteRawWithCharChecking(pSrcBegin, pSrcBegin + data.Length);
}
- textPos = bufPos;
+ _textPos = _bufPos;
}
// Flush all bytes in the buffer to output and close the output stream or writer.
finally
{
// Future calls to Close or Flush shouldn't write to Stream or Writer
- writeToNull = true;
+ _writeToNull = true;
- if (stream != null)
+ if (_stream != null)
{
try
{
- stream.Flush();
+ _stream.Flush();
}
finally
{
try
{
- if (closeOutput)
+ if (_closeOutput)
{
- stream.Dispose();
+ _stream.Dispose();
}
}
finally
{
- stream = null;
+ _stream = null;
}
}
}
<# if (WriterType == RawTextWriterType.Encoded) { #>
- else if (writer != null)
+ else if (_writer != null)
{
try
{
- writer.Flush();
+ _writer.Flush();
}
finally
{
try
{
- if (closeOutput)
+ if (_closeOutput)
{
- writer.Dispose();
+ _writer.Dispose();
}
}
finally
{
- writer = null;
+ _writer = null;
}
}
}
FlushBuffer();
FlushEncoder();
<# if (WriterType == RawTextWriterType.Utf8) { #>
- if (stream != null)
+ if (_stream != null)
{
- stream.Flush();
+ _stream.Flush();
}
<# } else { #>
- if (stream != null)
+ if (_stream != null)
{
- stream.Flush();
+ _stream.Flush();
}
- else if (writer != null)
+ else if (_writer != null)
{
- writer.Flush();
+ _writer.Flush();
}
<# } #>
}
try
{
// Output all characters (except for previous characters stored at beginning of buffer)
- if (!writeToNull)
+ if (!_writeToNull)
{
<# if (WriterType == RawTextWriterType.Utf8) { #>
- if (bufPos - 1 > 0)
+ if (_bufPos - 1 > 0)
{
- Debug.Assert(stream != null);
- stream.Write(<#= BufferName #>, 1, bufPos - 1);
+ Debug.Assert(_stream != null);
+ _stream.Write(<#= BufferName #>, 1, _bufPos - 1);
}
<# } else { #>
- Debug.Assert(stream != null || writer != null);
+ Debug.Assert(_stream != null || _writer != null);
- if (stream != null)
+ if (_stream != null)
{
- if (trackTextContent)
+ if (_trackTextContent)
{
_charEntityFallback.Reset(_textContentMarks, _lastMarkPos);
// reset text content tracking
}
Debug.Assert(_textContentMarks[0] == 1);
}
- EncodeChars(1, bufPos, true);
+ EncodeChars(1, _bufPos, true);
}
else
{
- if (bufPos - 1 > 0)
+ if (_bufPos - 1 > 0)
{
// Write text to TextWriter
- writer.Write(<#= BufferName #>, 1, bufPos - 1);
+ _writer.Write(<#= BufferName #>, 1, _bufPos - 1);
}
}
<# } #>
catch
{
// Future calls to flush (i.e. when Close() is called) don't attempt to write to stream
- writeToNull = true;
+ _writeToNull = true;
throw;
}
finally
{
// Move last buffer character to the beginning of the buffer (so that previous character can always be determined)
- <#= BufferName #>[0] = <#= BufferName #>[bufPos - 1];
+ <#= BufferName #>[0] = <#= BufferName #>[_bufPos - 1];
<# if (WriterType == RawTextWriterType.Utf8) { #>
if (IsSurrogateByte(<#= BufferName #>[0]))
{
// Last character was the first byte in a surrogate encoding, so move last three
// bytes of encoding to the beginning of the buffer.
- <#= BufferName #>[1] = <#= BufferName #>[bufPos];
- <#= BufferName #>[2] = <#= BufferName #>[bufPos + 1];
- <#= BufferName #>[3] = <#= BufferName #>[bufPos + 2];
+ <#= BufferName #>[1] = <#= BufferName #>[_bufPos];
+ <#= BufferName #>[2] = <#= BufferName #>[_bufPos + 1];
+ <#= BufferName #>[3] = <#= BufferName #>[_bufPos + 2];
}
<# } #>
// Reset buffer position
- textPos = (textPos == bufPos) ? 1 : 0;
- attrEndPos = (attrEndPos == bufPos) ? 1 : 0;
- contentPos = 0; // Needs to be zero, since overwriting '>' character is no longer possible
- cdataPos = 0; // Needs to be zero, since overwriting ']]>' characters is no longer possible
- bufPos = 1; // Buffer position starts at 1, because we need to be able to safely step back -1 in case we need to
+ _textPos = (_textPos == _bufPos) ? 1 : 0;
+ _attrEndPos = (_attrEndPos == _bufPos) ? 1 : 0;
+ _contentPos = 0; // Needs to be zero, since overwriting '>' character is no longer possible
+ _cdataPos = 0; // Needs to be zero, since overwriting ']]>' characters is no longer possible
+ _bufPos = 1; // Buffer position starts at 1, because we need to be able to safely step back -1 in case we need to
// close an empty element or in CDATA section detection of double ]; <#= BufferName #>[0] will always be 0
}
}
{
_charEntityFallback.StartOffset = startOffset;
}
- encoder.Convert(<#= BufferName #>, startOffset, endOffset - startOffset, bufBytes, bufBytesUsed, bufBytes.Length - bufBytesUsed, false, out chEnc, out bEnc, out completed);
+ _encoder.Convert(<#= BufferName #>, startOffset, endOffset - startOffset, _bufBytes, _bufBytesUsed, _bufBytes.Length - _bufBytesUsed, false, out chEnc, out bEnc, out completed);
startOffset += chEnc;
- bufBytesUsed += bEnc;
- if (bufBytesUsed >= (bufBytes.Length - 16))
+ _bufBytesUsed += bEnc;
+ if (_bufBytesUsed >= (_bufBytes.Length - 16))
{
- stream.Write(bufBytes, 0, bufBytesUsed);
- bufBytesUsed = 0;
+ _stream.Write(_bufBytes, 0, _bufBytesUsed);
+ _bufBytesUsed = 0;
}
}
- if (writeAllToStream && bufBytesUsed > 0)
+ if (writeAllToStream && _bufBytesUsed > 0)
{
- stream.Write(bufBytes, 0, bufBytesUsed);
- bufBytesUsed = 0;
+ _stream.Write(_bufBytes, 0, _bufBytesUsed);
+ _bufBytesUsed = 0;
}
}
private void FlushEncoder()
{
- Debug.Assert(bufPos == 1);
- if (stream != null)
+ Debug.Assert(_bufPos == 1);
+ if (_stream != null)
{
int chEnc;
int bEnc;
bool completed;
// decode no chars, just flush
- encoder.Convert(<#= BufferName #>, 1, 0, bufBytes, 0, bufBytes.Length, true, out chEnc, out bEnc, out completed);
+ _encoder.Convert(<#= BufferName #>, 1, 0, _bufBytes, 0, _bufBytes.Length, true, out chEnc, out bEnc, out completed);
if (bEnc != 0)
{
- stream.Write(bufBytes, 0, bEnc);
+ _stream.Write(_bufBytes, 0, bEnc);
}
}
}
{
fixed (<#= BufferType #>* pDstBegin = <#= BufferName #>)
{
- <#= BufferType #>* pDst = pDstBegin + bufPos;
+ <#= BufferType #>* pDst = pDstBegin + _bufPos;
int ch = 0;
for (;;)
{
<#= BufferType #>* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
<# if (WriterType == RawTextWriterType.Utf8) { #>
- while (pDst < pDstEnd && (xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch <= 0x7F))
+ while (pDst < pDstEnd && (_xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch <= 0x7F))
<# } else { #>
- while (pDst < pDstEnd && xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)))
+ while (pDst < pDstEnd && _xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)))
<# } #>
{
*pDst = (<#= BufferType #>)ch;
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
FlushBuffer();
pDst = pDstBegin + 1;
continue;
pDst++;
break;
case (char)0x9:
- if (newLineHandling == NewLineHandling.None)
+ if (_newLineHandling == NewLineHandling.None)
{
*pDst = (<#= BufferType #>)ch;
pDst++;
}
break;
case (char)0xD:
- if (newLineHandling == NewLineHandling.None)
+ if (_newLineHandling == NewLineHandling.None)
{
*pDst = (<#= BufferType #>)ch;
pDst++;
}
break;
case (char)0xA:
- if (newLineHandling == NewLineHandling.None)
+ if (_newLineHandling == NewLineHandling.None)
{
*pDst = (<#= BufferType #>)ch;
pDst++;
}
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
}
}
{
fixed (<#= BufferType #>* pDstBegin = <#= BufferName #>)
{
- <#= BufferType #>* pDst = pDstBegin + bufPos;
+ <#= BufferType #>* pDst = pDstBegin + _bufPos;
int ch = 0;
for (;;)
{
<#= BufferType #>* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
<# if (WriterType == RawTextWriterType.Utf8) { #>
- while (pDst < pDstEnd && (xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch <= 0x7F))
+ while (pDst < pDstEnd && (_xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch <= 0x7F))
<# } else { #>
- while (pDst < pDstEnd && xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)))
+ while (pDst < pDstEnd && _xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)))
<# } #>
{
*pDst = (<#= BufferType #>)ch;
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
FlushBuffer();
pDst = pDstBegin + 1;
continue;
pDst++;
break;
case (char)0xA:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
pDst = WriteNewLine(pDst);
}
}
break;
case (char)0xD:
- switch (newLineHandling)
+ switch (_newLineHandling)
{
case NewLineHandling.Replace:
// Replace "\r\n", or "\r" with NewLineChars
}
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
- textPos = bufPos;
- contentPos = 0;
+ _bufPos = (int)(pDst - pDstBegin);
+ _textPos = _bufPos;
+ _contentPos = 0;
}
}
{
fixed (<#= BufferType #>* pDstBegin = <#= BufferName #>)
{
- <#= BufferType #>* pDst = pDstBegin + bufPos;
+ <#= BufferType #>* pDst = pDstBegin + _bufPos;
char* pSrc = pSrcBegin;
int ch = 0;
for (;;)
{
<#= BufferType #>* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
<# if (WriterType == RawTextWriterType.Utf8) { #>
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
FlushBuffer();
pDst = pDstBegin + 1;
continue;
<#= EncodeChar(5, false) #>
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
}
}
fixed (<#= BufferType #>* pDstBegin = <#= BufferName #>)
{
char* pSrc = pSrcBegin;
- <#= BufferType #>* pDst = pDstBegin + bufPos;
+ <#= BufferType #>* pDst = pDstBegin + _bufPos;
int ch = 0;
for (;;)
{
<#= BufferType #>* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
<# if (WriterType == RawTextWriterType.Utf8) { #>
- while (pDst < pDstEnd && (xmlCharType.IsTextChar((char)(ch = *pSrc)) && ch <= 0x7F))
+ while (pDst < pDstEnd && (_xmlCharType.IsTextChar((char)(ch = *pSrc)) && ch <= 0x7F))
<# } else { #>
- while (pDst < pDstEnd && xmlCharType.IsTextChar((char)(ch = *pSrc)))
+ while (pDst < pDstEnd && _xmlCharType.IsTextChar((char)(ch = *pSrc)))
<# } #>
{
*pDst = (<#= BufferType #>)ch;
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
FlushBuffer();
pDst = pDstBegin + 1;
continue;
pDst++;
break;
case (char)0xD:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
// Normalize "\r\n", or "\r" to NewLineChars
if (pSrc + 1 < pSrcEnd && pSrc[1] == '\n')
}
break;
case (char)0xA:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
pDst = WriteNewLine(pDst);
}
}
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
}
}
{
if (text.Length == 0)
{
- if (bufPos >= bufLen)
+ if (_bufPos >= _bufLen)
{
FlushBuffer();
}
char* pSrcEnd = pSrcBegin + text.Length;
- <#= BufferType #>* pDst = pDstBegin + bufPos;
+ <#= BufferType #>* pDst = pDstBegin + _bufPos;
int ch = 0;
for (;;)
{
<#= BufferType #>* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
<# if (WriterType == RawTextWriterType.Utf8) { #>
- while (pDst < pDstEnd && (xmlCharType.IsTextChar((char)(ch = *pSrc)) && ch != stopChar && ch <= 0x7F))
+ while (pDst < pDstEnd && (_xmlCharType.IsTextChar((char)(ch = *pSrc)) && ch != stopChar && ch <= 0x7F))
<# } else { #>
- while (pDst < pDstEnd && (xmlCharType.IsTextChar((char)(ch = *pSrc)) && ch != stopChar))
+ while (pDst < pDstEnd && (_xmlCharType.IsTextChar((char)(ch = *pSrc)) && ch != stopChar))
<# } #>
{
*pDst = (<#= BufferType #>)ch;
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
FlushBuffer();
pDst = pDstBegin + 1;
continue;
pDst++;
break;
case (char)0xD:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
// Normalize "\r\n", or "\r" to NewLineChars
if (pSrc + 1 < pSrcEnd && pSrc[1] == '\n')
}
break;
case (char)0xA:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
pDst = WriteNewLine(pDst);
}
}
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
}
}
{
if (text.Length == 0)
{
- if (bufPos >= bufLen)
+ if (_bufPos >= _bufLen)
{
FlushBuffer();
}
char* pSrcEnd = pSrcBegin + text.Length;
- <#= BufferType #>* pDst = pDstBegin + bufPos;
+ <#= BufferType #>* pDst = pDstBegin + _bufPos;
int ch = 0;
for (;;)
{
<#= BufferType #>* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
<# if (WriterType == RawTextWriterType.Utf8) { #>
- while (pDst < pDstEnd && (xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch != ']' && ch <= 0x7F))
+ while (pDst < pDstEnd && (_xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch != ']' && ch <= 0x7F))
<# } else { #>
- while (pDst < pDstEnd && (xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch != ']'))
+ while (pDst < pDstEnd && (_xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch != ']'))
<# } #>
{
*pDst = (<#= BufferType #>)ch;
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
FlushBuffer();
pDst = pDstBegin + 1;
continue;
switch (ch)
{
case '>':
- if (hadDoubleBracket && pDst[-1] == (<#= BufferType #>)']')
+ if (_hadDoubleBracket && pDst[-1] == (<#= BufferType #>)']')
{ // pDst[-1] will always correct - there is a padding character at <#= BufferName #>[0]
// The characters "]]>" were found within the CData text
pDst = RawEndCData(pDst);
case ']':
if (pDst[-1] == (<#= BufferType #>)']')
{ // pDst[-1] will always correct - there is a padding character at <#= BufferName #>[0]
- hadDoubleBracket = true;
+ _hadDoubleBracket = true;
}
else
{
- hadDoubleBracket = false;
+ _hadDoubleBracket = false;
}
*pDst = (<#= BufferType #>)']';
pDst++;
break;
case (char)0xD:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
// Normalize "\r\n", or "\r" to NewLineChars
if (pSrc + 1 < pSrcEnd && pSrc[1] == '\n')
}
break;
case (char)0xA:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
pDst = WriteNewLine(pDst);
}
}
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
}
}
private unsafe <#= BufferType #>* InvalidXmlChar(int ch, <#= BufferType #>* pDst, bool entitize)
{
- Debug.Assert(!xmlCharType.IsWhiteSpace((char)ch));
- Debug.Assert(!xmlCharType.IsAttributeValueChar((char)ch));
+ Debug.Assert(!_xmlCharType.IsWhiteSpace((char)ch));
+ Debug.Assert(!_xmlCharType.IsAttributeValueChar((char)ch));
- if (checkCharacters)
+ if (_checkCharacters)
{
// This method will never be called on surrogates, so it is ok to pass in '\0' to the CreateInvalidCharException
throw XmlConvert.CreateInvalidCharException((char)ch, '\0');
<# if (WriterType == RawTextWriterType.Encoded) { #>
protected void ChangeTextContentMark(bool value)
{
- Debug.Assert(inTextContent != value);
- Debug.Assert(inTextContent || ((_lastMarkPos & 1) == 0));
- inTextContent = value;
+ Debug.Assert(_inTextContent != value);
+ Debug.Assert(_inTextContent || ((_lastMarkPos & 1) == 0));
+ _inTextContent = value;
if (_lastMarkPos + 1 == _textContentMarks.Length)
{
GrowTextContentMarks();
}
- _textContentMarks[++_lastMarkPos] = bufPos;
+ _textContentMarks[++_lastMarkPos] = _bufPos;
}
private void GrowTextContentMarks()
{
fixed (<#= BufferType #>* pDstBegin = <#= BufferName #>)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
// Let RawText do the real work
- RawText(newLineChars);
- return pDstBegin + bufPos;
+ RawText(_newLineChars);
+ return pDstBegin + _bufPos;
}
}
{
if (allowOnlyWhitespace)
{
- if (!xmlCharType.IsOnlyWhitespace(chars))
+ if (!_xmlCharType.IsOnlyWhitespace(chars))
{
throw new ArgumentException(SR.Format(SR.Xml_IndentCharsNotWhitespace, propertyName));
}
string error = null;
for (int i = 0; i < chars.Length; i++)
{
- if (!xmlCharType.IsTextChar(chars[i]))
+ if (!_xmlCharType.IsTextChar(chars[i]))
{
switch (chars[i])
{
//
// Fields
//
- protected int indentLevel;
- protected bool newLineOnAttributes;
- protected string indentChars;
+ protected int _indentLevel;
+ protected bool _newLineOnAttributes;
+ protected string _indentChars;
- protected bool mixedContent;
+ protected bool _mixedContent;
private BitStack _mixedContentStack;
- protected ConformanceLevel conformanceLevel = ConformanceLevel.Auto;
+ protected ConformanceLevel _conformanceLevel = ConformanceLevel.Auto;
//
// Constructors
settings.ReadOnly = false;
settings.Indent = true;
- settings.IndentChars = indentChars;
- settings.NewLineOnAttributes = newLineOnAttributes;
+ settings.IndentChars = _indentChars;
+ settings.NewLineOnAttributes = _newLineOnAttributes;
settings.ReadOnly = true;
return settings;
public override void WriteDocType(string name, string pubid, string sysid, string subset)
{
// Add indentation
- if (!mixedContent && base.textPos != base.bufPos)
+ if (!_mixedContent && base._textPos != base._bufPos)
{
WriteIndent();
}
Debug.Assert(localName != null && localName.Length != 0 && prefix != null && ns != null);
// Add indentation
- if (!mixedContent && base.textPos != base.bufPos)
+ if (!_mixedContent && base._textPos != base._bufPos)
{
WriteIndent();
}
- indentLevel++;
- _mixedContentStack.PushBit(mixedContent);
+ _indentLevel++;
+ _mixedContentStack.PushBit(_mixedContent);
base.WriteStartElement(prefix, localName, ns);
}
internal override void StartElementContent()
{
// If this is the root element and we're writing a document
- // do not inherit the mixedContent flag into the root element.
+ // do not inherit the _mixedContent flag into the root element.
// This is to allow for whitespace nodes on root level
// without disabling indentation for the whole document.
- if (indentLevel == 1 && conformanceLevel == ConformanceLevel.Document)
+ if (_indentLevel == 1 && _conformanceLevel == ConformanceLevel.Document)
{
- mixedContent = false;
+ _mixedContent = false;
}
else
{
- mixedContent = _mixedContentStack.PeekBit();
+ _mixedContent = _mixedContentStack.PeekBit();
}
base.StartElementContent();
}
internal override void OnRootElement(ConformanceLevel currentConformanceLevel)
{
// Just remember the current conformance level
- conformanceLevel = currentConformanceLevel;
+ _conformanceLevel = currentConformanceLevel;
}
internal override void WriteEndElement(string prefix, string localName, string ns)
{
// Add indentation
- indentLevel--;
- if (!mixedContent && base.contentPos != base.bufPos)
+ _indentLevel--;
+ if (!_mixedContent && base._contentPos != base._bufPos)
{
// There was content, so try to indent
- if (base.textPos != base.bufPos)
+ if (base._textPos != base._bufPos)
{
WriteIndent();
}
}
- mixedContent = _mixedContentStack.PopBit();
+ _mixedContent = _mixedContentStack.PopBit();
base.WriteEndElement(prefix, localName, ns);
}
internal override void WriteFullEndElement(string prefix, string localName, string ns)
{
// Add indentation
- indentLevel--;
- if (!mixedContent && base.contentPos != base.bufPos)
+ _indentLevel--;
+ if (!_mixedContent && base._contentPos != base._bufPos)
{
// There was content, so try to indent
- if (base.textPos != base.bufPos)
+ if (base._textPos != base._bufPos)
{
WriteIndent();
}
}
- mixedContent = _mixedContentStack.PopBit();
+ _mixedContent = _mixedContentStack.PopBit();
base.WriteFullEndElement(prefix, localName, ns);
}
public override void WriteStartAttribute(string prefix, string localName, string ns)
{
// Add indentation
- if (newLineOnAttributes)
+ if (_newLineOnAttributes)
{
WriteIndent();
}
public override void WriteCData(string text)
{
- mixedContent = true;
+ _mixedContent = true;
base.WriteCData(text);
}
public override void WriteComment(string text)
{
- if (!mixedContent && base.textPos != base.bufPos)
+ if (!_mixedContent && base._textPos != base._bufPos)
{
WriteIndent();
}
public override void WriteProcessingInstruction(string target, string text)
{
- if (!mixedContent && base.textPos != base.bufPos)
+ if (!_mixedContent && base._textPos != base._bufPos)
{
WriteIndent();
}
public override void WriteEntityRef(string name)
{
- mixedContent = true;
+ _mixedContent = true;
base.WriteEntityRef(name);
}
public override void WriteCharEntity(char ch)
{
- mixedContent = true;
+ _mixedContent = true;
base.WriteCharEntity(ch);
}
public override void WriteSurrogateCharEntity(char lowChar, char highChar)
{
- mixedContent = true;
+ _mixedContent = true;
base.WriteSurrogateCharEntity(lowChar, highChar);
}
public override void WriteWhitespace(string ws)
{
- mixedContent = true;
+ _mixedContent = true;
base.WriteWhitespace(ws);
}
public override void WriteString(string text)
{
- mixedContent = true;
+ _mixedContent = true;
base.WriteString(text);
}
public override void WriteChars(char[] buffer, int index, int count)
{
- mixedContent = true;
+ _mixedContent = true;
base.WriteChars(buffer, index, count);
}
public override void WriteRaw(char[] buffer, int index, int count)
{
- mixedContent = true;
+ _mixedContent = true;
base.WriteRaw(buffer, index, count);
}
public override void WriteRaw(string data)
{
- mixedContent = true;
+ _mixedContent = true;
base.WriteRaw(data);
}
public override void WriteBase64(byte[] buffer, int index, int count)
{
- mixedContent = true;
+ _mixedContent = true;
base.WriteBase64(buffer, index, count);
}
//
private void Init(XmlWriterSettings settings)
{
- indentLevel = 0;
- indentChars = settings.IndentChars;
- newLineOnAttributes = settings.NewLineOnAttributes;
+ _indentLevel = 0;
+ _indentChars = settings.IndentChars;
+ _newLineOnAttributes = settings.NewLineOnAttributes;
_mixedContentStack = new BitStack();
// check indent characters that they are valid XML characters
- if (base.checkCharacters)
+ if (base._checkCharacters)
{
- if (newLineOnAttributes)
+ if (_newLineOnAttributes)
{
- base.ValidateContentChars(indentChars, "IndentChars", true);
- base.ValidateContentChars(newLineChars, "NewLineChars", true);
+ base.ValidateContentChars(_indentChars, "IndentChars", true);
+ base.ValidateContentChars(_newLineChars, "NewLineChars", true);
}
else
{
- base.ValidateContentChars(indentChars, "IndentChars", false);
- if (base.newLineHandling != NewLineHandling.Replace)
+ base.ValidateContentChars(_indentChars, "IndentChars", false);
+ if (base._newLineHandling != NewLineHandling.Replace)
{
- base.ValidateContentChars(newLineChars, "NewLineChars", false);
+ base.ValidateContentChars(_newLineChars, "NewLineChars", false);
}
}
}
// Add indentation to output. Write newline and then repeat IndentChars for each indent level.
private void WriteIndent()
{
- RawText(base.newLineChars);
- for (int i = indentLevel; i > 0; i--)
+ RawText(base._newLineChars);
+ for (int i = _indentLevel; i > 0; i--)
{
- RawText(indentChars);
+ RawText(_indentChars);
}
}
}
{
CheckAsyncCall();
// Output xml declaration only if user allows it and it was not already output
- if (!omitXmlDeclaration && !autoXmlDeclaration)
+ if (!_omitXmlDeclaration && !_autoXmlDeclaration)
{<# /* Code block is to squash extra line. */
#><#= SetTextContentMark(4, 1, false) #>
await RawTextAsync("<?xml version=\"").ConfigureAwait(false);
await RawTextAsync("1.0").ConfigureAwait(false);
// Encoding
- if (encoding != null)
+ if (_encoding != null)
{
await RawTextAsync("\" encoding=\"").ConfigureAwait(false);
- await RawTextAsync(encoding.WebName).ConfigureAwait(false);
+ await RawTextAsync(_encoding.WebName).ConfigureAwait(false);
}
// Standalone
- if (standalone != XmlStandalone.Omit)
+ if (_standalone != XmlStandalone.Omit)
{
await RawTextAsync("\" standalone=\"").ConfigureAwait(false);
await RawTextAsync(standalone == XmlStandalone.Yes ? "yes" : "no").ConfigureAwait(false);
{
CheckAsyncCall();
// Output xml declaration only if user allows it and it was not already output
- if (!omitXmlDeclaration && !autoXmlDeclaration)
+ if (!_omitXmlDeclaration && !_autoXmlDeclaration)
{
return WriteProcessingInstructionAsync("xml", xmldecl);
}
finally
{
// Future calls to Close or Flush shouldn't write to Stream or Writer
- writeToNull = true;
+ _writeToNull = true;
- if (stream != null)
+ if (_stream != null)
{
try
{
- await stream.FlushAsync().ConfigureAwait(false);
+ await _stream.FlushAsync().ConfigureAwait(false);
}
finally
{
try
{
- if (closeOutput)
+ if (_closeOutput)
{
- await stream.DisposeAsync().ConfigureAwait(false);
+ await _stream.DisposeAsync().ConfigureAwait(false);
}
}
finally
{
- stream = null;
+ _stream = null;
}
}
}
<# if (WriterType == RawTextWriterType.Encoded) { #>
- else if (writer != null)
+ else if (_writer != null)
{
try
{
- await writer.FlushAsync().ConfigureAwait(false);
+ await _writer.FlushAsync().ConfigureAwait(false);
}
finally
{
try
{
- if (closeOutput)
+ if (_closeOutput)
{
- await writer.DisposeAsync().ConfigureAwait(false);
+ await _writer.DisposeAsync().ConfigureAwait(false);
}
}
finally
{
- writer = null;
+ _writer = null;
}
}
}
{
await RawTextAsync(sysid).ConfigureAwait(false);
}
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'"';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'"';
}
else if (sysid != null)
{
await RawTextAsync(" SYSTEM \"").ConfigureAwait(false);
await RawTextAsync(sysid).ConfigureAwait(false);
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'"';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'"';
}
else
{
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)' ';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)' ';
}
if (subset != null)
{
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'[';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'[';
await RawTextAsync(subset).ConfigureAwait(false);
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)']';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)']';
}
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'>';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'>';
}
// Serialize the beginning of an element start tag: "<prefix:localName"
#><#= SetTextContentMark(3, false) #>
Task task;
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'<';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'<';
if (prefix != null && prefix.Length != 0)
{
task = RawTextAsync(prefix, ":", localName);
private void WriteStartElementAsync_SetAttEndPos()
{
- attrEndPos = bufPos;
+ _attrEndPos = _bufPos;
}
// Serialize an element end tag: "</prefix:localName>", if content was output. Otherwise, serialize
#><#= SetTextContentMark(3, false) #>
- if (contentPos != bufPos)
+ if (_contentPos != _bufPos)
{
// Content has been output, so can't use shortcut syntax
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'<';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'/';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'<';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'/';
if (prefix != null && prefix.Length != 0)
{
else
{
// Use shortcut syntax; overwrite the already output '>' character
- bufPos--;
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)' ';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'/';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'>';
+ _bufPos--;
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)' ';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'/';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'>';
}
return Task.CompletedTask;
}
#><#= SetTextContentMark(3, false) #>
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'<';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'/';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'<';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'/';
if (prefix != null && prefix.Length != 0)
{
#><#= SetTextContentMark(3, false) #>
- if (attrEndPos == bufPos)
+ if (_attrEndPos == _bufPos)
{
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)' ';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)' ';
}
Task task;
if (prefix != null && prefix.Length > 0)
private void WriteStartAttribute_SetInAttribute()
{
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'=';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'"';
- inAttributeValue = true;
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'=';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'"';
+ _inAttributeValue = true;
}
// Serialize the end of an attribute value using double quotes: '"'
#><#= SetTextContentMark(3, false) #>
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'"';
- inAttributeValue = false;
- attrEndPos = bufPos;
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'"';
+ _inAttributeValue = false;
+ _attrEndPos = _bufPos;
return Task.CompletedTask;
}
{
await RawTextAsync(" xmlns:").ConfigureAwait(false);
await RawTextAsync(prefix).ConfigureAwait(false);
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'=';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'"';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'=';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'"';
}
- inAttributeValue = true;<#
+ _inAttributeValue = true;<#
#><#= SetTextContentMark(3, true) #>
}
#><#= SetTextContentMark(3, false) #>
- inAttributeValue = false;
+ _inAttributeValue = false;
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'"';
- attrEndPos = bufPos;
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'"';
+ _attrEndPos = _bufPos;
return Task.CompletedTask;
}
#><#= SetTextContentMark(3, false) #>
- if (mergeCDataSections && bufPos == cdataPos)
+ if (_mergeCDataSections && _bufPos == _cdataPos)
{
// Merge adjacent cdata sections - overwrite the "]]>" characters
- Debug.Assert(bufPos >= 4);
- bufPos -= 3;
+ Debug.Assert(_bufPos >= 4);
+ _bufPos -= 3;
}
else
{
// Start a new cdata section
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'<';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'!';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'[';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'C';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'D';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'A';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'T';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'A';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'[';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'<';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'!';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'[';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'C';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'D';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'A';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'T';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'A';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'[';
}
await WriteCDataSectionAsync(text).ConfigureAwait(false);
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)']';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)']';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'>';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)']';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)']';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'>';
- textPos = bufPos;
- cdataPos = bufPos;
+ _textPos = _bufPos;
+ _cdataPos = _bufPos;
}
// Serialize a comment.
#><#= SetTextContentMark(3, false) #>
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'<';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'!';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'-';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'-';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'<';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'!';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'-';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'-';
await WriteCommentOrPiAsync(text, '-').ConfigureAwait(false);
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'-';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'-';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'>';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'-';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'-';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'>';
}
// Serialize a processing instruction.
#><#= SetTextContentMark(3, false) #>
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'<';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'?';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'<';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'?';
await RawTextAsync(name).ConfigureAwait(false);
if (text.Length > 0)
{
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)' ';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)' ';
await WriteCommentOrPiAsync(text, '?').ConfigureAwait(false);
}
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'?';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'>';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'?';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'>';
}
// Serialize an entity reference.
#><#= SetTextContentMark(3, false) #>
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'&';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'&';
await RawTextAsync(name).ConfigureAwait(false);
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)';';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)';';
- if (bufPos > bufLen)
+ if (_bufPos > _bufLen)
{
await FlushBufferAsync().ConfigureAwait(false);
}
- textPos = bufPos;
+ _textPos = _bufPos;
}
// Serialize a character entity reference.
CheckAsyncCall();
string strVal = ((int)ch).ToString("X", NumberFormatInfo.InvariantInfo);
- if (checkCharacters && !xmlCharType.IsCharData(ch))
+ if (_checkCharacters && !_xmlCharType.IsCharData(ch))
{
// we just have a single char, not a surrogate, therefore we have to pass in '\0' for the second char
throw XmlConvert.CreateInvalidCharException(ch, '\0');
#><#= SetTextContentMark(3, false) #>
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'&';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'#';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'x';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'&';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'#';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'x';
await RawTextAsync(strVal).ConfigureAwait(false);
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)';';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)';';
- if (bufPos > bufLen)
+ if (_bufPos > _bufLen)
{
await FlushBufferAsync().ConfigureAwait(false);
}
- textPos = bufPos;
+ _textPos = _bufPos;
}
// Serialize a whitespace node.
Debug.Assert(ws != null);<#
#><#= SetTextContentMark(3, false) #>
- if (inAttributeValue)
+ if (_inAttributeValue)
{
return WriteAttributeTextBlockAsync(ws);
}
Debug.Assert(text != null);<#
#><#= SetTextContentMark(3, true) #>
- if (inAttributeValue)
+ if (_inAttributeValue)
{
return WriteAttributeTextBlockAsync(text);
}
int surrogateChar = XmlCharType.CombineSurrogateChar(lowChar, highChar);
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'&';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'#';
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)'x';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'&';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'#';
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)'x';
await RawTextAsync(surrogateChar.ToString("X", NumberFormatInfo.InvariantInfo)).ConfigureAwait(false);
- <#= BufferName #>[bufPos++] = (<#= BufferType #>)';';
- textPos = bufPos;
+ <#= BufferName #>[_bufPos++] = (<#= BufferType #>)';';
+ _textPos = _bufPos;
}
// Serialize either attribute or element text using XML rules.
#><#= SetTextContentMark(3, true) #>
- if (inAttributeValue)
+ if (_inAttributeValue)
{
return WriteAttributeTextBlockAsync(buffer, index, count);
}
await WriteRawWithCharCheckingAsync(buffer, index, count).ConfigureAwait(false);
- textPos = bufPos;
+ _textPos = _bufPos;
}
// Serialize raw data.
await WriteRawWithCharCheckingAsync(data).ConfigureAwait(false);
- textPos = bufPos;
+ _textPos = _bufPos;
}
// Flush all characters in the buffer to output and call Flush() on the output object.
await FlushEncoderAsync().ConfigureAwait(false);
<# } #>
- if (stream != null)
+ if (_stream != null)
{
- await stream.FlushAsync().ConfigureAwait(false);
+ await _stream.FlushAsync().ConfigureAwait(false);
}
<# if (WriterType == RawTextWriterType.Encoded) { #>
- else if (writer != null)
+ else if (_writer != null)
{
- await writer.FlushAsync().ConfigureAwait(false);
+ await _writer.FlushAsync().ConfigureAwait(false);
}
<# } #>
}
try
{
// Output all characters (except for previous characters stored at beginning of buffer)
- if (!writeToNull)
+ if (!_writeToNull)
{
<# if (WriterType == RawTextWriterType.Utf8) { #>
- if (bufPos - 1 > 0)
+ if (_bufPos - 1 > 0)
{
- Debug.Assert(stream != null);
- await stream.WriteAsync(bufBytes.AsMemory(1, bufPos - 1)).ConfigureAwait(false);
+ Debug.Assert(_stream != null);
+ await _stream.WriteAsync(_bufBytes.AsMemory(1, _bufPos - 1)).ConfigureAwait(false);
}
<# } else { #>
- Debug.Assert(stream != null || writer != null);
+ Debug.Assert(_stream != null || _writer != null);
- if (stream != null)
+ if (_stream != null)
{
- if (trackTextContent)
+ if (_trackTextContent)
{
_charEntityFallback.Reset(_textContentMarks, _lastMarkPos);
// reset text content tracking
}
Debug.Assert(_textContentMarks[0] == 1);
}
- await EncodeCharsAsync(1, bufPos, true).ConfigureAwait(false);
+ await EncodeCharsAsync(1, _bufPos, true).ConfigureAwait(false);
}
else
{
- if (bufPos - 1 > 0)
+ if (_bufPos - 1 > 0)
{
// Write text to TextWriter
- await writer.WriteAsync(<#= BufferName #>.AsMemory(1, bufPos - 1)).ConfigureAwait(false);
+ await _writer.WriteAsync(<#= BufferName #>.AsMemory(1, _bufPos - 1)).ConfigureAwait(false);
}
}
<# } #>
catch
{
// Future calls to flush (i.e. when Close() is called) don't attempt to write to stream
- writeToNull = true;
+ _writeToNull = true;
throw;
}
finally
{
// Move last buffer character to the beginning of the buffer (so that previous character can always be determined)
- <#= BufferName #>[0] = <#= BufferName #>[bufPos - 1];
+ <#= BufferName #>[0] = <#= BufferName #>[_bufPos - 1];
<# if (WriterType == RawTextWriterType.Utf8) { #>
- if (IsSurrogateByte(bufBytes[0]))
+ if (IsSurrogateByte(_bufBytes[0]))
{
// Last character was the first byte in a surrogate encoding, so move last three
// bytes of encoding to the beginning of the buffer.
- bufBytes[1] = bufBytes[bufPos];
- bufBytes[2] = bufBytes[bufPos + 1];
- bufBytes[3] = bufBytes[bufPos + 2];
+ _bufBytes[1] = _bufBytes[_bufPos];
+ _bufBytes[2] = _bufBytes[_bufPos + 1];
+ _bufBytes[3] = _bufBytes[_bufPos + 2];
}
<# } #>
// Reset buffer position
- textPos = (textPos == bufPos) ? 1 : 0;
- attrEndPos = (attrEndPos == bufPos) ? 1 : 0;
- contentPos = 0; // Needs to be zero, since overwriting '>' character is no longer possible
- cdataPos = 0; // Needs to be zero, since overwriting ']]>' characters is no longer possible
- bufPos = 1; // Buffer position starts at 1, because we need to be able to safely step back -1 in case we need to
+ _textPos = (_textPos == _bufPos) ? 1 : 0;
+ _attrEndPos = (_attrEndPos == _bufPos) ? 1 : 0;
+ _contentPos = 0; // Needs to be zero, since overwriting '>' character is no longer possible
+ _cdataPos = 0; // Needs to be zero, since overwriting ']]>' characters is no longer possible
+ _bufPos = 1; // Buffer position starts at 1, because we need to be able to safely step back -1 in case we need to
// close an empty element or in CDATA section detection of double ]; _BUFFER[0] will always be 0
}
}
{
_charEntityFallback.StartOffset = startOffset;
}
- encoder.Convert(<#= BufferName #>, startOffset, endOffset - startOffset, bufBytes, bufBytesUsed, bufBytes.Length - bufBytesUsed, false, out chEnc, out bEnc, out completed);
+ _encoder.Convert(<#= BufferName #>, startOffset, endOffset - startOffset, _bufBytes, _bufBytesUsed, _bufBytes.Length - _bufBytesUsed, false, out chEnc, out bEnc, out completed);
startOffset += chEnc;
- bufBytesUsed += bEnc;
- if (bufBytesUsed >= (bufBytes.Length - 16))
+ _bufBytesUsed += bEnc;
+ if (_bufBytesUsed >= (_bufBytes.Length - 16))
{
- await stream.WriteAsync(bufBytes.AsMemory(0, bufBytesUsed)).ConfigureAwait(false);
- bufBytesUsed = 0;
+ await _stream.WriteAsync(_bufBytes.AsMemory(0, _bufBytesUsed)).ConfigureAwait(false);
+ _bufBytesUsed = 0;
}
}
- if (writeAllToStream && bufBytesUsed > 0)
+ if (writeAllToStream && _bufBytesUsed > 0)
{
- await stream.WriteAsync(bufBytes.AsMemory(0, bufBytesUsed)).ConfigureAwait(false);
- bufBytesUsed = 0;
+ await _stream.WriteAsync(_bufBytes.AsMemory(0, _bufBytesUsed)).ConfigureAwait(false);
+ _bufBytesUsed = 0;
}
}
private Task FlushEncoderAsync()
{
- Debug.Assert(bufPos == 1);
- if (stream != null)
+ Debug.Assert(_bufPos == 1);
+ if (_stream != null)
{
int chEnc;
int bEnc;
bool completed;
// decode no chars, just flush
- encoder.Convert(<#= BufferName #>, 1, 0, bufBytes, 0, bufBytes.Length, true, out chEnc, out bEnc, out completed);
+ _encoder.Convert(<#= BufferName #>, 1, 0, _bufBytes, 0, _bufBytes.Length, true, out chEnc, out bEnc, out completed);
if (bEnc != 0)
{
- return stream.WriteAsync(bufBytes, 0, bEnc);
+ return _stream.WriteAsync(_bufBytes, 0, bEnc);
}
}
fixed (<#= BufferType #>* pDstBegin = <#= BufferName #>)
{
- <#= BufferType #>* pDst = pDstBegin + bufPos;
+ <#= BufferType #>* pDst = pDstBegin + _bufPos;
int ch = 0;
while (true)
{
<#= BufferType #>* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
<# if (WriterType == RawTextWriterType.Utf8) { #>
- while (pDst < pDstEnd && (xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch <= 0x7F))
+ while (pDst < pDstEnd && (_xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch <= 0x7F))
<# } else { #>
- while (pDst < pDstEnd && xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)))
+ while (pDst < pDstEnd && _xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)))
<# } #>
{
*pDst = (<#= BufferType #>)ch;
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
return (int)(pSrc - pRaw);
}
pDst++;
break;
case (char)0x9:
- if (newLineHandling == NewLineHandling.None)
+ if (_newLineHandling == NewLineHandling.None)
{
*pDst = (<#= BufferType #>)ch;
pDst++;
}
break;
case (char)0xD:
- if (newLineHandling == NewLineHandling.None)
+ if (_newLineHandling == NewLineHandling.None)
{
*pDst = (<#= BufferType #>)ch;
pDst++;
}
break;
case (char)0xA:
- if (newLineHandling == NewLineHandling.None)
+ if (_newLineHandling == NewLineHandling.None)
{
*pDst = (<#= BufferType #>)ch;
pDst++;
}
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
}
return -1;
fixed (<#= BufferType #>* pDstBegin = <#= BufferName #>)
{
- <#= BufferType #>* pDst = pDstBegin + bufPos;
+ <#= BufferType #>* pDst = pDstBegin + _bufPos;
int ch = 0;
while (true)
{
<#= BufferType #>* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
<# if (WriterType == RawTextWriterType.Utf8) { #>
- while (pDst < pDstEnd && (xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch <= 0x7F))
+ while (pDst < pDstEnd && (_xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch <= 0x7F))
<# } else { #>
- while (pDst < pDstEnd && xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)))
+ while (pDst < pDstEnd && _xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)))
<# } #>
{
*pDst = (<#= BufferType #>)ch;
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
return (int)(pSrc - pRaw);
}
pDst++;
break;
case (char)0xA:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
needWriteNewLine = true;
return (int)(pSrc - pRaw);
}
}
break;
case (char)0xD:
- switch (newLineHandling)
+ switch (_newLineHandling)
{
case NewLineHandling.Replace:
// Replace "\r\n", or "\r" with NewLineChars
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
needWriteNewLine = true;
return (int)(pSrc - pRaw);
}
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
- textPos = bufPos;
- contentPos = 0;
+ _bufPos = (int)(pDst - pDstBegin);
+ _textPos = _bufPos;
+ _contentPos = 0;
}
return -1;
needWriteNewLine = false;
if (count == 0)
{
- contentPos = 0;
+ _contentPos = 0;
return -1;
}
fixed (char* pSrc = &chars[index])
needWriteNewLine = false;
if (count == 0)
{
- contentPos = 0;
+ _contentPos = 0;
return -1;
}
fixed (char* pSrc = text)
if (needWriteNewLine)
{
//hit WriteNewLine
- await RawTextAsync(newLineChars).ConfigureAwait(false);
+ await RawTextAsync(_newLineChars).ConfigureAwait(false);
curIndex++;
leftCount--;
}
if (newLine)
{
- await RawTextAsync(newLineChars).ConfigureAwait(false);
+ await RawTextAsync(_newLineChars).ConfigureAwait(false);
curIndex++;
leftCount--;
}
if (needWriteNewLine)
{
//hit WriteNewLine
- await RawTextAsync(newLineChars).ConfigureAwait(false);
+ await RawTextAsync(_newLineChars).ConfigureAwait(false);
curIndex++;
leftCount--;
}
fixed (<#= BufferType #>* pDstBegin = <#= BufferName #>)
{
- <#= BufferType #>* pDst = pDstBegin + bufPos;
+ <#= BufferType #>* pDst = pDstBegin + _bufPos;
char* pSrc = pSrcBegin;
int ch = 0;
while (true)
{
<#= BufferType #>* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
<# if (WriterType == RawTextWriterType.Utf8) { #>
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
return (int)(pSrc - pRaw);
}
<#= EncodeChar(5, false) #>
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
}
return -1;
fixed (<#= BufferType #>* pDstBegin = <#= BufferName #>)
{
char* pSrc = pSrcBegin;
- <#= BufferType #>* pDst = pDstBegin + bufPos;
+ <#= BufferType #>* pDst = pDstBegin + _bufPos;
int ch = 0;
while (true)
{
<#= BufferType #>* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
<# if (WriterType == RawTextWriterType.Utf8) { #>
- while (pDst < pDstEnd && (xmlCharType.IsTextChar((char)(ch = *pSrc)) && ch <= 0x7F))
+ while (pDst < pDstEnd && (_xmlCharType.IsTextChar((char)(ch = *pSrc)) && ch <= 0x7F))
<# } else { #>
- while (pDst < pDstEnd && xmlCharType.IsTextChar((char)(ch = *pSrc)))
+ while (pDst < pDstEnd && _xmlCharType.IsTextChar((char)(ch = *pSrc)))
<# } #>
{
*pDst = (<#= BufferType #>)ch;
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
return (int)(pSrc - pRaw);
}
pDst++;
break;
case (char)0xD:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
// Normalize "\r\n", or "\r" to NewLineChars
if (pSrc + 1 < pSrcEnd && pSrc[1] == '\n')
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
needWriteNewLine = true;
return (int)(pSrc - pRaw);
}
}
break;
case (char)0xA:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
needWriteNewLine = true;
return (int)(pSrc - pRaw);
}
}
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
}
return -1;
leftCount -= writeLen;
if (needWriteNewLine)
{
- await RawTextAsync(newLineChars).ConfigureAwait(false);
+ await RawTextAsync(_newLineChars).ConfigureAwait(false);
curIndex++;
leftCount--;
}
leftCount -= writeLen;
if (needWriteNewLine)
{
- await RawTextAsync(newLineChars).ConfigureAwait(false);
+ await RawTextAsync(_newLineChars).ConfigureAwait(false);
curIndex++;
leftCount--;
}
char* pSrcEnd = pSrcBegin + count;
- <#= BufferType #>* pDst = pDstBegin + bufPos;
+ <#= BufferType #>* pDst = pDstBegin + _bufPos;
int ch = 0;
while (true)
{
<#= BufferType #>* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
<# if (WriterType == RawTextWriterType.Utf8) { #>
- while (pDst < pDstEnd && (xmlCharType.IsTextChar((char)(ch = *pSrc)) && ch != stopChar && ch <= 0x7F))
+ while (pDst < pDstEnd && (_xmlCharType.IsTextChar((char)(ch = *pSrc)) && ch != stopChar && ch <= 0x7F))
<# } else { #>
- while (pDst < pDstEnd && (xmlCharType.IsTextChar((char)(ch = *pSrc)) && ch != stopChar))
+ while (pDst < pDstEnd && (_xmlCharType.IsTextChar((char)(ch = *pSrc)) && ch != stopChar))
<# } #>
{
*pDst = (<#= BufferType #>)ch;
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
return (int)(pSrc - pRaw);
}
pDst++;
break;
case (char)0xD:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
// Normalize "\r\n", or "\r" to NewLineChars
if (pSrc + 1 < pSrcEnd && pSrc[1] == '\n')
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
needWriteNewLine = true;
return (int)(pSrc - pRaw);
}
}
break;
case (char)0xA:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
needWriteNewLine = true;
return (int)(pSrc - pRaw);
}
}
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
}
return -1;
{
if (text.Length == 0)
{
- if (bufPos >= bufLen)
+ if (_bufPos >= _bufLen)
{
await FlushBufferAsync().ConfigureAwait(false);
}
leftCount -= writeLen;
if (needWriteNewLine)
{
- await RawTextAsync(newLineChars).ConfigureAwait(false);
+ await RawTextAsync(_newLineChars).ConfigureAwait(false);
curIndex++;
leftCount--;
}
char* pRaw = pSrc;
- <#= BufferType #>* pDst = pDstBegin + bufPos;
+ <#= BufferType #>* pDst = pDstBegin + _bufPos;
int ch = 0;
while (true)
{
<#= BufferType #>* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
<# if (WriterType == RawTextWriterType.Utf8) { #>
- while (pDst < pDstEnd && (xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch != ']' && ch <= 0x7F))
+ while (pDst < pDstEnd && (_xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch != ']' && ch <= 0x7F))
<# } else { #>
- while (pDst < pDstEnd && (xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch != ']'))
+ while (pDst < pDstEnd && (_xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch != ']'))
<# } #>
{
*pDst = (<#= BufferType #>)ch;
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
return (int)(pSrc - pRaw);
}
switch (ch)
{
case '>':
- if (hadDoubleBracket && pDst[-1] == (<#= BufferType #>)']')
+ if (_hadDoubleBracket && pDst[-1] == (<#= BufferType #>)']')
{ // pDst[-1] will always correct - there is a padding character at _BUFFER[0]
// The characters "]]>" were found within the CData text
pDst = RawEndCData(pDst);
case ']':
if (pDst[-1] == (<#= BufferType #>)']')
{ // pDst[-1] will always correct - there is a padding character at _BUFFER[0]
- hadDoubleBracket = true;
+ _hadDoubleBracket = true;
}
else
{
- hadDoubleBracket = false;
+ _hadDoubleBracket = false;
}
*pDst = (<#= BufferType #>)']';
pDst++;
break;
case (char)0xD:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
// Normalize "\r\n", or "\r" to NewLineChars
if (pSrc + 1 < pSrcEnd && pSrc[1] == '\n')
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
needWriteNewLine = true;
return (int)(pSrc - pRaw);
}
}
break;
case (char)0xA:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
needWriteNewLine = true;
return (int)(pSrc - pRaw);
}
}
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
}
return -1;
{
if (text.Length == 0)
{
- if (bufPos >= bufLen)
+ if (_bufPos >= _bufLen)
{
await FlushBufferAsync().ConfigureAwait(false);
}
leftCount -= writeLen;
if (needWriteNewLine)
{
- await RawTextAsync(newLineChars).ConfigureAwait(false);
+ await RawTextAsync(_newLineChars).ConfigureAwait(false);
curIndex++;
leftCount--;
}
{
CheckAsyncCall();
// Add indentation
- if (!mixedContent && base.textPos != base.bufPos)
+ if (!_mixedContent && base._textPos != base._bufPos)
{
await WriteIndentAsync().ConfigureAwait(false);
}
Debug.Assert(localName != null && localName.Length != 0 && prefix != null && ns != null);
// Add indentation
- if (!mixedContent && base.textPos != base.bufPos)
+ if (!_mixedContent && base._textPos != base._bufPos)
{
await WriteIndentAsync().ConfigureAwait(false);
}
- indentLevel++;
- _mixedContentStack.PushBit(mixedContent);
+ _indentLevel++;
+ _mixedContentStack.PushBit(_mixedContent);
await base.WriteStartElementAsync(prefix, localName, ns).ConfigureAwait(false);
}
{
CheckAsyncCall();
// Add indentation
- indentLevel--;
- if (!mixedContent && base.contentPos != base.bufPos)
+ _indentLevel--;
+ if (!_mixedContent && base._contentPos != base._bufPos)
{
// There was content, so try to indent
- if (base.textPos != base.bufPos)
+ if (base._textPos != base._bufPos)
{
await WriteIndentAsync().ConfigureAwait(false);
}
}
- mixedContent = _mixedContentStack.PopBit();
+ _mixedContent = _mixedContentStack.PopBit();
await base.WriteEndElementAsync(prefix, localName, ns).ConfigureAwait(false);
}
{
CheckAsyncCall();
// Add indentation
- indentLevel--;
- if (!mixedContent && base.contentPos != base.bufPos)
+ _indentLevel--;
+ if (!_mixedContent && base._contentPos != base._bufPos)
{
// There was content, so try to indent
- if (base.textPos != base.bufPos)
+ if (base._textPos != base._bufPos)
{
await WriteIndentAsync().ConfigureAwait(false);
}
}
- mixedContent = _mixedContentStack.PopBit();
+ _mixedContent = _mixedContentStack.PopBit();
await base.WriteFullEndElementAsync(prefix, localName, ns).ConfigureAwait(false);
}
{
CheckAsyncCall();
// Add indentation
- if (newLineOnAttributes)
+ if (_newLineOnAttributes)
{
await WriteIndentAsync().ConfigureAwait(false);
}
public override Task WriteCDataAsync(string text)
{
CheckAsyncCall();
- mixedContent = true;
+ _mixedContent = true;
return base.WriteCDataAsync(text);
}
public override async Task WriteCommentAsync(string text)
{
CheckAsyncCall();
- if (!mixedContent && base.textPos != base.bufPos)
+ if (!_mixedContent && base._textPos != base._bufPos)
{
await WriteIndentAsync().ConfigureAwait(false);
}
public override async Task WriteProcessingInstructionAsync(string target, string text)
{
CheckAsyncCall();
- if (!mixedContent && base.textPos != base.bufPos)
+ if (!_mixedContent && base._textPos != base._bufPos)
{
await WriteIndentAsync().ConfigureAwait(false);
}
public override Task WriteEntityRefAsync(string name)
{
CheckAsyncCall();
- mixedContent = true;
+ _mixedContent = true;
return base.WriteEntityRefAsync(name);
}
public override Task WriteCharEntityAsync(char ch)
{
CheckAsyncCall();
- mixedContent = true;
+ _mixedContent = true;
return base.WriteCharEntityAsync(ch);
}
public override Task WriteSurrogateCharEntityAsync(char lowChar, char highChar)
{
CheckAsyncCall();
- mixedContent = true;
+ _mixedContent = true;
return base.WriteSurrogateCharEntityAsync(lowChar, highChar);
}
public override Task WriteWhitespaceAsync(string ws)
{
CheckAsyncCall();
- mixedContent = true;
+ _mixedContent = true;
return base.WriteWhitespaceAsync(ws);
}
public override Task WriteStringAsync(string text)
{
CheckAsyncCall();
- mixedContent = true;
+ _mixedContent = true;
return base.WriteStringAsync(text);
}
public override Task WriteCharsAsync(char[] buffer, int index, int count)
{
CheckAsyncCall();
- mixedContent = true;
+ _mixedContent = true;
return base.WriteCharsAsync(buffer, index, count);
}
public override Task WriteRawAsync(char[] buffer, int index, int count)
{
CheckAsyncCall();
- mixedContent = true;
+ _mixedContent = true;
return base.WriteRawAsync(buffer, index, count);
}
public override Task WriteRawAsync(string data)
{
CheckAsyncCall();
- mixedContent = true;
+ _mixedContent = true;
return base.WriteRawAsync(data);
}
public override Task WriteBase64Async(byte[] buffer, int index, int count)
{
CheckAsyncCall();
- mixedContent = true;
+ _mixedContent = true;
return base.WriteBase64Async(buffer, index, count);
}
private async Task WriteIndentAsync()
{
CheckAsyncCall();
- await RawTextAsync(base.newLineChars).ConfigureAwait(false);
- for (int i = indentLevel; i > 0; i--)
+ await RawTextAsync(base._newLineChars).ConfigureAwait(false);
+ for (int i = _indentLevel; i > 0; i--)
{
- await RawTextAsync(indentChars).ConfigureAwait(false);
+ await RawTextAsync(_indentChars).ConfigureAwait(false);
}
}
}
// Fields
//
// base64 converter
- protected XmlRawWriterBase64Encoder? base64Encoder;
+ protected XmlRawWriterBase64Encoder? _base64Encoder;
// namespace resolver
- protected IXmlNamespaceResolver? resolver;
+ protected IXmlNamespaceResolver? _resolver;
//
// XmlWriter implementation
// By default, convert base64 value to string and call WriteString.
public override void WriteBase64(byte[] buffer, int index, int count)
{
- if (base64Encoder == null)
+ if (_base64Encoder == null)
{
- base64Encoder = new XmlRawWriterBase64Encoder(this);
+ _base64Encoder = new XmlRawWriterBase64Encoder(this);
}
// Encode will call WriteRaw to write out the encoded characters
- base64Encoder.Encode(buffer, index, count);
+ _base64Encoder.Encode(buffer, index, count);
}
// Raw writers do not have to keep track of namespaces.
throw new ArgumentNullException(nameof(value));
}
- WriteString(XmlUntypedConverter.Untyped.ToString(value, resolver));
+ WriteString(XmlUntypedConverter.Untyped.ToString(value, _resolver));
}
// Override in order to handle Xml simple typed values and to pass resolver for QName values
{
get
{
- return resolver;
+ return _resolver;
}
set
{
- resolver = value;
+ _resolver = value;
}
}
internal virtual void WriteEndBase64()
{
// The Flush will call WriteRaw to write out the rest of the encoded characters
- Debug.Assert(base64Encoder != null);
- base64Encoder.Flush();
+ Debug.Assert(_base64Encoder != null);
+ _base64Encoder.Flush();
}
internal virtual void Close(WriteState currentState)
// By default, convert base64 value to string and call WriteString.
public override Task WriteBase64Async(byte[] buffer, int index, int count)
{
- if (base64Encoder == null)
+ if (_base64Encoder == null)
{
- base64Encoder = new XmlRawWriterBase64Encoder(this);
+ _base64Encoder = new XmlRawWriterBase64Encoder(this);
}
// Encode will call WriteRaw to write out the encoded characters
- return base64Encoder.EncodeAsync(buffer, index, count);
+ return _base64Encoder.EncodeAsync(buffer, index, count);
}
// Raw writers do not have to verify NmToken values.
internal virtual Task WriteEndBase64Async()
{
// The Flush will call WriteRaw to write out the rest of the encoded characters
- Debug.Assert(base64Encoder != null);
- return base64Encoder.FlushAsync();
+ Debug.Assert(_base64Encoder != null);
+ return _base64Encoder.FlushAsync();
}
internal virtual ValueTask DisposeAsyncCore(WriteState currentState)
private readonly bool _useAsync;
// main buffer
- protected byte[] bufBytes;
+ protected byte[] _bufBytes;
// output stream
- protected Stream stream;
+ protected Stream _stream;
// encoding of the stream or text writer
- protected Encoding encoding;
+ protected Encoding _encoding;
// char type tables
- protected XmlCharType xmlCharType = XmlCharType.Instance;
+ protected XmlCharType _xmlCharType = XmlCharType.Instance;
// buffer positions
- protected int bufPos = 1; // buffer position starts at 1, because we need to be able to safely step back -1 in case we need to
- // close an empty element or in CDATA section detection of double ]; bufBytes[0] will always be 0
- protected int textPos = 1; // text end position; don't indent first element, pi, or comment
- protected int contentPos; // element content end position
- protected int cdataPos; // cdata end position
- protected int attrEndPos; // end of the last attribute
- protected int bufLen = BUFSIZE;
+ protected int _bufPos = 1; // buffer position starts at 1, because we need to be able to safely step back -1 in case we need to
+ // close an empty element or in CDATA section detection of double ]; bufBytes[0] will always be 0
+ protected int _textPos = 1; // text end position; don't indent first element, pi, or comment
+ protected int _contentPos; // element content end position
+ protected int _cdataPos; // cdata end position
+ protected int _attrEndPos; // end of the last attribute
+ protected int _bufLen = BUFSIZE;
// flags
- protected bool writeToNull;
- protected bool hadDoubleBracket;
- protected bool inAttributeValue;
+ protected bool _writeToNull;
+ protected bool _hadDoubleBracket;
+ protected bool _inAttributeValue;
// writer settings
- protected NewLineHandling newLineHandling;
- protected bool closeOutput;
- protected bool omitXmlDeclaration;
- protected string newLineChars;
- protected bool checkCharacters;
+ protected NewLineHandling _newLineHandling;
+ protected bool _closeOutput;
+ protected bool _omitXmlDeclaration;
+ protected string _newLineChars;
+ protected bool _checkCharacters;
- protected XmlStandalone standalone;
- protected XmlOutputMethod outputMethod;
+ protected XmlStandalone _standalone;
+ protected XmlOutputMethod _outputMethod;
- protected bool autoXmlDeclaration;
- protected bool mergeCDataSections;
+ protected bool _autoXmlDeclaration;
+ protected bool _mergeCDataSections;
//
// Constants
_useAsync = settings.Async;
// copy settings
- newLineHandling = settings.NewLineHandling;
- omitXmlDeclaration = settings.OmitXmlDeclaration;
- newLineChars = settings.NewLineChars;
- checkCharacters = settings.CheckCharacters;
- closeOutput = settings.CloseOutput;
+ _newLineHandling = settings.NewLineHandling;
+ _omitXmlDeclaration = settings.OmitXmlDeclaration;
+ _newLineChars = settings.NewLineChars;
+ _checkCharacters = settings.CheckCharacters;
+ _closeOutput = settings.CloseOutput;
- standalone = settings.Standalone;
- outputMethod = settings.OutputMethod;
- mergeCDataSections = settings.MergeCDataSections;
+ _standalone = settings.Standalone;
+ _outputMethod = settings.OutputMethod;
+ _mergeCDataSections = settings.MergeCDataSections;
- if (checkCharacters && newLineHandling == NewLineHandling.Replace)
+ if (_checkCharacters && _newLineHandling == NewLineHandling.Replace)
{
- ValidateContentChars(newLineChars, "NewLineChars", false);
+ ValidateContentChars(_newLineChars, "NewLineChars", false);
}
}
{
Debug.Assert(stream != null && settings != null);
- this.stream = stream;
- this.encoding = settings.Encoding;
+ this._stream = stream;
+ this._encoding = settings.Encoding;
// the buffer is allocated will OVERFLOW in order to reduce checks when writing out constant size markup
if (settings.Async)
{
- bufLen = ASYNCBUFSIZE;
+ _bufLen = ASYNCBUFSIZE;
}
- bufBytes = new byte[bufLen + OVERFLOW];
+ _bufBytes = new byte[_bufLen + OVERFLOW];
// Output UTF-8 byte order mark if Encoding object wants it
if (!stream.CanSeek || stream.Position == 0)
{
- ReadOnlySpan<byte> bom = encoding.Preamble;
+ ReadOnlySpan<byte> bom = _encoding.Preamble;
if (bom.Length != 0)
{
- bom.CopyTo(new Span<byte>(bufBytes).Slice(1));
- bufPos += bom.Length;
- textPos += bom.Length;
+ bom.CopyTo(new Span<byte>(_bufBytes).Slice(1));
+ _bufPos += bom.Length;
+ _textPos += bom.Length;
}
}
// Write the xml declaration
if (settings.AutoXmlDeclaration)
{
- WriteXmlDeclaration(standalone);
- autoXmlDeclaration = true;
+ WriteXmlDeclaration(_standalone);
+ _autoXmlDeclaration = true;
}
}
{
XmlWriterSettings settings = new XmlWriterSettings();
- settings.Encoding = encoding;
- settings.OmitXmlDeclaration = omitXmlDeclaration;
- settings.NewLineHandling = newLineHandling;
- settings.NewLineChars = newLineChars;
- settings.CloseOutput = closeOutput;
+ settings.Encoding = _encoding;
+ settings.OmitXmlDeclaration = _omitXmlDeclaration;
+ settings.NewLineHandling = _newLineHandling;
+ settings.NewLineChars = _newLineChars;
+ settings.CloseOutput = _closeOutput;
settings.ConformanceLevel = ConformanceLevel.Auto;
- settings.CheckCharacters = checkCharacters;
+ settings.CheckCharacters = _checkCharacters;
- settings.AutoXmlDeclaration = autoXmlDeclaration;
- settings.Standalone = standalone;
- settings.OutputMethod = outputMethod;
+ settings.AutoXmlDeclaration = _autoXmlDeclaration;
+ settings.Standalone = _standalone;
+ settings.OutputMethod = _outputMethod;
settings.ReadOnly = true;
return settings;
internal override void WriteXmlDeclaration(XmlStandalone standalone)
{
// Output xml declaration only if user allows it and it was not already output
- if (!omitXmlDeclaration && !autoXmlDeclaration)
+ if (!_omitXmlDeclaration && !_autoXmlDeclaration)
{
RawText("<?xml version=\"");
RawText("1.0");
// Encoding
- if (encoding != null)
+ if (_encoding != null)
{
RawText("\" encoding=\"");
- RawText(encoding.WebName);
+ RawText(_encoding.WebName);
}
// Standalone
internal override void WriteXmlDeclaration(string xmldecl)
{
// Output xml declaration only if user allows it and it was not already output
- if (!omitXmlDeclaration && !autoXmlDeclaration)
+ if (!_omitXmlDeclaration && !_autoXmlDeclaration)
{
WriteProcessingInstruction("xml", xmldecl);
}
{
RawText(sysid);
}
- bufBytes[bufPos++] = (byte)'"';
+ _bufBytes[_bufPos++] = (byte)'"';
}
else if (sysid != null)
{
RawText(" SYSTEM \"");
RawText(sysid);
- bufBytes[bufPos++] = (byte)'"';
+ _bufBytes[_bufPos++] = (byte)'"';
}
else
{
- bufBytes[bufPos++] = (byte)' ';
+ _bufBytes[_bufPos++] = (byte)' ';
}
if (subset != null)
{
- bufBytes[bufPos++] = (byte)'[';
+ _bufBytes[_bufPos++] = (byte)'[';
RawText(subset);
- bufBytes[bufPos++] = (byte)']';
+ _bufBytes[_bufPos++] = (byte)']';
}
- bufBytes[bufPos++] = (byte)'>';
+ _bufBytes[_bufPos++] = (byte)'>';
}
// Serialize the beginning of an element start tag: "<prefix:localName"
Debug.Assert(localName != null && localName.Length > 0);
Debug.Assert(prefix != null);
- bufBytes[bufPos++] = (byte)'<';
+ _bufBytes[_bufPos++] = (byte)'<';
if (prefix != null && prefix.Length != 0)
{
RawText(prefix);
- bufBytes[bufPos++] = (byte)':';
+ _bufBytes[_bufPos++] = (byte)':';
}
RawText(localName);
- attrEndPos = bufPos;
+ _attrEndPos = _bufPos;
}
// Serialize the end of an element start tag in preparation for content serialization: ">"
internal override void StartElementContent()
{
- bufBytes[bufPos++] = (byte)'>';
+ _bufBytes[_bufPos++] = (byte)'>';
// StartElementContent is always called; therefore, in order to allow shortcut syntax, we save the
// position of the '>' character. If WriteEndElement is called and no other characters have been
// output, then the '>' character can be overwritten with the shortcut syntax " />".
- contentPos = bufPos;
+ _contentPos = _bufPos;
}
// Serialize an element end tag: "</prefix:localName>", if content was output. Otherwise, serialize
Debug.Assert(localName != null && localName.Length > 0);
Debug.Assert(prefix != null);
- if (contentPos != bufPos)
+ if (_contentPos != _bufPos)
{
// Content has been output, so can't use shortcut syntax
- bufBytes[bufPos++] = (byte)'<';
- bufBytes[bufPos++] = (byte)'/';
+ _bufBytes[_bufPos++] = (byte)'<';
+ _bufBytes[_bufPos++] = (byte)'/';
if (prefix != null && prefix.Length != 0)
{
RawText(prefix);
- bufBytes[bufPos++] = (byte)':';
+ _bufBytes[_bufPos++] = (byte)':';
}
RawText(localName);
- bufBytes[bufPos++] = (byte)'>';
+ _bufBytes[_bufPos++] = (byte)'>';
}
else
{
// Use shortcut syntax; overwrite the already output '>' character
- bufPos--;
- bufBytes[bufPos++] = (byte)' ';
- bufBytes[bufPos++] = (byte)'/';
- bufBytes[bufPos++] = (byte)'>';
+ _bufPos--;
+ _bufBytes[_bufPos++] = (byte)' ';
+ _bufBytes[_bufPos++] = (byte)'/';
+ _bufBytes[_bufPos++] = (byte)'>';
}
}
Debug.Assert(localName != null && localName.Length > 0);
Debug.Assert(prefix != null);
- bufBytes[bufPos++] = (byte)'<';
- bufBytes[bufPos++] = (byte)'/';
+ _bufBytes[_bufPos++] = (byte)'<';
+ _bufBytes[_bufPos++] = (byte)'/';
if (prefix != null && prefix.Length != 0)
{
RawText(prefix);
- bufBytes[bufPos++] = (byte)':';
+ _bufBytes[_bufPos++] = (byte)':';
}
RawText(localName);
- bufBytes[bufPos++] = (byte)'>';
+ _bufBytes[_bufPos++] = (byte)'>';
}
// Serialize an attribute tag using double quotes around the attribute value: 'prefix:localName="'
Debug.Assert(localName != null && localName.Length > 0);
Debug.Assert(prefix != null);
- if (attrEndPos == bufPos)
+ if (_attrEndPos == _bufPos)
{
- bufBytes[bufPos++] = (byte)' ';
+ _bufBytes[_bufPos++] = (byte)' ';
}
if (prefix != null && prefix.Length > 0)
{
RawText(prefix);
- bufBytes[bufPos++] = (byte)':';
+ _bufBytes[_bufPos++] = (byte)':';
}
RawText(localName);
- bufBytes[bufPos++] = (byte)'=';
- bufBytes[bufPos++] = (byte)'"';
+ _bufBytes[_bufPos++] = (byte)'=';
+ _bufBytes[_bufPos++] = (byte)'"';
- inAttributeValue = true;
+ _inAttributeValue = true;
}
// Serialize the end of an attribute value using double quotes: '"'
public override void WriteEndAttribute()
{
- bufBytes[bufPos++] = (byte)'"';
- inAttributeValue = false;
- attrEndPos = bufPos;
+ _bufBytes[_bufPos++] = (byte)'"';
+ _inAttributeValue = false;
+ _attrEndPos = _bufPos;
}
internal override void WriteNamespaceDeclaration(string prefix, string namespaceName)
{
RawText(" xmlns:");
RawText(prefix);
- bufBytes[bufPos++] = (byte)'=';
- bufBytes[bufPos++] = (byte)'"';
+ _bufBytes[_bufPos++] = (byte)'=';
+ _bufBytes[_bufPos++] = (byte)'"';
}
- inAttributeValue = true;
+ _inAttributeValue = true;
}
internal override void WriteEndNamespaceDeclaration()
{
- inAttributeValue = false;
+ _inAttributeValue = false;
- bufBytes[bufPos++] = (byte)'"';
- attrEndPos = bufPos;
+ _bufBytes[_bufPos++] = (byte)'"';
+ _attrEndPos = _bufPos;
}
// Serialize a CData section. If the "]]>" pattern is found within
{
Debug.Assert(text != null);
- if (mergeCDataSections && bufPos == cdataPos)
+ if (_mergeCDataSections && _bufPos == _cdataPos)
{
// Merge adjacent cdata sections - overwrite the "]]>" characters
- Debug.Assert(bufPos >= 4);
- bufPos -= 3;
+ Debug.Assert(_bufPos >= 4);
+ _bufPos -= 3;
}
else
{
// Start a new cdata section
- bufBytes[bufPos++] = (byte)'<';
- bufBytes[bufPos++] = (byte)'!';
- bufBytes[bufPos++] = (byte)'[';
- bufBytes[bufPos++] = (byte)'C';
- bufBytes[bufPos++] = (byte)'D';
- bufBytes[bufPos++] = (byte)'A';
- bufBytes[bufPos++] = (byte)'T';
- bufBytes[bufPos++] = (byte)'A';
- bufBytes[bufPos++] = (byte)'[';
+ _bufBytes[_bufPos++] = (byte)'<';
+ _bufBytes[_bufPos++] = (byte)'!';
+ _bufBytes[_bufPos++] = (byte)'[';
+ _bufBytes[_bufPos++] = (byte)'C';
+ _bufBytes[_bufPos++] = (byte)'D';
+ _bufBytes[_bufPos++] = (byte)'A';
+ _bufBytes[_bufPos++] = (byte)'T';
+ _bufBytes[_bufPos++] = (byte)'A';
+ _bufBytes[_bufPos++] = (byte)'[';
}
WriteCDataSection(text);
- bufBytes[bufPos++] = (byte)']';
- bufBytes[bufPos++] = (byte)']';
- bufBytes[bufPos++] = (byte)'>';
+ _bufBytes[_bufPos++] = (byte)']';
+ _bufBytes[_bufPos++] = (byte)']';
+ _bufBytes[_bufPos++] = (byte)'>';
- textPos = bufPos;
- cdataPos = bufPos;
+ _textPos = _bufPos;
+ _cdataPos = _bufPos;
}
// Serialize a comment.
{
Debug.Assert(text != null);
- bufBytes[bufPos++] = (byte)'<';
- bufBytes[bufPos++] = (byte)'!';
- bufBytes[bufPos++] = (byte)'-';
- bufBytes[bufPos++] = (byte)'-';
+ _bufBytes[_bufPos++] = (byte)'<';
+ _bufBytes[_bufPos++] = (byte)'!';
+ _bufBytes[_bufPos++] = (byte)'-';
+ _bufBytes[_bufPos++] = (byte)'-';
WriteCommentOrPi(text, '-');
- bufBytes[bufPos++] = (byte)'-';
- bufBytes[bufPos++] = (byte)'-';
- bufBytes[bufPos++] = (byte)'>';
+ _bufBytes[_bufPos++] = (byte)'-';
+ _bufBytes[_bufPos++] = (byte)'-';
+ _bufBytes[_bufPos++] = (byte)'>';
}
// Serialize a processing instruction.
Debug.Assert(name != null && name.Length > 0);
Debug.Assert(text != null);
- bufBytes[bufPos++] = (byte)'<';
- bufBytes[bufPos++] = (byte)'?';
+ _bufBytes[_bufPos++] = (byte)'<';
+ _bufBytes[_bufPos++] = (byte)'?';
RawText(name);
if (text.Length > 0)
{
- bufBytes[bufPos++] = (byte)' ';
+ _bufBytes[_bufPos++] = (byte)' ';
WriteCommentOrPi(text, '?');
}
- bufBytes[bufPos++] = (byte)'?';
- bufBytes[bufPos++] = (byte)'>';
+ _bufBytes[_bufPos++] = (byte)'?';
+ _bufBytes[_bufPos++] = (byte)'>';
}
// Serialize an entity reference.
{
Debug.Assert(name != null && name.Length > 0);
- bufBytes[bufPos++] = (byte)'&';
+ _bufBytes[_bufPos++] = (byte)'&';
RawText(name);
- bufBytes[bufPos++] = (byte)';';
+ _bufBytes[_bufPos++] = (byte)';';
- if (bufPos > bufLen)
+ if (_bufPos > _bufLen)
{
FlushBuffer();
}
- textPos = bufPos;
+ _textPos = _bufPos;
}
// Serialize a character entity reference.
{
string strVal = ((int)ch).ToString("X", NumberFormatInfo.InvariantInfo);
- if (checkCharacters && !xmlCharType.IsCharData(ch))
+ if (_checkCharacters && !_xmlCharType.IsCharData(ch))
{
// we just have a single char, not a surrogate, therefore we have to pass in '\0' for the second char
throw XmlConvert.CreateInvalidCharException(ch, '\0');
}
- bufBytes[bufPos++] = (byte)'&';
- bufBytes[bufPos++] = (byte)'#';
- bufBytes[bufPos++] = (byte)'x';
+ _bufBytes[_bufPos++] = (byte)'&';
+ _bufBytes[_bufPos++] = (byte)'#';
+ _bufBytes[_bufPos++] = (byte)'x';
RawText(strVal);
- bufBytes[bufPos++] = (byte)';';
+ _bufBytes[_bufPos++] = (byte)';';
- if (bufPos > bufLen)
+ if (_bufPos > _bufLen)
{
FlushBuffer();
}
- textPos = bufPos;
+ _textPos = _bufPos;
}
// Serialize a whitespace node.
fixed (char* pSrc = ws)
{
char* pSrcEnd = pSrc + ws.Length;
- if (inAttributeValue)
+ if (_inAttributeValue)
{
WriteAttributeTextBlock(pSrc, pSrcEnd);
}
fixed (char* pSrc = text)
{
char* pSrcEnd = pSrc + text.Length;
- if (inAttributeValue)
+ if (_inAttributeValue)
{
WriteAttributeTextBlock(pSrc, pSrcEnd);
}
{
int surrogateChar = XmlCharType.CombineSurrogateChar(lowChar, highChar);
- bufBytes[bufPos++] = (byte)'&';
- bufBytes[bufPos++] = (byte)'#';
- bufBytes[bufPos++] = (byte)'x';
+ _bufBytes[_bufPos++] = (byte)'&';
+ _bufBytes[_bufPos++] = (byte)'#';
+ _bufBytes[_bufPos++] = (byte)'x';
RawText(surrogateChar.ToString("X", NumberFormatInfo.InvariantInfo));
- bufBytes[bufPos++] = (byte)';';
- textPos = bufPos;
+ _bufBytes[_bufPos++] = (byte)';';
+ _textPos = _bufPos;
}
// Serialize either attribute or element text using XML rules.
fixed (char* pSrcBegin = &buffer[index])
{
- if (inAttributeValue)
+ if (_inAttributeValue)
{
WriteAttributeTextBlock(pSrcBegin, pSrcBegin + count);
}
WriteRawWithCharChecking(pSrcBegin, pSrcBegin + count);
}
- textPos = bufPos;
+ _textPos = _bufPos;
}
// Serialize raw data.
WriteRawWithCharChecking(pSrcBegin, pSrcBegin + data.Length);
}
- textPos = bufPos;
+ _textPos = _bufPos;
}
// Flush all bytes in the buffer to output and close the output stream or writer.
finally
{
// Future calls to Close or Flush shouldn't write to Stream or Writer
- writeToNull = true;
+ _writeToNull = true;
- if (stream != null)
+ if (_stream != null)
{
try
{
- stream.Flush();
+ _stream.Flush();
}
finally
{
try
{
- if (closeOutput)
+ if (_closeOutput)
{
- stream.Dispose();
+ _stream.Dispose();
}
}
finally
{
- stream = null;
+ _stream = null;
}
}
}
{
FlushBuffer();
FlushEncoder();
- if (stream != null)
+ if (_stream != null)
{
- stream.Flush();
+ _stream.Flush();
}
}
try
{
// Output all characters (except for previous characters stored at beginning of buffer)
- if (!writeToNull)
+ if (!_writeToNull)
{
- if (bufPos - 1 > 0)
+ if (_bufPos - 1 > 0)
{
- Debug.Assert(stream != null);
- stream.Write(bufBytes, 1, bufPos - 1);
+ Debug.Assert(_stream != null);
+ _stream.Write(_bufBytes, 1, _bufPos - 1);
}
}
}
catch
{
// Future calls to flush (i.e. when Close() is called) don't attempt to write to stream
- writeToNull = true;
+ _writeToNull = true;
throw;
}
finally
{
// Move last buffer character to the beginning of the buffer (so that previous character can always be determined)
- bufBytes[0] = bufBytes[bufPos - 1];
- if (IsSurrogateByte(bufBytes[0]))
+ _bufBytes[0] = _bufBytes[_bufPos - 1];
+ if (IsSurrogateByte(_bufBytes[0]))
{
// Last character was the first byte in a surrogate encoding, so move last three
// bytes of encoding to the beginning of the buffer.
- bufBytes[1] = bufBytes[bufPos];
- bufBytes[2] = bufBytes[bufPos + 1];
- bufBytes[3] = bufBytes[bufPos + 2];
+ _bufBytes[1] = _bufBytes[_bufPos];
+ _bufBytes[2] = _bufBytes[_bufPos + 1];
+ _bufBytes[3] = _bufBytes[_bufPos + 2];
}
// Reset buffer position
- textPos = (textPos == bufPos) ? 1 : 0;
- attrEndPos = (attrEndPos == bufPos) ? 1 : 0;
- contentPos = 0; // Needs to be zero, since overwriting '>' character is no longer possible
- cdataPos = 0; // Needs to be zero, since overwriting ']]>' characters is no longer possible
- bufPos = 1; // Buffer position starts at 1, because we need to be able to safely step back -1 in case we need to
+ _textPos = (_textPos == _bufPos) ? 1 : 0;
+ _attrEndPos = (_attrEndPos == _bufPos) ? 1 : 0;
+ _contentPos = 0; // Needs to be zero, since overwriting '>' character is no longer possible
+ _cdataPos = 0; // Needs to be zero, since overwriting ']]>' characters is no longer possible
+ _bufPos = 1; // Buffer position starts at 1, because we need to be able to safely step back -1 in case we need to
// close an empty element or in CDATA section detection of double ]; bufBytes[0] will always be 0
}
}
// are entitized.
protected unsafe void WriteAttributeTextBlock(char* pSrc, char* pSrcEnd)
{
- fixed (byte* pDstBegin = bufBytes)
+ fixed (byte* pDstBegin = _bufBytes)
{
- byte* pDst = pDstBegin + bufPos;
+ byte* pDst = pDstBegin + _bufPos;
int ch = 0;
while (true)
{
byte* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
- while (pDst < pDstEnd && (xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch <= 0x7F))
+ while (pDst < pDstEnd && (_xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch <= 0x7F))
{
*pDst = (byte)ch;
pDst++;
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
FlushBuffer();
pDst = pDstBegin + 1;
continue;
pDst++;
break;
case (char)0x9:
- if (newLineHandling == NewLineHandling.None)
+ if (_newLineHandling == NewLineHandling.None)
{
*pDst = (byte)ch;
pDst++;
}
break;
case (char)0xD:
- if (newLineHandling == NewLineHandling.None)
+ if (_newLineHandling == NewLineHandling.None)
{
*pDst = (byte)ch;
pDst++;
}
break;
case (char)0xA:
- if (newLineHandling == NewLineHandling.None)
+ if (_newLineHandling == NewLineHandling.None)
{
*pDst = (byte)ch;
pDst++;
}
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
}
}
// are entitized.
protected unsafe void WriteElementTextBlock(char* pSrc, char* pSrcEnd)
{
- fixed (byte* pDstBegin = bufBytes)
+ fixed (byte* pDstBegin = _bufBytes)
{
- byte* pDst = pDstBegin + bufPos;
+ byte* pDst = pDstBegin + _bufPos;
int ch = 0;
while (true)
{
byte* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
- while (pDst < pDstEnd && (xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch <= 0x7F))
+ while (pDst < pDstEnd && (_xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch <= 0x7F))
{
*pDst = (byte)ch;
pDst++;
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
FlushBuffer();
pDst = pDstBegin + 1;
continue;
pDst++;
break;
case (char)0xA:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
pDst = WriteNewLine(pDst);
}
}
break;
case (char)0xD:
- switch (newLineHandling)
+ switch (_newLineHandling)
{
case NewLineHandling.Replace:
// Replace "\r\n", or "\r" with NewLineChars
}
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
- textPos = bufPos;
- contentPos = 0;
+ _bufPos = (int)(pDst - pDstBegin);
+ _textPos = _bufPos;
+ _contentPos = 0;
}
}
protected unsafe void RawText(char* pSrcBegin, char* pSrcEnd)
{
- fixed (byte* pDstBegin = bufBytes)
+ fixed (byte* pDstBegin = _bufBytes)
{
- byte* pDst = pDstBegin + bufPos;
+ byte* pDst = pDstBegin + _bufPos;
char* pSrc = pSrcBegin;
int ch = 0;
while (true)
{
byte* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
while (pDst < pDstEnd && ((ch = *pSrc) <= 0x7F))
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
FlushBuffer();
pDst = pDstBegin + 1;
continue;
}
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
}
}
protected unsafe void WriteRawWithCharChecking(char* pSrcBegin, char* pSrcEnd)
{
- fixed (byte* pDstBegin = bufBytes)
+ fixed (byte* pDstBegin = _bufBytes)
{
char* pSrc = pSrcBegin;
- byte* pDst = pDstBegin + bufPos;
+ byte* pDst = pDstBegin + _bufPos;
int ch = 0;
while (true)
{
byte* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
- while (pDst < pDstEnd && (xmlCharType.IsTextChar((char)(ch = *pSrc)) && ch <= 0x7F))
+ while (pDst < pDstEnd && (_xmlCharType.IsTextChar((char)(ch = *pSrc)) && ch <= 0x7F))
{
*pDst = (byte)ch;
pDst++;
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
FlushBuffer();
pDst = pDstBegin + 1;
continue;
pDst++;
break;
case (char)0xD:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
// Normalize "\r\n", or "\r" to NewLineChars
if (pSrc + 1 < pSrcEnd && pSrc[1] == '\n')
}
break;
case (char)0xA:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
pDst = WriteNewLine(pDst);
}
}
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
}
}
{
if (text.Length == 0)
{
- if (bufPos >= bufLen)
+ if (_bufPos >= _bufLen)
{
FlushBuffer();
}
// write text
fixed (char* pSrcBegin = text)
- fixed (byte* pDstBegin = bufBytes)
+ fixed (byte* pDstBegin = _bufBytes)
{
char* pSrc = pSrcBegin;
char* pSrcEnd = pSrcBegin + text.Length;
- byte* pDst = pDstBegin + bufPos;
+ byte* pDst = pDstBegin + _bufPos;
int ch = 0;
while (true)
{
byte* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
- while (pDst < pDstEnd && (xmlCharType.IsTextChar((char)(ch = *pSrc)) && ch != stopChar && ch <= 0x7F))
+ while (pDst < pDstEnd && (_xmlCharType.IsTextChar((char)(ch = *pSrc)) && ch != stopChar && ch <= 0x7F))
{
*pDst = (byte)ch;
pDst++;
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
FlushBuffer();
pDst = pDstBegin + 1;
continue;
pDst++;
break;
case (char)0xD:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
// Normalize "\r\n", or "\r" to NewLineChars
if (pSrc + 1 < pSrcEnd && pSrc[1] == '\n')
}
break;
case (char)0xA:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
pDst = WriteNewLine(pDst);
}
}
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
}
}
{
if (text.Length == 0)
{
- if (bufPos >= bufLen)
+ if (_bufPos >= _bufLen)
{
FlushBuffer();
}
fixed (char* pSrcBegin = text)
- fixed (byte* pDstBegin = bufBytes)
+ fixed (byte* pDstBegin = _bufBytes)
{
char* pSrc = pSrcBegin;
char* pSrcEnd = pSrcBegin + text.Length;
- byte* pDst = pDstBegin + bufPos;
+ byte* pDst = pDstBegin + _bufPos;
int ch = 0;
while (true)
{
byte* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
- while (pDst < pDstEnd && (xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch != ']' && ch <= 0x7F))
+ while (pDst < pDstEnd && (_xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch != ']' && ch <= 0x7F))
{
*pDst = (byte)ch;
pDst++;
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
FlushBuffer();
pDst = pDstBegin + 1;
continue;
switch (ch)
{
case '>':
- if (hadDoubleBracket && pDst[-1] == (byte)']')
+ if (_hadDoubleBracket && pDst[-1] == (byte)']')
{ // pDst[-1] will always correct - there is a padding character at bufBytes[0]
// The characters "]]>" were found within the CData text
pDst = RawEndCData(pDst);
case ']':
if (pDst[-1] == (byte)']')
{ // pDst[-1] will always correct - there is a padding character at bufBytes[0]
- hadDoubleBracket = true;
+ _hadDoubleBracket = true;
}
else
{
- hadDoubleBracket = false;
+ _hadDoubleBracket = false;
}
*pDst = (byte)']';
pDst++;
break;
case (char)0xD:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
// Normalize "\r\n", or "\r" to NewLineChars
if (pSrc + 1 < pSrcEnd && pSrc[1] == '\n')
}
break;
case (char)0xA:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
pDst = WriteNewLine(pDst);
}
}
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
}
}
private unsafe byte* InvalidXmlChar(int ch, byte* pDst, bool entitize)
{
- Debug.Assert(!xmlCharType.IsWhiteSpace((char)ch));
- Debug.Assert(!xmlCharType.IsAttributeValueChar((char)ch));
+ Debug.Assert(!_xmlCharType.IsWhiteSpace((char)ch));
+ Debug.Assert(!_xmlCharType.IsAttributeValueChar((char)ch));
- if (checkCharacters)
+ if (_checkCharacters)
{
// This method will never be called on surrogates, so it is ok to pass in '\0' to the CreateInvalidCharException
throw XmlConvert.CreateInvalidCharException((char)ch, '\0');
// Write NewLineChars to the specified buffer position and return an updated position.
protected unsafe byte* WriteNewLine(byte* pDst)
{
- fixed (byte* pDstBegin = bufBytes)
+ fixed (byte* pDstBegin = _bufBytes)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
// Let RawText do the real work
- RawText(newLineChars);
- return pDstBegin + bufPos;
+ RawText(_newLineChars);
+ return pDstBegin + _bufPos;
}
}
{
if (allowOnlyWhitespace)
{
- if (!xmlCharType.IsOnlyWhitespace(chars))
+ if (!_xmlCharType.IsOnlyWhitespace(chars))
{
throw new ArgumentException(SR.Format(SR.Xml_IndentCharsNotWhitespace, propertyName));
}
string error = null;
for (int i = 0; i < chars.Length; i++)
{
- if (!xmlCharType.IsTextChar(chars[i]))
+ if (!_xmlCharType.IsTextChar(chars[i]))
{
switch (chars[i])
{
//
// Fields
//
- protected int indentLevel;
- protected bool newLineOnAttributes;
- protected string indentChars;
+ protected int _indentLevel;
+ protected bool _newLineOnAttributes;
+ protected string _indentChars;
- protected bool mixedContent;
+ protected bool _mixedContent;
private BitStack _mixedContentStack;
- protected ConformanceLevel conformanceLevel = ConformanceLevel.Auto;
+ protected ConformanceLevel _conformanceLevel = ConformanceLevel.Auto;
//
// Constructors
settings.ReadOnly = false;
settings.Indent = true;
- settings.IndentChars = indentChars;
- settings.NewLineOnAttributes = newLineOnAttributes;
+ settings.IndentChars = _indentChars;
+ settings.NewLineOnAttributes = _newLineOnAttributes;
settings.ReadOnly = true;
return settings;
public override void WriteDocType(string name, string pubid, string sysid, string subset)
{
// Add indentation
- if (!mixedContent && base.textPos != base.bufPos)
+ if (!_mixedContent && base._textPos != base._bufPos)
{
WriteIndent();
}
Debug.Assert(localName != null && localName.Length != 0 && prefix != null && ns != null);
// Add indentation
- if (!mixedContent && base.textPos != base.bufPos)
+ if (!_mixedContent && base._textPos != base._bufPos)
{
WriteIndent();
}
- indentLevel++;
- _mixedContentStack.PushBit(mixedContent);
+ _indentLevel++;
+ _mixedContentStack.PushBit(_mixedContent);
base.WriteStartElement(prefix, localName, ns);
}
internal override void StartElementContent()
{
// If this is the root element and we're writing a document
- // do not inherit the mixedContent flag into the root element.
+ // do not inherit the _mixedContent flag into the root element.
// This is to allow for whitespace nodes on root level
// without disabling indentation for the whole document.
- if (indentLevel == 1 && conformanceLevel == ConformanceLevel.Document)
+ if (_indentLevel == 1 && _conformanceLevel == ConformanceLevel.Document)
{
- mixedContent = false;
+ _mixedContent = false;
}
else
{
- mixedContent = _mixedContentStack.PeekBit();
+ _mixedContent = _mixedContentStack.PeekBit();
}
base.StartElementContent();
}
internal override void OnRootElement(ConformanceLevel currentConformanceLevel)
{
// Just remember the current conformance level
- conformanceLevel = currentConformanceLevel;
+ _conformanceLevel = currentConformanceLevel;
}
internal override void WriteEndElement(string prefix, string localName, string ns)
{
// Add indentation
- indentLevel--;
- if (!mixedContent && base.contentPos != base.bufPos)
+ _indentLevel--;
+ if (!_mixedContent && base._contentPos != base._bufPos)
{
// There was content, so try to indent
- if (base.textPos != base.bufPos)
+ if (base._textPos != base._bufPos)
{
WriteIndent();
}
}
- mixedContent = _mixedContentStack.PopBit();
+ _mixedContent = _mixedContentStack.PopBit();
base.WriteEndElement(prefix, localName, ns);
}
internal override void WriteFullEndElement(string prefix, string localName, string ns)
{
// Add indentation
- indentLevel--;
- if (!mixedContent && base.contentPos != base.bufPos)
+ _indentLevel--;
+ if (!_mixedContent && base._contentPos != base._bufPos)
{
// There was content, so try to indent
- if (base.textPos != base.bufPos)
+ if (base._textPos != base._bufPos)
{
WriteIndent();
}
}
- mixedContent = _mixedContentStack.PopBit();
+ _mixedContent = _mixedContentStack.PopBit();
base.WriteFullEndElement(prefix, localName, ns);
}
public override void WriteStartAttribute(string prefix, string localName, string ns)
{
// Add indentation
- if (newLineOnAttributes)
+ if (_newLineOnAttributes)
{
WriteIndent();
}
public override void WriteCData(string text)
{
- mixedContent = true;
+ _mixedContent = true;
base.WriteCData(text);
}
public override void WriteComment(string text)
{
- if (!mixedContent && base.textPos != base.bufPos)
+ if (!_mixedContent && base._textPos != base._bufPos)
{
WriteIndent();
}
public override void WriteProcessingInstruction(string target, string text)
{
- if (!mixedContent && base.textPos != base.bufPos)
+ if (!_mixedContent && base._textPos != base._bufPos)
{
WriteIndent();
}
public override void WriteEntityRef(string name)
{
- mixedContent = true;
+ _mixedContent = true;
base.WriteEntityRef(name);
}
public override void WriteCharEntity(char ch)
{
- mixedContent = true;
+ _mixedContent = true;
base.WriteCharEntity(ch);
}
public override void WriteSurrogateCharEntity(char lowChar, char highChar)
{
- mixedContent = true;
+ _mixedContent = true;
base.WriteSurrogateCharEntity(lowChar, highChar);
}
public override void WriteWhitespace(string ws)
{
- mixedContent = true;
+ _mixedContent = true;
base.WriteWhitespace(ws);
}
public override void WriteString(string text)
{
- mixedContent = true;
+ _mixedContent = true;
base.WriteString(text);
}
public override void WriteChars(char[] buffer, int index, int count)
{
- mixedContent = true;
+ _mixedContent = true;
base.WriteChars(buffer, index, count);
}
public override void WriteRaw(char[] buffer, int index, int count)
{
- mixedContent = true;
+ _mixedContent = true;
base.WriteRaw(buffer, index, count);
}
public override void WriteRaw(string data)
{
- mixedContent = true;
+ _mixedContent = true;
base.WriteRaw(data);
}
public override void WriteBase64(byte[] buffer, int index, int count)
{
- mixedContent = true;
+ _mixedContent = true;
base.WriteBase64(buffer, index, count);
}
//
private void Init(XmlWriterSettings settings)
{
- indentLevel = 0;
- indentChars = settings.IndentChars;
- newLineOnAttributes = settings.NewLineOnAttributes;
+ _indentLevel = 0;
+ _indentChars = settings.IndentChars;
+ _newLineOnAttributes = settings.NewLineOnAttributes;
_mixedContentStack = new BitStack();
// check indent characters that they are valid XML characters
- if (base.checkCharacters)
+ if (base._checkCharacters)
{
- if (newLineOnAttributes)
+ if (_newLineOnAttributes)
{
- base.ValidateContentChars(indentChars, "IndentChars", true);
- base.ValidateContentChars(newLineChars, "NewLineChars", true);
+ base.ValidateContentChars(_indentChars, "IndentChars", true);
+ base.ValidateContentChars(_newLineChars, "NewLineChars", true);
}
else
{
- base.ValidateContentChars(indentChars, "IndentChars", false);
- if (base.newLineHandling != NewLineHandling.Replace)
+ base.ValidateContentChars(_indentChars, "IndentChars", false);
+ if (base._newLineHandling != NewLineHandling.Replace)
{
- base.ValidateContentChars(newLineChars, "NewLineChars", false);
+ base.ValidateContentChars(_newLineChars, "NewLineChars", false);
}
}
}
// Add indentation to output. Write newline and then repeat IndentChars for each indent level.
private void WriteIndent()
{
- RawText(base.newLineChars);
- for (int i = indentLevel; i > 0; i--)
+ RawText(base._newLineChars);
+ for (int i = _indentLevel; i > 0; i--)
{
- RawText(indentChars);
+ RawText(_indentChars);
}
}
}
{
CheckAsyncCall();
// Output xml declaration only if user allows it and it was not already output
- if (!omitXmlDeclaration && !autoXmlDeclaration)
+ if (!_omitXmlDeclaration && !_autoXmlDeclaration)
{
await RawTextAsync("<?xml version=\"").ConfigureAwait(false);
await RawTextAsync("1.0").ConfigureAwait(false);
// Encoding
- if (encoding != null)
+ if (_encoding != null)
{
await RawTextAsync("\" encoding=\"").ConfigureAwait(false);
- await RawTextAsync(encoding.WebName).ConfigureAwait(false);
+ await RawTextAsync(_encoding.WebName).ConfigureAwait(false);
}
// Standalone
{
CheckAsyncCall();
// Output xml declaration only if user allows it and it was not already output
- if (!omitXmlDeclaration && !autoXmlDeclaration)
+ if (!_omitXmlDeclaration && !_autoXmlDeclaration)
{
return WriteProcessingInstructionAsync("xml", xmldecl);
}
finally
{
// Future calls to Close or Flush shouldn't write to Stream or Writer
- writeToNull = true;
+ _writeToNull = true;
- if (stream != null)
+ if (_stream != null)
{
try
{
- await stream.FlushAsync().ConfigureAwait(false);
+ await _stream.FlushAsync().ConfigureAwait(false);
}
finally
{
try
{
- if (closeOutput)
+ if (_closeOutput)
{
- await stream.DisposeAsync().ConfigureAwait(false);
+ await _stream.DisposeAsync().ConfigureAwait(false);
}
}
finally
{
- stream = null;
+ _stream = null;
}
}
}
{
await RawTextAsync(sysid).ConfigureAwait(false);
}
- bufBytes[bufPos++] = (byte)'"';
+ _bufBytes[_bufPos++] = (byte)'"';
}
else if (sysid != null)
{
await RawTextAsync(" SYSTEM \"").ConfigureAwait(false);
await RawTextAsync(sysid).ConfigureAwait(false);
- bufBytes[bufPos++] = (byte)'"';
+ _bufBytes[_bufPos++] = (byte)'"';
}
else
{
- bufBytes[bufPos++] = (byte)' ';
+ _bufBytes[_bufPos++] = (byte)' ';
}
if (subset != null)
{
- bufBytes[bufPos++] = (byte)'[';
+ _bufBytes[_bufPos++] = (byte)'[';
await RawTextAsync(subset).ConfigureAwait(false);
- bufBytes[bufPos++] = (byte)']';
+ _bufBytes[_bufPos++] = (byte)']';
}
- bufBytes[bufPos++] = (byte)'>';
+ _bufBytes[_bufPos++] = (byte)'>';
}
// Serialize the beginning of an element start tag: "<prefix:localName"
Debug.Assert(prefix != null);
Task task;
- bufBytes[bufPos++] = (byte)'<';
+ _bufBytes[_bufPos++] = (byte)'<';
if (prefix != null && prefix.Length != 0)
{
task = RawTextAsync(prefix, ":", localName);
private void WriteStartElementAsync_SetAttEndPos()
{
- attrEndPos = bufPos;
+ _attrEndPos = _bufPos;
}
// Serialize an element end tag: "</prefix:localName>", if content was output. Otherwise, serialize
Debug.Assert(localName != null && localName.Length > 0);
Debug.Assert(prefix != null);
- if (contentPos != bufPos)
+ if (_contentPos != _bufPos)
{
// Content has been output, so can't use shortcut syntax
- bufBytes[bufPos++] = (byte)'<';
- bufBytes[bufPos++] = (byte)'/';
+ _bufBytes[_bufPos++] = (byte)'<';
+ _bufBytes[_bufPos++] = (byte)'/';
if (prefix != null && prefix.Length != 0)
{
else
{
// Use shortcut syntax; overwrite the already output '>' character
- bufPos--;
- bufBytes[bufPos++] = (byte)' ';
- bufBytes[bufPos++] = (byte)'/';
- bufBytes[bufPos++] = (byte)'>';
+ _bufPos--;
+ _bufBytes[_bufPos++] = (byte)' ';
+ _bufBytes[_bufPos++] = (byte)'/';
+ _bufBytes[_bufPos++] = (byte)'>';
}
return Task.CompletedTask;
}
Debug.Assert(localName != null && localName.Length > 0);
Debug.Assert(prefix != null);
- bufBytes[bufPos++] = (byte)'<';
- bufBytes[bufPos++] = (byte)'/';
+ _bufBytes[_bufPos++] = (byte)'<';
+ _bufBytes[_bufPos++] = (byte)'/';
if (prefix != null && prefix.Length != 0)
{
Debug.Assert(localName != null && localName.Length > 0);
Debug.Assert(prefix != null);
- if (attrEndPos == bufPos)
+ if (_attrEndPos == _bufPos)
{
- bufBytes[bufPos++] = (byte)' ';
+ _bufBytes[_bufPos++] = (byte)' ';
}
Task task;
if (prefix != null && prefix.Length > 0)
private void WriteStartAttribute_SetInAttribute()
{
- bufBytes[bufPos++] = (byte)'=';
- bufBytes[bufPos++] = (byte)'"';
- inAttributeValue = true;
+ _bufBytes[_bufPos++] = (byte)'=';
+ _bufBytes[_bufPos++] = (byte)'"';
+ _inAttributeValue = true;
}
// Serialize the end of an attribute value using double quotes: '"'
{
CheckAsyncCall();
- bufBytes[bufPos++] = (byte)'"';
- inAttributeValue = false;
- attrEndPos = bufPos;
+ _bufBytes[_bufPos++] = (byte)'"';
+ _inAttributeValue = false;
+ _attrEndPos = _bufPos;
return Task.CompletedTask;
}
{
await RawTextAsync(" xmlns:").ConfigureAwait(false);
await RawTextAsync(prefix).ConfigureAwait(false);
- bufBytes[bufPos++] = (byte)'=';
- bufBytes[bufPos++] = (byte)'"';
+ _bufBytes[_bufPos++] = (byte)'=';
+ _bufBytes[_bufPos++] = (byte)'"';
}
- inAttributeValue = true;
+ _inAttributeValue = true;
}
internal override Task WriteEndNamespaceDeclarationAsync()
{
CheckAsyncCall();
- inAttributeValue = false;
+ _inAttributeValue = false;
- bufBytes[bufPos++] = (byte)'"';
- attrEndPos = bufPos;
+ _bufBytes[_bufPos++] = (byte)'"';
+ _attrEndPos = _bufPos;
return Task.CompletedTask;
}
CheckAsyncCall();
Debug.Assert(text != null);
- if (mergeCDataSections && bufPos == cdataPos)
+ if (_mergeCDataSections && _bufPos == _cdataPos)
{
// Merge adjacent cdata sections - overwrite the "]]>" characters
- Debug.Assert(bufPos >= 4);
- bufPos -= 3;
+ Debug.Assert(_bufPos >= 4);
+ _bufPos -= 3;
}
else
{
// Start a new cdata section
- bufBytes[bufPos++] = (byte)'<';
- bufBytes[bufPos++] = (byte)'!';
- bufBytes[bufPos++] = (byte)'[';
- bufBytes[bufPos++] = (byte)'C';
- bufBytes[bufPos++] = (byte)'D';
- bufBytes[bufPos++] = (byte)'A';
- bufBytes[bufPos++] = (byte)'T';
- bufBytes[bufPos++] = (byte)'A';
- bufBytes[bufPos++] = (byte)'[';
+ _bufBytes[_bufPos++] = (byte)'<';
+ _bufBytes[_bufPos++] = (byte)'!';
+ _bufBytes[_bufPos++] = (byte)'[';
+ _bufBytes[_bufPos++] = (byte)'C';
+ _bufBytes[_bufPos++] = (byte)'D';
+ _bufBytes[_bufPos++] = (byte)'A';
+ _bufBytes[_bufPos++] = (byte)'T';
+ _bufBytes[_bufPos++] = (byte)'A';
+ _bufBytes[_bufPos++] = (byte)'[';
}
await WriteCDataSectionAsync(text).ConfigureAwait(false);
- bufBytes[bufPos++] = (byte)']';
- bufBytes[bufPos++] = (byte)']';
- bufBytes[bufPos++] = (byte)'>';
+ _bufBytes[_bufPos++] = (byte)']';
+ _bufBytes[_bufPos++] = (byte)']';
+ _bufBytes[_bufPos++] = (byte)'>';
- textPos = bufPos;
- cdataPos = bufPos;
+ _textPos = _bufPos;
+ _cdataPos = _bufPos;
}
// Serialize a comment.
CheckAsyncCall();
Debug.Assert(text != null);
- bufBytes[bufPos++] = (byte)'<';
- bufBytes[bufPos++] = (byte)'!';
- bufBytes[bufPos++] = (byte)'-';
- bufBytes[bufPos++] = (byte)'-';
+ _bufBytes[_bufPos++] = (byte)'<';
+ _bufBytes[_bufPos++] = (byte)'!';
+ _bufBytes[_bufPos++] = (byte)'-';
+ _bufBytes[_bufPos++] = (byte)'-';
await WriteCommentOrPiAsync(text, '-').ConfigureAwait(false);
- bufBytes[bufPos++] = (byte)'-';
- bufBytes[bufPos++] = (byte)'-';
- bufBytes[bufPos++] = (byte)'>';
+ _bufBytes[_bufPos++] = (byte)'-';
+ _bufBytes[_bufPos++] = (byte)'-';
+ _bufBytes[_bufPos++] = (byte)'>';
}
// Serialize a processing instruction.
Debug.Assert(name != null && name.Length > 0);
Debug.Assert(text != null);
- bufBytes[bufPos++] = (byte)'<';
- bufBytes[bufPos++] = (byte)'?';
+ _bufBytes[_bufPos++] = (byte)'<';
+ _bufBytes[_bufPos++] = (byte)'?';
await RawTextAsync(name).ConfigureAwait(false);
if (text.Length > 0)
{
- bufBytes[bufPos++] = (byte)' ';
+ _bufBytes[_bufPos++] = (byte)' ';
await WriteCommentOrPiAsync(text, '?').ConfigureAwait(false);
}
- bufBytes[bufPos++] = (byte)'?';
- bufBytes[bufPos++] = (byte)'>';
+ _bufBytes[_bufPos++] = (byte)'?';
+ _bufBytes[_bufPos++] = (byte)'>';
}
// Serialize an entity reference.
CheckAsyncCall();
Debug.Assert(name != null && name.Length > 0);
- bufBytes[bufPos++] = (byte)'&';
+ _bufBytes[_bufPos++] = (byte)'&';
await RawTextAsync(name).ConfigureAwait(false);
- bufBytes[bufPos++] = (byte)';';
+ _bufBytes[_bufPos++] = (byte)';';
- if (bufPos > bufLen)
+ if (_bufPos > _bufLen)
{
await FlushBufferAsync().ConfigureAwait(false);
}
- textPos = bufPos;
+ _textPos = _bufPos;
}
// Serialize a character entity reference.
CheckAsyncCall();
string strVal = ((int)ch).ToString("X", NumberFormatInfo.InvariantInfo);
- if (checkCharacters && !xmlCharType.IsCharData(ch))
+ if (_checkCharacters && !_xmlCharType.IsCharData(ch))
{
// we just have a single char, not a surrogate, therefore we have to pass in '\0' for the second char
throw XmlConvert.CreateInvalidCharException(ch, '\0');
}
- bufBytes[bufPos++] = (byte)'&';
- bufBytes[bufPos++] = (byte)'#';
- bufBytes[bufPos++] = (byte)'x';
+ _bufBytes[_bufPos++] = (byte)'&';
+ _bufBytes[_bufPos++] = (byte)'#';
+ _bufBytes[_bufPos++] = (byte)'x';
await RawTextAsync(strVal).ConfigureAwait(false);
- bufBytes[bufPos++] = (byte)';';
+ _bufBytes[_bufPos++] = (byte)';';
- if (bufPos > bufLen)
+ if (_bufPos > _bufLen)
{
await FlushBufferAsync().ConfigureAwait(false);
}
- textPos = bufPos;
+ _textPos = _bufPos;
}
// Serialize a whitespace node.
CheckAsyncCall();
Debug.Assert(ws != null);
- if (inAttributeValue)
+ if (_inAttributeValue)
{
return WriteAttributeTextBlockAsync(ws);
}
CheckAsyncCall();
Debug.Assert(text != null);
- if (inAttributeValue)
+ if (_inAttributeValue)
{
return WriteAttributeTextBlockAsync(text);
}
int surrogateChar = XmlCharType.CombineSurrogateChar(lowChar, highChar);
- bufBytes[bufPos++] = (byte)'&';
- bufBytes[bufPos++] = (byte)'#';
- bufBytes[bufPos++] = (byte)'x';
+ _bufBytes[_bufPos++] = (byte)'&';
+ _bufBytes[_bufPos++] = (byte)'#';
+ _bufBytes[_bufPos++] = (byte)'x';
await RawTextAsync(surrogateChar.ToString("X", NumberFormatInfo.InvariantInfo)).ConfigureAwait(false);
- bufBytes[bufPos++] = (byte)';';
- textPos = bufPos;
+ _bufBytes[_bufPos++] = (byte)';';
+ _textPos = _bufPos;
}
// Serialize either attribute or element text using XML rules.
Debug.Assert(index >= 0);
Debug.Assert(count >= 0 && index + count <= buffer.Length);
- if (inAttributeValue)
+ if (_inAttributeValue)
{
return WriteAttributeTextBlockAsync(buffer, index, count);
}
await WriteRawWithCharCheckingAsync(buffer, index, count).ConfigureAwait(false);
- textPos = bufPos;
+ _textPos = _bufPos;
}
// Serialize raw data.
await WriteRawWithCharCheckingAsync(data).ConfigureAwait(false);
- textPos = bufPos;
+ _textPos = _bufPos;
}
// Flush all characters in the buffer to output and call Flush() on the output object.
CheckAsyncCall();
await FlushBufferAsync().ConfigureAwait(false);
- if (stream != null)
+ if (_stream != null)
{
- await stream.FlushAsync().ConfigureAwait(false);
+ await _stream.FlushAsync().ConfigureAwait(false);
}
}
try
{
// Output all characters (except for previous characters stored at beginning of buffer)
- if (!writeToNull)
+ if (!_writeToNull)
{
- if (bufPos - 1 > 0)
+ if (_bufPos - 1 > 0)
{
- Debug.Assert(stream != null);
- await stream.WriteAsync(bufBytes.AsMemory(1, bufPos - 1)).ConfigureAwait(false);
+ Debug.Assert(_stream != null);
+ await _stream.WriteAsync(_bufBytes.AsMemory(1, _bufPos - 1)).ConfigureAwait(false);
}
}
}
catch
{
// Future calls to flush (i.e. when Close() is called) don't attempt to write to stream
- writeToNull = true;
+ _writeToNull = true;
throw;
}
finally
{
// Move last buffer character to the beginning of the buffer (so that previous character can always be determined)
- bufBytes[0] = bufBytes[bufPos - 1];
+ _bufBytes[0] = _bufBytes[_bufPos - 1];
- if (IsSurrogateByte(bufBytes[0]))
+ if (IsSurrogateByte(_bufBytes[0]))
{
// Last character was the first byte in a surrogate encoding, so move last three
// bytes of encoding to the beginning of the buffer.
- bufBytes[1] = bufBytes[bufPos];
- bufBytes[2] = bufBytes[bufPos + 1];
- bufBytes[3] = bufBytes[bufPos + 2];
+ _bufBytes[1] = _bufBytes[_bufPos];
+ _bufBytes[2] = _bufBytes[_bufPos + 1];
+ _bufBytes[3] = _bufBytes[_bufPos + 2];
}
// Reset buffer position
- textPos = (textPos == bufPos) ? 1 : 0;
- attrEndPos = (attrEndPos == bufPos) ? 1 : 0;
- contentPos = 0; // Needs to be zero, since overwriting '>' character is no longer possible
- cdataPos = 0; // Needs to be zero, since overwriting ']]>' characters is no longer possible
- bufPos = 1; // Buffer position starts at 1, because we need to be able to safely step back -1 in case we need to
+ _textPos = (_textPos == _bufPos) ? 1 : 0;
+ _attrEndPos = (_attrEndPos == _bufPos) ? 1 : 0;
+ _contentPos = 0; // Needs to be zero, since overwriting '>' character is no longer possible
+ _cdataPos = 0; // Needs to be zero, since overwriting ']]>' characters is no longer possible
+ _bufPos = 1; // Buffer position starts at 1, because we need to be able to safely step back -1 in case we need to
// close an empty element or in CDATA section detection of double ]; _BUFFER[0] will always be 0
}
}
{
char* pRaw = pSrc;
- fixed (byte* pDstBegin = bufBytes)
+ fixed (byte* pDstBegin = _bufBytes)
{
- byte* pDst = pDstBegin + bufPos;
+ byte* pDst = pDstBegin + _bufPos;
int ch = 0;
while (true)
{
byte* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
- while (pDst < pDstEnd && (xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch <= 0x7F))
+ while (pDst < pDstEnd && (_xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch <= 0x7F))
{
*pDst = (byte)ch;
pDst++;
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
return (int)(pSrc - pRaw);
}
pDst++;
break;
case (char)0x9:
- if (newLineHandling == NewLineHandling.None)
+ if (_newLineHandling == NewLineHandling.None)
{
*pDst = (byte)ch;
pDst++;
}
break;
case (char)0xD:
- if (newLineHandling == NewLineHandling.None)
+ if (_newLineHandling == NewLineHandling.None)
{
*pDst = (byte)ch;
pDst++;
}
break;
case (char)0xA:
- if (newLineHandling == NewLineHandling.None)
+ if (_newLineHandling == NewLineHandling.None)
{
*pDst = (byte)ch;
pDst++;
}
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
}
return -1;
needWriteNewLine = false;
char* pRaw = pSrc;
- fixed (byte* pDstBegin = bufBytes)
+ fixed (byte* pDstBegin = _bufBytes)
{
- byte* pDst = pDstBegin + bufPos;
+ byte* pDst = pDstBegin + _bufPos;
int ch = 0;
while (true)
{
byte* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
- while (pDst < pDstEnd && (xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch <= 0x7F))
+ while (pDst < pDstEnd && (_xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch <= 0x7F))
{
*pDst = (byte)ch;
pDst++;
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
return (int)(pSrc - pRaw);
}
pDst++;
break;
case (char)0xA:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
needWriteNewLine = true;
return (int)(pSrc - pRaw);
}
}
break;
case (char)0xD:
- switch (newLineHandling)
+ switch (_newLineHandling)
{
case NewLineHandling.Replace:
// Replace "\r\n", or "\r" with NewLineChars
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
needWriteNewLine = true;
return (int)(pSrc - pRaw);
}
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
- textPos = bufPos;
- contentPos = 0;
+ _bufPos = (int)(pDst - pDstBegin);
+ _textPos = _bufPos;
+ _contentPos = 0;
}
return -1;
needWriteNewLine = false;
if (count == 0)
{
- contentPos = 0;
+ _contentPos = 0;
return -1;
}
fixed (char* pSrc = &chars[index])
needWriteNewLine = false;
if (count == 0)
{
- contentPos = 0;
+ _contentPos = 0;
return -1;
}
fixed (char* pSrc = text)
if (needWriteNewLine)
{
//hit WriteNewLine
- await RawTextAsync(newLineChars).ConfigureAwait(false);
+ await RawTextAsync(_newLineChars).ConfigureAwait(false);
curIndex++;
leftCount--;
}
if (newLine)
{
- await RawTextAsync(newLineChars).ConfigureAwait(false);
+ await RawTextAsync(_newLineChars).ConfigureAwait(false);
curIndex++;
leftCount--;
}
if (needWriteNewLine)
{
//hit WriteNewLine
- await RawTextAsync(newLineChars).ConfigureAwait(false);
+ await RawTextAsync(_newLineChars).ConfigureAwait(false);
curIndex++;
leftCount--;
}
{
char* pRaw = pSrcBegin;
- fixed (byte* pDstBegin = bufBytes)
+ fixed (byte* pDstBegin = _bufBytes)
{
- byte* pDst = pDstBegin + bufPos;
+ byte* pDst = pDstBegin + _bufPos;
char* pSrc = pSrcBegin;
int ch = 0;
while (true)
{
byte* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
while (pDst < pDstEnd && ((ch = *pSrc) <= 0x7F))
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
return (int)(pSrc - pRaw);
}
}
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
}
return -1;
needWriteNewLine = false;
char* pRaw = pSrcBegin;
- fixed (byte* pDstBegin = bufBytes)
+ fixed (byte* pDstBegin = _bufBytes)
{
char* pSrc = pSrcBegin;
- byte* pDst = pDstBegin + bufPos;
+ byte* pDst = pDstBegin + _bufPos;
int ch = 0;
while (true)
{
byte* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
- while (pDst < pDstEnd && (xmlCharType.IsTextChar((char)(ch = *pSrc)) && ch <= 0x7F))
+ while (pDst < pDstEnd && (_xmlCharType.IsTextChar((char)(ch = *pSrc)) && ch <= 0x7F))
{
*pDst = (byte)ch;
pDst++;
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
return (int)(pSrc - pRaw);
}
pDst++;
break;
case (char)0xD:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
// Normalize "\r\n", or "\r" to NewLineChars
if (pSrc + 1 < pSrcEnd && pSrc[1] == '\n')
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
needWriteNewLine = true;
return (int)(pSrc - pRaw);
}
}
break;
case (char)0xA:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
needWriteNewLine = true;
return (int)(pSrc - pRaw);
}
}
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
}
return -1;
leftCount -= writeLen;
if (needWriteNewLine)
{
- await RawTextAsync(newLineChars).ConfigureAwait(false);
+ await RawTextAsync(_newLineChars).ConfigureAwait(false);
curIndex++;
leftCount--;
}
leftCount -= writeLen;
if (needWriteNewLine)
{
- await RawTextAsync(newLineChars).ConfigureAwait(false);
+ await RawTextAsync(_newLineChars).ConfigureAwait(false);
curIndex++;
leftCount--;
}
{
char* pSrcBegin = pSrcText + index;
- fixed (byte* pDstBegin = bufBytes)
+ fixed (byte* pDstBegin = _bufBytes)
{
char* pSrc = pSrcBegin;
char* pSrcEnd = pSrcBegin + count;
- byte* pDst = pDstBegin + bufPos;
+ byte* pDst = pDstBegin + _bufPos;
int ch = 0;
while (true)
{
byte* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
- while (pDst < pDstEnd && (xmlCharType.IsTextChar((char)(ch = *pSrc)) && ch != stopChar && ch <= 0x7F))
+ while (pDst < pDstEnd && (_xmlCharType.IsTextChar((char)(ch = *pSrc)) && ch != stopChar && ch <= 0x7F))
{
*pDst = (byte)ch;
pDst++;
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
return (int)(pSrc - pRaw);
}
pDst++;
break;
case (char)0xD:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
// Normalize "\r\n", or "\r" to NewLineChars
if (pSrc + 1 < pSrcEnd && pSrc[1] == '\n')
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
needWriteNewLine = true;
return (int)(pSrc - pRaw);
}
}
break;
case (char)0xA:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
needWriteNewLine = true;
return (int)(pSrc - pRaw);
}
}
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
}
return -1;
{
if (text.Length == 0)
{
- if (bufPos >= bufLen)
+ if (_bufPos >= _bufLen)
{
await FlushBufferAsync().ConfigureAwait(false);
}
leftCount -= writeLen;
if (needWriteNewLine)
{
- await RawTextAsync(newLineChars).ConfigureAwait(false);
+ await RawTextAsync(_newLineChars).ConfigureAwait(false);
curIndex++;
leftCount--;
}
{
char* pSrcBegin = pSrcText + index;
- fixed (byte* pDstBegin = bufBytes)
+ fixed (byte* pDstBegin = _bufBytes)
{
char* pSrc = pSrcBegin;
char* pRaw = pSrc;
- byte* pDst = pDstBegin + bufPos;
+ byte* pDst = pDstBegin + _bufPos;
int ch = 0;
while (true)
{
byte* pDstEnd = pDst + (pSrcEnd - pSrc);
- if (pDstEnd > pDstBegin + bufLen)
+ if (pDstEnd > pDstBegin + _bufLen)
{
- pDstEnd = pDstBegin + bufLen;
+ pDstEnd = pDstBegin + _bufLen;
}
- while (pDst < pDstEnd && (xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch != ']' && ch <= 0x7F))
+ while (pDst < pDstEnd && (_xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch != ']' && ch <= 0x7F))
{
*pDst = (byte)ch;
pDst++;
// end of buffer
if (pDst >= pDstEnd)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
return (int)(pSrc - pRaw);
}
switch (ch)
{
case '>':
- if (hadDoubleBracket && pDst[-1] == (byte)']')
+ if (_hadDoubleBracket && pDst[-1] == (byte)']')
{ // pDst[-1] will always correct - there is a padding character at _BUFFER[0]
// The characters "]]>" were found within the CData text
pDst = RawEndCData(pDst);
case ']':
if (pDst[-1] == (byte)']')
{ // pDst[-1] will always correct - there is a padding character at _BUFFER[0]
- hadDoubleBracket = true;
+ _hadDoubleBracket = true;
}
else
{
- hadDoubleBracket = false;
+ _hadDoubleBracket = false;
}
*pDst = (byte)']';
pDst++;
break;
case (char)0xD:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
// Normalize "\r\n", or "\r" to NewLineChars
if (pSrc + 1 < pSrcEnd && pSrc[1] == '\n')
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
needWriteNewLine = true;
return (int)(pSrc - pRaw);
}
}
break;
case (char)0xA:
- if (newLineHandling == NewLineHandling.Replace)
+ if (_newLineHandling == NewLineHandling.Replace)
{
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
needWriteNewLine = true;
return (int)(pSrc - pRaw);
}
}
pSrc++;
}
- bufPos = (int)(pDst - pDstBegin);
+ _bufPos = (int)(pDst - pDstBegin);
}
return -1;
{
if (text.Length == 0)
{
- if (bufPos >= bufLen)
+ if (_bufPos >= _bufLen)
{
await FlushBufferAsync().ConfigureAwait(false);
}
leftCount -= writeLen;
if (needWriteNewLine)
{
- await RawTextAsync(newLineChars).ConfigureAwait(false);
+ await RawTextAsync(_newLineChars).ConfigureAwait(false);
curIndex++;
leftCount--;
}
{
CheckAsyncCall();
// Add indentation
- if (!mixedContent && base.textPos != base.bufPos)
+ if (!_mixedContent && base._textPos != base._bufPos)
{
await WriteIndentAsync().ConfigureAwait(false);
}
Debug.Assert(localName != null && localName.Length != 0 && prefix != null && ns != null);
// Add indentation
- if (!mixedContent && base.textPos != base.bufPos)
+ if (!_mixedContent && base._textPos != base._bufPos)
{
await WriteIndentAsync().ConfigureAwait(false);
}
- indentLevel++;
- _mixedContentStack.PushBit(mixedContent);
+ _indentLevel++;
+ _mixedContentStack.PushBit(_mixedContent);
await base.WriteStartElementAsync(prefix, localName, ns).ConfigureAwait(false);
}
{
CheckAsyncCall();
// Add indentation
- indentLevel--;
- if (!mixedContent && base.contentPos != base.bufPos)
+ _indentLevel--;
+ if (!_mixedContent && base._contentPos != base._bufPos)
{
// There was content, so try to indent
- if (base.textPos != base.bufPos)
+ if (base._textPos != base._bufPos)
{
await WriteIndentAsync().ConfigureAwait(false);
}
}
- mixedContent = _mixedContentStack.PopBit();
+ _mixedContent = _mixedContentStack.PopBit();
await base.WriteEndElementAsync(prefix, localName, ns).ConfigureAwait(false);
}
{
CheckAsyncCall();
// Add indentation
- indentLevel--;
- if (!mixedContent && base.contentPos != base.bufPos)
+ _indentLevel--;
+ if (!_mixedContent && base._contentPos != base._bufPos)
{
// There was content, so try to indent
- if (base.textPos != base.bufPos)
+ if (base._textPos != base._bufPos)
{
await WriteIndentAsync().ConfigureAwait(false);
}
}
- mixedContent = _mixedContentStack.PopBit();
+ _mixedContent = _mixedContentStack.PopBit();
await base.WriteFullEndElementAsync(prefix, localName, ns).ConfigureAwait(false);
}
{
CheckAsyncCall();
// Add indentation
- if (newLineOnAttributes)
+ if (_newLineOnAttributes)
{
await WriteIndentAsync().ConfigureAwait(false);
}
public override Task WriteCDataAsync(string text)
{
CheckAsyncCall();
- mixedContent = true;
+ _mixedContent = true;
return base.WriteCDataAsync(text);
}
public override async Task WriteCommentAsync(string text)
{
CheckAsyncCall();
- if (!mixedContent && base.textPos != base.bufPos)
+ if (!_mixedContent && base._textPos != base._bufPos)
{
await WriteIndentAsync().ConfigureAwait(false);
}
public override async Task WriteProcessingInstructionAsync(string target, string text)
{
CheckAsyncCall();
- if (!mixedContent && base.textPos != base.bufPos)
+ if (!_mixedContent && base._textPos != base._bufPos)
{
await WriteIndentAsync().ConfigureAwait(false);
}
public override Task WriteEntityRefAsync(string name)
{
CheckAsyncCall();
- mixedContent = true;
+ _mixedContent = true;
return base.WriteEntityRefAsync(name);
}
public override Task WriteCharEntityAsync(char ch)
{
CheckAsyncCall();
- mixedContent = true;
+ _mixedContent = true;
return base.WriteCharEntityAsync(ch);
}
public override Task WriteSurrogateCharEntityAsync(char lowChar, char highChar)
{
CheckAsyncCall();
- mixedContent = true;
+ _mixedContent = true;
return base.WriteSurrogateCharEntityAsync(lowChar, highChar);
}
public override Task WriteWhitespaceAsync(string ws)
{
CheckAsyncCall();
- mixedContent = true;
+ _mixedContent = true;
return base.WriteWhitespaceAsync(ws);
}
public override Task WriteStringAsync(string text)
{
CheckAsyncCall();
- mixedContent = true;
+ _mixedContent = true;
return base.WriteStringAsync(text);
}
public override Task WriteCharsAsync(char[] buffer, int index, int count)
{
CheckAsyncCall();
- mixedContent = true;
+ _mixedContent = true;
return base.WriteCharsAsync(buffer, index, count);
}
public override Task WriteRawAsync(char[] buffer, int index, int count)
{
CheckAsyncCall();
- mixedContent = true;
+ _mixedContent = true;
return base.WriteRawAsync(buffer, index, count);
}
public override Task WriteRawAsync(string data)
{
CheckAsyncCall();
- mixedContent = true;
+ _mixedContent = true;
return base.WriteRawAsync(data);
}
public override Task WriteBase64Async(byte[] buffer, int index, int count)
{
CheckAsyncCall();
- mixedContent = true;
+ _mixedContent = true;
return base.WriteBase64Async(buffer, index, count);
}
private async Task WriteIndentAsync()
{
CheckAsyncCall();
- await RawTextAsync(base.newLineChars).ConfigureAwait(false);
- for (int i = indentLevel; i > 0; i--)
+ await RawTextAsync(base._newLineChars).ConfigureAwait(false);
+ for (int i = _indentLevel; i > 0; i--)
{
- await RawTextAsync(indentChars).ConfigureAwait(false);
+ await RawTextAsync(_indentChars).ConfigureAwait(false);
}
}
}