Skip to content

Commit f1f7681

Browse files
authored
Update xml char type (dotnet#41756)
1 parent 2b43b86 commit f1f7681

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+4383
-484
lines changed

src/libraries/System.Private.Xml/src/System.Private.Xml.csproj

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,9 @@
77
<Nullable>enable</Nullable>
88
</PropertyGroup>
99
<ItemGroup>
10-
<Compile Include="$(CommonPath)System\Text\StringBuilderCache.cs"
11-
Link="Common\System\StringBuilderCache.cs" />
12-
<Compile Include="$(CommonPath)System\Marvin.cs"
13-
Link="Common\System\Marvin.cs" />
14-
<Compile Include="$(CommonPath)System\HexConverter.cs"
15-
Link="Common\System\HexConverter.cs" />
10+
<Compile Include="$(CommonPath)System\Text\StringBuilderCache.cs" Link="Common\System\StringBuilderCache.cs" />
11+
<Compile Include="$(CommonPath)System\Marvin.cs" Link="Common\System\Marvin.cs" />
12+
<Compile Include="$(CommonPath)System\HexConverter.cs" Link="Common\System\HexConverter.cs" />
1613
<Compile Include="System\Xml\BinaryXml\XmlBinaryReader.cs" />
1714
<Compile Include="System\Xml\BinaryXml\BinXmlToken.cs" />
1815
<Compile Include="System\Xml\BinaryXml\SqlUtils.cs" />
@@ -552,11 +549,6 @@
552549
<LogicalName>rss-0.91.dtd</LogicalName>
553550
</EmbeddedResource>
554551
</ItemGroup>
555-
<ItemGroup>
556-
<EmbeddedResource Include="System\Xml\XmlCharType.bin">
557-
<LogicalName>XmlCharType.bin</LogicalName>
558-
</EmbeddedResource>
559-
</ItemGroup>
560552
<ItemGroup>
561553
<Reference Include="System.Reflection.Emit" />
562554
<Reference Include="System.Reflection.Emit.ILGeneration" />
@@ -579,6 +571,7 @@
579571
<Reference Include="System.ObjectModel" />
580572
<Reference Include="System.Reflection.Primitives" />
581573
<Reference Include="System.Runtime" />
574+
<Reference Include="System.Runtime.CompilerServices.Unsafe" />
582575
<Reference Include="System.Runtime.Extensions" />
583576
<Reference Include="System.Runtime.InteropServices" />
584577
<Reference Include="System.Security.Cryptography.Algorithms" />
@@ -790,8 +783,7 @@
790783
<Compile Include="System\Xml\Xsl\Xslt\XsltLoader.cs" />
791784
<Compile Include="System\Xml\Xsl\Xslt\XsltQilFactory.cs" />
792785
<Compile Include="System\Xml\Xsl\Xslt\XslVisitor.cs" />
793-
<Compile Include="$(CommonPath)System\LocalAppContextSwitches.Common.cs"
794-
Link="System\LocalAppContextSwitches.Common.cs" />
786+
<Compile Include="$(CommonPath)System\LocalAppContextSwitches.Common.cs" Link="System\LocalAppContextSwitches.Common.cs" />
795787
<Compile Include="System\Xml\Core\LocalAppContextSwitches.cs" />
796788
<Compile Include="$(CommonPath)System\CSharpHelpers.cs" />
797789
</ItemGroup>

src/libraries/System.Private.Xml/src/System/Xml/Base64Decoder.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System;
54
using System.Diagnostics;
65

76
namespace System.Xml
@@ -166,7 +165,6 @@ private unsafe void Decode(char* pChars, char* pCharsEndPos,
166165
char* pChar = pChars;
167166
int b = _bits;
168167
int bFilled = _bitsFilled;
169-
XmlCharType xmlCharType = XmlCharType.Instance;
170168
while (pChar < pCharsEndPos && pByte < pBytesEndPos)
171169
{
172170
char ch = *pChar;
@@ -178,7 +176,7 @@ private unsafe void Decode(char* pChars, char* pCharsEndPos,
178176
pChar++;
179177

180178
// ignore whitespace
181-
if (xmlCharType.IsWhiteSpace(ch))
179+
if (XmlCharType.IsWhiteSpace(ch))
182180
{
183181
continue;
184182
}
@@ -219,7 +217,7 @@ private unsafe void Decode(char* pChars, char* pCharsEndPos,
219217
{
220218
do
221219
{
222-
if (!(xmlCharType.IsWhiteSpace(*pChar++)))
220+
if (!XmlCharType.IsWhiteSpace(*pChar++))
223221
{
224222
throw new XmlException(SR.Xml_InvalidBase64Value, new string(pChars, 0, (int)(pCharsEndPos - pChars)));
225223
}

src/libraries/System.Private.Xml/src/System/Xml/BinHexDecoder.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ private static unsafe void Decode(char* pChars, char* pCharsEndPos,
192192

193193
char* pChar = pChars;
194194
byte* pByte = pBytes;
195-
XmlCharType xmlCharType = XmlCharType.Instance;
196195
while (pChar < pCharsEndPos && pByte < pBytesEndPos)
197196
{
198197
byte halfByte;
@@ -203,7 +202,7 @@ private static unsafe void Decode(char* pChars, char* pCharsEndPos,
203202
{
204203
halfByte = (byte)val;
205204
}
206-
else if (xmlCharType.IsWhiteSpace(ch))
205+
else if (XmlCharType.IsWhiteSpace(ch))
207206
{
208207
continue;
209208
}

src/libraries/System.Private.Xml/src/System/Xml/BinaryXml/XmlBinaryReader.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,6 @@ public NestedBinXml(SymbolTables symbolTables, int docState, NestedBinXml? next)
333333
private readonly bool _ignoreComments;
334334
private readonly DtdProcessing _dtdProcessing;
335335

336-
private XmlCharType _xmlCharType;
337336
private readonly Encoding _unicode;
338337

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

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

35363533
fixed (byte* pb = _data)
35373534
{
@@ -3546,7 +3543,7 @@ private unsafe XmlNodeType CheckText(bool attr)
35463543
int posNext = pos + 2;
35473544
if (posNext > end)
35483545
return _xmlspacePreserve ? XmlNodeType.SignificantWhitespace : XmlNodeType.Whitespace;
3549-
if (pb[pos + 1] != 0 || !xmlCharType.IsWhiteSpace((char)pb[pos]))
3546+
if (pb[pos + 1] != 0 || !XmlCharType.IsWhiteSpace((char)pb[pos]))
35503547
break;
35513548
pos = posNext;
35523549
}
@@ -3561,7 +3558,7 @@ private unsafe XmlNodeType CheckText(bool attr)
35613558
if (posNext > end)
35623559
return XmlNodeType.Text;
35633560
ch = (char)(pb[pos] | ((int)(pb[pos + 1]) << 8));
3564-
if (!_xmlCharType.IsCharData(ch))
3561+
if (!XmlCharType.IsCharData(ch))
35653562
break;
35663563
pos = posNext;
35673564
}

src/libraries/System.Private.Xml/src/System/Xml/Core/HtmlEncodedRawTextWriter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ private unsafe void WriteHtmlAttributeText(char* pSrc, char* pSrcEnd)
572572
pDstEnd = pDstBegin + _bufLen;
573573
}
574574

575-
while (pDst < pDstEnd && _xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)))
575+
while (pDst < pDstEnd && XmlCharType.IsAttributeValueChar((char)(ch = *pSrc)))
576576
{
577577
*pDst++ = (char)ch;
578578
pSrc++;
@@ -660,7 +660,7 @@ private unsafe void WriteUriAttributeText(char* pSrc, char* pSrcEnd)
660660
pDstEnd = pDstBegin + _bufLen;
661661
}
662662

663-
while (pDst < pDstEnd && (_xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch < 0x80))
663+
while (pDst < pDstEnd && (XmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch < 0x80))
664664
{
665665
*pDst++ = (char)ch;
666666
pSrc++;

src/libraries/System.Private.Xml/src/System/Xml/Core/HtmlUtf8RawTextWriter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ private unsafe void WriteHtmlAttributeText(char* pSrc, char* pSrcEnd)
549549
pDstEnd = pDstBegin + _bufLen;
550550
}
551551

552-
while (pDst < pDstEnd && (_xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch <= 0x7F))
552+
while (pDst < pDstEnd && XmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch <= 0x7F)
553553
{
554554
*pDst++ = (byte)ch;
555555
pSrc++;
@@ -637,7 +637,7 @@ private unsafe void WriteUriAttributeText(char* pSrc, char* pSrcEnd)
637637
pDstEnd = pDstBegin + _bufLen;
638638
}
639639

640-
while (pDst < pDstEnd && (_xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch < 0x80))
640+
while (pDst < pDstEnd && XmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch < 0x80)
641641
{
642642
*pDst++ = (byte)ch;
643643
pSrc++;

src/libraries/System.Private.Xml/src/System/Xml/Core/XmlAutoDetectWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ private bool TextBlockCreatesWriter(string? textBlock)
396396
if (_wrapped == null)
397397
{
398398
// Whitespace-only text blocks aren't enough to determine Xml vs. Html
399-
if (XmlCharType.Instance.IsOnlyWhitespace(textBlock))
399+
if (XmlCharType.IsOnlyWhitespace(textBlock))
400400
{
401401
return false;
402402
}

src/libraries/System.Private.Xml/src/System/Xml/Core/XmlCharCheckingReader.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ private enum State
3939
private readonly DtdProcessing _dtdProcessing; // -1 means do nothing
4040

4141
private XmlNodeType _lastNodeType;
42-
private XmlCharType _xmlCharType;
4342

4443
private ReadContentAsBinaryHelper? _readBinaryHelper;
4544

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

6261
_lastNodeType = XmlNodeType.None;
63-
64-
if (checkCharacters)
65-
{
66-
_xmlCharType = XmlCharType.Instance;
67-
}
6862
}
6963

7064
//
@@ -320,7 +314,7 @@ public override bool Read()
320314
if (str != null)
321315
{
322316
int i;
323-
if ((i = _xmlCharType.IsPublicId(str)) >= 0)
317+
if ((i = XmlCharType.IsPublicId(str)) >= 0)
324318
{
325319
Throw(SR.Xml_InvalidCharacter, XmlException.BuildCharExceptionArgs(str, i));
326320
}
@@ -622,7 +616,7 @@ private void Throw(string res, string[] args)
622616
private void CheckWhitespace(string value)
623617
{
624618
int i;
625-
if ((i = _xmlCharType.IsOnlyWhitespaceWithPos(value)) != -1)
619+
if ((i = XmlCharType.IsOnlyWhitespaceWithPos(value)) != -1)
626620
{
627621
Throw(SR.Xml_InvalidWhitespaceCharacter, XmlException.BuildCharExceptionArgs(value, i));
628622
}

src/libraries/System.Private.Xml/src/System/Xml/Core/XmlCharCheckingReaderAsync.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public override async Task<bool> ReadAsync()
172172
if (str != null)
173173
{
174174
int i;
175-
if ((i = _xmlCharType.IsPublicId(str)) >= 0)
175+
if ((i = XmlCharType.IsPublicId(str)) >= 0)
176176
{
177177
Throw(SR.Xml_InvalidCharacter, XmlException.BuildCharExceptionArgs(str, i));
178178
}

src/libraries/System.Private.Xml/src/System/Xml/Core/XmlCharCheckingWriter.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ internal partial class XmlCharCheckingWriter : XmlWrappingWriter
2424
private readonly bool _replaceNewLines;
2525
private readonly string _newLineChars;
2626

27-
private XmlCharType _xmlCharType;
2827
//
2928
// Constructor
3029
//
@@ -37,10 +36,6 @@ internal XmlCharCheckingWriter(XmlWriter baseWriter, bool checkValues, bool chec
3736
_replaceNewLines = replaceNewLines;
3837
_newLineChars = newLineChars;
3938

40-
if (checkValues)
41-
{
42-
_xmlCharType = XmlCharType.Instance;
43-
}
4439
}
4540

4641
//
@@ -83,7 +78,7 @@ public override void WriteDocType(string name, string? pubid, string? sysid, str
8378
if (pubid != null)
8479
{
8580
int i;
86-
if ((i = _xmlCharType.IsPublicId(pubid)) >= 0)
81+
if ((i = XmlCharType.IsPublicId(pubid)) >= 0)
8782
{
8883
throw XmlConvert.CreateInvalidCharException(pubid, i);
8984
}
@@ -238,7 +233,7 @@ public override void WriteWhitespace(string? ws)
238233
if (_checkNames)
239234
{
240235
int i;
241-
if ((i = _xmlCharType.IsOnlyWhitespaceWithPos(ws)) != -1)
236+
if ((i = XmlCharType.IsOnlyWhitespaceWithPos(ws)) != -1)
242237
{
243238
throw new ArgumentException(SR.Format(SR.Xml_InvalidWhitespaceCharacter, XmlException.BuildCharExceptionArgs(ws, i)));
244239
}

0 commit comments

Comments
 (0)