private const int CodePageUTF32 = 12000;
private const int CodePageUTF32BE = 12001;
- internal int m_codePage = 0;
+ internal int _codePage = 0;
- // dataItem should be internal (not private). otherwise it will break during the deserialization
- // of the data came from Everett
- internal CodePageDataItem dataItem = null;
-
- [NonSerialized]
- internal bool m_deserializedFromEverett = false;
+ internal CodePageDataItem _dataItem = null;
// Because of encoders we may be read only
[OptionalField(VersionAdded = 2)]
- private bool m_isReadOnly = true;
+ private bool _isReadOnly = true;
// Encoding (encoder) fallback
- [OptionalField(VersionAdded = 2)]
internal EncoderFallback encoderFallback = null;
- [OptionalField(VersionAdded = 2)]
internal DecoderFallback decoderFallback = null;
protected Encoding() : this(0)
Contract.EndContractBlock();
// Remember code page
- m_codePage = codePage;
+ _codePage = codePage;
// Use default encoder/decoder fallbacks
this.SetDefaultFallbacks();
Contract.EndContractBlock();
// Remember code page
- m_codePage = codePage;
+ _codePage = codePage;
- this.encoderFallback = encoderFallback ?? new InternalEncoderBestFitFallback(this);
- this.decoderFallback = decoderFallback ?? new InternalDecoderBestFitFallback(this);
+ encoderFallback = encoderFallback ?? new InternalEncoderBestFitFallback(this);
+ decoderFallback = decoderFallback ?? new InternalDecoderBestFitFallback(this);
}
// Default fallback that we'll use.
{
// For UTF-X encodings, we use a replacement fallback with an "\xFFFD" string,
// For ASCII we use "?" replacement fallback, etc.
- this.encoderFallback = new InternalEncoderBestFitFallback(this);
- this.decoderFallback = new InternalDecoderBestFitFallback(this);
- }
-
-
- #region Serialization
- internal void OnDeserializing()
- {
- // intialize the optional Whidbey fields
- encoderFallback = null;
- decoderFallback = null;
- m_isReadOnly = true;
- }
-
- internal void OnDeserialized()
- {
- if (encoderFallback == null || decoderFallback == null)
- {
- m_deserializedFromEverett = true;
- SetDefaultFallbacks();
- }
-
- // dataItem is always recalculated from the code page #
- dataItem = null;
- }
-
- [OnDeserializing]
- private void OnDeserializing(StreamingContext ctx)
- {
- OnDeserializing();
- }
-
-
- [OnDeserialized]
- private void OnDeserialized(StreamingContext ctx)
- {
- OnDeserialized();
- }
-
- [OnSerializing]
- private void OnSerializing(StreamingContext ctx)
- {
- // to be consistent with SerializeEncoding
- dataItem = null;
+ encoderFallback = new InternalEncoderBestFitFallback(this);
+ decoderFallback = new InternalDecoderBestFitFallback(this);
}
- // the following two methods are used for the inherited classes which implemented ISerializable
- // Deserialization Helper
- internal void DeserializeEncoding(SerializationInfo info, StreamingContext context)
- {
- // Any info?
- if (info == null) throw new ArgumentNullException(nameof(info));
- Contract.EndContractBlock();
-
- // All versions have a code page
- this.m_codePage = (int)info.GetValue("m_codePage", typeof(int));
-
- // We can get dataItem on the fly if needed, and the index is different between versions
- // so ignore whatever dataItem data we get from Everett.
- this.dataItem = null;
-
- // See if we have a code page
- try
- {
- //
- // Try Whidbey V2.0 Fields
- //
-
- m_isReadOnly = (bool)info.GetValue("m_isReadOnly", typeof(bool));
-
- this.encoderFallback = (EncoderFallback)info.GetValue("encoderFallback", typeof(EncoderFallback));
- this.decoderFallback = (DecoderFallback)info.GetValue("decoderFallback", typeof(DecoderFallback));
- }
- catch (SerializationException)
- {
- //
- // Didn't have Whidbey things, must be Everett
- //
- this.m_deserializedFromEverett = true;
-
- // May as well be read only
- m_isReadOnly = true;
- SetDefaultFallbacks();
- }
- }
-
- // Serialization Helper
- internal void SerializeEncoding(SerializationInfo info, StreamingContext context)
- {
- // Any Info?
- if (info == null) throw new ArgumentNullException(nameof(info));
- Contract.EndContractBlock();
-
- // These are new V2.0 Whidbey stuff
- info.AddValue("m_isReadOnly", m_isReadOnly);
- info.AddValue("encoderFallback", this.EncoderFallback);
- info.AddValue("decoderFallback", this.DecoderFallback);
-
- // These were in Everett V1.1 as well
- info.AddValue("m_codePage", this.m_codePage);
-
- // This was unique to Everett V1.1
- info.AddValue("dataItem", null);
-
- // Everett duplicated these fields, so these are needed for portability
- info.AddValue("Encoding+m_codePage", this.m_codePage);
- info.AddValue("Encoding+dataItem", null);
- }
-
- #endregion Serialization
-
// Converts a byte array from one encoding to another. The bytes in the
// bytes array are converted from srcEncoding to
// dstEncoding, and the returned value is a new byte array
private void GetDataItem()
{
- if (dataItem == null)
+ if (_dataItem == null)
{
- dataItem = EncodingTable.GetCodePageDataItem(m_codePage);
- if (dataItem == null)
+ _dataItem = EncodingTable.GetCodePageDataItem(_codePage);
+ if (_dataItem == null)
{
- throw new NotSupportedException(
- SR.Format(SR.NotSupported_NoCodepageData, m_codePage));
+ throw new NotSupportedException(SR.Format(SR.NotSupported_NoCodepageData, _codePage));
}
}
}
{
get
{
- if (dataItem == null)
+ if (_dataItem == null)
{
GetDataItem();
}
- return (dataItem.BodyName);
+ return (_dataItem.BodyName);
}
}
{
get
{
- return SR.GetResourceString("Globalization_cp_" + m_codePage.ToString());
+ return SR.GetResourceString("Globalization_cp_" + _codePage.ToString());
}
}
#endif
{
get
{
- if (dataItem == null)
+ if (_dataItem == null)
{
GetDataItem();
}
- return (dataItem.HeaderName);
+ return (_dataItem.HeaderName);
}
}
{
get
{
- if (dataItem == null)
+ if (_dataItem == null)
{
GetDataItem();
}
- return (dataItem.WebName);
+ return (_dataItem.WebName);
}
}
{
get
{
- if (dataItem == null)
+ if (_dataItem == null)
{
GetDataItem();
}
- return (dataItem.UIFamilyCodePage);
+ return (_dataItem.UIFamilyCodePage);
}
}
{
get
{
- if (dataItem == null)
+ if (_dataItem == null)
{
GetDataItem();
}
- return ((dataItem.Flags & MIMECONTF_BROWSER) != 0);
+ return ((_dataItem.Flags & MIMECONTF_BROWSER) != 0);
}
}
{
get
{
- if (dataItem == null)
+ if (_dataItem == null)
{
GetDataItem();
}
- return ((dataItem.Flags & MIMECONTF_SAVABLE_BROWSER) != 0);
+ return ((_dataItem.Flags & MIMECONTF_SAVABLE_BROWSER) != 0);
}
}
{
get
{
- if (dataItem == null)
+ if (_dataItem == null)
{
GetDataItem();
}
- return ((dataItem.Flags & MIMECONTF_MAILNEWS) != 0);
+ return ((_dataItem.Flags & MIMECONTF_MAILNEWS) != 0);
}
}
{
get
{
- if (dataItem == null)
+ if (_dataItem == null)
{
GetDataItem();
}
- return ((dataItem.Flags & MIMECONTF_SAVABLE_MAILNEWS) != 0);
+ return ((_dataItem.Flags & MIMECONTF_SAVABLE_MAILNEWS) != 0);
}
}
Encoding newEncoding = (Encoding)this.MemberwiseClone();
// New one should be readable
- newEncoding.m_isReadOnly = false;
+ newEncoding._isReadOnly = false;
return newEncoding;
}
{
get
{
- return (m_isReadOnly);
+ return (_isReadOnly);
}
}
{
get
{
- return m_codePage;
+ return _codePage;
}
}
{
Encoding that = value as Encoding;
if (that != null)
- return (m_codePage == that.m_codePage) &&
+ return (_codePage == that._codePage) &&
(EncoderFallback.Equals(that.EncoderFallback)) &&
(DecoderFallback.Equals(that.DecoderFallback));
return (false);
public override int GetHashCode()
{
- return m_codePage + this.EncoderFallback.GetHashCode() + this.DecoderFallback.GetHashCode();
+ return _codePage + this.EncoderFallback.GetHashCode() + this.DecoderFallback.GetHashCode();
}
internal virtual char[] GetBestFitUnicodeToBytesData()
internal static readonly UTF7Encoding s_default = new UTF7Encoding();
// The set of base 64 characters.
- private byte[] base64Bytes;
+ private byte[] _base64Bytes;
// The decoded bits for every base64 values. This array has a size of 128 elements.
// The index is the code point value of the base 64 characters. The value is -1 if
// the code point is not a valid base 64 character. Otherwise, the value is a value
// from 0 ~ 63.
- private sbyte[] base64Values;
+ private sbyte[] _base64Values;
// The array to decide if a Unicode code point below 0x80 can be directly encoded in UTF7.
// This array has a size of 128.
- private bool[] directEncode;
+ private bool[] _directEncode;
- [OptionalField(VersionAdded = 2)]
- private bool m_allowOptionals;
+ private bool _allowOptionals;
private const int UTF7_CODEPAGE = 65000;
: base(UTF7_CODEPAGE) //Set the data item.
{
// Allowing optionals?
- m_allowOptionals = allowOptionals;
+ _allowOptionals = allowOptionals;
// Make our tables
MakeTables();
private void MakeTables()
{
// Build our tables
- base64Bytes = new byte[64];
- for (int i = 0; i < 64; i++) base64Bytes[i] = (byte)base64Chars[i];
- base64Values = new sbyte[128];
- for (int i = 0; i < 128; i++) base64Values[i] = -1;
- for (int i = 0; i < 64; i++) base64Values[base64Bytes[i]] = (sbyte)i;
- directEncode = new bool[128];
+ _base64Bytes = new byte[64];
+ for (int i = 0; i < 64; i++) _base64Bytes[i] = (byte)base64Chars[i];
+ _base64Values = new sbyte[128];
+ for (int i = 0; i < 128; i++) _base64Values[i] = -1;
+ for (int i = 0; i < 64; i++) _base64Values[_base64Bytes[i]] = (sbyte)i;
+ _directEncode = new bool[128];
int count = directChars.Length;
for (int i = 0; i < count; i++)
{
- directEncode[directChars[i]] = true;
+ _directEncode[directChars[i]] = true;
}
- if (m_allowOptionals)
+ if (_allowOptionals)
{
count = optionalChars.Length;
for (int i = 0; i < count; i++)
{
- directEncode[optionalChars[i]] = true;
+ _directEncode[optionalChars[i]] = true;
}
}
}
this.decoderFallback = new DecoderUTF7Fallback();
}
-
- [OnDeserializing]
- private void OnDeserializing(StreamingContext ctx)
- {
- // make sure the optional fields initialized correctly.
- base.OnDeserializing();
- }
-
- [OnDeserialized]
- private void OnDeserialized(StreamingContext ctx)
- {
- base.OnDeserialized();
-
- if (m_deserializedFromEverett)
- {
- // If 1st optional char is encoded we're allowing optionals
- m_allowOptionals = directEncode[optionalChars[0]];
- }
-
- MakeTables();
- }
-
-
-
public override bool Equals(Object value)
{
UTF7Encoding that = value as UTF7Encoding;
if (that != null)
{
- return (m_allowOptionals == that.m_allowOptionals) &&
+ return (_allowOptionals == that._allowOptionals) &&
(EncoderFallback.Equals(that.EncoderFallback)) &&
(DecoderFallback.Equals(that.DecoderFallback));
}
{
bitCount -= 6;
// If we fail we'll never really have enough room
- if (!buffer.AddByte(base64Bytes[(bits >> bitCount) & 0x3F]))
+ if (!buffer.AddByte(_base64Bytes[(bits >> bitCount) & 0x3F]))
ThrowBytesOverflow(encoder, buffer.Count == 0);
}
}
{
char currentChar = buffer.GetNextChar();
- if (currentChar < 0x80 && directEncode[currentChar])
+ if (currentChar < 0x80 && _directEncode[currentChar])
{
if (bitCount >= 0)
{
if (bitCount > 0)
{
// Try to add the next byte
- if (!buffer.AddByte(base64Bytes[bits << 6 - bitCount & 0x3F]))
+ if (!buffer.AddByte(_base64Bytes[bits << 6 - bitCount & 0x3F]))
break; // Stop here, didn't throw
bitCount = 0;
while (bitCount >= 6)
{
bitCount -= 6;
- if (!buffer.AddByte(base64Bytes[(bits >> bitCount) & 0x3F]))
+ if (!buffer.AddByte(_base64Bytes[(bits >> bitCount) & 0x3F]))
{
bitCount += 6; // We didn't use these bits
currentChar = buffer.GetNextChar(); // We're processing this char still, but AddByte
// Do we have bits we have to stick in?
if (bitCount > 0)
{
- if (buffer.AddByte(base64Bytes[(bits << (6 - bitCount)) & 0x3F]))
+ if (buffer.AddByte(_base64Bytes[(bits << (6 - bitCount)) & 0x3F]))
{
// Emitted spare bits, 0 bits left
bitCount = 0;
// Modified base 64 encoding.
//
sbyte v;
- if (currentByte < 0x80 && ((v = base64Values[currentByte]) >= 0))
+ if (currentByte < 0x80 && ((v = _base64Values[currentByte]) >= 0))
{
firstByte = false;
bits = (bits << 6) | ((byte)v);
if (currentByte != '-')
{
// >= 0x80 (because of 1st if statemtn)
- // We need this check since the base64Values[b] check below need b <= 0x7f.
+ // We need this check since the _base64Values[b] check below need b <= 0x7f.
// This is not a valid base 64 byte. Terminate the shifted-sequence and
// emit this byte.