Skip to content

Commit

Permalink
Nullable: System.Xml, part 3
Browse files Browse the repository at this point in the history
  • Loading branch information
krwq committed May 29, 2020
1 parent 0955d7f commit 67c258e
Show file tree
Hide file tree
Showing 102 changed files with 1,149 additions and 857 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System.Runtime.CompilerServices;

namespace System
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System.Threading.Tasks;

namespace System.Xml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System;
using System.Diagnostics;

Expand All @@ -12,7 +13,7 @@ internal class Base64Decoder : IncrementalReadDecoder
//
// Fields
//
private byte[] _buffer;
private byte[]? _buffer;
private int _startIndex;
private int _curIndex;
private int _endIndex;
Expand Down Expand Up @@ -70,7 +71,7 @@ internal override unsafe int Decode(char[] chars, int startPos, int len)
int bytesDecoded, charsDecoded;
fixed (char* pChars = &chars[startPos])
{
fixed (byte* pBytes = &_buffer[_curIndex])
fixed (byte* pBytes = &_buffer![_curIndex])
{
Decode(pChars, pChars + len, pBytes, pBytes + (_endIndex - _curIndex), out charsDecoded, out bytesDecoded);
}
Expand Down Expand Up @@ -102,14 +103,16 @@ internal override unsafe int Decode(string str, int startPos, int len)
{
return 0;
}

int bytesDecoded, charsDecoded;
fixed (char* pChars = str)
{
fixed (byte* pBytes = &_buffer[_curIndex])
fixed (byte* pBytes = &_buffer![_curIndex])
{
Decode(pChars + startPos, pChars + startPos + len, pBytes, pBytes + (_endIndex - _curIndex), out charsDecoded, out bytesDecoded);
}
}

_curIndex += bytesDecoded;
return charsDecoded;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System.Text;
using System.Diagnostics;

namespace System.Xml
{
internal abstract partial class Base64Encoder
{
private byte[] _leftOverBytes;
private byte[]? _leftOverBytes;
private int _leftOverBytesCount;
private readonly char[] _charsLine;

Expand Down Expand Up @@ -48,7 +49,7 @@ internal void Encode(byte[] buffer, int index, int count)
int i = _leftOverBytesCount;
while (i < 3 && count > 0)
{
_leftOverBytes[i++] = buffer[index++];
_leftOverBytes![i++] = buffer[index++];
count--;
}

Expand All @@ -60,7 +61,7 @@ internal void Encode(byte[] buffer, int index, int count)
}

// encode the left-over buffer and write out
int leftOverChars = Convert.ToBase64CharArray(_leftOverBytes, 0, 3, _charsLine, 0);
int leftOverChars = Convert.ToBase64CharArray(_leftOverBytes!, 0, 3, _charsLine, 0);
WriteChars(_charsLine, 0, leftOverChars);
}

Expand Down Expand Up @@ -99,7 +100,7 @@ internal void Flush()
{
if (_leftOverBytesCount > 0)
{
int leftOverChars = Convert.ToBase64CharArray(_leftOverBytes, 0, _leftOverBytesCount, _charsLine, 0);
int leftOverChars = Convert.ToBase64CharArray(_leftOverBytes!, 0, _leftOverBytesCount, _charsLine, 0);
WriteChars(_charsLine, 0, leftOverChars);
_leftOverBytesCount = 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System.Text;
using System.Diagnostics;

Expand Down Expand Up @@ -38,7 +39,7 @@ internal async Task EncodeAsync(byte[] buffer, int index, int count)
int i = _leftOverBytesCount;
while (i < 3 && count > 0)
{
_leftOverBytes[i++] = buffer[index++];
_leftOverBytes![i++] = buffer[index++];
count--;
}

Expand All @@ -50,7 +51,7 @@ internal async Task EncodeAsync(byte[] buffer, int index, int count)
}

// encode the left-over buffer and write out
int leftOverChars = Convert.ToBase64CharArray(_leftOverBytes, 0, 3, _charsLine, 0);
int leftOverChars = Convert.ToBase64CharArray(_leftOverBytes!, 0, 3, _charsLine, 0);
await WriteCharsAsync(_charsLine, 0, leftOverChars).ConfigureAwait(false);
}

Expand Down Expand Up @@ -89,7 +90,7 @@ internal async Task FlushAsync()
{
if (_leftOverBytesCount > 0)
{
int leftOverChars = Convert.ToBase64CharArray(_leftOverBytes, 0, _leftOverBytesCount, _charsLine, 0);
int leftOverChars = Convert.ToBase64CharArray(_leftOverBytes!, 0, _leftOverBytesCount, _charsLine, 0);
await WriteCharsAsync(_charsLine, 0, leftOverChars).ConfigureAwait(false);
_leftOverBytesCount = 0;
}
Expand Down
10 changes: 7 additions & 3 deletions src/libraries/System.Private.Xml/src/System/Xml/BinHexDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System;
using System.Diagnostics;

Expand All @@ -12,7 +13,7 @@ internal class BinHexDecoder : IncrementalReadDecoder
//
// Fields
//
private byte[] _buffer;
private byte[]? _buffer;
private int _startIndex;
private int _curIndex;
private int _endIndex;
Expand Down Expand Up @@ -61,10 +62,11 @@ internal override unsafe int Decode(char[] chars, int startPos, int len)
{
return 0;
}

int bytesDecoded, charsDecoded;
fixed (char* pChars = &chars[startPos])
{
fixed (byte* pBytes = &_buffer[_curIndex])
fixed (byte* pBytes = &_buffer![_curIndex])
{
Decode(pChars, pChars + len, pBytes, pBytes + (_endIndex - _curIndex),
ref _hasHalfByteCached, ref _cachedHalfByte, out charsDecoded, out bytesDecoded);
Expand Down Expand Up @@ -97,15 +99,17 @@ internal override unsafe int Decode(string str, int startPos, int len)
{
return 0;
}

int bytesDecoded, charsDecoded;
fixed (char* pChars = str)
{
fixed (byte* pBytes = &_buffer[_curIndex])
fixed (byte* pBytes = &_buffer![_curIndex])
{
Decode(pChars + startPos, pChars + startPos + len, pBytes, pBytes + (_endIndex - _curIndex),
ref _hasHalfByteCached, ref _cachedHalfByte, out charsDecoded, out bytesDecoded);
}
}

_curIndex += bytesDecoded;
return charsDecoded;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
namespace System.Xml
{
internal static partial class BinHexEncoder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System.Threading.Tasks;

namespace System.Xml
Expand Down
5 changes: 3 additions & 2 deletions src/libraries/System.Private.Xml/src/System/Xml/BitStack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System;
using System.Diagnostics;

Expand All @@ -12,7 +13,7 @@ namespace System.Xml
/// </summary>
internal class BitStack
{
private uint[] _bitStack;
private uint[]? _bitStack;
private int _stackPos;
private uint _curr;

Expand Down Expand Up @@ -108,7 +109,7 @@ private void PushCurr()
private void PopCurr()
{
if (_stackPos > 0)
_curr = _bitStack[--_stackPos];
_curr = _bitStack![--_stackPos];
}
}
}
1 change: 1 addition & 0 deletions src/libraries/System.Private.Xml/src/System/Xml/Bits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System;
using System.Diagnostics;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System;

namespace System.Xml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
#if ENABLEDATABINDING
using System;
using System.Xml;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
#if ENABLEDATABINDING
using System;
using System.Xml;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
#if ENABLEDATABINDING
using System;
using System.Xml;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
#if ENABLEDATABINDING
using System;
using System.Xml;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
#if ENABLEDATABINDING
using System;
using System.Xml;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,15 @@ internal interface IDtdEntityInfo
/// <summary>
/// SYSTEM identifier (URI) of the entity value - only used for external entities
/// </summary>
string SystemId { get; }
string? SystemId { get; }
/// <summary>
/// PUBLIC identifier of the entity value - only used for external entities
/// </summary>
string PublicId { get; }
string? PublicId { get; }
/// <summary>
/// Replacement text of an entity. Valid only for internal entities.
/// </summary>
string Text { get; }
string? Text { get; }
/// <summary>
/// The line number of the entity value
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#nullable enable
using System;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using System.Xml.Schema;

Expand All @@ -16,7 +17,7 @@ internal partial interface IDtdParserAdapter

Uri? BaseUri { get; }

char[]? ParsingBuffer { get; }
char[] ParsingBuffer { get; }
int ParsingBufferLength { get; }
int CurrentPosition { get; set; }
int LineNo { get; }
Expand All @@ -29,21 +30,22 @@ internal partial interface IDtdParserAdapter

void OnNewLine(int pos);

int ParseNumericCharRef(StringBuilder internalSubsetBuilder);
int ParseNamedCharRef(bool expand, StringBuilder internalSubsetBuilder);
void ParsePI(StringBuilder sb);
void ParseComment(StringBuilder sb);
int ParseNumericCharRef(StringBuilder? internalSubsetBuilder);
int ParseNamedCharRef(bool expand, StringBuilder? internalSubsetBuilder);
void ParsePI(StringBuilder? sb);
void ParseComment(StringBuilder? sb);

bool PushEntity(IDtdEntityInfo entity, out int entityId);

bool PopEntity(out IDtdEntityInfo? oldEntity, out int newEntityId);

bool PushExternalSubset(string systemId, string publicId);
bool PushExternalSubset(string? systemId, string? publicId);

void PushInternalDtd(string baseUri, string internalDtd);
void OnSystemId(string systemId, LineInfo keywordLineInfo, LineInfo systemLiteralLineInfo);
void OnPublicId(string publicId, LineInfo keywordLineInfo, LineInfo publicLiteralLineInfo);

[DoesNotReturn]
void Throw(Exception e);
}

Expand Down
Loading

0 comments on commit 67c258e

Please sign in to comment.