Skip to content

Commit

Permalink
Update xml char type (dotnet#41756)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wraith2 authored Sep 9, 2020
1 parent 2b43b86 commit f1f7681
Show file tree
Hide file tree
Showing 44 changed files with 4,383 additions and 484 deletions.
18 changes: 5 additions & 13 deletions src/libraries/System.Private.Xml/src/System.Private.Xml.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(CommonPath)System\Text\StringBuilderCache.cs"
Link="Common\System\StringBuilderCache.cs" />
<Compile Include="$(CommonPath)System\Marvin.cs"
Link="Common\System\Marvin.cs" />
<Compile Include="$(CommonPath)System\HexConverter.cs"
Link="Common\System\HexConverter.cs" />
<Compile Include="$(CommonPath)System\Text\StringBuilderCache.cs" Link="Common\System\StringBuilderCache.cs" />
<Compile Include="$(CommonPath)System\Marvin.cs" Link="Common\System\Marvin.cs" />
<Compile Include="$(CommonPath)System\HexConverter.cs" Link="Common\System\HexConverter.cs" />
<Compile Include="System\Xml\BinaryXml\XmlBinaryReader.cs" />
<Compile Include="System\Xml\BinaryXml\BinXmlToken.cs" />
<Compile Include="System\Xml\BinaryXml\SqlUtils.cs" />
Expand Down Expand Up @@ -552,11 +549,6 @@
<LogicalName>rss-0.91.dtd</LogicalName>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="System\Xml\XmlCharType.bin">
<LogicalName>XmlCharType.bin</LogicalName>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Reference Include="System.Reflection.Emit" />
<Reference Include="System.Reflection.Emit.ILGeneration" />
Expand All @@ -579,6 +571,7 @@
<Reference Include="System.ObjectModel" />
<Reference Include="System.Reflection.Primitives" />
<Reference Include="System.Runtime" />
<Reference Include="System.Runtime.CompilerServices.Unsafe" />
<Reference Include="System.Runtime.Extensions" />
<Reference Include="System.Runtime.InteropServices" />
<Reference Include="System.Security.Cryptography.Algorithms" />
Expand Down Expand Up @@ -790,8 +783,7 @@
<Compile Include="System\Xml\Xsl\Xslt\XsltLoader.cs" />
<Compile Include="System\Xml\Xsl\Xslt\XsltQilFactory.cs" />
<Compile Include="System\Xml\Xsl\Xslt\XslVisitor.cs" />
<Compile Include="$(CommonPath)System\LocalAppContextSwitches.Common.cs"
Link="System\LocalAppContextSwitches.Common.cs" />
<Compile Include="$(CommonPath)System\LocalAppContextSwitches.Common.cs" Link="System\LocalAppContextSwitches.Common.cs" />
<Compile Include="System\Xml\Core\LocalAppContextSwitches.cs" />
<Compile Include="$(CommonPath)System\CSharpHelpers.cs" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics;

namespace System.Xml
Expand Down Expand Up @@ -166,7 +165,6 @@ private unsafe void Decode(char* pChars, char* pCharsEndPos,
char* pChar = pChars;
int b = _bits;
int bFilled = _bitsFilled;
XmlCharType xmlCharType = XmlCharType.Instance;
while (pChar < pCharsEndPos && pByte < pBytesEndPos)
{
char ch = *pChar;
Expand All @@ -178,7 +176,7 @@ private unsafe void Decode(char* pChars, char* pCharsEndPos,
pChar++;

// ignore whitespace
if (xmlCharType.IsWhiteSpace(ch))
if (XmlCharType.IsWhiteSpace(ch))
{
continue;
}
Expand Down Expand Up @@ -219,7 +217,7 @@ private unsafe void Decode(char* pChars, char* pCharsEndPos,
{
do
{
if (!(xmlCharType.IsWhiteSpace(*pChar++)))
if (!XmlCharType.IsWhiteSpace(*pChar++))
{
throw new XmlException(SR.Xml_InvalidBase64Value, new string(pChars, 0, (int)(pCharsEndPos - pChars)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ private static unsafe void Decode(char* pChars, char* pCharsEndPos,

char* pChar = pChars;
byte* pByte = pBytes;
XmlCharType xmlCharType = XmlCharType.Instance;
while (pChar < pCharsEndPos && pByte < pBytesEndPos)
{
byte halfByte;
Expand All @@ -203,7 +202,7 @@ private static unsafe void Decode(char* pChars, char* pCharsEndPos,
{
halfByte = (byte)val;
}
else if (xmlCharType.IsWhiteSpace(ch))
else if (XmlCharType.IsWhiteSpace(ch))
{
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ public NestedBinXml(SymbolTables symbolTables, int docState, NestedBinXml? next)
private readonly bool _ignoreComments;
private readonly DtdProcessing _dtdProcessing;

private XmlCharType _xmlCharType;
private readonly Encoding _unicode;

// current version of the protocol
Expand All @@ -342,7 +341,6 @@ public NestedBinXml(SymbolTables symbolTables, int docState, NestedBinXml? next)
public XmlSqlBinaryReader(Stream stream, byte[] data, int len, string baseUri, bool closeInput, XmlReaderSettings settings)
{
_unicode = System.Text.Encoding.Unicode;
_xmlCharType = XmlCharType.Instance;

_xnt = settings.NameTable!;
if (_xnt == null)
Expand Down Expand Up @@ -3531,7 +3529,6 @@ private unsafe XmlNodeType CheckText(bool attr)
// assert that size is an even number
Debug.Assert(0 == ((_pos - _tokDataPos) & 1), "Data size should not be odd");
// grab local copy (perf)
XmlCharType xmlCharType = _xmlCharType;

fixed (byte* pb = _data)
{
Expand All @@ -3546,7 +3543,7 @@ private unsafe XmlNodeType CheckText(bool attr)
int posNext = pos + 2;
if (posNext > end)
return _xmlspacePreserve ? XmlNodeType.SignificantWhitespace : XmlNodeType.Whitespace;
if (pb[pos + 1] != 0 || !xmlCharType.IsWhiteSpace((char)pb[pos]))
if (pb[pos + 1] != 0 || !XmlCharType.IsWhiteSpace((char)pb[pos]))
break;
pos = posNext;
}
Expand All @@ -3561,7 +3558,7 @@ private unsafe XmlNodeType CheckText(bool attr)
if (posNext > end)
return XmlNodeType.Text;
ch = (char)(pb[pos] | ((int)(pb[pos + 1]) << 8));
if (!_xmlCharType.IsCharData(ch))
if (!XmlCharType.IsCharData(ch))
break;
pos = posNext;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ private unsafe void WriteHtmlAttributeText(char* pSrc, char* pSrcEnd)
pDstEnd = pDstBegin + _bufLen;
}

while (pDst < pDstEnd && _xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)))
while (pDst < pDstEnd && XmlCharType.IsAttributeValueChar((char)(ch = *pSrc)))
{
*pDst++ = (char)ch;
pSrc++;
Expand Down Expand Up @@ -660,7 +660,7 @@ private unsafe void WriteUriAttributeText(char* pSrc, char* pSrcEnd)
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++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ private unsafe void WriteHtmlAttributeText(char* pSrc, char* pSrcEnd)
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++;
Expand Down Expand Up @@ -637,7 +637,7 @@ private unsafe void WriteUriAttributeText(char* pSrc, char* pSrcEnd)
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++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ private bool TextBlockCreatesWriter(string? textBlock)
if (_wrapped == null)
{
// Whitespace-only text blocks aren't enough to determine Xml vs. Html
if (XmlCharType.Instance.IsOnlyWhitespace(textBlock))
if (XmlCharType.IsOnlyWhitespace(textBlock))
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ private enum State
private readonly DtdProcessing _dtdProcessing; // -1 means do nothing

private XmlNodeType _lastNodeType;
private XmlCharType _xmlCharType;

private ReadContentAsBinaryHelper? _readBinaryHelper;

Expand All @@ -60,11 +59,6 @@ internal XmlCharCheckingReader(XmlReader reader, bool checkCharacters, bool igno
_dtdProcessing = dtdProcessing;

_lastNodeType = XmlNodeType.None;

if (checkCharacters)
{
_xmlCharType = XmlCharType.Instance;
}
}

//
Expand Down Expand Up @@ -320,7 +314,7 @@ public override bool Read()
if (str != null)
{
int i;
if ((i = _xmlCharType.IsPublicId(str)) >= 0)
if ((i = XmlCharType.IsPublicId(str)) >= 0)
{
Throw(SR.Xml_InvalidCharacter, XmlException.BuildCharExceptionArgs(str, i));
}
Expand Down Expand Up @@ -622,7 +616,7 @@ private void Throw(string res, string[] args)
private void CheckWhitespace(string value)
{
int i;
if ((i = _xmlCharType.IsOnlyWhitespaceWithPos(value)) != -1)
if ((i = XmlCharType.IsOnlyWhitespaceWithPos(value)) != -1)
{
Throw(SR.Xml_InvalidWhitespaceCharacter, XmlException.BuildCharExceptionArgs(value, i));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public override async Task<bool> ReadAsync()
if (str != null)
{
int i;
if ((i = _xmlCharType.IsPublicId(str)) >= 0)
if ((i = XmlCharType.IsPublicId(str)) >= 0)
{
Throw(SR.Xml_InvalidCharacter, XmlException.BuildCharExceptionArgs(str, i));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ internal partial class XmlCharCheckingWriter : XmlWrappingWriter
private readonly bool _replaceNewLines;
private readonly string _newLineChars;

private XmlCharType _xmlCharType;
//
// Constructor
//
Expand All @@ -37,10 +36,6 @@ internal XmlCharCheckingWriter(XmlWriter baseWriter, bool checkValues, bool chec
_replaceNewLines = replaceNewLines;
_newLineChars = newLineChars;

if (checkValues)
{
_xmlCharType = XmlCharType.Instance;
}
}

//
Expand Down Expand Up @@ -83,7 +78,7 @@ public override void WriteDocType(string name, string? pubid, string? sysid, str
if (pubid != null)
{
int i;
if ((i = _xmlCharType.IsPublicId(pubid)) >= 0)
if ((i = XmlCharType.IsPublicId(pubid)) >= 0)
{
throw XmlConvert.CreateInvalidCharException(pubid, i);
}
Expand Down Expand Up @@ -238,7 +233,7 @@ public override void WriteWhitespace(string? ws)
if (_checkNames)
{
int i;
if ((i = _xmlCharType.IsOnlyWhitespaceWithPos(ws)) != -1)
if ((i = XmlCharType.IsOnlyWhitespaceWithPos(ws)) != -1)
{
throw new ArgumentException(SR.Format(SR.Xml_InvalidWhitespaceCharacter, XmlException.BuildCharExceptionArgs(ws, i)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override Task WriteDocTypeAsync(string name, string? pubid, string? sysid
if (pubid != null)
{
int i;
if ((i = _xmlCharType.IsPublicId(pubid)) >= 0)
if ((i = XmlCharType.IsPublicId(pubid)) >= 0)
{
throw XmlConvert.CreateInvalidCharException(pubid, i);
}
Expand Down Expand Up @@ -180,7 +180,7 @@ public override Task WriteWhitespaceAsync(string? ws)
if (_checkNames)
{
int i;
if ((i = _xmlCharType.IsOnlyWhitespaceWithPos(ws)) != -1)
if ((i = XmlCharType.IsOnlyWhitespaceWithPos(ws)) != -1)
{
throw new ArgumentException(SR.Format(SR.Xml_InvalidWhitespaceCharacter, XmlException.BuildCharExceptionArgs(ws, i)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
// Instead, modify XmlRawTextWriterGenerator.ttinclude

#nullable disable
using System;
using System.IO;
using System.Xml;
using System.Text;
using System.Diagnostics;
using System.Globalization;
Expand All @@ -34,9 +32,6 @@ internal partial class XmlEncodedRawTextWriter : XmlRawWriter
// encoding of the stream or text writer
protected Encoding _encoding;

// char type tables
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
Expand Down Expand Up @@ -567,7 +562,7 @@ public override void WriteCharEntity(char ch)
{
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');
Expand Down Expand Up @@ -908,7 +903,7 @@ protected unsafe void WriteAttributeTextBlock(char* pSrc, char* pSrcEnd)
pDstEnd = pDstBegin + _bufLen;
}

while (pDst < pDstEnd && _xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)))
while (pDst < pDstEnd && XmlCharType.IsAttributeValueChar((char)(ch = *pSrc)))
{
*pDst = (char)ch;
pDst++;
Expand Down Expand Up @@ -1032,7 +1027,7 @@ protected unsafe void WriteElementTextBlock(char* pSrc, char* pSrcEnd)
pDstEnd = pDstBegin + _bufLen;
}

while (pDst < pDstEnd && _xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)))
while (pDst < pDstEnd && XmlCharType.IsAttributeValueChar((char)(ch = *pSrc)))
{
*pDst = (char)ch;
pDst++;
Expand Down Expand Up @@ -1227,7 +1222,7 @@ protected unsafe void WriteRawWithCharChecking(char* pSrcBegin, char* pSrcEnd)
pDstEnd = pDstBegin + _bufLen;
}

while (pDst < pDstEnd && _xmlCharType.IsTextChar((char)(ch = *pSrc)))
while (pDst < pDstEnd && XmlCharType.IsTextChar((char)(ch = *pSrc)))
{
*pDst = (char)ch;
pDst++;
Expand Down Expand Up @@ -1347,7 +1342,7 @@ protected unsafe void WriteCommentOrPi(string text, int stopChar)
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++;
Expand Down Expand Up @@ -1498,7 +1493,7 @@ protected unsafe void WriteCDataSection(string text)
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++;
Expand Down Expand Up @@ -1639,8 +1634,8 @@ protected unsafe void WriteCDataSection(string text)

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)
{
Expand Down Expand Up @@ -1853,7 +1848,7 @@ protected void ValidateContentChars(string chars, string propertyName, bool allo
{
if (allowOnlyWhitespace)
{
if (!_xmlCharType.IsOnlyWhitespace(chars))
if (!XmlCharType.IsOnlyWhitespace(chars))
{
throw new ArgumentException(SR.Format(SR.Xml_IndentCharsNotWhitespace, propertyName));
}
Expand All @@ -1863,7 +1858,7 @@ protected void ValidateContentChars(string chars, string propertyName, bool allo
string error = null;
for (int i = 0; i < chars.Length; i++)
{
if (!_xmlCharType.IsTextChar(chars[i]))
if (!XmlCharType.IsTextChar(chars[i]))
{
switch (chars[i])
{
Expand Down
Loading

0 comments on commit f1f7681

Please sign in to comment.