<Compile Include="$(BclSourcesRoot)\System\Runtime\Serialization\SerializationInfo.cs" />
</ItemGroup>
<ItemGroup>
- <Compile Include="$(BclSourcesRoot)\System\Text\DecoderNLS.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Text\DecoderBestFitFallback.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Text\DecoderExceptionFallback.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Text\DecoderFallback.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Text\DecoderReplacementFallback.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Text\EncoderNLS.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Text\EncoderBestFitFallback.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Text\EncoderExceptionFallback.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Text\EncoderFallback.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Text\EncoderReplacementFallback.cs" />
- </ItemGroup>
- <ItemGroup>
<Compile Include="$(BclSourcesRoot)\Microsoft\Win32\UnsafeNativeMethods.cs" />
<Compile Include="$(BclSourcesRoot)\Microsoft\Win32\Win32Native.cs" />
<Compile Condition="'$(FeatureWin32Registry)' == 'true'" Include="$(BclSourcesRoot)\Microsoft\Win32\Registry.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\SystemException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Text\ASCIIEncoding.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Text\Decoder.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Text\DecoderNLS.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Text\DecoderBestFitFallback.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Text\DecoderExceptionFallback.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Text\DecoderFallback.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Text\DecoderReplacementFallback.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Text\Encoder.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Text\EncoderNLS.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Text\EncoderBestFitFallback.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Text\EncoderExceptionFallback.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Text\EncoderFallback.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Text\EncoderReplacementFallback.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Text\Encoding.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Text\EncodingInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Text\EncodingNLS.cs" />
using System;
using System.Diagnostics;
using System.Diagnostics.Contracts;
-using System.Runtime.Serialization;
namespace System.Text
{
if (encoder != null)
{
- charLeftOver = encoder.charLeftOver;
+ charLeftOver = encoder._charLeftOver;
Debug.Assert(charLeftOver == 0 || Char.IsHighSurrogate(charLeftOver),
"[ASCIIEncoding.GetByteCount]leftover character should be high surrogate");
{
// We always need the fallback buffer in get bytes so we can flush any remaining ones if necessary
fallbackBuffer = encoder.FallbackBuffer;
- if (fallbackBuffer.Remaining > 0 && encoder.m_throwOnOverflow)
+ if (fallbackBuffer.Remaining > 0 && encoder._throwOnOverflow)
throw new ArgumentException(SR.Format(SR.Argument_EncoderFallbackNotEmpty, this.EncodingName, encoder.Fallback.GetType()));
// Set our internal fallback interesting things.
}
// Verify that we have no fallbackbuffer, for ASCII its always empty, so just assert
- Debug.Assert(!encoder.m_throwOnOverflow || !encoder.InternalHasFallbackBuffer ||
+ Debug.Assert(!encoder._throwOnOverflow || !encoder.InternalHasFallbackBuffer ||
encoder.FallbackBuffer.Remaining == 0,
"[ASCIICodePageEncoding.GetByteCount]Expected empty fallback buffer");
}
if (encoder != null)
{
- charLeftOver = encoder.charLeftOver;
+ charLeftOver = encoder._charLeftOver;
fallback = encoder.Fallback as EncoderReplacementFallback;
// We mustn't have left over fallback data when counting
{
// We always need the fallback buffer in get bytes so we can flush any remaining ones if necessary
fallbackBuffer = encoder.FallbackBuffer;
- if (fallbackBuffer.Remaining > 0 && encoder.m_throwOnOverflow)
+ if (fallbackBuffer.Remaining > 0 && encoder._throwOnOverflow)
throw new ArgumentException(SR.Format(SR.Argument_EncoderFallbackNotEmpty, this.EncodingName, encoder.Fallback.GetType()));
// Set our internal fallback interesting things.
"[ASCIIEncoding.GetBytes]leftover character should be high surrogate");
// Verify that we have no fallbackbuffer, for ASCII its always empty, so just assert
- Debug.Assert(!encoder.m_throwOnOverflow || !encoder.InternalHasFallbackBuffer ||
+ Debug.Assert(!encoder._throwOnOverflow || !encoder.InternalHasFallbackBuffer ||
encoder.FallbackBuffer.Remaining == 0,
"[ASCIICodePageEncoding.GetBytes]Expected empty fallback buffer");
}
// Clear encoder
if (encoder != null)
{
- encoder.charLeftOver = (char)0;
- encoder.m_charsUsed = (int)(chars - charStart);
+ encoder._charLeftOver = (char)0;
+ encoder._charsUsed = (int)(chars - charStart);
}
return (int)(bytes - byteStart);
// Fallback stuck it in encoder if necessary, but we have to clear MustFlush cases
if (fallbackBuffer != null && !fallbackBuffer.bUsedEncoder)
// Clear it in case of MustFlush
- encoder.charLeftOver = (char)0;
+ encoder._charLeftOver = (char)0;
// Set our chars used count
- encoder.m_charsUsed = (int)(chars - charStart);
+ encoder._charsUsed = (int)(chars - charStart);
}
Debug.Assert(fallbackBuffer == null || fallbackBuffer.Remaining == 0 ||
- (encoder != null && !encoder.m_throwOnOverflow),
+ (encoder != null && !encoder._throwOnOverflow),
"[ASCIIEncoding.GetBytes]Expected Empty fallback buffer at end");
return (int)(bytes - byteStart);
else
{
fallback = decoder.Fallback as DecoderReplacementFallback;
- Debug.Assert(!decoder.m_throwOnOverflow || !decoder.InternalHasFallbackBuffer ||
+ Debug.Assert(!decoder._throwOnOverflow || !decoder.InternalHasFallbackBuffer ||
decoder.FallbackBuffer.Remaining == 0,
"[ASCIICodePageEncoding.GetCharCount]Expected empty fallback buffer");
}
else
{
fallback = decoder.Fallback as DecoderReplacementFallback;
- Debug.Assert(!decoder.m_throwOnOverflow || !decoder.InternalHasFallbackBuffer ||
+ Debug.Assert(!decoder._throwOnOverflow || !decoder.InternalHasFallbackBuffer ||
decoder.FallbackBuffer.Remaining == 0,
"[ASCIICodePageEncoding.GetChars]Expected empty fallback buffer");
}
// bytes & chars used are the same
if (decoder != null)
- decoder.m_bytesUsed = (int)(bytes - byteStart);
+ decoder._bytesUsed = (int)(bytes - byteStart);
return (int)(chars - charStart);
}
// Might have had decoder fallback stuff.
if (decoder != null)
- decoder.m_bytesUsed = (int)(bytes - byteStart);
+ decoder._bytesUsed = (int)(bytes - byteStart);
// Expect Empty fallback buffer for GetChars
Debug.Assert(fallbackBuffer == null || fallbackBuffer.Remaining == 0,
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System.Runtime.Serialization;
using System.Text;
using System;
using System.Diagnostics;
//
public abstract class Decoder
{
- internal DecoderFallback m_fallback = null;
+ internal DecoderFallback _fallback = null;
- [NonSerialized]
- internal DecoderFallbackBuffer m_fallbackBuffer = null;
-
- internal void SerializeDecoder(SerializationInfo info)
- {
- info.AddValue("m_fallback", this.m_fallback);
- }
+ internal DecoderFallbackBuffer _fallbackBuffer = null;
protected Decoder()
{
{
get
{
- return m_fallback;
+ return _fallback;
}
set
Contract.EndContractBlock();
// Can't change fallback if buffer is wrong
- if (m_fallbackBuffer != null && m_fallbackBuffer.Remaining > 0)
+ if (_fallbackBuffer != null && _fallbackBuffer.Remaining > 0)
throw new ArgumentException(
SR.Argument_FallbackBufferNotEmpty, nameof(value));
- m_fallback = value;
- m_fallbackBuffer = null;
+ _fallback = value;
+ _fallbackBuffer = null;
}
}
{
get
{
- if (m_fallbackBuffer == null)
+ if (_fallbackBuffer == null)
{
- if (m_fallback != null)
- m_fallbackBuffer = m_fallback.CreateFallbackBuffer();
+ if (_fallback != null)
+ _fallbackBuffer = _fallback.CreateFallbackBuffer();
else
- m_fallbackBuffer = DecoderFallback.ReplacementFallback.CreateFallbackBuffer();
+ _fallbackBuffer = DecoderFallback.ReplacementFallback.CreateFallbackBuffer();
}
- return m_fallbackBuffer;
+ return _fallbackBuffer;
}
}
{
get
{
- return m_fallbackBuffer != null;
+ return _fallbackBuffer != null;
}
}
byte[] byteTemp = Array.Empty<byte>();
char[] charTemp = new char[GetCharCount(byteTemp, 0, 0, true)];
GetChars(byteTemp, 0, 0, charTemp, 0, true);
- if (m_fallbackBuffer != null)
- m_fallbackBuffer.Reset();
+ _fallbackBuffer?.Reset();
}
// Returns the number of characters the next call to GetChars will
{
charsUsed = GetChars(bytes, byteIndex, bytesUsed, chars, charIndex, flush);
completed = (bytesUsed == byteCount &&
- (m_fallbackBuffer == null || m_fallbackBuffer.Remaining == 0));
+ (_fallbackBuffer == null || _fallbackBuffer.Remaining == 0));
return;
}
{
charsUsed = GetChars(bytes, bytesUsed, chars, charCount, flush);
completed = (bytesUsed == byteCount &&
- (m_fallbackBuffer == null || m_fallbackBuffer.Remaining == 0));
+ (_fallbackBuffer == null || _fallbackBuffer.Remaining == 0));
return;
}
// This is used internally to create best fit behavior as per the original windows best fit behavior.
//
-using System;
-using System.Text;
-using System.Threading;
using System.Diagnostics;
-using System.Diagnostics.Contracts;
+using System.Threading;
namespace System.Text
{
internal sealed class InternalDecoderBestFitFallback : DecoderFallback
{
// Our variables
- internal Encoding encoding = null;
- internal char[] arrayBestFit = null;
- internal char cReplacement = '?';
+ internal Encoding _encoding = null;
+ internal char[] _arrayBestFit = null;
+ internal char _cReplacement = '?';
internal InternalDecoderBestFitFallback(Encoding encoding)
{
// Need to load our replacement characters table.
- this.encoding = encoding;
- this.bIsMicrosoftBestFitFallback = true;
+ _encoding = encoding;
}
public override DecoderFallbackBuffer CreateFallbackBuffer()
InternalDecoderBestFitFallback that = value as InternalDecoderBestFitFallback;
if (that != null)
{
- return (this.encoding.CodePage == that.encoding.CodePage);
+ return (_encoding.CodePage == that._encoding.CodePage);
}
return (false);
}
public override int GetHashCode()
{
- return this.encoding.CodePage;
+ return _encoding.CodePage;
}
}
internal sealed class InternalDecoderBestFitFallbackBuffer : DecoderFallbackBuffer
{
// Our variables
- internal char cBestFit = '\0';
- internal int iCount = -1;
- internal int iSize;
- private InternalDecoderBestFitFallback oFallback;
+ private char _cBestFit = '\0';
+ private int _iCount = -1;
+ private int _iSize;
+ private InternalDecoderBestFitFallback _oFallback;
// Private object for locking instead of locking on a public type for SQL reliability work.
private static Object s_InternalSyncObject;
// Constructor
public InternalDecoderBestFitFallbackBuffer(InternalDecoderBestFitFallback fallback)
{
- oFallback = fallback;
+ _oFallback = fallback;
- if (oFallback.arrayBestFit == null)
+ if (_oFallback._arrayBestFit == null)
{
// Lock so we don't confuse ourselves.
lock (InternalSyncObject)
{
// Double check before we do it again.
- if (oFallback.arrayBestFit == null)
- oFallback.arrayBestFit = fallback.encoding.GetBestFitBytesToUnicodeData();
+ if (_oFallback._arrayBestFit == null)
+ _oFallback._arrayBestFit = fallback._encoding.GetBestFitBytesToUnicodeData();
}
}
}
public override bool Fallback(byte[] bytesUnknown, int index)
{
// We expect no previous fallback in our buffer
- Debug.Assert(iCount < 1, "[DecoderReplacementFallbackBuffer.Fallback] Calling fallback without a previously empty buffer");
+ Debug.Assert(_iCount < 1, "[DecoderReplacementFallbackBuffer.Fallback] Calling fallback without a previously empty buffer");
- cBestFit = TryBestFit(bytesUnknown);
- if (cBestFit == '\0')
- cBestFit = oFallback.cReplacement;
+ _cBestFit = TryBestFit(bytesUnknown);
+ if (_cBestFit == '\0')
+ _cBestFit = _oFallback._cReplacement;
- iCount = iSize = 1;
+ _iCount = _iSize = 1;
return true;
}
{
// We want it to get < 0 because == 0 means that the current/last character is a fallback
// and we need to detect recursion. We could have a flag but we already have this counter.
- iCount--;
+ _iCount--;
// Do we have anything left? 0 is now last fallback char, negative is nothing left
- if (iCount < 0)
+ if (_iCount < 0)
return '\0';
// Need to get it out of the buffer.
// Make sure it didn't wrap from the fast count-- path
- if (iCount == int.MaxValue)
+ if (_iCount == int.MaxValue)
{
- iCount = -1;
+ _iCount = -1;
return '\0';
}
// Return the best fit character
- return cBestFit;
+ return _cBestFit;
}
public override bool MovePrevious()
{
// Exception fallback doesn't have anywhere to back up to.
- if (iCount >= 0)
- iCount++;
+ if (_iCount >= 0)
+ _iCount++;
// Return true if we could do it.
- return (iCount >= 0 && iCount <= iSize);
+ return (_iCount >= 0 && _iCount <= _iSize);
}
// How many characters left to output?
{
get
{
- return (iCount > 0) ? iCount : 0;
+ return (_iCount > 0) ? _iCount : 0;
}
}
// Clear the buffer
public override unsafe void Reset()
{
- iCount = -1;
+ _iCount = -1;
byteStart = null;
}
{
// Need to figure out our best fit character, low is beginning of array, high is 1 AFTER end of array
int lowBound = 0;
- int highBound = oFallback.arrayBestFit.Length;
+ int highBound = _oFallback._arrayBestFit.Length;
int index;
char cCheck;
cCheck = unchecked((char)((bytesCheck[0] << 8) + bytesCheck[1]));
// Check trivial out of range case
- if (cCheck < oFallback.arrayBestFit[0] || cCheck > oFallback.arrayBestFit[highBound - 2])
+ if (cCheck < _oFallback._arrayBestFit[0] || cCheck > _oFallback._arrayBestFit[highBound - 2])
return '\0';
// Binary search the array
// Also note that index can never == highBound (because diff is rounded down)
index = ((iDiff / 2) + lowBound) & 0xFFFE;
- char cTest = oFallback.arrayBestFit[index];
+ char cTest = _oFallback._arrayBestFit[index];
if (cTest == cCheck)
{
// We found it
- Debug.Assert(index + 1 < oFallback.arrayBestFit.Length,
+ Debug.Assert(index + 1 < _oFallback._arrayBestFit.Length,
"[InternalDecoderBestFitFallbackBuffer.TryBestFit]Expected replacement character at end of array");
- return oFallback.arrayBestFit[index + 1];
+ return _oFallback._arrayBestFit[index + 1];
}
else if (cTest < cCheck)
{
for (index = lowBound; index < highBound; index += 2)
{
- if (oFallback.arrayBestFit[index] == cCheck)
+ if (_oFallback._arrayBestFit[index] == cCheck)
{
// We found it
- Debug.Assert(index + 1 < oFallback.arrayBestFit.Length,
+ Debug.Assert(index + 1 < _oFallback._arrayBestFit.Length,
"[InternalDecoderBestFitFallbackBuffer.TryBestFit]Expected replacement character at end of array");
- return oFallback.arrayBestFit[index + 1];
+ return _oFallback._arrayBestFit[index + 1];
}
}
// See the LICENSE file in the project root for more information.
using System;
-using System.Runtime.Serialization;
using System.Globalization;
namespace System.Text
int i;
for (i = 0; i < bytesUnknown.Length && i < 20; i++)
{
- strBytes.Append("[");
+ strBytes.Append('[');
strBytes.Append(bytesUnknown[i].ToString("X2", CultureInfo.InvariantCulture));
- strBytes.Append("]");
+ strBytes.Append(']');
}
// In case the string's really long
// Known index
throw new DecoderFallbackException(
- SR.Format(SR.Argument_InvalidCodePageBytesIndex, strBytes, index), bytesUnknown, index);
+ SR.Format(SR.Argument_InvalidCodePageBytesIndex,
+ strBytes, index), bytesUnknown, index);
}
}
// Exception for decoding unknown byte sequences.
public sealed class DecoderFallbackException : ArgumentException
{
- private byte[] bytesUnknown = null;
- private int index = 0;
+ private byte[] _bytesUnknown = null;
+ private int _index = 0;
public DecoderFallbackException()
: base(SR.Arg_ArgumentException)
HResult = __HResults.COR_E_ARGUMENT;
}
- internal DecoderFallbackException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- throw new PlatformNotSupportedException();
- }
-
- public DecoderFallbackException(
- String message, byte[] bytesUnknown, int index) : base(message)
+ public DecoderFallbackException(String message, byte[] bytesUnknown, int index)
+ : base(message)
{
- this.bytesUnknown = bytesUnknown;
- this.index = index;
+ _bytesUnknown = bytesUnknown;
+ _index = index;
}
public byte[] BytesUnknown
{
get
{
- return (bytesUnknown);
+ return (_bytesUnknown);
}
}
{
get
{
- return index;
+ return _index;
}
}
}
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-//
-
-using System;
-using System.Security;
-using System.Threading;
-using System.Globalization;
using System.Diagnostics;
-using System.Diagnostics.Contracts;
+using System.Globalization;
+using System.Threading;
namespace System.Text
{
public abstract class DecoderFallback
{
- internal bool bIsMicrosoftBestFitFallback = false;
-
- private static volatile DecoderFallback replacementFallback; // Default fallback, uses no best fit & "?"
- private static volatile DecoderFallback exceptionFallback;
-
- // Private object for locking instead of locking on a internal type for SQL reliability work.
- private static Object s_InternalSyncObject;
- private static Object InternalSyncObject
- {
- get
- {
- if (s_InternalSyncObject == null)
- {
- Object o = new Object();
- Interlocked.CompareExchange<Object>(ref s_InternalSyncObject, o, null);
- }
- return s_InternalSyncObject;
- }
- }
+ private static DecoderFallback s_replacementFallback; // Default fallback, uses no best fit & "?"
+ private static DecoderFallback s_exceptionFallback;
- // Get each of our generic fallbacks.
+ public static DecoderFallback ReplacementFallback =>
+ s_replacementFallback ?? Interlocked.CompareExchange(ref s_replacementFallback, new DecoderReplacementFallback(), null) ?? s_replacementFallback;
- public static DecoderFallback ReplacementFallback
- {
- get
- {
- if (replacementFallback == null)
- lock (InternalSyncObject)
- if (replacementFallback == null)
- replacementFallback = new DecoderReplacementFallback();
- return replacementFallback;
- }
- }
-
-
- public static DecoderFallback ExceptionFallback
- {
- get
- {
- if (exceptionFallback == null)
- lock (InternalSyncObject)
- if (exceptionFallback == null)
- exceptionFallback = new DecoderExceptionFallback();
-
- return exceptionFallback;
- }
- }
+ public static DecoderFallback ExceptionFallback =>
+ s_exceptionFallback ?? Interlocked.CompareExchange<DecoderFallback>(ref s_exceptionFallback, new DecoderExceptionFallback(), null) ?? s_exceptionFallback;
// Fallback
//
// Return the appropriate unicode string alternative to the character that need to fall back.
- // Most implimentations will be:
+ // Most implementations will be:
// return new MyCustomDecoderFallbackBuffer(this);
public abstract DecoderFallbackBuffer CreateFallbackBuffer();
public abstract class DecoderFallbackBuffer
{
- // Most implimentations will probably need an implimenation-specific constructor
+ // Most implementations will probably need an implementation-specific constructor
- // internal methods that cannot be overriden that let us do our fallback thing
+ // internal methods that cannot be overridden that let us do our fallback thing
// These wrap the internal methods so that we can check for people doing stuff that's incorrect
public abstract bool Fallback(byte[] bytesUnknown, int index);
}
// Set the above values
- // This can't be part of the constructor because DecoderFallbacks would have to know how to impliment these.
+ // This can't be part of the constructor because DecoderFallbacks would have to know how to implement these.
internal unsafe void InternalInitialize(byte* byteStart, char* charEnd)
{
this.byteStart = byteStart;
// Don't touch ref chars unless we succeed
internal unsafe virtual bool InternalFallback(byte[] bytes, byte* pBytes, ref char* chars)
{
- // Copy bytes to array (slow, but right now that's what we get to do.
- // byte[] bytesUnknown = new byte[count];
- // for (int i = 0; i < count; i++)
- // bytesUnknown[i] = *(bytes++);
-
Debug.Assert(byteStart != null, "[DecoderFallback.InternalFallback]Used InternalFallback without calling InternalInitialize");
// See if there's a fallback character and we have an output buffer then copy our string.
// Right now this has both bytes and bytes[], since we might have extra bytes, hence the
// array, and we might need the index, hence the byte*
{
- // Copy bytes to array (slow, but right now that's what we get to do.
- // byte[] bytesUnknown = new byte[count];
- // for (int i = 0; i < count; i++)
- // bytesUnknown[i] = *(bytes++);
-
Debug.Assert(byteStart != null, "[DecoderFallback.InternalFallback]Used InternalFallback without calling InternalInitialize");
// See if there's a fallback character and we have an output buffer then copy our string.
for (i = 0; i < bytesUnknown.Length && i < 20; i++)
{
if (strBytes.Length > 0)
- strBytes.Append(" ");
- strBytes.Append(String.Format(CultureInfo.InvariantCulture, "\\x{0:X2}", bytesUnknown[i]));
+ strBytes.Append(' ');
+ strBytes.AppendFormat(CultureInfo.InvariantCulture, "\\x{0:X2}", bytesUnknown[i]);
}
// In case the string's really long
if (i == 20)
// Throw it, using our complete bytes
throw new ArgumentException(
- SR.Format(SR.Argument_RecursiveFallbackBytes, strBytes.ToString()), nameof(bytesUnknown));
+ SR.Format(SR.Argument_RecursiveFallbackBytes,
+ strBytes.ToString()), nameof(bytesUnknown));
}
}
}
// Instances of specific implementations of the Decoder abstract base
// class are typically obtained through calls to the GetDecoder method
// of Encoding objects.
- //
- internal class DecoderNLS : Decoder, ISerializable
+ internal class DecoderNLS : Decoder
{
// Remember our encoding
- protected Encoding m_encoding;
- [NonSerialized] protected bool m_mustFlush;
- [NonSerialized] internal bool m_throwOnOverflow;
- [NonSerialized] internal int m_bytesUsed;
-
- #region Serialization
-
- // ISerializable implementation.
- void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException();
- }
-
- #endregion Serialization
+ private Encoding _encoding;
+ private bool _mustFlush;
+ internal bool _throwOnOverflow;
+ internal int _bytesUsed;
internal DecoderNLS(Encoding encoding)
{
- this.m_encoding = encoding;
- this.m_fallback = this.m_encoding.DecoderFallback;
+ _encoding = encoding;
+ _fallback = this._encoding.DecoderFallback;
this.Reset();
}
// This is used by our child deserializers
internal DecoderNLS()
{
- this.m_encoding = null;
+ _encoding = null;
this.Reset();
}
public override void Reset()
{
- if (m_fallbackBuffer != null)
- m_fallbackBuffer.Reset();
+ _fallbackBuffer?.Reset();
}
public override unsafe int GetCharCount(byte[] bytes, int index, int count)
Contract.EndContractBlock();
// Remember the flush
- this.m_mustFlush = flush;
- this.m_throwOnOverflow = true;
+ _mustFlush = flush;
+ _throwOnOverflow = true;
// By default just call the encoding version, no flush by default
- return m_encoding.GetCharCount(bytes, count, this);
+ return _encoding.GetCharCount(bytes, count, this);
}
public override unsafe int GetChars(byte[] bytes, int byteIndex, int byteCount,
Contract.EndContractBlock();
// Remember our flush
- m_mustFlush = flush;
- m_throwOnOverflow = true;
+ _mustFlush = flush;
+ _throwOnOverflow = true;
- // By default just call the encoding's version
- return m_encoding.GetChars(bytes, byteCount, chars, charCount, this);
+ // By default just call the encodings version
+ return _encoding.GetChars(bytes, byteCount, chars, charCount, this);
}
// This method is used when the output buffer might not be big enough.
Contract.EndContractBlock();
// We don't want to throw
- this.m_mustFlush = flush;
- this.m_throwOnOverflow = false;
- this.m_bytesUsed = 0;
+ _mustFlush = flush;
+ _throwOnOverflow = false;
+ _bytesUsed = 0;
// Do conversion
- charsUsed = this.m_encoding.GetChars(bytes, byteCount, chars, charCount, this);
- bytesUsed = this.m_bytesUsed;
+ charsUsed = _encoding.GetChars(bytes, byteCount, chars, charCount, this);
+ bytesUsed = _bytesUsed;
// Its completed if they've used what they wanted AND if they didn't want flush or if we are flushed
completed = (bytesUsed == byteCount) && (!flush || !this.HasState) &&
- (m_fallbackBuffer == null || m_fallbackBuffer.Remaining == 0);
+ (_fallbackBuffer == null || _fallbackBuffer.Remaining == 0);
- // Our data thingys are now full, we can return
+ // Our data thingy are now full, we can return
}
public bool MustFlush
{
get
{
- return m_mustFlush;
+ return _mustFlush;
}
}
// Allow encoding to clear our must flush instead of throwing (in ThrowCharsOverflow)
internal void ClearMustFlush()
{
- m_mustFlush = false;
+ _mustFlush = false;
}
}
}
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System;
using System.Diagnostics;
using System.Diagnostics.Contracts;
public sealed class DecoderReplacementFallback : DecoderFallback
{
// Our variables
- private String strDefault;
+ private String _strDefault;
// Construction. Default replacement fallback uses no best fit and ? replacement string
public DecoderReplacementFallback() : this("?")
if (bFoundHigh)
throw new ArgumentException(SR.Format(SR.Argument_InvalidCharSequenceNoIndex, nameof(replacement)));
- strDefault = replacement;
+ _strDefault = replacement;
}
public String DefaultString
{
get
{
- return strDefault;
+ return _strDefault;
}
}
{
get
{
- return strDefault.Length;
+ return _strDefault.Length;
}
}
DecoderReplacementFallback that = value as DecoderReplacementFallback;
if (that != null)
{
- return (strDefault == that.strDefault);
+ return (_strDefault == that._strDefault);
}
return (false);
}
public override int GetHashCode()
{
- return strDefault.GetHashCode();
+ return _strDefault.GetHashCode();
}
}
public sealed class DecoderReplacementFallbackBuffer : DecoderFallbackBuffer
{
// Store our default string
- private String strDefault;
- private int fallbackCount = -1;
- private int fallbackIndex = -1;
+ private String _strDefault;
+ private int _fallbackCount = -1;
+ private int _fallbackIndex = -1;
// Construction
public DecoderReplacementFallbackBuffer(DecoderReplacementFallback fallback)
{
- strDefault = fallback.DefaultString;
+ _strDefault = fallback.DefaultString;
}
// Fallback Methods
{
// We expect no previous fallback in our buffer
// We can't call recursively but others might (note, we don't test on last char!!!)
- if (fallbackCount >= 1)
+ if (_fallbackCount >= 1)
{
ThrowLastBytesRecursive(bytesUnknown);
}
// Go ahead and get our fallback
- if (strDefault.Length == 0)
+ if (_strDefault.Length == 0)
return false;
- fallbackCount = strDefault.Length;
- fallbackIndex = -1;
+ _fallbackCount = _strDefault.Length;
+ _fallbackIndex = -1;
return true;
}
{
// We want it to get < 0 because == 0 means that the current/last character is a fallback
// and we need to detect recursion. We could have a flag but we already have this counter.
- fallbackCount--;
- fallbackIndex++;
+ _fallbackCount--;
+ _fallbackIndex++;
// Do we have anything left? 0 is now last fallback char, negative is nothing left
- if (fallbackCount < 0)
+ if (_fallbackCount < 0)
return '\0';
// Need to get it out of the buffer.
// Make sure it didn't wrap from the fast count-- path
- if (fallbackCount == int.MaxValue)
+ if (_fallbackCount == int.MaxValue)
{
- fallbackCount = -1;
+ _fallbackCount = -1;
return '\0';
}
// Now make sure its in the expected range
- Debug.Assert(fallbackIndex < strDefault.Length && fallbackIndex >= 0,
+ Debug.Assert(_fallbackIndex < _strDefault.Length && _fallbackIndex >= 0,
"Index exceeds buffer range");
- return strDefault[fallbackIndex];
+ return _strDefault[_fallbackIndex];
}
public override bool MovePrevious()
{
// Back up one, only if we just processed the last character (or earlier)
- if (fallbackCount >= -1 && fallbackIndex >= 0)
+ if (_fallbackCount >= -1 && _fallbackIndex >= 0)
{
- fallbackIndex--;
- fallbackCount++;
+ _fallbackIndex--;
+ _fallbackCount++;
return true;
}
get
{
// Our count is 0 for 1 character left.
- return (fallbackCount < 0) ? 0 : fallbackCount;
+ return (_fallbackCount < 0) ? 0 : _fallbackCount;
}
}
// Clear the buffer
public override unsafe void Reset()
{
- fallbackCount = -1;
- fallbackIndex = -1;
+ _fallbackCount = -1;
+ _fallbackIndex = -1;
byteStart = null;
}
// array, and we might need the index, hence the byte*
{
// return our replacement string Length
- return strDefault.Length;
+ return _strDefault.Length;
}
}
}
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System.Runtime.Serialization;
using System.Text;
using System;
using System.Diagnostics;
//
public abstract class Encoder
{
- internal EncoderFallback m_fallback = null;
+ internal EncoderFallback _fallback = null;
- [NonSerialized]
- internal EncoderFallbackBuffer m_fallbackBuffer = null;
-
- internal void SerializeEncoder(SerializationInfo info)
- {
- info.AddValue("m_fallback", this.m_fallback);
- }
+ internal EncoderFallbackBuffer _fallbackBuffer = null;
protected Encoder()
{
{
get
{
- return m_fallback;
+ return _fallback;
}
set
Contract.EndContractBlock();
// Can't change fallback if buffer is wrong
- if (m_fallbackBuffer != null && m_fallbackBuffer.Remaining > 0)
+ if (_fallbackBuffer != null && _fallbackBuffer.Remaining > 0)
throw new ArgumentException(
SR.Argument_FallbackBufferNotEmpty, nameof(value));
- m_fallback = value;
- m_fallbackBuffer = null;
+ _fallback = value;
+ _fallbackBuffer = null;
}
}
{
get
{
- if (m_fallbackBuffer == null)
+ if (_fallbackBuffer == null)
{
- if (m_fallback != null)
- m_fallbackBuffer = m_fallback.CreateFallbackBuffer();
+ if (_fallback != null)
+ _fallbackBuffer = _fallback.CreateFallbackBuffer();
else
- m_fallbackBuffer = EncoderFallback.ReplacementFallback.CreateFallbackBuffer();
+ _fallbackBuffer = EncoderFallback.ReplacementFallback.CreateFallbackBuffer();
}
- return m_fallbackBuffer;
+ return _fallbackBuffer;
}
}
{
get
{
- return m_fallbackBuffer != null;
+ return _fallbackBuffer != null;
}
}
char[] charTemp = { };
byte[] byteTemp = new byte[GetByteCount(charTemp, 0, 0, true)];
GetBytes(charTemp, 0, 0, byteTemp, 0, true);
- if (m_fallbackBuffer != null)
- m_fallbackBuffer.Reset();
+ if (_fallbackBuffer != null)
+ _fallbackBuffer.Reset();
}
// Returns the number of bytes the next call to GetBytes will
{
bytesUsed = GetBytes(chars, charIndex, charsUsed, bytes, byteIndex, flush);
completed = (charsUsed == charCount &&
- (m_fallbackBuffer == null || m_fallbackBuffer.Remaining == 0));
+ (_fallbackBuffer == null || _fallbackBuffer.Remaining == 0));
return;
}
{
bytesUsed = GetBytes(chars, charsUsed, bytes, byteCount, flush);
completed = (charsUsed == charCount &&
- (m_fallbackBuffer == null || m_fallbackBuffer.Remaining == 0));
+ (_fallbackBuffer == null || _fallbackBuffer.Remaining == 0));
return;
}
// This is used internally to create best fit behavior as per the original windows best fit behavior.
//
-using System;
-using System.Globalization;
-using System.Text;
-using System.Threading;
using System.Diagnostics;
using System.Diagnostics.Contracts;
+using System.Globalization;
+using System.Threading;
namespace System.Text
{
- internal sealed class InternalEncoderBestFitFallback : EncoderFallback
+ internal class InternalEncoderBestFitFallback : EncoderFallback
{
// Our variables
- internal Encoding encoding = null;
- internal char[] arrayBestFit = null;
+ internal Encoding _encoding = null;
+ internal char[] _arrayBestFit = null;
internal InternalEncoderBestFitFallback(Encoding encoding)
{
// Need to load our replacement characters table.
- this.encoding = encoding;
- this.bIsMicrosoftBestFitFallback = true;
+ _encoding = encoding;
}
public override EncoderFallbackBuffer CreateFallbackBuffer()
InternalEncoderBestFitFallback that = value as InternalEncoderBestFitFallback;
if (that != null)
{
- return (this.encoding.CodePage == that.encoding.CodePage);
+ return (_encoding.CodePage == that._encoding.CodePage);
}
return (false);
}
public override int GetHashCode()
{
- return this.encoding.CodePage;
+ return _encoding.CodePage;
}
}
internal sealed class InternalEncoderBestFitFallbackBuffer : EncoderFallbackBuffer
{
// Our variables
- private char cBestFit = '\0';
- private InternalEncoderBestFitFallback oFallback;
- private int iCount = -1;
- private int iSize;
+ private char _cBestFit = '\0';
+ private InternalEncoderBestFitFallback _oFallback;
+ private int _iCount = -1;
+ private int _iSize;
// Private object for locking instead of locking on a public type for SQL reliability work.
private static Object s_InternalSyncObject;
// Constructor
public InternalEncoderBestFitFallbackBuffer(InternalEncoderBestFitFallback fallback)
{
- oFallback = fallback;
+ _oFallback = fallback;
- if (oFallback.arrayBestFit == null)
+ if (_oFallback._arrayBestFit == null)
{
// Lock so we don't confuse ourselves.
lock (InternalSyncObject)
{
// Double check before we do it again.
- if (oFallback.arrayBestFit == null)
- oFallback.arrayBestFit = fallback.encoding.GetBestFitUnicodeToBytesData();
+ if (_oFallback._arrayBestFit == null)
+ _oFallback._arrayBestFit = fallback._encoding.GetBestFitUnicodeToBytesData();
}
}
}
// If we had a buffer already we're being recursive, throw, it's probably at the suspect
// character in our array.
// Shouldn't be able to get here for all of our code pages, table would have to be messed up.
- Debug.Assert(iCount < 1, "[InternalEncoderBestFitFallbackBuffer.Fallback(non surrogate)] Fallback char " + ((int)cBestFit).ToString("X4", CultureInfo.InvariantCulture) + " caused recursive fallback");
+ Debug.Assert(_iCount < 1, "[InternalEncoderBestFitFallbackBuffer.Fallback(non surrogate)] Fallback char " + ((int)_cBestFit).ToString("X4", CultureInfo.InvariantCulture) + " caused recursive fallback");
- iCount = iSize = 1;
- cBestFit = TryBestFit(charUnknown);
- if (cBestFit == '\0')
- cBestFit = '?';
+ _iCount = _iSize = 1;
+ _cBestFit = TryBestFit(charUnknown);
+ if (_cBestFit == '\0')
+ _cBestFit = '?';
return true;
}
// Double check input surrogate pair
if (!Char.IsHighSurrogate(charUnknownHigh))
throw new ArgumentOutOfRangeException(nameof(charUnknownHigh),
- SR.Format(SR.ArgumentOutOfRange_Range, 0xD800, 0xDBFF));
+ SR.Format(SR.ArgumentOutOfRange_Range,
+ 0xD800, 0xDBFF));
if (!Char.IsLowSurrogate(charUnknownLow))
throw new ArgumentOutOfRangeException(nameof(charUnknownLow),
- SR.Format(SR.ArgumentOutOfRange_Range, 0xDC00, 0xDFFF));
+ SR.Format(SR.ArgumentOutOfRange_Range,
+ 0xDC00, 0xDFFF));
Contract.EndContractBlock();
// If we had a buffer already we're being recursive, throw, it's probably at the suspect
// character in our array. 0 is processing last character, < 0 is not falling back
// Shouldn't be able to get here, table would have to be messed up.
- Debug.Assert(iCount < 1, "[InternalEncoderBestFitFallbackBuffer.Fallback(surrogate)] Fallback char " + ((int)cBestFit).ToString("X4", CultureInfo.InvariantCulture) + " caused recursive fallback");
+ Debug.Assert(_iCount < 1, "[InternalEncoderBestFitFallbackBuffer.Fallback(surrogate)] Fallback char " + ((int)_cBestFit).ToString("X4", CultureInfo.InvariantCulture) + " caused recursive fallback");
// Go ahead and get our fallback, surrogates don't have best fit
- cBestFit = '?';
- iCount = iSize = 2;
+ _cBestFit = '?';
+ _iCount = _iSize = 2;
return true;
}
{
// We want it to get < 0 because == 0 means that the current/last character is a fallback
// and we need to detect recursion. We could have a flag but we already have this counter.
- iCount--;
+ _iCount--;
// Do we have anything left? 0 is now last fallback char, negative is nothing left
- if (iCount < 0)
+ if (_iCount < 0)
return '\0';
// Need to get it out of the buffer.
// Make sure it didn't wrap from the fast count-- path
- if (iCount == int.MaxValue)
+ if (_iCount == int.MaxValue)
{
- iCount = -1;
+ _iCount = -1;
return '\0';
}
// Return the best fit character
- return cBestFit;
+ return _cBestFit;
}
public override bool MovePrevious()
{
// Exception fallback doesn't have anywhere to back up to.
- if (iCount >= 0)
- iCount++;
+ if (_iCount >= 0)
+ _iCount++;
// Return true if we could do it.
- return (iCount >= 0 && iCount <= iSize);
+ return (_iCount >= 0 && _iCount <= _iSize);
}
{
get
{
- return (iCount > 0) ? iCount : 0;
+ return (_iCount > 0) ? _iCount : 0;
}
}
// Clear the buffer
public override unsafe void Reset()
{
- iCount = -1;
+ _iCount = -1;
charStart = null;
bFallingBack = false;
}
{
// Need to figure out our best fit character, low is beginning of array, high is 1 AFTER end of array
int lowBound = 0;
- int highBound = oFallback.arrayBestFit.Length;
+ int highBound = _oFallback._arrayBestFit.Length;
int index;
// Binary search the array
// Also note that index can never == highBound (because diff is rounded down)
index = ((iDiff / 2) + lowBound) & 0xFFFE;
- char cTest = oFallback.arrayBestFit[index];
+ char cTest = _oFallback._arrayBestFit[index];
if (cTest == cUnknown)
{
// We found it
- Debug.Assert(index + 1 < oFallback.arrayBestFit.Length,
+ Debug.Assert(index + 1 < _oFallback._arrayBestFit.Length,
"[InternalEncoderBestFitFallbackBuffer.TryBestFit]Expected replacement character at end of array");
- return oFallback.arrayBestFit[index + 1];
+ return _oFallback._arrayBestFit[index + 1];
}
else if (cTest < cUnknown)
{
for (index = lowBound; index < highBound; index += 2)
{
- if (oFallback.arrayBestFit[index] == cUnknown)
+ if (_oFallback._arrayBestFit[index] == cUnknown)
{
// We found it
- Debug.Assert(index + 1 < oFallback.arrayBestFit.Length,
+ Debug.Assert(index + 1 < _oFallback._arrayBestFit.Length,
"[InternalEncoderBestFitFallbackBuffer.TryBestFit]Expected replacement character at end of array");
- return oFallback.arrayBestFit[index + 1];
+ return _oFallback._arrayBestFit[index + 1];
}
}
public sealed class EncoderFallbackException : ArgumentException
{
- private char charUnknown;
- private char charUnknownHigh;
- private char charUnknownLow;
- private int index;
+ private char _charUnknown;
+ private char _charUnknownHigh;
+ private char _charUnknownLow;
+ private int _index;
public EncoderFallbackException()
: base(SR.Arg_ArgumentException)
internal EncoderFallbackException(
String message, char charUnknown, int index) : base(message)
{
- this.charUnknown = charUnknown;
- this.index = index;
+ _charUnknown = charUnknown;
+ _index = index;
}
internal EncoderFallbackException(
}
Contract.EndContractBlock();
- this.charUnknownHigh = charUnknownHigh;
- this.charUnknownLow = charUnknownLow;
- this.index = index;
+ _charUnknownHigh = charUnknownHigh;
+ _charUnknownLow = charUnknownLow;
+ _index = index;
}
public char CharUnknown
{
get
{
- return (charUnknown);
+ return (_charUnknown);
}
}
{
get
{
- return (charUnknownHigh);
+ return (_charUnknownHigh);
}
}
{
get
{
- return (charUnknownLow);
+ return (_charUnknownLow);
}
}
{
get
{
- return index;
+ return _index;
}
}
// Return true if the unknown character is a surrogate pair.
public bool IsUnknownSurrogate()
{
- return (charUnknownHigh != '\0');
+ return (_charUnknownHigh != '\0');
}
}
}
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System;
-using System.Security;
-using System.Threading;
using System.Diagnostics;
-using System.Diagnostics.Contracts;
+using System.Threading;
namespace System.Text
{
public abstract class EncoderFallback
{
- // disable csharp compiler warning #0414: field assigned unused value
-#pragma warning disable 0414
- internal bool bIsMicrosoftBestFitFallback = false;
-#pragma warning restore 0414
-
- private static volatile EncoderFallback replacementFallback; // Default fallback, uses no best fit & "?"
- private static volatile EncoderFallback exceptionFallback;
-
- // Private object for locking instead of locking on a public type for SQL reliability work.
- private static Object s_InternalSyncObject;
- private static Object InternalSyncObject
- {
- get
- {
- if (s_InternalSyncObject == null)
- {
- Object o = new Object();
- Interlocked.CompareExchange<Object>(ref s_InternalSyncObject, o, null);
- }
- return s_InternalSyncObject;
- }
- }
+ private static EncoderFallback s_replacementFallback; // Default fallback, uses no best fit & "?"
+ private static EncoderFallback s_exceptionFallback;
// Get each of our generic fallbacks.
{
get
{
- if (replacementFallback == null)
- lock (InternalSyncObject)
- if (replacementFallback == null)
- replacementFallback = new EncoderReplacementFallback();
+ if (s_replacementFallback == null)
+ Interlocked.CompareExchange<EncoderFallback>(ref s_replacementFallback, new EncoderReplacementFallback(), null);
- return replacementFallback;
+ return s_replacementFallback;
}
}
{
get
{
- if (exceptionFallback == null)
- lock (InternalSyncObject)
- if (exceptionFallback == null)
- exceptionFallback = new EncoderExceptionFallback();
+ if (s_exceptionFallback == null)
+ Interlocked.CompareExchange<EncoderFallback>(ref s_exceptionFallback, new EncoderExceptionFallback(), null);
- return exceptionFallback;
+ return s_exceptionFallback;
}
}
// Fallback
//
// Return the appropriate unicode string alternative to the character that need to fall back.
- // Most implimentations will be:
+ // Most implementations will be:
// return new MyCustomEncoderFallbackBuffer(this);
public abstract EncoderFallbackBuffer CreateFallbackBuffer();
public abstract class EncoderFallbackBuffer
{
- // Most implementations will probably need an implemenation-specific constructor
+ // Most implementations will probably need an implementation-specific constructor
- // Public methods that cannot be overriden that let us do our fallback thing
+ // Public methods that cannot be overridden that let us do our fallback thing
// These wrap the internal methods so that we can check for people doing stuff that is incorrect
public abstract bool Fallback(char charUnknown, int index);
}
// Set the above values
- // This can't be part of the constructor because EncoderFallbacks would have to know how to impliment these.
+ // This can't be part of the constructor because EncoderFallbacks would have to know how to implement these.
internal unsafe void InternalInitialize(char* charStart, char* charEnd, EncoderNLS encoder, bool setEncoder)
{
this.charStart = charStart;
if (this.setEncoder)
{
bUsedEncoder = true;
- this.encoder.charLeftOver = ch;
+ this.encoder._charLeftOver = ch;
}
bFallingBack = false;
return false;
bFallingBack = Fallback(ch, cNext, index);
return bFallingBack;
}
-
// Next isn't a low surrogate, just fallback the high surrogate
}
}
{
// Throw it, using our complete character
throw new ArgumentException(
- SR.Format(SR.Argument_RecursiveFallback, charRecursive), "chars");
+ SR.Format(SR.Argument_RecursiveFallback,
+ charRecursive), "chars");
}
}
}
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System.Runtime.Serialization;
using System.Text;
using System;
using System.Diagnostics.Contracts;
// of Encoding objects.
//
- internal class EncoderNLS : Encoder, ISerializable
+ internal class EncoderNLS : Encoder
{
// Need a place for the last left over character, most of our encodings use this
- internal char charLeftOver;
-
- protected Encoding m_encoding;
-
- [NonSerialized] protected bool m_mustFlush;
- [NonSerialized] internal bool m_throwOnOverflow;
- [NonSerialized] internal int m_charsUsed;
-
- #region Serialization
-
- // ISerializable implementation.
- void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException();
- }
-
- #endregion Serialization
+ internal char _charLeftOver;
+ private Encoding _encoding;
+ private bool _mustFlush;
+ internal bool _throwOnOverflow;
+ internal int _charsUsed;
internal EncoderNLS(Encoding encoding)
{
- this.m_encoding = encoding;
- this.m_fallback = this.m_encoding.EncoderFallback;
+ _encoding = encoding;
+ _fallback = _encoding.EncoderFallback;
this.Reset();
}
- // This one is used when deserializing (like UTF7Encoding.Encoder)
internal EncoderNLS()
{
- this.m_encoding = null;
+ _encoding = null;
this.Reset();
}
public override void Reset()
{
- this.charLeftOver = (char)0;
- if (m_fallbackBuffer != null)
- m_fallbackBuffer.Reset();
+ _charLeftOver = (char)0;
+ if (_fallbackBuffer != null)
+ _fallbackBuffer.Reset();
}
public override unsafe int GetByteCount(char[] chars, int index, int count, bool flush)
SR.ArgumentOutOfRange_NeedNonNegNum);
Contract.EndContractBlock();
- this.m_mustFlush = flush;
- this.m_throwOnOverflow = true;
- return m_encoding.GetByteCount(chars, count, this);
+ _mustFlush = flush;
+ _throwOnOverflow = true;
+ return _encoding.GetByteCount(chars, count, this);
}
public override unsafe int GetBytes(char[] chars, int charIndex, int charCount,
SR.ArgumentOutOfRange_NeedNonNegNum);
Contract.EndContractBlock();
- this.m_mustFlush = flush;
- this.m_throwOnOverflow = true;
- return m_encoding.GetBytes(chars, charCount, bytes, byteCount, this);
+ _mustFlush = flush;
+ _throwOnOverflow = true;
+ return _encoding.GetBytes(chars, charCount, bytes, byteCount, this);
}
// This method is used when your output buffer might not be large enough for the entire result.
Contract.EndContractBlock();
// We don't want to throw
- this.m_mustFlush = flush;
- this.m_throwOnOverflow = false;
- this.m_charsUsed = 0;
+ _mustFlush = flush;
+ _throwOnOverflow = false;
+ _charsUsed = 0;
// Do conversion
- bytesUsed = this.m_encoding.GetBytes(chars, charCount, bytes, byteCount, this);
- charsUsed = this.m_charsUsed;
+ bytesUsed = _encoding.GetBytes(chars, charCount, bytes, byteCount, this);
+ charsUsed = _charsUsed;
// Its completed if they've used what they wanted AND if they didn't want flush or if we are flushed
completed = (charsUsed == charCount) && (!flush || !this.HasState) &&
- (m_fallbackBuffer == null || m_fallbackBuffer.Remaining == 0);
+ (_fallbackBuffer == null || _fallbackBuffer.Remaining == 0);
// Our data thingys are now full, we can return
}
{
get
{
- return m_encoding;
+ return _encoding;
}
}
{
get
{
- return m_mustFlush;
+ return _mustFlush;
}
}
{
get
{
- return (this.charLeftOver != (char)0);
+ return (_charLeftOver != (char)0);
}
}
// Allow encoding to clear our must flush instead of throwing (in ThrowBytesOverflow)
internal void ClearMustFlush()
{
- m_mustFlush = false;
+ _mustFlush = false;
}
}
}
public sealed class EncoderReplacementFallback : EncoderFallback
{
// Our variables
- private String strDefault;
+ private String _strDefault;
// Construction. Default replacement fallback uses no best fit and ? replacement string
public EncoderReplacementFallback() : this("?")
if (bFoundHigh)
throw new ArgumentException(SR.Format(SR.Argument_InvalidCharSequenceNoIndex, nameof(replacement)));
- strDefault = replacement;
+ _strDefault = replacement;
}
public String DefaultString
{
get
{
- return strDefault;
+ return _strDefault;
}
}
{
get
{
- return strDefault.Length;
+ return _strDefault.Length;
}
}
EncoderReplacementFallback that = value as EncoderReplacementFallback;
if (that != null)
{
- return (strDefault == that.strDefault);
+ return (_strDefault == that._strDefault);
}
return (false);
}
public override int GetHashCode()
{
- return strDefault.GetHashCode();
+ return _strDefault.GetHashCode();
}
}
public sealed class EncoderReplacementFallbackBuffer : EncoderFallbackBuffer
{
// Store our default string
- private String strDefault;
- private int fallbackCount = -1;
- private int fallbackIndex = -1;
+ private String _strDefault;
+ private int _fallbackCount = -1;
+ private int _fallbackIndex = -1;
// Construction
public EncoderReplacementFallbackBuffer(EncoderReplacementFallback fallback)
{
// 2X in case we're a surrogate pair
- strDefault = fallback.DefaultString + fallback.DefaultString;
+ _strDefault = fallback.DefaultString + fallback.DefaultString;
}
// Fallback Methods
{
// If we had a buffer already we're being recursive, throw, it's probably at the suspect
// character in our array.
- if (fallbackCount >= 1)
+ if (_fallbackCount >= 1)
{
// If we're recursive we may still have something in our buffer that makes this a surrogate
- if (char.IsHighSurrogate(charUnknown) && fallbackCount >= 0 &&
- char.IsLowSurrogate(strDefault[fallbackIndex + 1]))
- ThrowLastCharRecursive(Char.ConvertToUtf32(charUnknown, strDefault[fallbackIndex + 1]));
+ if (char.IsHighSurrogate(charUnknown) && _fallbackCount >= 0 &&
+ char.IsLowSurrogate(_strDefault[_fallbackIndex + 1]))
+ ThrowLastCharRecursive(Char.ConvertToUtf32(charUnknown, _strDefault[_fallbackIndex + 1]));
// Nope, just one character
ThrowLastCharRecursive(unchecked((int)charUnknown));
// Go ahead and get our fallback
// Divide by 2 because we aren't a surrogate pair
- fallbackCount = strDefault.Length / 2;
- fallbackIndex = -1;
+ _fallbackCount = _strDefault.Length / 2;
+ _fallbackIndex = -1;
- return fallbackCount != 0;
+ return _fallbackCount != 0;
}
public override bool Fallback(char charUnknownHigh, char charUnknownLow, int index)
// If we had a buffer already we're being recursive, throw, it's probably at the suspect
// character in our array.
- if (fallbackCount >= 1)
+ if (_fallbackCount >= 1)
ThrowLastCharRecursive(Char.ConvertToUtf32(charUnknownHigh, charUnknownLow));
// Go ahead and get our fallback
- fallbackCount = strDefault.Length;
- fallbackIndex = -1;
+ _fallbackCount = _strDefault.Length;
+ _fallbackIndex = -1;
- return fallbackCount != 0;
+ return _fallbackCount != 0;
}
public override char GetNextChar()
{
// We want it to get < 0 because == 0 means that the current/last character is a fallback
// and we need to detect recursion. We could have a flag but we already have this counter.
- fallbackCount--;
- fallbackIndex++;
+ _fallbackCount--;
+ _fallbackIndex++;
// Do we have anything left? 0 is now last fallback char, negative is nothing left
- if (fallbackCount < 0)
+ if (_fallbackCount < 0)
return '\0';
// Need to get it out of the buffer.
// Make sure it didn't wrap from the fast count-- path
- if (fallbackCount == int.MaxValue)
+ if (_fallbackCount == int.MaxValue)
{
- fallbackCount = -1;
+ _fallbackCount = -1;
return '\0';
}
// Now make sure its in the expected range
- Debug.Assert(fallbackIndex < strDefault.Length && fallbackIndex >= 0,
+ Debug.Assert(_fallbackIndex < _strDefault.Length && _fallbackIndex >= 0,
"Index exceeds buffer range");
- return strDefault[fallbackIndex];
+ return _strDefault[_fallbackIndex];
}
public override bool MovePrevious()
{
// Back up one, only if we just processed the last character (or earlier)
- if (fallbackCount >= -1 && fallbackIndex >= 0)
+ if (_fallbackCount >= -1 && _fallbackIndex >= 0)
{
- fallbackIndex--;
- fallbackCount++;
+ _fallbackIndex--;
+ _fallbackCount++;
return true;
}
get
{
// Our count is 0 for 1 character left.
- return (fallbackCount < 0) ? 0 : fallbackCount;
+ return (_fallbackCount < 0) ? 0 : _fallbackCount;
}
}
// Clear the buffer
public override unsafe void Reset()
{
- fallbackCount = -1;
- fallbackIndex = 0;
+ _fallbackCount = -1;
+ _fallbackIndex = 0;
charStart = null;
bFallingBack = false;
}
// GetCharCount method can be used to determine the exact number of
// characters that will be produced for a given range of bytes.
// Alternatively, the GetMaxCharCount method can be used to
- // determine the maximum number of characterss that will be produced for a
+ // determine the maximum number of characters that will be produced for a
// given number of bytes, regardless of the actual byte values.
//
internal void ThrowBytesOverflow()
{
// Special message to include fallback type in case fallback's GetMaxCharCount is broken
- // This happens if user has implimented an encoder fallback with a broken GetMaxCharCount
+ // This happens if user has implemented an encoder fallback with a broken GetMaxCharCount
throw new ArgumentException(
SR.Format(SR.Argument_EncodingConversionOverflowBytes, EncodingName, EncoderFallback.GetType()), "bytes");
}
internal void ThrowBytesOverflow(EncoderNLS encoder, bool nothingEncoded)
{
- if (encoder == null || encoder.m_throwOnOverflow || nothingEncoded)
+ if (encoder == null || encoder._throwOnOverflow || nothingEncoded)
{
if (encoder != null && encoder.InternalHasFallbackBuffer)
encoder.FallbackBuffer.InternalReset();
// Special message to include fallback type in case fallback's GetMaxCharCount is broken
- // This happens if user has implimented an encoder fallback with a broken GetMaxCharCount
+ // This happens if user has implemented an encoder fallback with a broken GetMaxCharCount
ThrowBytesOverflow();
}
internal void ThrowCharsOverflow()
{
// Special message to include fallback type in case fallback's GetMaxCharCount is broken
- // This happens if user has implimented a decoder fallback with a broken GetMaxCharCount
+ // This happens if user has implemented a decoder fallback with a broken GetMaxCharCount
throw new ArgumentException(
SR.Format(SR.Argument_EncodingConversionOverflowChars, EncodingName, DecoderFallback.GetType()), "chars");
}
internal void ThrowCharsOverflow(DecoderNLS decoder, bool nothingDecoded)
{
- if (decoder == null || decoder.m_throwOnOverflow || nothingDecoded)
+ if (decoder == null || decoder._throwOnOverflow || nothingDecoded)
{
if (decoder != null && decoder.InternalHasFallbackBuffer)
decoder.FallbackBuffer.InternalReset();
// Special message to include fallback type in case fallback's GetMaxCharCount is broken
- // This happens if user has implimented a decoder fallback with a broken GetMaxCharCount
+ // This happens if user has implemented a decoder fallback with a broken GetMaxCharCount
ThrowCharsOverflow();
}
decoder.ClearMustFlush();
}
- internal sealed class DefaultEncoder : Encoder, IObjectReference, ISerializable
+ internal sealed class DefaultEncoder : Encoder, IObjectReference
{
- private Encoding m_encoding;
+ private Encoding _encoding;
public DefaultEncoder(Encoding encoding)
{
- m_encoding = encoding;
+ _encoding = encoding;
}
public Object GetRealObject(StreamingContext context)
throw new PlatformNotSupportedException();
}
- // ISerializable implementation, get data for this object
- void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException();
- }
-
// Returns the number of bytes the next call to GetBytes will
// produce if presented with the given range of characters and the given
// value of the flush parameter. The returned value takes into
public override int GetByteCount(char[] chars, int index, int count, bool flush)
{
- return m_encoding.GetByteCount(chars, index, count);
+ return _encoding.GetByteCount(chars, index, count);
}
[SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public unsafe override int GetByteCount(char* chars, int count, bool flush)
{
- return m_encoding.GetByteCount(chars, count);
+ return _encoding.GetByteCount(chars, count);
}
// Encodes a range of characters in a character array into a range of bytes
public override int GetBytes(char[] chars, int charIndex, int charCount,
byte[] bytes, int byteIndex, bool flush)
{
- return m_encoding.GetBytes(chars, charIndex, charCount, bytes, byteIndex);
+ return _encoding.GetBytes(chars, charIndex, charCount, bytes, byteIndex);
}
[SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public unsafe override int GetBytes(char* chars, int charCount,
byte* bytes, int byteCount, bool flush)
{
- return m_encoding.GetBytes(chars, charCount, bytes, byteCount);
+ return _encoding.GetBytes(chars, charCount, bytes, byteCount);
}
}
- internal sealed class DefaultDecoder : Decoder, IObjectReference, ISerializable
+ internal sealed class DefaultDecoder : Decoder, IObjectReference
{
- private Encoding m_encoding;
+ private Encoding _encoding;
public DefaultDecoder(Encoding encoding)
{
- m_encoding = encoding;
+ _encoding = encoding;
}
public Object GetRealObject(StreamingContext context)
throw new PlatformNotSupportedException();
}
- // ISerializable implementation
- void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException();
- }
-
// Returns the number of characters the next call to GetChars will
// produce if presented with the given range of bytes. The returned value
// takes into account the state in which the decoder was left following the
public override int GetCharCount(byte[] bytes, int index, int count, bool flush)
{
- return m_encoding.GetCharCount(bytes, index, count);
+ return _encoding.GetCharCount(bytes, index, count);
}
[SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public unsafe override int GetCharCount(byte* bytes, int count, bool flush)
{
// By default just call the encoding version, no flush by default
- return m_encoding.GetCharCount(bytes, count);
+ return _encoding.GetCharCount(bytes, count);
}
// Decodes a range of bytes in a byte array into a range of characters
public override int GetChars(byte[] bytes, int byteIndex, int byteCount,
char[] chars, int charIndex, bool flush)
{
- return m_encoding.GetChars(bytes, byteIndex, byteCount, chars, charIndex);
+ return _encoding.GetChars(bytes, byteIndex, byteCount, chars, charIndex);
}
[SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
char* chars, int charCount, bool flush)
{
// By default just call the encoding's version
- return m_encoding.GetChars(bytes, byteCount, chars, charCount);
+ return _encoding.GetChars(bytes, byteCount, chars, charCount);
}
}
{
this.fallbackBuffer = _encoder.FallbackBuffer;
// If we're not converting we must not have data in our fallback buffer
- if (_encoder.m_throwOnOverflow && _encoder.InternalHasFallbackBuffer &&
+ if (_encoder._throwOnOverflow && _encoder.InternalHasFallbackBuffer &&
this.fallbackBuffer.Remaining > 0)
throw new ArgumentException(SR.Format(SR.Argument_EncoderFallbackNotEmpty,
_encoder.Encoding.EncodingName, _encoder.Fallback.GetType()));
using System;
using System.Diagnostics;
using System.Diagnostics.Contracts;
-using System.Runtime.Serialization;
namespace System.Text
{
// Latin1Encoding is a simple override to optimize the GetString version of Latin1Encoding.
// because of the best fit cases we can't do this when encoding the string, only when decoding
//
- internal class Latin1Encoding : EncodingNLS, ISerializable
+ internal class Latin1Encoding : EncodingNLS
{
// Used by Encoding.Latin1 for lazy initialization
// The initialization code will not be run until a static member of the class is referenced
{
}
- // ISerializable implementation
- void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException();
- }
-
// GetByteCount
// Note: We start by assuming that the output will be the same as count. Having
// an encoder or fallback may change that assumption
EncoderReplacementFallback fallback;
if (encoder != null)
{
- charLeftOver = encoder.charLeftOver;
+ charLeftOver = encoder._charLeftOver;
Debug.Assert(charLeftOver == 0 || Char.IsHighSurrogate(charLeftOver),
"[Latin1Encoding.GetByteCount]leftover character should be high surrogate");
fallback = encoder.Fallback as EncoderReplacementFallback;
// Verify that we have no fallbackbuffer, for Latin1 its always empty, so just assert
- Debug.Assert(!encoder.m_throwOnOverflow || !encoder.InternalHasFallbackBuffer ||
+ Debug.Assert(!encoder._throwOnOverflow || !encoder.InternalHasFallbackBuffer ||
encoder.FallbackBuffer.Remaining == 0,
"[Latin1CodePageEncoding.GetByteCount]Expected empty fallback buffer");
}
EncoderReplacementFallback fallback = null;
if (encoder != null)
{
- charLeftOver = encoder.charLeftOver;
+ charLeftOver = encoder._charLeftOver;
fallback = encoder.Fallback as EncoderReplacementFallback;
Debug.Assert(charLeftOver == 0 || Char.IsHighSurrogate(charLeftOver),
"[Latin1Encoding.GetBytes]leftover character should be high surrogate");
// Verify that we have no fallbackbuffer, for ASCII its always empty, so just assert
- Debug.Assert(!encoder.m_throwOnOverflow || !encoder.InternalHasFallbackBuffer ||
+ Debug.Assert(!encoder._throwOnOverflow || !encoder.InternalHasFallbackBuffer ||
encoder.FallbackBuffer.Remaining == 0,
"[Latin1CodePageEncoding.GetBytes]Expected empty fallback buffer");
}
// Clear encoder
if (encoder != null)
{
- encoder.charLeftOver = (char)0;
- encoder.m_charsUsed = (int)(chars - charStart);
+ encoder._charLeftOver = (char)0;
+ encoder._charsUsed = (int)(chars - charStart);
}
return (int)(bytes - byteStart);
}
// Fallback stuck it in encoder if necessary, but we have to clear MustFlush cases
if (fallbackBuffer != null && !fallbackBuffer.bUsedEncoder)
// Clear it in case of MustFlush
- encoder.charLeftOver = (char)0;
+ encoder._charLeftOver = (char)0;
// Set our chars used count
- encoder.m_charsUsed = (int)(chars - charStart);
+ encoder._charsUsed = (int)(chars - charStart);
}
Debug.Assert(fallbackBuffer == null || fallbackBuffer.Remaining == 0,
// Might need to know input bytes used
if (decoder != null)
- decoder.m_bytesUsed = byteCount;
+ decoder._bytesUsed = byteCount;
// Converted sequence is same length as input, so output charsUsed is same as byteCount;
return byteCount;
// The following methods are copied from EncodingNLS.cs.
- // Unfortunately EncodingNLS.cs is internal and we're public, so we have to reimpliment them here.
+ // Unfortunately EncodingNLS.cs is internal and we're public, so we have to re-implement them here.
// These should be kept in sync for the following classes:
// EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
if (encoder != null)
{
- highSurrogate = encoder.charLeftOver;
+ highSurrogate = encoder._charLeftOver;
fallbackBuffer = encoder.FallbackBuffer;
// We mustn't have left over fallback data when counting
throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_GetByteCountOverflow);
// Shouldn't have anything in fallback buffer for GetByteCount
- // (don't have to check m_throwOnOverflow for count)
+ // (don't have to check _throwOnOverflow for count)
Debug.Assert(fallbackBuffer.Remaining == 0,
"[UTF32Encoding.GetByteCount]Expected empty fallback buffer at end");
if (encoder != null)
{
- highSurrogate = encoder.charLeftOver;
+ highSurrogate = encoder._charLeftOver;
fallbackBuffer = encoder.FallbackBuffer;
// We mustn't have left over fallback data when not converting
- if (encoder.m_throwOnOverflow && fallbackBuffer.Remaining > 0)
+ if (encoder._throwOnOverflow && fallbackBuffer.Remaining > 0)
throw new ArgumentException(SR.Format(SR.Argument_EncoderFallbackNotEmpty, this.EncodingName, encoder.Fallback.GetType()));
}
else
if (encoder != null)
{
// Remember our left over surrogate (or 0 if flushing)
- encoder.charLeftOver = highSurrogate;
+ encoder._charLeftOver = highSurrogate;
// Need # chars used
- encoder.m_charsUsed = (int)(chars - charStart);
+ encoder._charsUsed = (int)(chars - charStart);
}
// return the new length
fallbackBuffer = decoder.FallbackBuffer;
// Shouldn't have anything in fallback buffer for GetCharCount
- // (don't have to check m_throwOnOverflow for chars or count)
+ // (don't have to check _throwOnOverflow for chars or count)
Debug.Assert(fallbackBuffer.Remaining == 0,
"[UTF32Encoding.GetCharCount]Expected empty fallback buffer at start");
}
throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_GetByteCountOverflow);
// Shouldn't have anything in fallback buffer for GetCharCount
- // (don't have to check m_throwOnOverflow for chars or count)
+ // (don't have to check _throwOnOverflow for chars or count)
Debug.Assert(fallbackBuffer.Remaining == 0,
"[UTF32Encoding.GetCharCount]Expected empty fallback buffer at end");
fallbackBuffer = baseDecoder.FallbackBuffer;
// Shouldn't have anything in fallback buffer for GetChars
- // (don't have to check m_throwOnOverflow for chars)
+ // (don't have to check _throwOnOverflow for chars)
Debug.Assert(fallbackBuffer.Remaining == 0,
"[UTF32Encoding.GetChars]Expected empty fallback buffer at start");
}
{
decoder.iChar = (int)iChar;
decoder.readByteCount = readCount;
- decoder.m_bytesUsed = (int)(bytes - byteStart);
+ decoder._bytesUsed = (int)(bytes - byteStart);
}
// Shouldn't have anything in fallback buffer for GetChars
- // (don't have to check m_throwOnOverflow for chars)
+ // (don't have to check _throwOnOverflow for chars)
Debug.Assert(fallbackBuffer.Remaining == 0,
"[UTF32Encoding.GetChars]Expected empty fallback buffer at end");
{
this.iChar = 0;
this.readByteCount = 0;
- if (m_fallbackBuffer != null)
- m_fallbackBuffer.Reset();
+ if (_fallbackBuffer != null)
+ _fallbackBuffer.Reset();
}
// Anything left in our decoder?
//
using System;
-using System.Runtime.Serialization;
using System.Diagnostics;
using System.Diagnostics.Contracts;
}
// The following methods are copied from EncodingNLS.cs.
- // Unfortunately EncodingNLS.cs is internal and we're public, so we have to reimpliment them here.
+ // Unfortunately EncodingNLS.cs is internal and we're public, so we have to re-implement them here.
// These should be kept in sync for the following classes:
// EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
// We already cleared bits & bitcount for mustflush case
encoder.bits = bits;
encoder.bitCount = bitCount;
- encoder.m_charsUsed = buffer.CharsUsed;
+ encoder._charsUsed = buffer.CharsUsed;
}
return buffer.Count;
decoder.bitCount = bitCount;
decoder.firstByte = firstByte;
}
- decoder.m_bytesUsed = buffer.BytesUsed;
+ decoder._bytesUsed = buffer.BytesUsed;
}
// else ignore any hanging bits.
// Of all the amazing things... This MUST be Decoder so that our com name
// for System.Text.Decoder doesn't change
- private sealed class Decoder : DecoderNLS, ISerializable
+ private sealed class Decoder : DecoderNLS
{
/*private*/
internal int bits;
// base calls reset
}
- // ISerializable implementation, get data for this object
- void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException();
- }
-
public override void Reset()
{
this.bits = 0;
this.bitCount = -1;
this.firstByte = false;
- if (m_fallbackBuffer != null)
- m_fallbackBuffer.Reset();
+ if (_fallbackBuffer != null)
+ _fallbackBuffer.Reset();
}
// Anything left in our encoder?
// Of all the amazing things... This MUST be Encoder so that our com name
// for System.Text.Encoder doesn't change
- private sealed class Encoder : EncoderNLS, ISerializable
+ private sealed class Encoder : EncoderNLS
{
/*private*/
internal int bits;
// base calls reset
}
- // ISerializable implementation
- void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException();
- }
-
public override void Reset()
{
this.bitCount = -1;
this.bits = 0;
- if (m_fallbackBuffer != null)
- m_fallbackBuffer.Reset();
+ if (_fallbackBuffer != null)
+ _fallbackBuffer.Reset();
}
// Anything left in our encoder?
#define FASTLOOP
using System;
-using System.Runtime.Serialization;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Globalization;
private const int UTF8_CODEPAGE = 65001;
- // Allow for devirtualization (see https://github.com/dotnet/coreclr/pull/9230)
+ // Allow for de-virtualization (see https://github.com/dotnet/coreclr/pull/9230)
internal sealed class UTF8EncodingSealed : UTF8Encoding
{
public UTF8EncodingSealed(bool encoderShouldEmitUTF8Identifier) : base(encoderShouldEmitUTF8Identifier) { }
// WARNING: otherwise it'll break VB's way of declaring these.
//
// The following methods are copied from EncodingNLS.cs.
- // Unfortunately EncodingNLS.cs is internal and we're public, so we have to reimpliment them here.
+ // Unfortunately EncodingNLS.cs is internal and we're public, so we have to re-implement them here.
// These should be kept in sync for the following classes:
// EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
// Do our fallback. Actually we already know its a mixed up surrogate,
// so the ref pSrc isn't gonna do anything.
- pSrcForFallback = pSrc; // Avoid passing pSrc by reference to allow it to be enregistered
+ pSrcForFallback = pSrc; // Avoid passing pSrc by reference to allow it to be en-registered
fallbackBuffer.InternalFallback(unchecked((char)ch), ref pSrcForFallback);
pSrc = pSrcForFallback;
if (availableChars <= 13)
{
// try to get over the remainder of the ascii characters fast though
- char* pLocalEnd = pEnd; // hint to get pLocalEnd enregistered
+ char* pLocalEnd = pEnd; // hint to get pLocalEnd en-registered
while (pSrc < pLocalEnd)
{
ch = *pSrc;
int ch = 0;
- // assume that JIT will enregister pSrc, pTarget and ch
+ // assume that JIT will en-register pSrc, pTarget and ch
if (baseEncoder != null)
{
{
// We always need the fallback buffer in get bytes so we can flush any remaining ones if necessary
fallbackBuffer = encoder.FallbackBuffer;
- if (fallbackBuffer.Remaining > 0 && encoder.m_throwOnOverflow)
+ if (fallbackBuffer.Remaining > 0 && encoder._throwOnOverflow)
throw new ArgumentException(SR.Format(SR.Argument_EncoderFallbackNotEmpty, this.EncodingName, encoder.Fallback.GetType()));
// Set our internal fallback interesting things.
// Do our fallback. Actually we already know its a mixed up surrogate,
// so the ref pSrc isn't gonna do anything.
- pSrcForFallback = pSrc; // Avoid passing pSrc by reference to allow it to be enregistered
+ pSrcForFallback = pSrc; // Avoid passing pSrc by reference to allow it to be en-registered
fallbackBuffer.InternalFallback(unchecked((char)ch), ref pSrcForFallback);
pSrc = pSrcForFallback;
Debug.Assert(pSrc >= chars || pTarget == bytes,
"[UTF8Encoding.GetBytes]Expected pSrc to be within buffer or to throw with insufficient room.");
ThrowBytesOverflow(encoder, pTarget == bytes); // Throw if we must
- ch = 0; // Nothing left over (we backed up to start of pair if supplimentary)
+ ch = 0; // Nothing left over (we backed up to start of pair if supplementary)
break;
}
}
// try to get over the remainder of the ascii characters fast though
- char* pLocalEnd = pEnd; // hint to get pLocalEnd enregistered
+ char* pLocalEnd = pEnd; // hint to get pLocalEnd en-registered
while (pSrc < pLocalEnd)
{
ch = *pSrc;
"[UTF8Encoding.GetBytes] Expected no mustflush or 0 leftover ch " + ch.ToString("X2", CultureInfo.InvariantCulture));
encoder.surrogateChar = ch;
- encoder.m_charsUsed = (int)(pSrc - chars);
+ encoder._charsUsed = (int)(pSrc - chars);
}
Debug.Assert(fallbackBuffer == null || fallbackBuffer.Remaining == 0 ||
- baseEncoder == null || !baseEncoder.m_throwOnOverflow,
+ baseEncoder == null || !baseEncoder._throwOnOverflow,
"[UTF8Encoding.GetBytes]Expected empty fallback buffer if not converting");
return (int)(pTarget - bytes);
charCount -= (ch >> 30); // Adjust char count for # of expected bytes and expected output chars.
// Shouldn't have anything in fallback buffer for GetCharCount
- // (don't have to check m_throwOnOverflow for count)
+ // (don't have to check _throwOnOverflow for count)
Debug.Assert(!decoder.InternalHasFallbackBuffer || decoder.FallbackBuffer.Remaining == 0,
"[UTF8Encoding.GetCharCount]Expected empty fallback buffer at start");
}
{
if ((ch & (FinalByte >> 6)) != 0)
{
- // this is 3rd byte (of 4 byte supplimentary) - nothing to do
+ // this is 3rd byte (of 4 byte supplementary) - nothing to do
continue;
}
- // 2nd byte, check for non-shortest form of supplimentary char and the valid
- // supplimentary characters in range 0x010000 - 0x10FFFF at the same time
+ // 2nd byte, check for non-shortest form of supplementary char and the valid
+ // supplementary characters in range 0x010000 - 0x10FFFF at the same time
if (!InRange(ch & 0x1F0, 0x10, 0x100))
{
goto InvalidByteSequence;
goto EncodeChar;
InvalidByteSequence:
- // this code fragment should be close to the gotos referencing it
+ // this code fragment should be close to the goto referencing it
// Have to do fallback for invalid bytes
if (fallback == null)
{
if (availableBytes <= 13)
{
// try to get over the remainder of the ascii characters fast though
- byte* pLocalEnd = pEnd; // hint to get pLocalEnd enregistered
+ byte* pLocalEnd = pEnd; // hint to get pLocalEnd en-registered
while (pSrc < pLocalEnd)
{
ch = *pSrc;
// May have a problem if we have to flush
if (ch != 0)
{
- // We were already adjusting for these, so need to unadjust
+ // We were already adjusting for these, so need to un-adjust
charCount += (ch >> 30);
if (baseDecoder == null || baseDecoder.MustFlush)
{
}
// Shouldn't have anything in fallback buffer for GetCharCount
- // (don't have to check m_throwOnOverflow for count)
+ // (don't have to check _throwOnOverflow for count)
Debug.Assert(fallback == null || fallback.Remaining == 0,
"[UTF8Encoding.GetCharCount]Expected empty fallback buffer at end");
ch = decoder.bits;
// Shouldn't have anything in fallback buffer for GetChars
- // (don't have to check m_throwOnOverflow for chars, we always use all or none so always should be empty)
+ // (don't have to check _throwOnOverflow for chars, we always use all or none so always should be empty)
Debug.Assert(!decoder.InternalHasFallbackBuffer || decoder.FallbackBuffer.Remaining == 0,
"[UTF8Encoding.GetChars]Expected empty fallback buffer at start");
}
fallback = baseDecoder.FallbackBuffer;
fallback.InternalInitialize(bytes, pAllocatedBufferEnd);
}
- // This'll back us up the appropriate # of bytes if we didn't get anywhere
- pSrcForFallback = pSrc; // Avoid passing pSrc by reference to allow it to be enregistered
- pTargetForFallback = pTarget; // Avoid passing pTarget by reference to allow it to be enregistered
+ // That'll back us up the appropriate # of bytes if we didn't get anywhere
+ pSrcForFallback = pSrc; // Avoid passing pSrc by reference to allow it to be en-registered
+ pTargetForFallback = pTarget; // Avoid passing pTarget by reference to allow it to be en-registered
bool fallbackResult = FallbackInvalidByteSequence(ref pSrcForFallback, ch, fallback, ref pTargetForFallback);
pSrc = pSrcForFallback;
pTarget = pTargetForFallback;
pSrc--;
// Throw that we don't have enough room (pSrc could be < chars if we had started to process
- // a 4 byte sequence alredy)
+ // a 4 byte sequence already)
Debug.Assert(pSrc >= bytes || pTarget == chars,
"[UTF8Encoding.GetChars]Expected pSrc to be within input buffer or throw due to no output]");
ThrowCharsOverflow(baseDecoder, pTarget == chars);
fallback.InternalInitialize(bytes, pAllocatedBufferEnd);
}
- // This'll back us up the appropriate # of bytes if we didn't get anywhere
- pSrcForFallback = pSrc; // Avoid passing pSrc by reference to allow it to be enregistered
- pTargetForFallback = pTarget; // Avoid passing pTarget by reference to allow it to be enregistered
+ // That'll back us up the appropriate # of bytes if we didn't get anywhere
+ pSrcForFallback = pSrc; // Avoid passing pSrc by reference to allow it to be en-registered
+ pTargetForFallback = pTarget; // Avoid passing pTarget by reference to allow it to be en-registered
bool fallbackResult = FallbackInvalidByteSequence(ref pSrcForFallback, ch, fallback, ref pTargetForFallback);
pSrc = pSrcForFallback;
pTarget = pTargetForFallback;
// If we're storing flush data we expect all bits to be used or else
// we're stuck in the middle of a conversion
- Debug.Assert(!baseDecoder.MustFlush || ch == 0 || !baseDecoder.m_throwOnOverflow,
+ Debug.Assert(!baseDecoder.MustFlush || ch == 0 || !baseDecoder._throwOnOverflow,
"[UTF8Encoding.GetChars]Expected no must flush or no left over bits or no throw on overflow.");
// Remember our leftover bits.
decoder.bits = ch;
- baseDecoder.m_bytesUsed = (int)(pSrc - bytes);
+ baseDecoder._bytesUsed = (int)(pSrc - bytes);
}
// Shouldn't have anything in fallback buffer for GetChars
- // (don't have to check m_throwOnOverflow for chars)
+ // (don't have to check _throwOnOverflow for chars)
Debug.Assert(fallback == null || fallback.Remaining == 0,
"[UTF8Encoding.GetChars]Expected empty fallback buffer at end");
// During GetChars we had an invalid byte sequence
// pSrc is backed up to the start of the bad sequence if we didn't have room to
- // fall it back. Otherwise pSrc remains wher it is.
+ // fall it back. Otherwise pSrc remains where it is.
private unsafe bool FallbackInvalidByteSequence(
ref byte* pSrc, int ch, DecoderFallbackBuffer fallback, ref char* pTarget)
{
UTF8_CODEPAGE + (_emitUTF8Identifier ? 1 : 0);
}
- private sealed class UTF8Encoder : EncoderNLS, ISerializable
+ private sealed class UTF8Encoder : EncoderNLS
{
// We must save a high surrogate value until the next call, looking
// for a low surrogate value.
// base calls reset
}
- // ISerializable implementation
- void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException();
- }
-
public override void Reset()
{
this.surrogateChar = 0;
- if (m_fallbackBuffer != null)
- m_fallbackBuffer.Reset();
+ if (_fallbackBuffer != null)
+ _fallbackBuffer.Reset();
}
// Anything left in our encoder?
}
}
- private sealed class UTF8Decoder : DecoderNLS, ISerializable
+ private sealed class UTF8Decoder : DecoderNLS
{
// We'll need to remember the previous information. See the comments around definition
// of FinalByte for details.
// base calls reset
}
- // Constructor called by serialization, have to handle deserializing from Everett
- internal UTF8Decoder(SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException();
- }
-
- // ISerializable implementation, get data for this object
- void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException();
- }
-
public override void Reset()
{
this.bits = 0;
- if (m_fallbackBuffer != null)
- m_fallbackBuffer.Reset();
+ if (_fallbackBuffer != null)
+ _fallbackBuffer.Reset();
}
// Anything left in our decoder?
using System;
using System.Globalization;
-using System.Runtime.Serialization;
using System.Diagnostics;
using System.Diagnostics.Contracts;
internal static readonly UnicodeEncoding s_bigEndianDefault = new UnicodeEncoding(bigEndian: true, byteOrderMark: true);
internal static readonly UnicodeEncoding s_littleEndianDefault = new UnicodeEncoding(bigEndian: false, byteOrderMark: true);
- [OptionalField(VersionAdded = 2)]
internal bool isThrowException = false;
internal bool bigEndian = false;
SetDefaultFallbacks();
}
- #region Serialization
- [OnDeserializing]
- private void OnDeserializing(StreamingContext ctx)
- {
- // In Everett it is false. Whidbey will overwrite this value.
- isThrowException = false;
- }
- #endregion Serialization
-
internal override void SetDefaultFallbacks()
{
// For UTF-X encodings, we use a replacement fallback with an empty string
}
// The following methods are copied from EncodingNLS.cs.
- // Unfortunately EncodingNLS.cs is internal and we're public, so we have to reimpliment them here.
+ // Unfortunately EncodingNLS.cs is internal and we're public, so we have to re-implement them here.
// These should be kept in sync for the following classes:
// EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
//
if (encoder != null)
{
- charLeftOver = encoder.charLeftOver;
+ charLeftOver = encoder._charLeftOver;
// Assume extra bytes to encode charLeftOver if it existed
if (charLeftOver > 0)
{
// See if we potentially have surrogates (0x8000 bit set)
// (We're either big endian on a big endian machine or little endian on
- // a little endian machine so this'll work)
+ // a little endian machine so that'll work)
if ((0x8000800080008000 & *longChars) != 0)
{
// See if any of these are high or low surrogates (0xd800 - 0xdfff). If the high
// Set our internal fallback interesting things.
fallbackBuffer.InternalInitialize(charStart, charEnd, encoder, false);
}
- charsForFallback = chars; // Avoid passing chars by reference to allow it to be enregistered
+ charsForFallback = chars; // Avoid passing chars by reference to allow it to be en-registered
fallbackBuffer.InternalFallback(ch, ref charsForFallback);
chars = charsForFallback;
continue;
// Set our internal fallback interesting things.
fallbackBuffer.InternalInitialize(charStart, charEnd, encoder, false);
}
- charsForFallback = chars; // Avoid passing chars by reference to allow it to be enregistered
+ charsForFallback = chars; // Avoid passing chars by reference to allow it to be en-registered
fallbackBuffer.InternalFallback(charLeftOver, ref charsForFallback);
chars = charsForFallback;
// Set our internal fallback interesting things.
fallbackBuffer.InternalInitialize(charStart, charEnd, encoder, false);
}
- charsForFallback = chars; // Avoid passing chars by reference to allow it to be enregistered
+ charsForFallback = chars; // Avoid passing chars by reference to allow it to be en-registered
fallbackBuffer.InternalFallback(charLeftOver, ref charsForFallback);
chars = charsForFallback;
charLeftOver = (char)0;
}
// Shouldn't have anything in fallback buffer for GetByteCount
- // (don't have to check m_throwOnOverflow for count)
+ // (don't have to check _throwOnOverflow for count)
Debug.Assert(fallbackBuffer == null || fallbackBuffer.Remaining == 0,
"[UnicodeEncoding.GetByteCount]Expected empty fallback buffer at end");
// Get our encoder, but don't clear it yet.
if (encoder != null)
{
- charLeftOver = encoder.charLeftOver;
+ charLeftOver = encoder._charLeftOver;
// We mustn't have left over fallback data when counting
if (encoder.InternalHasFallbackBuffer)
{
// We always need the fallback buffer in get bytes so we can flush any remaining ones if necessary
fallbackBuffer = encoder.FallbackBuffer;
- if (fallbackBuffer.Remaining > 0 && encoder.m_throwOnOverflow)
+ if (fallbackBuffer.Remaining > 0 && encoder._throwOnOverflow)
throw new ArgumentException(SR.Format(SR.Argument_EncoderFallbackNotEmpty, this.EncodingName, encoder.Fallback.GetType()));
// Set our internal fallback interesting things.
{
// See if we potentially have surrogates (0x8000 bit set)
// (We're either big endian on a big endian machine or little endian on
- // a little endian machine so this'll work)
+ // a little endian machine so that'll work)
if ((0x8000800080008000 & *longChars) != 0)
{
// See if any of these are high or low surrogates (0xd800 - 0xdfff). If the high
#endif // BIGENDIAN
#if BIT64
- (unchecked((long)chars) & 7) != (unchecked((long)bytes) & 7) && // Only do this if chars & bytes are out of line, otherwise faster loop'll be faster next time
+ (unchecked((long)chars) & 7) != (unchecked((long)bytes) & 7) && // Only do this if chars & bytes are out of line, otherwise faster loop will be faster next time
#else
- (unchecked((int)chars) & 3) != (unchecked((int)bytes) & 3) && // Only do this if chars & bytes are out of line, otherwise faster loop'll be faster next time
+ (unchecked((int)chars) & 3) != (unchecked((int)bytes) & 3) && // Only do this if chars & bytes are out of line, otherwise faster loop will be faster next time
#endif // BIT64
(unchecked((int)(bytes)) & 1) == 0)
{
fallbackBuffer.InternalInitialize(charStart, charEnd, encoder, true);
}
- charsForFallback = chars; // Avoid passing chars by reference to allow it to be enregistered
+ charsForFallback = chars; // Avoid passing chars by reference to allow it to be en-registered
fallbackBuffer.InternalFallback(charLeftOver, ref charsForFallback);
chars = charsForFallback;
fallbackBuffer.InternalInitialize(charStart, charEnd, encoder, true);
}
- charsForFallback = chars; // Avoid passing chars by reference to allow it to be enregistered
+ charsForFallback = chars; // Avoid passing chars by reference to allow it to be en-registered
fallbackBuffer.InternalFallback(ch, ref charsForFallback);
chars = charsForFallback;
continue;
fallbackBuffer.InternalInitialize(charStart, charEnd, encoder, true);
}
- charsForFallback = chars; // Avoid passing chars by reference to allow it to be enregistered
+ charsForFallback = chars; // Avoid passing chars by reference to allow it to be en-registered
fallbackBuffer.InternalFallback(charLeftOver, ref charsForFallback);
chars = charsForFallback;
fallbackBuffer.InternalInitialize(charStart, charEnd, encoder, true);
}
- // If we're not flushing, this'll remember the left over character.
- charsForFallback = chars; // Avoid passing chars by reference to allow it to be enregistered
+ // If we're not flushing, that'll remember the left over character.
+ charsForFallback = chars; // Avoid passing chars by reference to allow it to be en-registered
fallbackBuffer.InternalFallback(charLeftOver, ref charsForFallback);
chars = charsForFallback;
// Not flushing, remember it in the encoder
if (encoder != null)
{
- encoder.charLeftOver = charLeftOver;
- encoder.m_charsUsed = (int)(chars - charStart);
+ encoder._charLeftOver = charLeftOver;
+ encoder._charsUsed = (int)(chars - charStart);
}
// Remember charLeftOver if we must, or clear it if we're flushing
"[UnicodeEncoding.GetBytes] Expected no left over characters if flushing");
Debug.Assert(fallbackBuffer == null || fallbackBuffer.Remaining == 0 ||
- encoder == null || !encoder.m_throwOnOverflow,
+ encoder == null || !encoder._throwOnOverflow,
"[UnicodeEncoding.GetBytes]Expected empty fallback buffer if not converting");
// We used to copy it fast, but this doesn't check for surrogates
}
// Shouldn't have anything in fallback buffer for GetCharCount
- // (don't have to check m_throwOnOverflow for count)
+ // (don't have to check _throwOnOverflow for count)
Debug.Assert(!decoder.InternalHasFallbackBuffer || decoder.FallbackBuffer.Remaining == 0,
"[UnicodeEncoding.GetCharCount]Expected empty fallback buffer at start");
}
while (bytes < byteEnd)
{
// If we're aligned then maybe we can do it fast
- // This'll hurt if we're unaligned because we'll always test but never be aligned
+ // That'll hurt if we're unaligned because we'll always test but never be aligned
#if !NO_FAST_UNICODE_LOOP
#if BIGENDIAN
if (bigEndian &&
{
// See if we potentially have surrogates (0x8000 bit set)
// (We're either big endian on a big endian machine or little endian on
- // a little endian machine so this'll work)
+ // a little endian machine so that'll work)
if ((0x8000800080008000 & *longBytes) != 0)
{
// See if any of these are high or low surrogates (0xd800 - 0xdfff). If the high
else if (lastChar > 0)
{
// Had a high surrogate, expected a low surrogate
- // Uncount the last high surrogate
+ // Un-count the last high surrogate
charCount--;
// fall back the high surrogate.
charCount--;
// Shouldn't have anything in fallback buffer for GetCharCount
- // (don't have to check m_throwOnOverflow for count)
+ // (don't have to check _throwOnOverflow for count)
Debug.Assert(fallbackBuffer == null || fallbackBuffer.Remaining == 0,
"[UnicodeEncoding.GetCharCount]Expected empty fallback buffer at end");
lastChar = decoder.lastChar;
// Shouldn't have anything in fallback buffer for GetChars
- // (don't have to check m_throwOnOverflow for chars)
+ // (don't have to check _throwOnOverflow for chars)
Debug.Assert(!decoder.InternalHasFallbackBuffer || decoder.FallbackBuffer.Remaining == 0,
"[UnicodeEncoding.GetChars]Expected empty fallback buffer at start");
}
while (bytes < byteEnd)
{
// If we're aligned then maybe we can do it fast
- // This'll hurt if we're unaligned because we'll always test but never be aligned
+ // That'll hurt if we're unaligned because we'll always test but never be aligned
#if !NO_FAST_UNICODE_LOOP
#if BIGENDIAN
if (bigEndian &&
{
// See if we potentially have surrogates (0x8000 bit set)
// (We're either big endian on a big endian machine or little endian on
- // a little endian machine so this'll work)
+ // a little endian machine so that'll work)
if ((0x8000800080008000 & *longBytes) != 0)
{
// See if any of these are high or low surrogates (0xd800 - 0xdfff). If the high
fallbackBuffer.InternalInitialize(byteStart, charEnd);
}
- charsForFallback = chars; // Avoid passing chars by reference to allow it to be enregistered
+ charsForFallback = chars; // Avoid passing chars by reference to allow it to be en-registered
bool fallbackResult = fallbackBuffer.InternalFallback(byteBuffer, bytes, ref charsForFallback);
chars = charsForFallback;
fallbackBuffer.InternalInitialize(byteStart, charEnd);
}
- charsForFallback = chars; // Avoid passing chars by reference to allow it to be enregistered
+ charsForFallback = chars; // Avoid passing chars by reference to allow it to be en-registered
bool fallbackResult = fallbackBuffer.InternalFallback(byteBuffer, bytes, ref charsForFallback);
chars = charsForFallback;
fallbackBuffer.InternalInitialize(byteStart, charEnd);
}
- charsForFallback = chars; // Avoid passing chars by reference to allow it to be enregistered
+ charsForFallback = chars; // Avoid passing chars by reference to allow it to be en-registered
bool fallbackResult = fallbackBuffer.InternalFallback(byteBuffer, bytes, ref charsForFallback);
chars = charsForFallback;
fallbackBuffer.InternalInitialize(byteStart, charEnd);
}
- charsForFallback = chars; // Avoid passing chars by reference to allow it to be enregistered
+ charsForFallback = chars; // Avoid passing chars by reference to allow it to be en-registered
bool fallbackResult = fallbackBuffer.InternalFallback(byteBuffer, bytes, ref charsForFallback);
chars = charsForFallback;
}
// No hanging odd bytes allowed if must flush
- charsForFallback = chars; // Avoid passing chars by reference to allow it to be enregistered
+ charsForFallback = chars; // Avoid passing chars by reference to allow it to be en-registered
bool fallbackResult = fallbackBuffer.InternalFallback(new byte[] { unchecked((byte)lastByte) }, bytes, ref charsForFallback);
chars = charsForFallback;
// + " " + ((int)lastChar).ToString("X4") + " " + lastByte.ToString("X2")
);
- decoder.m_bytesUsed = (int)(bytes - byteStart);
+ decoder._bytesUsed = (int)(bytes - byteStart);
decoder.lastChar = lastChar;
decoder.lastByte = lastByte;
}
// System.IO.__UnmanagedMemoryStream.memcpyimpl((byte*)chars, bytes, byteCount);
// Shouldn't have anything in fallback buffer for GetChars
- // (don't have to check m_throwOnOverflow for count or chars)
+ // (don't have to check _throwOnOverflow for count or chars)
Debug.Assert(fallbackBuffer == null || fallbackBuffer.Remaining == 0,
"[UnicodeEncoding.GetChars]Expected empty fallback buffer at end");
// Might also need an extra 1 if there's a left over high surrogate in the decoder.
long charCount = (long)(byteCount >> 1) + (byteCount & 1) + 1;
- // Don't forget fallback (in case they have a bunch of lonely surrogates or something bizzare like that)
+ // Don't forget fallback (in case they have a bunch of lonely surrogates or something bizarre like that)
if (DecoderFallback.MaxCharCount > 1)
charCount *= DecoderFallback.MaxCharCount;
{
//
// Big Endian Unicode has different code page (1201) than small Endian one (1200),
- // so we still have to check m_codePage here.
+ // so we still have to check _codePage here.
//
return (CodePage == that.CodePage) &&
byteOrderMark == that.byteOrderMark &&
(byteOrderMark ? 4 : 0) + (bigEndian ? 8 : 0);
}
- private sealed class Decoder : System.Text.DecoderNLS, ISerializable
+ private sealed class Decoder : System.Text.DecoderNLS
{
internal int lastByte = -1;
internal char lastChar = '\0';
// base calls reset
}
- internal Decoder(SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException();
- }
-
- // ISerializable implementation
- void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException();
- }
-
public override void Reset()
{
lastByte = -1;
lastChar = '\0';
- if (m_fallbackBuffer != null)
- m_fallbackBuffer.Reset();
+ if (_fallbackBuffer != null)
+ _fallbackBuffer.Reset();
}
// Anything left in our decoder?