<PackageReference Include="System.Text.Encoding.CodePages" Version="6.0.1" />

EncodingNLS

abstract class EncodingNLS : Encoding
using System.Diagnostics.CodeAnalysis; namespace System.Text { internal abstract class EncodingNLS : Encoding { private string _encodingName; private string _webName; public override string EncodingName { get { if (_encodingName == null) { _encodingName = GetLocalizedEncodingNameResource(CodePage); if (_encodingName == null) throw new NotSupportedException(System.SR.Format(System.SR.MissingEncodingNameResource, WebName, CodePage)); if (_encodingName.StartsWith("Globalization_cp_", StringComparison.OrdinalIgnoreCase)) { _encodingName = System.Text.EncodingTable.GetEnglishNameFromCodePage(CodePage); if (_encodingName == null) throw new NotSupportedException(System.SR.Format(System.SR.MissingEncodingNameResource, WebName, CodePage)); } } return _encodingName; } } public override string WebName { get { if (_webName == null) { _webName = System.Text.EncodingTable.GetWebNameFromCodePage(CodePage); if (_webName == null) throw new NotSupportedException(System.SR.Format(System.SR.NotSupported_NoCodepageData, CodePage)); } return _webName; } } public override string HeaderName { get { switch (CodePage) { case 932: return "iso-2022-jp"; case 50221: return "iso-2022-jp"; case 50225: return "euc-kr"; default: return WebName; } } } public override string BodyName { get { switch (CodePage) { case 932: return "iso-2022-jp"; case 1250: return "iso-8859-2"; case 1251: return "koi8-r"; case 1252: return "iso-8859-1"; case 1253: return "iso-8859-7"; case 1254: return "iso-8859-9"; case 50221: return "iso-2022-jp"; case 50225: return "iso-2022-kr"; default: return WebName; } } } protected EncodingNLS(int codePage) : base(codePage) { } protected EncodingNLS(int codePage, EncoderFallback enc, DecoderFallback dec) : base(codePage, enc, dec) { } public unsafe abstract int GetByteCount(char* chars, int count, System.Text.EncoderNLS encoder); public unsafe abstract int GetBytes(char* chars, int charCount, byte* bytes, int byteCount, System.Text.EncoderNLS encoder); public unsafe abstract int GetCharCount(byte* bytes, int count, System.Text.DecoderNLS decoder); public unsafe abstract int GetChars(byte* bytes, int byteCount, char* chars, int charCount, System.Text.DecoderNLS decoder); public unsafe override int GetByteCount(char[] chars, int index, int count) { if (chars == null) throw new ArgumentNullException("chars", System.SR.ArgumentNull_Array); if (index < 0 || count < 0) throw new ArgumentOutOfRangeException((index < 0) ? "index" : "count", System.SR.ArgumentOutOfRange_NeedNonNegNum); if (chars.Length - index < count) throw new ArgumentOutOfRangeException("chars", System.SR.ArgumentOutOfRange_IndexCountBuffer); if (chars.Length != 0) { fixed (char* ptr = &chars[0]) { return GetByteCount(ptr + index, count, null); } } return 0; } public unsafe override int GetByteCount(string s) { if (s != null) { fixed (char* chars = s) { return GetByteCount(chars, s.Length, null); } } throw new ArgumentNullException("s"); } public unsafe override int GetByteCount(char* chars, int count) { if (chars == null) throw new ArgumentNullException("chars", System.SR.ArgumentNull_Array); if (count < 0) throw new ArgumentOutOfRangeException("count", System.SR.ArgumentOutOfRange_NeedNonNegNum); return GetByteCount(chars, count, null); } public unsafe override int GetBytes(string s, int charIndex, int charCount, byte[] bytes, int byteIndex) { if (s == null || bytes == null) throw new ArgumentNullException((s == null) ? "s" : "bytes", System.SR.ArgumentNull_Array); if (charIndex < 0 || charCount < 0) throw new ArgumentOutOfRangeException((charIndex < 0) ? "charIndex" : "charCount", System.SR.ArgumentOutOfRange_NeedNonNegNum); if (s.Length - charIndex < charCount) throw new ArgumentOutOfRangeException("s", System.SR.ArgumentOutOfRange_IndexCount); if (byteIndex >= 0 && byteIndex <= bytes.Length) { int byteCount = bytes.Length - byteIndex; if (bytes.Length == 0) bytes = new byte[1]; fixed (char* ptr = s) { fixed (byte* ptr2 = &bytes[0]) { return GetBytes(ptr + charIndex, charCount, ptr2 + byteIndex, byteCount, null); } } } throw new ArgumentOutOfRangeException("byteIndex", System.SR.ArgumentOutOfRange_Index); } public unsafe override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) { if (chars == null || bytes == null) throw new ArgumentNullException((chars == null) ? "chars" : "bytes", System.SR.ArgumentNull_Array); if (charIndex < 0 || charCount < 0) throw new ArgumentOutOfRangeException((charIndex < 0) ? "charIndex" : "charCount", System.SR.ArgumentOutOfRange_NeedNonNegNum); if (chars.Length - charIndex < charCount) throw new ArgumentOutOfRangeException("chars", System.SR.ArgumentOutOfRange_IndexCountBuffer); if (byteIndex < 0 || byteIndex > bytes.Length) throw new ArgumentOutOfRangeException("byteIndex", System.SR.ArgumentOutOfRange_Index); if (chars.Length != 0) { int byteCount = bytes.Length - byteIndex; if (bytes.Length == 0) bytes = new byte[1]; fixed (char* ptr = &chars[0]) { fixed (byte* ptr2 = &bytes[0]) { return GetBytes(ptr + charIndex, charCount, ptr2 + byteIndex, byteCount, null); } } } return 0; } public unsafe override int GetBytes(char* chars, int charCount, byte* bytes, int byteCount) { if (bytes == null || chars == null) throw new ArgumentNullException((bytes == null) ? "bytes" : "chars", System.SR.ArgumentNull_Array); if (charCount < 0 || byteCount < 0) throw new ArgumentOutOfRangeException((charCount < 0) ? "charCount" : "byteCount", System.SR.ArgumentOutOfRange_NeedNonNegNum); return GetBytes(chars, charCount, bytes, byteCount, null); } public unsafe override int GetCharCount(byte[] bytes, int index, int count) { if (bytes == null) throw new ArgumentNullException("bytes", System.SR.ArgumentNull_Array); if (index < 0 || count < 0) throw new ArgumentOutOfRangeException((index < 0) ? "index" : "count", System.SR.ArgumentOutOfRange_NeedNonNegNum); if (bytes.Length - index < count) throw new ArgumentOutOfRangeException("bytes", System.SR.ArgumentOutOfRange_IndexCountBuffer); if (bytes.Length != 0) { fixed (byte* ptr = &bytes[0]) { return GetCharCount(ptr + index, count, null); } } return 0; } public unsafe override int GetCharCount(byte* bytes, int count) { if (bytes == null) throw new ArgumentNullException("bytes", System.SR.ArgumentNull_Array); if (count < 0) throw new ArgumentOutOfRangeException("count", System.SR.ArgumentOutOfRange_NeedNonNegNum); return GetCharCount(bytes, count, null); } public unsafe override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { if (bytes == null || chars == null) throw new ArgumentNullException((bytes == null) ? "bytes" : "chars", System.SR.ArgumentNull_Array); if (byteIndex < 0 || byteCount < 0) throw new ArgumentOutOfRangeException((byteIndex < 0) ? "byteIndex" : "byteCount", System.SR.ArgumentOutOfRange_NeedNonNegNum); if (bytes.Length - byteIndex < byteCount) throw new ArgumentOutOfRangeException("bytes", System.SR.ArgumentOutOfRange_IndexCountBuffer); if (charIndex < 0 || charIndex > chars.Length) throw new ArgumentOutOfRangeException("charIndex", System.SR.ArgumentOutOfRange_Index); if (bytes.Length != 0) { int charCount = chars.Length - charIndex; if (chars.Length == 0) chars = new char[1]; fixed (byte* ptr = &bytes[0]) { fixed (char* ptr2 = &chars[0]) { return GetChars(ptr + byteIndex, byteCount, ptr2 + charIndex, charCount, null); } } } return 0; } public unsafe override int GetChars(byte* bytes, int byteCount, char* chars, int charCount) { if (bytes == null || chars == null) throw new ArgumentNullException((bytes == null) ? "bytes" : "chars", System.SR.ArgumentNull_Array); if (charCount < 0 || byteCount < 0) throw new ArgumentOutOfRangeException((charCount < 0) ? "charCount" : "byteCount", System.SR.ArgumentOutOfRange_NeedNonNegNum); return GetChars(bytes, byteCount, chars, charCount, null); } public unsafe override string GetString(byte[] bytes, int index, int count) { if (bytes == null) throw new ArgumentNullException("bytes", System.SR.ArgumentNull_Array); if (index < 0 || count < 0) throw new ArgumentOutOfRangeException((index < 0) ? "index" : "count", System.SR.ArgumentOutOfRange_NeedNonNegNum); if (bytes.Length - index < count) throw new ArgumentOutOfRangeException("bytes", System.SR.ArgumentOutOfRange_IndexCountBuffer); if (bytes.Length != 0) { fixed (byte* ptr = &bytes[0]) { return GetString(ptr + index, count); } } return string.Empty; } public override Decoder GetDecoder() { return new System.Text.DecoderNLS(this); } public override Encoder GetEncoder() { return new System.Text.EncoderNLS(this); } internal void ThrowBytesOverflow(System.Text.EncoderNLS encoder, bool nothingEncoded) { if ((encoder?.m_throwOnOverflow ?? true) | nothingEncoded) { if (encoder != null && encoder.InternalHasFallbackBuffer) encoder.FallbackBuffer.Reset(); ThrowBytesOverflow(); } encoder.ClearMustFlush(); } internal void ThrowCharsOverflow(System.Text.DecoderNLS decoder, bool nothingDecoded) { if ((decoder?.m_throwOnOverflow ?? true) | nothingDecoded) { if (decoder != null && decoder.InternalHasFallbackBuffer) decoder.FallbackBuffer.Reset(); ThrowCharsOverflow(); } decoder.ClearMustFlush(); } [System.Diagnostics.CodeAnalysis.DoesNotReturn] internal void ThrowBytesOverflow() { throw new ArgumentException(System.SR.Format(System.SR.Argument_EncodingConversionOverflowBytes, EncodingName, base.EncoderFallback.GetType()), "bytes"); } [System.Diagnostics.CodeAnalysis.DoesNotReturn] internal void ThrowCharsOverflow() { throw new ArgumentException(System.SR.Format(System.SR.Argument_EncodingConversionOverflowChars, EncodingName, base.DecoderFallback.GetType()), "chars"); } internal static string GetLocalizedEncodingNameResource(int codePage) { switch (codePage) { case 37: return System.SR.Globalization_cp_37; case 437: return System.SR.Globalization_cp_437; case 500: return System.SR.Globalization_cp_500; case 708: return System.SR.Globalization_cp_708; case 720: return System.SR.Globalization_cp_720; case 737: return System.SR.Globalization_cp_737; case 775: return System.SR.Globalization_cp_775; case 850: return System.SR.Globalization_cp_850; case 852: return System.SR.Globalization_cp_852; case 855: return System.SR.Globalization_cp_855; case 857: return System.SR.Globalization_cp_857; case 858: return System.SR.Globalization_cp_858; case 860: return System.SR.Globalization_cp_860; case 861: return System.SR.Globalization_cp_861; case 862: return System.SR.Globalization_cp_862; case 863: return System.SR.Globalization_cp_863; case 864: return System.SR.Globalization_cp_864; case 865: return System.SR.Globalization_cp_865; case 866: return System.SR.Globalization_cp_866; case 869: return System.SR.Globalization_cp_869; case 870: return System.SR.Globalization_cp_870; case 874: return System.SR.Globalization_cp_874; case 875: return System.SR.Globalization_cp_875; case 932: return System.SR.Globalization_cp_932; case 936: return System.SR.Globalization_cp_936; case 949: return System.SR.Globalization_cp_949; case 950: return System.SR.Globalization_cp_950; case 1026: return System.SR.Globalization_cp_1026; case 1047: return System.SR.Globalization_cp_1047; case 1140: return System.SR.Globalization_cp_1140; case 1141: return System.SR.Globalization_cp_1141; case 1142: return System.SR.Globalization_cp_1142; case 1143: return System.SR.Globalization_cp_1143; case 1144: return System.SR.Globalization_cp_1144; case 1145: return System.SR.Globalization_cp_1145; case 1146: return System.SR.Globalization_cp_1146; case 1147: return System.SR.Globalization_cp_1147; case 1148: return System.SR.Globalization_cp_1148; case 1149: return System.SR.Globalization_cp_1149; case 1250: return System.SR.Globalization_cp_1250; case 1251: return System.SR.Globalization_cp_1251; case 1252: return System.SR.Globalization_cp_1252; case 1253: return System.SR.Globalization_cp_1253; case 1254: return System.SR.Globalization_cp_1254; case 1255: return System.SR.Globalization_cp_1255; case 1256: return System.SR.Globalization_cp_1256; case 1257: return System.SR.Globalization_cp_1257; case 1258: return System.SR.Globalization_cp_1258; case 1361: return System.SR.Globalization_cp_1361; case 10000: return System.SR.Globalization_cp_10000; case 10001: return System.SR.Globalization_cp_10001; case 10002: return System.SR.Globalization_cp_10002; case 10003: return System.SR.Globalization_cp_10003; case 10004: return System.SR.Globalization_cp_10004; case 10005: return System.SR.Globalization_cp_10005; case 10006: return System.SR.Globalization_cp_10006; case 10007: return System.SR.Globalization_cp_10007; case 10008: return System.SR.Globalization_cp_10008; case 10010: return System.SR.Globalization_cp_10010; case 10017: return System.SR.Globalization_cp_10017; case 10021: return System.SR.Globalization_cp_10021; case 10029: return System.SR.Globalization_cp_10029; case 10079: return System.SR.Globalization_cp_10079; case 10081: return System.SR.Globalization_cp_10081; case 10082: return System.SR.Globalization_cp_10082; case 20000: return System.SR.Globalization_cp_20000; case 20001: return System.SR.Globalization_cp_20001; case 20002: return System.SR.Globalization_cp_20002; case 20003: return System.SR.Globalization_cp_20003; case 20004: return System.SR.Globalization_cp_20004; case 20005: return System.SR.Globalization_cp_20005; case 20105: return System.SR.Globalization_cp_20105; case 20106: return System.SR.Globalization_cp_20106; case 20107: return System.SR.Globalization_cp_20107; case 20108: return System.SR.Globalization_cp_20108; case 20261: return System.SR.Globalization_cp_20261; case 20269: return System.SR.Globalization_cp_20269; case 20273: return System.SR.Globalization_cp_20273; case 20277: return System.SR.Globalization_cp_20277; case 20278: return System.SR.Globalization_cp_20278; case 20280: return System.SR.Globalization_cp_20280; case 20284: return System.SR.Globalization_cp_20284; case 20285: return System.SR.Globalization_cp_20285; case 20290: return System.SR.Globalization_cp_20290; case 20297: return System.SR.Globalization_cp_20297; case 20420: return System.SR.Globalization_cp_20420; case 20423: return System.SR.Globalization_cp_20423; case 20424: return System.SR.Globalization_cp_20424; case 20833: return System.SR.Globalization_cp_20833; case 20838: return System.SR.Globalization_cp_20838; case 20866: return System.SR.Globalization_cp_20866; case 20871: return System.SR.Globalization_cp_20871; case 20880: return System.SR.Globalization_cp_20880; case 20905: return System.SR.Globalization_cp_20905; case 20924: return System.SR.Globalization_cp_20924; case 20932: return System.SR.Globalization_cp_20932; case 20936: return System.SR.Globalization_cp_20936; case 20949: return System.SR.Globalization_cp_20949; case 21025: return System.SR.Globalization_cp_21025; case 21027: return System.SR.Globalization_cp_21027; case 21866: return System.SR.Globalization_cp_21866; case 28592: return System.SR.Globalization_cp_28592; case 28593: return System.SR.Globalization_cp_28593; case 28594: return System.SR.Globalization_cp_28594; case 28595: return System.SR.Globalization_cp_28595; case 28596: return System.SR.Globalization_cp_28596; case 28597: return System.SR.Globalization_cp_28597; case 28598: return System.SR.Globalization_cp_28598; case 28599: return System.SR.Globalization_cp_28599; case 28603: return System.SR.Globalization_cp_28603; case 28605: return System.SR.Globalization_cp_28605; case 29001: return System.SR.Globalization_cp_29001; case 38598: return System.SR.Globalization_cp_38598; case 50000: return System.SR.Globalization_cp_50000; case 50220: return System.SR.Globalization_cp_50220; case 50221: return System.SR.Globalization_cp_50221; case 50222: return System.SR.Globalization_cp_50222; case 50225: return System.SR.Globalization_cp_50225; case 50227: return System.SR.Globalization_cp_50227; case 50229: return System.SR.Globalization_cp_50229; case 50930: return System.SR.Globalization_cp_50930; case 50931: return System.SR.Globalization_cp_50931; case 50933: return System.SR.Globalization_cp_50933; case 50935: return System.SR.Globalization_cp_50935; case 50937: return System.SR.Globalization_cp_50937; case 50939: return System.SR.Globalization_cp_50939; case 51932: return System.SR.Globalization_cp_51932; case 51936: return System.SR.Globalization_cp_51936; case 51949: return System.SR.Globalization_cp_51949; case 52936: return System.SR.Globalization_cp_52936; case 54936: return System.SR.Globalization_cp_54936; case 57002: return System.SR.Globalization_cp_57002; case 57003: return System.SR.Globalization_cp_57003; case 57004: return System.SR.Globalization_cp_57004; case 57005: return System.SR.Globalization_cp_57005; case 57006: return System.SR.Globalization_cp_57006; case 57007: return System.SR.Globalization_cp_57007; case 57008: return System.SR.Globalization_cp_57008; case 57009: return System.SR.Globalization_cp_57009; case 57010: return System.SR.Globalization_cp_57010; case 57011: return System.SR.Globalization_cp_57011; default: return null; } } } }