From 88ee61203ca80f96642b8f797eba5dd32c07658a Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 26 Dec 2017 18:45:47 +0000 Subject: [PATCH] Refactor and code cleanup. --- Claunia.Encoding/ATASCII.cs | 774 ++++++---------- Claunia.Encoding/Apple2.cs | 582 +++++------- Claunia.Encoding/Apple2c.cs | 806 ++++++---------- Claunia.Encoding/Apple2e.cs | 765 ++++++---------- Claunia.Encoding/Apple2gs.cs | 707 ++++++--------- Claunia.Encoding/AtariST.cs | 1096 ++++++++-------------- Claunia.Encoding/Encoding.cs | 131 ++- Claunia.Encoding/EncodingInfo.cs | 70 +- Claunia.Encoding/LisaRoman.cs | 1043 ++++++++------------- Claunia.Encoding/MacArabic.cs | 1078 ++++++++-------------- Claunia.Encoding/MacCentralEuropean.cs | 1156 +++++++++-------------- Claunia.Encoding/MacCroatian.cs | 1156 +++++++++-------------- Claunia.Encoding/MacCyrillic.cs | 1156 +++++++++-------------- Claunia.Encoding/MacFarsi.cs | 1078 ++++++++-------------- Claunia.Encoding/MacGreek.cs | 1156 +++++++++-------------- Claunia.Encoding/MacHebrew.cs | 1045 ++++++++------------- Claunia.Encoding/MacRoman.cs | 1160 +++++++++--------------- Claunia.Encoding/MacRomanian.cs | 1160 +++++++++--------------- Claunia.Encoding/MacTurkish.cs | 1156 +++++++++-------------- Claunia.Encoding/MacUkrainian.cs | 1156 +++++++++-------------- Claunia.Encoding/PETSCII.cs | 411 ++++----- Claunia.Encoding/Pangrams.cs | 57 +- Claunia.Encoding/ZX80.cs | 607 +++++-------- Claunia.Encoding/ZX81.cs | 607 +++++-------- Claunia.Encoding/ZXSpectrum.cs | 727 ++++++--------- 25 files changed, 7710 insertions(+), 13130 deletions(-) diff --git a/Claunia.Encoding/ATASCII.cs b/Claunia.Encoding/ATASCII.cs index ce73615..ac5c5d9 100644 --- a/Claunia.Encoding/ATASCII.cs +++ b/Claunia.Encoding/ATASCII.cs @@ -29,7 +29,7 @@ using System; namespace Claunia.Encoding { /// - /// Represents an ATARI Standard Code for Information Interchange character encoding of Unicode characters. + /// Represents an ATARI Standard Code for Information Interchange character encoding of Unicode characters. /// public class ATASCII : Encoding { @@ -48,105 +48,151 @@ namespace Claunia.Encoding const bool singleByte = true; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. + /// The ATASCII to Unicode character map. /// - public override bool IsBrowserDisplay { - get { return browserDisplay; } - } + static readonly char[] ATASCIITable = + { + // 0x00 + '\u2665', '\u251C', '\uFFFD', '\u2518', '\u2524', '\u2510', '\u2571', '\u2572', + // 0x08 + '\u25E2', '\u2597', '\u25E3', '\u259D', '\u2598', '\uFFFD', '\u2582', '\u2596', + // 0x10 + '\u2663', '\u250C', '\u2500', '\u253C', '\u25CF', '\u2584', '\u258E', '\u252C', + // 0x18 + '\u2534', '\u258C', '\u2514', '\u001B', '\u2191', '\u2193', '\u2190', '\u2192', + // 0x20 + '\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027', + // 0x28 + '\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F', + // 0x30 + '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', + // 0x38 + '\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F', + // 0x40 + '\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047', + // 0x48 + '\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F', + // 0x50 + '\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057', + // 0x58 + '\u0058', '\u0059', '\u005A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F', + // 0x60 + '\u2666', '\u0061', '\u0062', '\u0063', '\u0064', '\u0065', '\u0066', '\u0067', + // 0x68 + '\u0068', '\u0069', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F', + // 0x70 + '\u0070', '\u0071', '\u0072', '\u0073', '\u0074', '\u0075', '\u0076', '\u0077', + // 0x78 + '\u0078', '\u0079', '\u007A', '\u2660', '\u007C', '\u21B0', '\u25C0', '\u25B6', + // 0x80 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0x88 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0x90 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0x98 + '\u0000', '\u0000', '\u0000', '\u000D', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xA0 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xA8 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xB0 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xB8 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xC0 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xC8 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xD0 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xD8 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xE0 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xE8 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xF0 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xF8 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0007', '\u0000', '\u0000' + }; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. + /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. /// - public override bool IsBrowserSave { - get { return browserSave; } - } + public override bool IsBrowserDisplay => browserDisplay; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. + /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. /// - public override bool IsMailNewsDisplay { - get { return mailNewsDisplay; } - } + public override bool IsBrowserSave => browserSave; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. /// - public override bool IsMailNewsSave { - get { return mailNewsSave; } - } + public override bool IsMailNewsDisplay => mailNewsDisplay; /// - /// Gets a value indicating whether the current encoding is read-only. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// + public override bool IsMailNewsSave => mailNewsSave; + + /// + /// Gets a value indicating whether the current encoding is read-only. /// /// The is single byte. - public override bool IsReadOnly { - get { return readOnly; } - } + public override bool IsReadOnly => readOnly; /// - /// Gets a value indicating whether the current encoding uses single-byte code points. + /// Gets a value indicating whether the current encoding uses single-byte code points. /// - public override bool IsSingleByte { - get { return singleByte; } - } + public override bool IsSingleByte => singleByte; /// - /// Gets the code page identifier of the current Encoding. + /// Gets the code page identifier of the current Encoding. /// - public override int CodePage { - get { return _codepage; } - } + public override int CodePage => _codepage; /// - /// Gets a name for the current encoding that can be used with mail agent body tags + /// Gets a name for the current encoding that can be used with mail agent body tags /// - public override string BodyName { - get { return _bodyname; } - } + public override string BodyName => _bodyname; /// - /// Gets a name for the current encoding that can be used with mail agent header tags + /// Gets a name for the current encoding that can be used with mail agent header tags /// - public override string HeaderName { - get { return _headername; } - } + public override string HeaderName => _headername; /// - /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. + /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. /// - public override string WebName { - get { return _webname; } - } + public override string WebName => _webname; /// - /// Gets the human-readable description of the current encoding. + /// Gets the human-readable description of the current encoding. /// - public override string EncodingName { - get { return _encodingname; } - } + public override string EncodingName => _encodingname; /// - /// Gets the Windows operating system code page that most closely corresponds to the current encoding. + /// Gets the Windows operating system code page that most closely corresponds to the current encoding. /// - public override int WindowsCodePage { - get { return _windowsCodepage; } - } + public override int WindowsCodePage => _windowsCodepage; /// - /// Calculates the number of bytes produced by encoding the characters in the specified . + /// Calculates the number of bytes produced by encoding the characters in the specified . /// /// The number of bytes produced by encoding the specified characters. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. public override int GetByteCount(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return s.Length; } /// - /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. + /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. /// /// The number of bytes produced by encoding the specified characters. /// The character array containing the set of characters to encode. @@ -154,36 +200,32 @@ namespace Claunia.Encoding /// The number of characters to encode. public override int GetByteCount(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0 || index >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0 || index >= chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0 || index + count > chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(count < 0 || index + count > chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); return count; } /// - /// Calculates the number of bytes produced by encoding all the characters in the specified character array. + /// Calculates the number of bytes produced by encoding all the characters in the specified character array. /// /// The number of bytes produced by encoding all the characters in the specified character array. /// The character array containing the characters to encode. public override int GetByteCount(char[] chars) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); return chars.Length; } /// - /// Encodes a set of characters from the specified into the specified byte array. + /// Encodes a set of characters from the specified into the specified byte array. /// /// The actual number of bytes written into bytes. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. /// The index of the first character to encode. /// The number of characters to encode. /// The byte array to contain the resulting sequence of bytes. @@ -194,20 +236,19 @@ namespace Claunia.Encoding } /// - /// Encodes all the characters in the specified string into a sequence of bytes. + /// Encodes all the characters in the specified string into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The string containing the characters to encode. public override byte[] GetBytes(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return GetBytes(s.ToCharArray(), 0, s.Length); } /// - /// Encodes a set of characters from the specified character array into the specified byte array. + /// Encodes a set of characters from the specified character array into the specified byte array. /// /// The actual number of bytes written into bytes. /// The character array containing the set of characters to encode. @@ -217,43 +258,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting sequence of bytes. public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount + charIndex > chars.Length) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount + charIndex > chars.Length) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteIndex + charCount > bytes.Length) - throw new ArgumentException(nameof(bytes)); + if(byteIndex + charCount > bytes.Length) throw new ArgumentException(nameof(bytes)); byte[] temp = GetBytes(chars, charIndex, charCount); - for(int i = 0; i < temp.Length; i++) - bytes[i + byteIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) bytes[i + byteIndex] = temp[i]; return charCount; } /// - /// Encodes a set of characters from the specified character array into a sequence of bytes. + /// Encodes a set of characters from the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the set of characters to encode. @@ -261,28 +292,23 @@ namespace Claunia.Encoding /// The number of characters to encode. public override byte[] GetBytes(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > chars.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > chars.Length) throw new ArgumentOutOfRangeException(nameof(count)); byte[] bytes = new byte[count]; - for(int i = 0; i < count; i++) - bytes[i] = GetByte(chars[index + i]); + for(int i = 0; i < count; i++) bytes[i] = GetByte(chars[index + i]); return bytes; } /// - /// Encodes all the characters in the specified character array into a sequence of bytes. + /// Encodes all the characters in the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the characters to encode. @@ -292,7 +318,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. + /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -302,7 +328,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. + /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -310,23 +336,19 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override int GetCharCount(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); return count; } /// - /// Decodes a sequence of bytes from the specified byte array into the specified character array. + /// Decodes a sequence of bytes from the specified byte array into the specified character array. /// /// The actual number of characters written into chars. /// The byte array containing the sequence of bytes to decode. @@ -336,43 +358,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting set of characters. public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount + byteIndex > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount + byteIndex > bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charIndex + byteCount > chars.Length) - throw new ArgumentException(nameof(chars)); + if(charIndex + byteCount > chars.Length) throw new ArgumentException(nameof(chars)); char[] temp = GetChars(bytes, byteIndex, byteCount); - for(int i = 0; i < temp.Length; i++) - chars[i + charIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) chars[i + charIndex] = temp[i]; return byteCount; } /// - /// Decodes all the bytes in the specified byte array into a set of characters. + /// Decodes all the bytes in the specified byte array into a set of characters. /// /// A character array containing the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -382,7 +394,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a set of characters. + /// Decodes a sequence of bytes from the specified byte array into a set of characters. /// /// The chars. /// The byte array containing the sequence of bytes to decode. @@ -390,54 +402,47 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override char[] GetChars(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); char[] chars = new char[count]; - for(int i = 0; i < count; i++) - chars[i] = GetChar(bytes[index + i]); + for(int i = 0; i < count; i++) chars[i] = GetChar(bytes[index + i]); return chars; } /// - /// Calculates the maximum number of bytes produced by encoding the specified number of characters. + /// Calculates the maximum number of bytes produced by encoding the specified number of characters. /// /// The maximum number of bytes produced by encoding the specified number of characters. /// The number of characters to encode. public override int GetMaxByteCount(int charCount) { - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); return charCount; } /// - /// Calculates the maximum number of characters produced by decoding the specified number of bytes. + /// Calculates the maximum number of characters produced by decoding the specified number of bytes. /// /// The maximum number of characters produced by decoding the specified number of bytes. /// The number of bytes to decode. public override int GetMaxCharCount(int byteCount) { - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); return byteCount; } /// - /// Returns a sequence of bytes that specifies the encoding used. + /// Returns a sequence of bytes that specifies the encoding used. /// /// A byte array of length zero, as a preamble is not required. public override byte[] GetPreamble() @@ -446,7 +451,7 @@ namespace Claunia.Encoding } /// - /// Decodes all the bytes in the specified byte array into a string. + /// Decodes all the bytes in the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -456,7 +461,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a string. + /// Decodes a sequence of bytes from the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -468,77 +473,7 @@ namespace Claunia.Encoding } /// - /// The ATASCII to Unicode character map. - /// - static readonly char[] ATASCIITable = { - // 0x00 - '\u2665','\u251C','\uFFFD','\u2518','\u2524','\u2510','\u2571','\u2572', - // 0x08 - '\u25E2','\u2597','\u25E3','\u259D','\u2598','\uFFFD','\u2582','\u2596', - // 0x10 - '\u2663','\u250C','\u2500','\u253C','\u25CF','\u2584','\u258E','\u252C', - // 0x18 - '\u2534','\u258C','\u2514','\u001B','\u2191','\u2193','\u2190','\u2192', - // 0x20 - '\u0020','\u0021','\u0022','\u0023','\u0024','\u0025','\u0026','\u0027', - // 0x28 - '\u0028','\u0029','\u002A','\u002B','\u002C','\u002D','\u002E','\u002F', - // 0x30 - '\u0030','\u0031','\u0032','\u0033','\u0034','\u0035','\u0036','\u0037', - // 0x38 - '\u0038','\u0039','\u003A','\u003B','\u003C','\u003D','\u003E','\u003F', - // 0x40 - '\u0040','\u0041','\u0042','\u0043','\u0044','\u0045','\u0046','\u0047', - // 0x48 - '\u0048','\u0049','\u004A','\u004B','\u004C','\u004D','\u004E','\u004F', - // 0x50 - '\u0050','\u0051','\u0052','\u0053','\u0054','\u0055','\u0056','\u0057', - // 0x58 - '\u0058','\u0059','\u005A','\u005B','\u005C','\u005D','\u005E','\u005F', - // 0x60 - '\u2666','\u0061','\u0062','\u0063','\u0064','\u0065','\u0066','\u0067', - // 0x68 - '\u0068','\u0069','\u006A','\u006B','\u006C','\u006D','\u006E','\u006F', - // 0x70 - '\u0070','\u0071','\u0072','\u0073','\u0074','\u0075','\u0076','\u0077', - // 0x78 - '\u0078','\u0079','\u007A','\u2660','\u007C','\u21B0','\u25C0','\u25B6', - // 0x80 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0x88 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0x90 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0x98 - '\u0000','\u0000','\u0000','\u000D','\u0000','\u0000','\u0000','\u0000', - // 0xA0 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xA8 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xB0 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xB8 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xC0 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xC8 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xD0 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xD8 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xE0 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xE8 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xF0 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xF8 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0007','\u0000','\u0000' - }; - - /// - /// Converts a ATASCII character to an Unicode character + /// Converts a ATASCII character to an Unicode character /// /// Unicode character. /// ATASCII character. @@ -548,273 +483,146 @@ namespace Claunia.Encoding } /// - /// Converts a Unicode character to an ATASCII character + /// Converts a Unicode character to an ATASCII character /// /// ATASCII character. /// Unicode character. static byte GetByte(char character) { - switch(character) { - case '\u2665': - return 0x00; - case '\u251C': - return 0x01; - case '\u2518': - return 0x03; - case '\u2524': - return 0x04; - case '\u2510': - return 0x05; - case '\u2571': - return 0x06; - case '\u2572': - return 0x07; - case '\u25E2': - return 0x08; - case '\u2597': - return 0x09; - case '\u25E3': - return 0x0A; - case '\u259D': - return 0x0B; - case '\u2598': - return 0x0C; - case '\u2582': - return 0x0E; - case '\u2596': - return 0x0F; - case '\u2663': - return 0x10; - case '\u250C': - return 0x11; - case '\u2500': - return 0x12; - case '\u253C': - return 0x13; - case '\u25CF': - return 0x14; - case '\u2584': - return 0x15; - case '\u258E': - return 0x16; - case '\u252C': - return 0x17; - case '\u2534': - return 0x18; - case '\u258C': - return 0x19; - case '\u2514': - return 0x1A; - case '\u001B': - return 0x1B; - case '\u2191': - return 0x1C; - case '\u2193': - return 0x1D; - case '\u2190': - return 0x1E; - case '\u2192': - return 0x1F; - case '\u0020': - return 0x20; - case '\u0021': - return 0x21; - case '\u0022': - return 0x22; - case '\u0023': - return 0x23; - case '\u0024': - return 0x24; - case '\u0025': - return 0x25; - case '\u0026': - return 0x26; - case '\u0027': - return 0x27; - case '\u0028': - return 0x28; - case '\u0029': - return 0x29; - case '\u002A': - return 0x2A; - case '\u002B': - return 0x2B; - case '\u002C': - return 0x2C; - case '\u002D': - return 0x2D; - case '\u002E': - return 0x2E; - case '\u002F': - return 0x2F; - case '\u0030': - return 0x30; - case '\u0031': - return 0x31; - case '\u0032': - return 0x32; - case '\u0033': - return 0x33; - case '\u0034': - return 0x34; - case '\u0035': - return 0x35; - case '\u0036': - return 0x36; - case '\u0037': - return 0x37; - case '\u0038': - return 0x38; - case '\u0039': - return 0x39; - case '\u003A': - return 0x3A; - case '\u003B': - return 0x3B; - case '\u003C': - return 0x3C; - case '\u003D': - return 0x3D; - case '\u003E': - return 0x3E; - case '\u003F': - return 0x3F; - case '\u0040': - return 0x40; - case '\u0041': - return 0x41; - case '\u0042': - return 0x42; - case '\u0043': - return 0x43; - case '\u0044': - return 0x44; - case '\u0045': - return 0x45; - case '\u0046': - return 0x46; - case '\u0047': - return 0x47; - case '\u0048': - return 0x48; - case '\u0049': - return 0x49; - case '\u004A': - return 0x4A; - case '\u004B': - return 0x4B; - case '\u004C': - return 0x4C; - case '\u004D': - return 0x4D; - case '\u004E': - return 0x4E; - case '\u004F': - return 0x4F; - case '\u0050': - return 0x50; - case '\u0051': - return 0x51; - case '\u0052': - return 0x52; - case '\u0053': - return 0x53; - case '\u0054': - return 0x54; - case '\u0055': - return 0x55; - case '\u0056': - return 0x56; - case '\u0057': - return 0x57; - case '\u0058': - return 0x58; - case '\u0059': - return 0x59; - case '\u005A': - return 0x5A; - case '\u005B': - return 0x5B; - case '\u005C': - return 0x5C; - case '\u005D': - return 0x5D; - case '\u005E': - return 0x5E; - case '\u005F': - return 0x5F; - case '\u2666': - return 0x60; - case '\u0061': - return 0x61; - case '\u0062': - return 0x62; - case '\u0063': - return 0x63; - case '\u0064': - return 0x64; - case '\u0065': - return 0x65; - case '\u0066': - return 0x66; - case '\u0067': - return 0x67; - case '\u0068': - return 0x68; - case '\u0069': - return 0x69; - case '\u006A': - return 0x6A; - case '\u006B': - return 0x6B; - case '\u006C': - return 0x6C; - case '\u006D': - return 0x6D; - case '\u006E': - return 0x6E; - case '\u006F': - return 0x6F; - case '\u0070': - return 0x70; - case '\u0071': - return 0x71; - case '\u0072': - return 0x72; - case '\u0073': - return 0x73; - case '\u0074': - return 0x74; - case '\u0075': - return 0x75; - case '\u0076': - return 0x76; - case '\u0077': - return 0x77; - case '\u0078': - return 0x78; - case '\u0079': - return 0x79; - case '\u007A': - return 0x7A; - case '\u2660': - return 0x7B; - case '\u007C': - return 0x7C; - case '\u21B0': - return 0x7D; - case '\u25C0': - return 0x7E; - case '\u25B6': - return 0x7F; - case '\u000D': - return 0x9B; - case '\u0007': - return 0xFD; + switch(character) + { + case '\u2665': return 0x00; + case '\u251C': return 0x01; + case '\u2518': return 0x03; + case '\u2524': return 0x04; + case '\u2510': return 0x05; + case '\u2571': return 0x06; + case '\u2572': return 0x07; + case '\u25E2': return 0x08; + case '\u2597': return 0x09; + case '\u25E3': return 0x0A; + case '\u259D': return 0x0B; + case '\u2598': return 0x0C; + case '\u2582': return 0x0E; + case '\u2596': return 0x0F; + case '\u2663': return 0x10; + case '\u250C': return 0x11; + case '\u2500': return 0x12; + case '\u253C': return 0x13; + case '\u25CF': return 0x14; + case '\u2584': return 0x15; + case '\u258E': return 0x16; + case '\u252C': return 0x17; + case '\u2534': return 0x18; + case '\u258C': return 0x19; + case '\u2514': return 0x1A; + case '\u001B': return 0x1B; + case '\u2191': return 0x1C; + case '\u2193': return 0x1D; + case '\u2190': return 0x1E; + case '\u2192': return 0x1F; + case '\u0020': return 0x20; + case '\u0021': return 0x21; + case '\u0022': return 0x22; + case '\u0023': return 0x23; + case '\u0024': return 0x24; + case '\u0025': return 0x25; + case '\u0026': return 0x26; + case '\u0027': return 0x27; + case '\u0028': return 0x28; + case '\u0029': return 0x29; + case '\u002A': return 0x2A; + case '\u002B': return 0x2B; + case '\u002C': return 0x2C; + case '\u002D': return 0x2D; + case '\u002E': return 0x2E; + case '\u002F': return 0x2F; + case '\u0030': return 0x30; + case '\u0031': return 0x31; + case '\u0032': return 0x32; + case '\u0033': return 0x33; + case '\u0034': return 0x34; + case '\u0035': return 0x35; + case '\u0036': return 0x36; + case '\u0037': return 0x37; + case '\u0038': return 0x38; + case '\u0039': return 0x39; + case '\u003A': return 0x3A; + case '\u003B': return 0x3B; + case '\u003C': return 0x3C; + case '\u003D': return 0x3D; + case '\u003E': return 0x3E; + case '\u003F': return 0x3F; + case '\u0040': return 0x40; + case '\u0041': return 0x41; + case '\u0042': return 0x42; + case '\u0043': return 0x43; + case '\u0044': return 0x44; + case '\u0045': return 0x45; + case '\u0046': return 0x46; + case '\u0047': return 0x47; + case '\u0048': return 0x48; + case '\u0049': return 0x49; + case '\u004A': return 0x4A; + case '\u004B': return 0x4B; + case '\u004C': return 0x4C; + case '\u004D': return 0x4D; + case '\u004E': return 0x4E; + case '\u004F': return 0x4F; + case '\u0050': return 0x50; + case '\u0051': return 0x51; + case '\u0052': return 0x52; + case '\u0053': return 0x53; + case '\u0054': return 0x54; + case '\u0055': return 0x55; + case '\u0056': return 0x56; + case '\u0057': return 0x57; + case '\u0058': return 0x58; + case '\u0059': return 0x59; + case '\u005A': return 0x5A; + case '\u005B': return 0x5B; + case '\u005C': return 0x5C; + case '\u005D': return 0x5D; + case '\u005E': return 0x5E; + case '\u005F': return 0x5F; + case '\u2666': return 0x60; + case '\u0061': return 0x61; + case '\u0062': return 0x62; + case '\u0063': return 0x63; + case '\u0064': return 0x64; + case '\u0065': return 0x65; + case '\u0066': return 0x66; + case '\u0067': return 0x67; + case '\u0068': return 0x68; + case '\u0069': return 0x69; + case '\u006A': return 0x6A; + case '\u006B': return 0x6B; + case '\u006C': return 0x6C; + case '\u006D': return 0x6D; + case '\u006E': return 0x6E; + case '\u006F': return 0x6F; + case '\u0070': return 0x70; + case '\u0071': return 0x71; + case '\u0072': return 0x72; + case '\u0073': return 0x73; + case '\u0074': return 0x74; + case '\u0075': return 0x75; + case '\u0076': return 0x76; + case '\u0077': return 0x77; + case '\u0078': return 0x78; + case '\u0079': return 0x79; + case '\u007A': return 0x7A; + case '\u2660': return 0x7B; + case '\u007C': return 0x7C; + case '\u21B0': return 0x7D; + case '\u25C0': return 0x7E; + case '\u25B6': return 0x7F; + case '\u000D': return 0x9B; + case '\u0007': return 0xFD; default: // Fallback to '?' return 0x3F; } } } -} +} \ No newline at end of file diff --git a/Claunia.Encoding/Apple2.cs b/Claunia.Encoding/Apple2.cs index 932ea74..bc1635c 100644 --- a/Claunia.Encoding/Apple2.cs +++ b/Claunia.Encoding/Apple2.cs @@ -29,7 +29,7 @@ using System; namespace Claunia.Encoding { /// - /// Represents an Apple II character encoding of Unicode characters. + /// Represents an Apple II character encoding of Unicode characters. /// public class Apple2 : Encoding { @@ -48,105 +48,151 @@ namespace Claunia.Encoding const bool singleByte = true; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. + /// The Apple II to Unicode character map. /// - public override bool IsBrowserDisplay { - get { return browserDisplay; } - } + static readonly char[] Apple2Table = + { + // 0x00 + '\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047', + // 0x08 + '\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F', + // 0x10 + '\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057', + // 0x18 + '\u0058', '\u0059', '\u005A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F', + // 0x20 + '\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027', + // 0x28 + '\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F', + // 0x30 + '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', + // 0x38 + '\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F', + // 0x40 + '\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047', + // 0x48 + '\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F', + // 0x50 + '\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057', + // 0x58 + '\u0058', '\u0059', '\u005A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F', + // 0x60 + '\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027', + // 0x68 + '\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F', + // 0x70 + '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', + // 0x78 + '\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F', + // 0x80 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0x88 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0x90 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0x98 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xA0 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xA8 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xB0 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xB8 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xC0 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xC8 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xD0 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xD8 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xE0 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xE8 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xF0 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xF8 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000' + }; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. + /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. /// - public override bool IsBrowserSave { - get { return browserSave; } - } + public override bool IsBrowserDisplay => browserDisplay; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. + /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. /// - public override bool IsMailNewsDisplay { - get { return mailNewsDisplay; } - } + public override bool IsBrowserSave => browserSave; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. /// - public override bool IsMailNewsSave { - get { return mailNewsSave; } - } + public override bool IsMailNewsDisplay => mailNewsDisplay; /// - /// Gets a value indicating whether the current encoding is read-only. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// + public override bool IsMailNewsSave => mailNewsSave; + + /// + /// Gets a value indicating whether the current encoding is read-only. /// /// The is single byte. - public override bool IsReadOnly { - get { return readOnly; } - } + public override bool IsReadOnly => readOnly; /// - /// Gets a value indicating whether the current encoding uses single-byte code points. + /// Gets a value indicating whether the current encoding uses single-byte code points. /// - public override bool IsSingleByte { - get { return singleByte; } - } + public override bool IsSingleByte => singleByte; /// - /// Gets the code page identifier of the current Encoding. + /// Gets the code page identifier of the current Encoding. /// - public override int CodePage { - get { return _codepage; } - } + public override int CodePage => _codepage; /// - /// Gets a name for the current encoding that can be used with mail agent body tags + /// Gets a name for the current encoding that can be used with mail agent body tags /// - public override string BodyName { - get { return _bodyname; } - } + public override string BodyName => _bodyname; /// - /// Gets a name for the current encoding that can be used with mail agent header tags + /// Gets a name for the current encoding that can be used with mail agent header tags /// - public override string HeaderName { - get { return _headername; } - } + public override string HeaderName => _headername; /// - /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. + /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. /// - public override string WebName { - get { return _webname; } - } + public override string WebName => _webname; /// - /// Gets the human-readable description of the current encoding. + /// Gets the human-readable description of the current encoding. /// - public override string EncodingName { - get { return _encodingname; } - } + public override string EncodingName => _encodingname; /// - /// Gets the Windows operating system code page that most closely corresponds to the current encoding. + /// Gets the Windows operating system code page that most closely corresponds to the current encoding. /// - public override int WindowsCodePage { - get { return _windowsCodepage; } - } + public override int WindowsCodePage => _windowsCodepage; /// - /// Calculates the number of bytes produced by encoding the characters in the specified . + /// Calculates the number of bytes produced by encoding the characters in the specified . /// /// The number of bytes produced by encoding the specified characters. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. public override int GetByteCount(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return s.Length; } /// - /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. + /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. /// /// The number of bytes produced by encoding the specified characters. /// The character array containing the set of characters to encode. @@ -154,36 +200,32 @@ namespace Claunia.Encoding /// The number of characters to encode. public override int GetByteCount(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0 || index >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0 || index >= chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0 || index + count > chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(count < 0 || index + count > chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); return count; } /// - /// Calculates the number of bytes produced by encoding all the characters in the specified character array. + /// Calculates the number of bytes produced by encoding all the characters in the specified character array. /// /// The number of bytes produced by encoding all the characters in the specified character array. /// The character array containing the characters to encode. public override int GetByteCount(char[] chars) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); return chars.Length; } /// - /// Encodes a set of characters from the specified into the specified byte array. + /// Encodes a set of characters from the specified into the specified byte array. /// /// The actual number of bytes written into bytes. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. /// The index of the first character to encode. /// The number of characters to encode. /// The byte array to contain the resulting sequence of bytes. @@ -194,20 +236,19 @@ namespace Claunia.Encoding } /// - /// Encodes all the characters in the specified string into a sequence of bytes. + /// Encodes all the characters in the specified string into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The string containing the characters to encode. public override byte[] GetBytes(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return GetBytes(s.ToCharArray(), 0, s.Length); } /// - /// Encodes a set of characters from the specified character array into the specified byte array. + /// Encodes a set of characters from the specified character array into the specified byte array. /// /// The actual number of bytes written into bytes. /// The character array containing the set of characters to encode. @@ -217,43 +258,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting sequence of bytes. public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount + charIndex > chars.Length) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount + charIndex > chars.Length) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteIndex + charCount > bytes.Length) - throw new ArgumentException(nameof(bytes)); + if(byteIndex + charCount > bytes.Length) throw new ArgumentException(nameof(bytes)); byte[] temp = GetBytes(chars, charIndex, charCount); - for(int i = 0; i < temp.Length; i++) - bytes[i + byteIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) bytes[i + byteIndex] = temp[i]; return charCount; } /// - /// Encodes a set of characters from the specified character array into a sequence of bytes. + /// Encodes a set of characters from the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the set of characters to encode. @@ -261,28 +292,23 @@ namespace Claunia.Encoding /// The number of characters to encode. public override byte[] GetBytes(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > chars.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > chars.Length) throw new ArgumentOutOfRangeException(nameof(count)); byte[] bytes = new byte[count]; - for(int i = 0; i < count; i++) - bytes[i] = GetByte(chars[index + i]); + for(int i = 0; i < count; i++) bytes[i] = GetByte(chars[index + i]); return bytes; } /// - /// Encodes all the characters in the specified character array into a sequence of bytes. + /// Encodes all the characters in the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the characters to encode. @@ -292,7 +318,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. + /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -302,7 +328,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. + /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -310,23 +336,19 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override int GetCharCount(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); return count; } /// - /// Decodes a sequence of bytes from the specified byte array into the specified character array. + /// Decodes a sequence of bytes from the specified byte array into the specified character array. /// /// The actual number of characters written into chars. /// The byte array containing the sequence of bytes to decode. @@ -336,43 +358,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting set of characters. public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount + byteIndex > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount + byteIndex > bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charIndex + byteCount > chars.Length) - throw new ArgumentException(nameof(chars)); + if(charIndex + byteCount > chars.Length) throw new ArgumentException(nameof(chars)); char[] temp = GetChars(bytes, byteIndex, byteCount); - for(int i = 0; i < temp.Length; i++) - chars[i + charIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) chars[i + charIndex] = temp[i]; return byteCount; } /// - /// Decodes all the bytes in the specified byte array into a set of characters. + /// Decodes all the bytes in the specified byte array into a set of characters. /// /// A character array containing the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -382,7 +394,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a set of characters. + /// Decodes a sequence of bytes from the specified byte array into a set of characters. /// /// The chars. /// The byte array containing the sequence of bytes to decode. @@ -390,54 +402,47 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override char[] GetChars(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); char[] chars = new char[count]; - for(int i = 0; i < count; i++) - chars[i] = GetChar(bytes[index + i]); + for(int i = 0; i < count; i++) chars[i] = GetChar(bytes[index + i]); return chars; } /// - /// Calculates the maximum number of bytes produced by encoding the specified number of characters. + /// Calculates the maximum number of bytes produced by encoding the specified number of characters. /// /// The maximum number of bytes produced by encoding the specified number of characters. /// The number of characters to encode. public override int GetMaxByteCount(int charCount) { - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); return charCount; } /// - /// Calculates the maximum number of characters produced by decoding the specified number of bytes. + /// Calculates the maximum number of characters produced by decoding the specified number of bytes. /// /// The maximum number of characters produced by decoding the specified number of bytes. /// The number of bytes to decode. public override int GetMaxCharCount(int byteCount) { - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); return byteCount; } /// - /// Returns a sequence of bytes that specifies the encoding used. + /// Returns a sequence of bytes that specifies the encoding used. /// /// A byte array of length zero, as a preamble is not required. public override byte[] GetPreamble() @@ -446,7 +451,7 @@ namespace Claunia.Encoding } /// - /// Decodes all the bytes in the specified byte array into a string. + /// Decodes all the bytes in the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -456,7 +461,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a string. + /// Decodes a sequence of bytes from the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -468,77 +473,7 @@ namespace Claunia.Encoding } /// - /// The Apple II to Unicode character map. - /// - static readonly char[] Apple2Table = { - // 0x00 - '\u0040','\u0041','\u0042','\u0043','\u0044','\u0045','\u0046','\u0047', - // 0x08 - '\u0048','\u0049','\u004A','\u004B','\u004C','\u004D','\u004E','\u004F', - // 0x10 - '\u0050','\u0051','\u0052','\u0053','\u0054','\u0055','\u0056','\u0057', - // 0x18 - '\u0058','\u0059','\u005A','\u005B','\u005C','\u005D','\u005E','\u005F', - // 0x20 - '\u0020','\u0021','\u0022','\u0023','\u0024','\u0025','\u0026','\u0027', - // 0x28 - '\u0028','\u0029','\u002A','\u002B','\u002C','\u002D','\u002E','\u002F', - // 0x30 - '\u0030','\u0031','\u0032','\u0033','\u0034','\u0035','\u0036','\u0037', - // 0x38 - '\u0038','\u0039','\u003A','\u003B','\u003C','\u003D','\u003E','\u003F', - // 0x40 - '\u0040','\u0041','\u0042','\u0043','\u0044','\u0045','\u0046','\u0047', - // 0x48 - '\u0048','\u0049','\u004A','\u004B','\u004C','\u004D','\u004E','\u004F', - // 0x50 - '\u0050','\u0051','\u0052','\u0053','\u0054','\u0055','\u0056','\u0057', - // 0x58 - '\u0058','\u0059','\u005A','\u005B','\u005C','\u005D','\u005E','\u005F', - // 0x60 - '\u0020','\u0021','\u0022','\u0023','\u0024','\u0025','\u0026','\u0027', - // 0x68 - '\u0028','\u0029','\u002A','\u002B','\u002C','\u002D','\u002E','\u002F', - // 0x70 - '\u0030','\u0031','\u0032','\u0033','\u0034','\u0035','\u0036','\u0037', - // 0x78 - '\u0038','\u0039','\u003A','\u003B','\u003C','\u003D','\u003E','\u003F', - // 0x80 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0x88 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0x90 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0x98 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xA0 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xA8 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xB0 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xB8 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xC0 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xC8 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xD0 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xD8 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xE0 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xE8 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xF0 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xF8 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - }; - - /// - /// Converts a Apple II character to an Unicode character + /// Converts a Apple II character to an Unicode character /// /// Unicode character. /// Apple II character. @@ -548,145 +483,82 @@ namespace Claunia.Encoding } /// - /// Converts a Unicode character to an Apple II character + /// Converts a Unicode character to an Apple II character /// /// Apple II character. /// Unicode character. static byte GetByte(char character) { - switch(character) { - case '\u0020': - return 0x20; - case '\u0021': - return 0x21; - case '\u0022': - return 0x22; - case '\u0023': - return 0x23; - case '\u0024': - return 0x24; - case '\u0025': - return 0x25; - case '\u0026': - return 0x26; - case '\u0027': - return 0x27; - case '\u0028': - return 0x28; - case '\u0029': - return 0x29; - case '\u002A': - return 0x2A; - case '\u002B': - return 0x2B; - case '\u002C': - return 0x2C; - case '\u002D': - return 0x2D; - case '\u002E': - return 0x2E; - case '\u002F': - return 0x2F; - case '\u0030': - return 0x30; - case '\u0031': - return 0x31; - case '\u0032': - return 0x32; - case '\u0033': - return 0x33; - case '\u0034': - return 0x34; - case '\u0035': - return 0x35; - case '\u0036': - return 0x36; - case '\u0037': - return 0x37; - case '\u0038': - return 0x38; - case '\u0039': - return 0x39; - case '\u003A': - return 0x3A; - case '\u003B': - return 0x3B; - case '\u003C': - return 0x3C; - case '\u003D': - return 0x3D; - case '\u003E': - return 0x3E; - case '\u003F': - return 0x3F; - case '\u0040': - return 0x40; - case '\u0041': - return 0x41; - case '\u0042': - return 0x42; - case '\u0043': - return 0x43; - case '\u0044': - return 0x44; - case '\u0045': - return 0x45; - case '\u0046': - return 0x46; - case '\u0047': - return 0x47; - case '\u0048': - return 0x48; - case '\u0049': - return 0x49; - case '\u004A': - return 0x4A; - case '\u004B': - return 0x4B; - case '\u004C': - return 0x4C; - case '\u004D': - return 0x4D; - case '\u004E': - return 0x4E; - case '\u004F': - return 0x4F; - case '\u0050': - return 0x50; - case '\u0051': - return 0x51; - case '\u0052': - return 0x52; - case '\u0053': - return 0x53; - case '\u0054': - return 0x54; - case '\u0055': - return 0x55; - case '\u0056': - return 0x56; - case '\u0057': - return 0x57; - case '\u0058': - return 0x58; - case '\u0059': - return 0x59; - case '\u005A': - return 0x5A; - case '\u005B': - return 0x5B; - case '\u005C': - return 0x5C; - case '\u005D': - return 0x5D; - case '\u005E': - return 0x5E; - case '\u005F': - return 0x5F; + switch(character) + { + case '\u0020': return 0x20; + case '\u0021': return 0x21; + case '\u0022': return 0x22; + case '\u0023': return 0x23; + case '\u0024': return 0x24; + case '\u0025': return 0x25; + case '\u0026': return 0x26; + case '\u0027': return 0x27; + case '\u0028': return 0x28; + case '\u0029': return 0x29; + case '\u002A': return 0x2A; + case '\u002B': return 0x2B; + case '\u002C': return 0x2C; + case '\u002D': return 0x2D; + case '\u002E': return 0x2E; + case '\u002F': return 0x2F; + case '\u0030': return 0x30; + case '\u0031': return 0x31; + case '\u0032': return 0x32; + case '\u0033': return 0x33; + case '\u0034': return 0x34; + case '\u0035': return 0x35; + case '\u0036': return 0x36; + case '\u0037': return 0x37; + case '\u0038': return 0x38; + case '\u0039': return 0x39; + case '\u003A': return 0x3A; + case '\u003B': return 0x3B; + case '\u003C': return 0x3C; + case '\u003D': return 0x3D; + case '\u003E': return 0x3E; + case '\u003F': return 0x3F; + case '\u0040': return 0x40; + case '\u0041': return 0x41; + case '\u0042': return 0x42; + case '\u0043': return 0x43; + case '\u0044': return 0x44; + case '\u0045': return 0x45; + case '\u0046': return 0x46; + case '\u0047': return 0x47; + case '\u0048': return 0x48; + case '\u0049': return 0x49; + case '\u004A': return 0x4A; + case '\u004B': return 0x4B; + case '\u004C': return 0x4C; + case '\u004D': return 0x4D; + case '\u004E': return 0x4E; + case '\u004F': return 0x4F; + case '\u0050': return 0x50; + case '\u0051': return 0x51; + case '\u0052': return 0x52; + case '\u0053': return 0x53; + case '\u0054': return 0x54; + case '\u0055': return 0x55; + case '\u0056': return 0x56; + case '\u0057': return 0x57; + case '\u0058': return 0x58; + case '\u0059': return 0x59; + case '\u005A': return 0x5A; + case '\u005B': return 0x5B; + case '\u005C': return 0x5C; + case '\u005D': return 0x5D; + case '\u005E': return 0x5E; + case '\u005F': return 0x5F; default: // Fallback to '?' return 0x3F; } } } -} +} \ No newline at end of file diff --git a/Claunia.Encoding/Apple2c.cs b/Claunia.Encoding/Apple2c.cs index 0cf9c74..bd45a4d 100644 --- a/Claunia.Encoding/Apple2c.cs +++ b/Claunia.Encoding/Apple2c.cs @@ -29,7 +29,7 @@ using System; namespace Claunia.Encoding { /// - /// Represents an Apple IIc character encoding of Unicode characters. + /// Represents an Apple IIc character encoding of Unicode characters. /// public class Apple2c : Encoding { @@ -48,105 +48,152 @@ namespace Claunia.Encoding const bool singleByte = true; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. + /// The Apple IIc to Unicode character map. + /// Inverted screen characters are mapped to normal characters. /// - public override bool IsBrowserDisplay { - get { return browserDisplay; } - } + static readonly char[] Apple2cTable = + { + // 0x00 + '\u0000', '\u0001', '\u0002', '\u0003', '\u0004', '\u0005', '\u0006', '\u0007', + // 0x08 + '\u0008', '\u0009', '\u000A', '\u000B', '\u000C', '\u000D', '\u000E', '\u000F', + // 0x10 + '\u0010', '\u0011', '\u0012', '\u0013', '\u0014', '\u0015', '\u0016', '\u0017', + // 0x18 + '\u0018', '\u0019', '\u001A', '\u001B', '\u001C', '\u001D', '\u001E', '\u001F', + // 0x20 + '\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027', + // 0x28 + '\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F', + // 0x30 + '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', + // 0x38 + '\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F', + // 0x40 + '\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047', + // 0x48 + '\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F', + // 0x50 + '\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057', + // 0x58 + '\u0058', '\u0059', '\u005A', '\u005B', '\u00A3', '\u005D', '\u005E', '\u005F', + // 0x60 + '\u0060', '\u0061', '\u0062', '\u0063', '\u0064', '\u0065', '\u0066', '\u0067', + // 0x68 + '\u0068', '\u0069', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F', + // 0x70 + '\u0070', '\u0071', '\u0072', '\u0073', '\u0074', '\u0075', '\u0076', '\u0077', + // 0x78 + '\u0078', '\u0079', '\u007A', '\u007B', '\u007C', '\u007D', '\u007E', '\u007F', + // 0x80 + '\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047', + // 0x88 + '\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F', + // 0x90 + '\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057', + // 0x98 + '\u0058', '\u0059', '\u005A', '\u005B', '\u00A3', '\u005D', '\u005E', '\u0020', + // 0xA0 + '\u2588', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027', + // 0xA8 + '\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F', + // 0xB0 + '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', + // 0xB8 + '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', + // 0xC0 + '\u0000', '\u0000', '\u0000', '\u231B', '\u2713', '\u0000', '\u0000', '\u0000', + // 0xC8 + '\u2190', '\u2026', '\u2193', '\u2191', '\u0000', '\u21B5', '\u0000', '\u0000', + // 0xD0 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u2192', '\u0000', '\u0000', + // 0xD8 + '\u0000', '\u0000', '\u0000', '\u25c6', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xE0 + '\u0060', '\u0061', '\u0062', '\u0063', '\u0064', '\u0065', '\u0066', '\u0067', + // 0xE8 + '\u0068', '\u0069', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F', + // 0xF0 + '\u0070', '\u0071', '\u0072', '\u0073', '\u0074', '\u0075', '\u0076', '\u0077', + // 0xF8 + '\u0078', '\u0079', '\u007A', '\u007B', '\u007C', '\u007D', '\u007E', '\u007F' + }; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. + /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. /// - public override bool IsBrowserSave { - get { return browserSave; } - } + public override bool IsBrowserDisplay => browserDisplay; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. + /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. /// - public override bool IsMailNewsDisplay { - get { return mailNewsDisplay; } - } + public override bool IsBrowserSave => browserSave; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. /// - public override bool IsMailNewsSave { - get { return mailNewsSave; } - } + public override bool IsMailNewsDisplay => mailNewsDisplay; /// - /// Gets a value indicating whether the current encoding is read-only. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// + public override bool IsMailNewsSave => mailNewsSave; + + /// + /// Gets a value indicating whether the current encoding is read-only. /// /// The is single byte. - public override bool IsReadOnly { - get { return readOnly; } - } + public override bool IsReadOnly => readOnly; /// - /// Gets a value indicating whether the current encoding uses single-byte code points. + /// Gets a value indicating whether the current encoding uses single-byte code points. /// - public override bool IsSingleByte { - get { return singleByte; } - } + public override bool IsSingleByte => singleByte; /// - /// Gets the code page identifier of the current Encoding. + /// Gets the code page identifier of the current Encoding. /// - public override int CodePage { - get { return _codepage; } - } + public override int CodePage => _codepage; /// - /// Gets a name for the current encoding that can be used with mail agent body tags + /// Gets a name for the current encoding that can be used with mail agent body tags /// - public override string BodyName { - get { return _bodyname; } - } + public override string BodyName => _bodyname; /// - /// Gets a name for the current encoding that can be used with mail agent header tags + /// Gets a name for the current encoding that can be used with mail agent header tags /// - public override string HeaderName { - get { return _headername; } - } + public override string HeaderName => _headername; /// - /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. + /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. /// - public override string WebName { - get { return _webname; } - } + public override string WebName => _webname; /// - /// Gets the human-readable description of the current encoding. + /// Gets the human-readable description of the current encoding. /// - public override string EncodingName { - get { return _encodingname; } - } + public override string EncodingName => _encodingname; /// - /// Gets the Windows operating system code page that most closely corresponds to the current encoding. + /// Gets the Windows operating system code page that most closely corresponds to the current encoding. /// - public override int WindowsCodePage { - get { return _windowsCodepage; } - } + public override int WindowsCodePage => _windowsCodepage; /// - /// Calculates the number of bytes produced by encoding the characters in the specified . + /// Calculates the number of bytes produced by encoding the characters in the specified . /// /// The number of bytes produced by encoding the specified characters. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. public override int GetByteCount(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return s.Length; } /// - /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. + /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. /// /// The number of bytes produced by encoding the specified characters. /// The character array containing the set of characters to encode. @@ -154,36 +201,32 @@ namespace Claunia.Encoding /// The number of characters to encode. public override int GetByteCount(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0 || index >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0 || index >= chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0 || index + count > chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(count < 0 || index + count > chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); return count; } /// - /// Calculates the number of bytes produced by encoding all the characters in the specified character array. + /// Calculates the number of bytes produced by encoding all the characters in the specified character array. /// /// The number of bytes produced by encoding all the characters in the specified character array. /// The character array containing the characters to encode. public override int GetByteCount(char[] chars) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); return chars.Length; } /// - /// Encodes a set of characters from the specified into the specified byte array. + /// Encodes a set of characters from the specified into the specified byte array. /// /// The actual number of bytes written into bytes. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. /// The index of the first character to encode. /// The number of characters to encode. /// The byte array to contain the resulting sequence of bytes. @@ -194,20 +237,19 @@ namespace Claunia.Encoding } /// - /// Encodes all the characters in the specified string into a sequence of bytes. + /// Encodes all the characters in the specified string into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The string containing the characters to encode. public override byte[] GetBytes(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return GetBytes(s.ToCharArray(), 0, s.Length); } /// - /// Encodes a set of characters from the specified character array into the specified byte array. + /// Encodes a set of characters from the specified character array into the specified byte array. /// /// The actual number of bytes written into bytes. /// The character array containing the set of characters to encode. @@ -217,43 +259,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting sequence of bytes. public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount + charIndex > chars.Length) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount + charIndex > chars.Length) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteIndex + charCount > bytes.Length) - throw new ArgumentException(nameof(bytes)); + if(byteIndex + charCount > bytes.Length) throw new ArgumentException(nameof(bytes)); byte[] temp = GetBytes(chars, charIndex, charCount); - for(int i = 0; i < temp.Length; i++) - bytes[i + byteIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) bytes[i + byteIndex] = temp[i]; return charCount; } /// - /// Encodes a set of characters from the specified character array into a sequence of bytes. + /// Encodes a set of characters from the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the set of characters to encode. @@ -261,28 +293,23 @@ namespace Claunia.Encoding /// The number of characters to encode. public override byte[] GetBytes(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > chars.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > chars.Length) throw new ArgumentOutOfRangeException(nameof(count)); byte[] bytes = new byte[count]; - for(int i = 0; i < count; i++) - bytes[i] = GetByte(chars[index + i]); + for(int i = 0; i < count; i++) bytes[i] = GetByte(chars[index + i]); return bytes; } /// - /// Encodes all the characters in the specified character array into a sequence of bytes. + /// Encodes all the characters in the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the characters to encode. @@ -292,7 +319,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. + /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -302,7 +329,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. + /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -310,23 +337,19 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override int GetCharCount(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); return count; } /// - /// Decodes a sequence of bytes from the specified byte array into the specified character array. + /// Decodes a sequence of bytes from the specified byte array into the specified character array. /// /// The actual number of characters written into chars. /// The byte array containing the sequence of bytes to decode. @@ -336,43 +359,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting set of characters. public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount + byteIndex > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount + byteIndex > bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charIndex + byteCount > chars.Length) - throw new ArgumentException(nameof(chars)); + if(charIndex + byteCount > chars.Length) throw new ArgumentException(nameof(chars)); char[] temp = GetChars(bytes, byteIndex, byteCount); - for(int i = 0; i < temp.Length; i++) - chars[i + charIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) chars[i + charIndex] = temp[i]; return byteCount; } /// - /// Decodes all the bytes in the specified byte array into a set of characters. + /// Decodes all the bytes in the specified byte array into a set of characters. /// /// A character array containing the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -382,7 +395,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a set of characters. + /// Decodes a sequence of bytes from the specified byte array into a set of characters. /// /// The chars. /// The byte array containing the sequence of bytes to decode. @@ -390,54 +403,47 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override char[] GetChars(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); char[] chars = new char[count]; - for(int i = 0; i < count; i++) - chars[i] = GetChar(bytes[index + i]); + for(int i = 0; i < count; i++) chars[i] = GetChar(bytes[index + i]); return chars; } /// - /// Calculates the maximum number of bytes produced by encoding the specified number of characters. + /// Calculates the maximum number of bytes produced by encoding the specified number of characters. /// /// The maximum number of bytes produced by encoding the specified number of characters. /// The number of characters to encode. public override int GetMaxByteCount(int charCount) { - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); return charCount; } /// - /// Calculates the maximum number of characters produced by decoding the specified number of bytes. + /// Calculates the maximum number of characters produced by decoding the specified number of bytes. /// /// The maximum number of characters produced by decoding the specified number of bytes. /// The number of bytes to decode. public override int GetMaxCharCount(int byteCount) { - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); return byteCount; } /// - /// Returns a sequence of bytes that specifies the encoding used. + /// Returns a sequence of bytes that specifies the encoding used. /// /// A byte array of length zero, as a preamble is not required. public override byte[] GetPreamble() @@ -446,7 +452,7 @@ namespace Claunia.Encoding } /// - /// Decodes all the bytes in the specified byte array into a string. + /// Decodes all the bytes in the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -456,7 +462,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a string. + /// Decodes a sequence of bytes from the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -468,78 +474,7 @@ namespace Claunia.Encoding } /// - /// The Apple IIc to Unicode character map. - /// Inverted screen characters are mapped to normal characters. - /// - static readonly char[] Apple2cTable = { - // 0x00 - '\u0000','\u0001','\u0002','\u0003','\u0004','\u0005','\u0006','\u0007', - // 0x08 - '\u0008','\u0009','\u000A','\u000B','\u000C','\u000D','\u000E','\u000F', - // 0x10 - '\u0010','\u0011','\u0012','\u0013','\u0014','\u0015','\u0016','\u0017', - // 0x18 - '\u0018','\u0019','\u001A','\u001B','\u001C','\u001D','\u001E','\u001F', - // 0x20 - '\u0020','\u0021','\u0022','\u0023','\u0024','\u0025','\u0026','\u0027', - // 0x28 - '\u0028','\u0029','\u002A','\u002B','\u002C','\u002D','\u002E','\u002F', - // 0x30 - '\u0030','\u0031','\u0032','\u0033','\u0034','\u0035','\u0036','\u0037', - // 0x38 - '\u0038','\u0039','\u003A','\u003B','\u003C','\u003D','\u003E','\u003F', - // 0x40 - '\u0040','\u0041','\u0042','\u0043','\u0044','\u0045','\u0046','\u0047', - // 0x48 - '\u0048','\u0049','\u004A','\u004B','\u004C','\u004D','\u004E','\u004F', - // 0x50 - '\u0050','\u0051','\u0052','\u0053','\u0054','\u0055','\u0056','\u0057', - // 0x58 - '\u0058','\u0059','\u005A','\u005B','\u00A3','\u005D','\u005E','\u005F', - // 0x60 - '\u0060','\u0061','\u0062','\u0063','\u0064','\u0065','\u0066','\u0067', - // 0x68 - '\u0068','\u0069','\u006A','\u006B','\u006C','\u006D','\u006E','\u006F', - // 0x70 - '\u0070','\u0071','\u0072','\u0073','\u0074','\u0075','\u0076','\u0077', - // 0x78 - '\u0078','\u0079','\u007A','\u007B','\u007C','\u007D','\u007E','\u007F', - // 0x80 - '\u0040','\u0041','\u0042','\u0043','\u0044','\u0045','\u0046','\u0047', - // 0x88 - '\u0048','\u0049','\u004A','\u004B','\u004C','\u004D','\u004E','\u004F', - // 0x90 - '\u0050','\u0051','\u0052','\u0053','\u0054','\u0055','\u0056','\u0057', - // 0x98 - '\u0058','\u0059','\u005A','\u005B','\u00A3','\u005D','\u005E','\u0020', - // 0xA0 - '\u2588','\u0021','\u0022','\u0023','\u0024','\u0025','\u0026','\u0027', - // 0xA8 - '\u0028','\u0029','\u002A','\u002B','\u002C','\u002D','\u002E','\u002F', - // 0xB0 - '\u0030','\u0031','\u0032','\u0033','\u0034','\u0035','\u0036','\u0037', - // 0xB8 - '\u0030','\u0031','\u0032','\u0033','\u0034','\u0035','\u0036','\u0037', - // 0xC0 - '\u0000','\u0000','\u0000','\u231B','\u2713','\u0000','\u0000','\u0000', - // 0xC8 - '\u2190','\u2026','\u2193','\u2191','\u0000','\u21B5','\u0000','\u0000', - // 0xD0 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u2192','\u0000','\u0000', - // 0xD8 - '\u0000','\u0000','\u0000','\u25c6','\u0000','\u0000','\u0000','\u0000', - // 0xE0 - '\u0060','\u0061','\u0062','\u0063','\u0064','\u0065','\u0066','\u0067', - // 0xE8 - '\u0068','\u0069','\u006A','\u006B','\u006C','\u006D','\u006E','\u006F', - // 0xF0 - '\u0070','\u0071','\u0072','\u0073','\u0074','\u0075','\u0076','\u0077', - // 0xF8 - '\u0078','\u0079','\u007A','\u007B','\u007C','\u007D','\u007E','\u007F', - }; - - /// - /// Converts a Apple IIc character to an Unicode character + /// Converts a Apple IIc character to an Unicode character /// /// Unicode character. /// Apple IIc character. @@ -549,293 +484,156 @@ namespace Claunia.Encoding } /// - /// Converts a Unicode character to an Apple IIc character + /// Converts a Unicode character to an Apple IIc character /// /// Apple IIc character. /// Unicode character. static byte GetByte(char character) { - switch(character) { - case '\u0000': - return 0x00; - case '\u0001': - return 0x01; - case '\u0002': - return 0x02; - case '\u0003': - return 0x03; - case '\u0004': - return 0x04; - case '\u0005': - return 0x05; - case '\u0006': - return 0x06; - case '\u0007': - return 0x07; - case '\u0008': - return 0x08; - case '\u0009': - return 0x09; - case '\u000A': - return 0x0A; - case '\u000B': - return 0x0B; - case '\u000C': - return 0x0C; - case '\u000D': - return 0x0D; - case '\u000E': - return 0x0E; - case '\u000F': - return 0x0F; - case '\u0010': - return 0x10; - case '\u0011': - return 0x11; - case '\u0012': - return 0x12; - case '\u0013': - return 0x13; - case '\u0014': - return 0x14; - case '\u0015': - return 0x15; - case '\u0016': - return 0x16; - case '\u0017': - return 0x17; - case '\u0018': - return 0x18; - case '\u0019': - return 0x19; - case '\u001A': - return 0x1A; - case '\u001B': - return 0x1B; - case '\u001C': - return 0x1C; - case '\u001D': - return 0x1D; - case '\u001E': - return 0x1E; - case '\u001F': - return 0x1F; - case '\u0020': - return 0x20; - case '\u0021': - return 0x21; - case '\u0022': - return 0x22; - case '\u0023': - return 0x23; - case '\u0024': - return 0x24; - case '\u0025': - return 0x25; - case '\u0026': - return 0x26; - case '\u0027': - return 0x27; - case '\u0028': - return 0x28; - case '\u0029': - return 0x29; - case '\u002A': - return 0x2A; - case '\u002B': - return 0x2B; - case '\u002C': - return 0x2C; - case '\u002D': - return 0x2D; - case '\u002E': - return 0x2E; - case '\u002F': - return 0x2F; - case '\u0030': - return 0x30; - case '\u0031': - return 0x31; - case '\u0032': - return 0x32; - case '\u0033': - return 0x33; - case '\u0034': - return 0x34; - case '\u0035': - return 0x35; - case '\u0036': - return 0x36; - case '\u0037': - return 0x37; - case '\u0038': - return 0x38; - case '\u0039': - return 0x39; - case '\u003A': - return 0x3A; - case '\u003B': - return 0x3B; - case '\u003C': - return 0x3C; - case '\u003D': - return 0x3D; - case '\u003E': - return 0x3E; - case '\u003F': - return 0x3F; - case '\u0040': - return 0x40; - case '\u0041': - return 0x41; - case '\u0042': - return 0x42; - case '\u0043': - return 0x43; - case '\u0044': - return 0x44; - case '\u0045': - return 0x45; - case '\u0046': - return 0x46; - case '\u0047': - return 0x47; - case '\u0048': - return 0x48; - case '\u0049': - return 0x49; - case '\u004A': - return 0x4A; - case '\u004B': - return 0x4B; - case '\u004C': - return 0x4C; - case '\u004D': - return 0x4D; - case '\u004E': - return 0x4E; - case '\u004F': - return 0x4F; - case '\u0050': - return 0x50; - case '\u0051': - return 0x51; - case '\u0052': - return 0x52; - case '\u0053': - return 0x53; - case '\u0054': - return 0x54; - case '\u0055': - return 0x55; - case '\u0056': - return 0x56; - case '\u0057': - return 0x57; - case '\u0058': - return 0x58; - case '\u0059': - return 0x59; - case '\u005A': - return 0x5A; - case '\u005B': - return 0x5B; - case '\u00A3': - return 0x5C; - case '\u005D': - return 0x5D; - case '\u005E': - return 0x5E; - case '\u005F': - return 0x5F; - case '\u0060': - return 0x60; - case '\u0061': - return 0x61; - case '\u0062': - return 0x62; - case '\u0063': - return 0x63; - case '\u0064': - return 0x64; - case '\u0065': - return 0x65; - case '\u0066': - return 0x66; - case '\u0067': - return 0x67; - case '\u0068': - return 0x68; - case '\u0069': - return 0x69; - case '\u006A': - return 0x6A; - case '\u006B': - return 0x6B; - case '\u006C': - return 0x6C; - case '\u006D': - return 0x6D; - case '\u006E': - return 0x6E; - case '\u006F': - return 0x6F; - case '\u0070': - return 0x70; - case '\u0071': - return 0x71; - case '\u0072': - return 0x72; - case '\u0073': - return 0x73; - case '\u0074': - return 0x74; - case '\u0075': - return 0x75; - case '\u0076': - return 0x76; - case '\u0077': - return 0x77; - case '\u0078': - return 0x78; - case '\u0079': - return 0x79; - case '\u007A': - return 0x7A; - case '\u007B': - return 0x7B; - case '\u007C': - return 0x7C; - case '\u007D': - return 0x7D; - case '\u007E': - return 0x7E; - case '\u007F': - return 0x7F; - case '\u2588': - return 0xA0; - case '\u231B': - return 0xC3; - case '\u2713': - return 0xC4; - case '\u2190': - return 0xC8; - case '\u2026': - return 0xC9; - case '\u2193': - return 0xCA; - case '\u2191': - return 0xCB; - case '\u21B5': - return 0xCD; - case '\u2192': - return 0xD5; - case '\u25C6': - return 0xDB; + switch(character) + { + case '\u0000': return 0x00; + case '\u0001': return 0x01; + case '\u0002': return 0x02; + case '\u0003': return 0x03; + case '\u0004': return 0x04; + case '\u0005': return 0x05; + case '\u0006': return 0x06; + case '\u0007': return 0x07; + case '\u0008': return 0x08; + case '\u0009': return 0x09; + case '\u000A': return 0x0A; + case '\u000B': return 0x0B; + case '\u000C': return 0x0C; + case '\u000D': return 0x0D; + case '\u000E': return 0x0E; + case '\u000F': return 0x0F; + case '\u0010': return 0x10; + case '\u0011': return 0x11; + case '\u0012': return 0x12; + case '\u0013': return 0x13; + case '\u0014': return 0x14; + case '\u0015': return 0x15; + case '\u0016': return 0x16; + case '\u0017': return 0x17; + case '\u0018': return 0x18; + case '\u0019': return 0x19; + case '\u001A': return 0x1A; + case '\u001B': return 0x1B; + case '\u001C': return 0x1C; + case '\u001D': return 0x1D; + case '\u001E': return 0x1E; + case '\u001F': return 0x1F; + case '\u0020': return 0x20; + case '\u0021': return 0x21; + case '\u0022': return 0x22; + case '\u0023': return 0x23; + case '\u0024': return 0x24; + case '\u0025': return 0x25; + case '\u0026': return 0x26; + case '\u0027': return 0x27; + case '\u0028': return 0x28; + case '\u0029': return 0x29; + case '\u002A': return 0x2A; + case '\u002B': return 0x2B; + case '\u002C': return 0x2C; + case '\u002D': return 0x2D; + case '\u002E': return 0x2E; + case '\u002F': return 0x2F; + case '\u0030': return 0x30; + case '\u0031': return 0x31; + case '\u0032': return 0x32; + case '\u0033': return 0x33; + case '\u0034': return 0x34; + case '\u0035': return 0x35; + case '\u0036': return 0x36; + case '\u0037': return 0x37; + case '\u0038': return 0x38; + case '\u0039': return 0x39; + case '\u003A': return 0x3A; + case '\u003B': return 0x3B; + case '\u003C': return 0x3C; + case '\u003D': return 0x3D; + case '\u003E': return 0x3E; + case '\u003F': return 0x3F; + case '\u0040': return 0x40; + case '\u0041': return 0x41; + case '\u0042': return 0x42; + case '\u0043': return 0x43; + case '\u0044': return 0x44; + case '\u0045': return 0x45; + case '\u0046': return 0x46; + case '\u0047': return 0x47; + case '\u0048': return 0x48; + case '\u0049': return 0x49; + case '\u004A': return 0x4A; + case '\u004B': return 0x4B; + case '\u004C': return 0x4C; + case '\u004D': return 0x4D; + case '\u004E': return 0x4E; + case '\u004F': return 0x4F; + case '\u0050': return 0x50; + case '\u0051': return 0x51; + case '\u0052': return 0x52; + case '\u0053': return 0x53; + case '\u0054': return 0x54; + case '\u0055': return 0x55; + case '\u0056': return 0x56; + case '\u0057': return 0x57; + case '\u0058': return 0x58; + case '\u0059': return 0x59; + case '\u005A': return 0x5A; + case '\u005B': return 0x5B; + case '\u00A3': return 0x5C; + case '\u005D': return 0x5D; + case '\u005E': return 0x5E; + case '\u005F': return 0x5F; + case '\u0060': return 0x60; + case '\u0061': return 0x61; + case '\u0062': return 0x62; + case '\u0063': return 0x63; + case '\u0064': return 0x64; + case '\u0065': return 0x65; + case '\u0066': return 0x66; + case '\u0067': return 0x67; + case '\u0068': return 0x68; + case '\u0069': return 0x69; + case '\u006A': return 0x6A; + case '\u006B': return 0x6B; + case '\u006C': return 0x6C; + case '\u006D': return 0x6D; + case '\u006E': return 0x6E; + case '\u006F': return 0x6F; + case '\u0070': return 0x70; + case '\u0071': return 0x71; + case '\u0072': return 0x72; + case '\u0073': return 0x73; + case '\u0074': return 0x74; + case '\u0075': return 0x75; + case '\u0076': return 0x76; + case '\u0077': return 0x77; + case '\u0078': return 0x78; + case '\u0079': return 0x79; + case '\u007A': return 0x7A; + case '\u007B': return 0x7B; + case '\u007C': return 0x7C; + case '\u007D': return 0x7D; + case '\u007E': return 0x7E; + case '\u007F': return 0x7F; + case '\u2588': return 0xA0; + case '\u231B': return 0xC3; + case '\u2713': return 0xC4; + case '\u2190': return 0xC8; + case '\u2026': return 0xC9; + case '\u2193': return 0xCA; + case '\u2191': return 0xCB; + case '\u21B5': return 0xCD; + case '\u2192': return 0xD5; + case '\u25C6': return 0xDB; default: // Fallback to '?' return 0x3F; } } } -} +} \ No newline at end of file diff --git a/Claunia.Encoding/Apple2e.cs b/Claunia.Encoding/Apple2e.cs index c21d9c7..6db9cb2 100644 --- a/Claunia.Encoding/Apple2e.cs +++ b/Claunia.Encoding/Apple2e.cs @@ -29,7 +29,7 @@ using System; namespace Claunia.Encoding { /// - /// Represents an Apple IIe character encoding of Unicode characters. + /// Represents an Apple IIe character encoding of Unicode characters. /// public class Apple2e : Encoding { @@ -48,105 +48,151 @@ namespace Claunia.Encoding const bool singleByte = true; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. + /// The Apple IIe to Unicode character map. /// - public override bool IsBrowserDisplay { - get { return browserDisplay; } - } + static readonly char[] Apple2eTable = + { + // 0x00 + '\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027', + // 0x08 + '\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F', + // 0x10 + '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', + // 0x18 + '\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F', + // 0x20 + '\u0040', '\u0061', '\u0062', '\u0063', '\u0064', '\u0065', '\u0066', '\u0067', + // 0x28 + '\u0068', '\u0069', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F', + // 0x30 + '\u0070', '\u0071', '\u0072', '\u0073', '\u0074', '\u0075', '\u0076', '\u0077', + // 0x38 + '\u0078', '\u0079', '\u007A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F', + // 0x40 + '\u00A0', '\u2575', '\u2574', '\u2577', '\u2576', '\u2518', '\u2510', '\u250C', + // 0x48 + '\u2514', '\u2500', '\u2502', '\u2534', '\u2524', '\u252C', '\u251C', '\u253C', + // 0x50 + '\u25E4', '\u25E5', '\u2592', '\u2598', '\u259D', '\u2580', '\u2596', '\u2597', + // 0x58 + '\u259A', '\u258C', '\u0000', '\u0000', '\u2190', '\u2191', '\u2192', '\u2193', + // 0x60 + '\u03C0', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047', + // 0x68 + '\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F', + // 0x70 + '\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057', + // 0x78 + '\u0058', '\u0059', '\u005A', '\u007B', '\u007C', '\u007D', '\u007E', '\u0000', + // 0x80 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0x88 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0x90 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0x98 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xA0 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xA8 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xB0 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xB8 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xC0 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xC8 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xD0 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xD8 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xE0 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xE8 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xF0 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xF8 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000' + }; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. + /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. /// - public override bool IsBrowserSave { - get { return browserSave; } - } + public override bool IsBrowserDisplay => browserDisplay; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. + /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. /// - public override bool IsMailNewsDisplay { - get { return mailNewsDisplay; } - } + public override bool IsBrowserSave => browserSave; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. /// - public override bool IsMailNewsSave { - get { return mailNewsSave; } - } + public override bool IsMailNewsDisplay => mailNewsDisplay; /// - /// Gets a value indicating whether the current encoding is read-only. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// + public override bool IsMailNewsSave => mailNewsSave; + + /// + /// Gets a value indicating whether the current encoding is read-only. /// /// The is single byte. - public override bool IsReadOnly { - get { return readOnly; } - } + public override bool IsReadOnly => readOnly; /// - /// Gets a value indicating whether the current encoding uses single-byte code points. + /// Gets a value indicating whether the current encoding uses single-byte code points. /// - public override bool IsSingleByte { - get { return singleByte; } - } + public override bool IsSingleByte => singleByte; /// - /// Gets the code page identifier of the current Encoding. + /// Gets the code page identifier of the current Encoding. /// - public override int CodePage { - get { return _codepage; } - } + public override int CodePage => _codepage; /// - /// Gets a name for the current encoding that can be used with mail agent body tags + /// Gets a name for the current encoding that can be used with mail agent body tags /// - public override string BodyName { - get { return _bodyname; } - } + public override string BodyName => _bodyname; /// - /// Gets a name for the current encoding that can be used with mail agent header tags + /// Gets a name for the current encoding that can be used with mail agent header tags /// - public override string HeaderName { - get { return _headername; } - } + public override string HeaderName => _headername; /// - /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. + /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. /// - public override string WebName { - get { return _webname; } - } + public override string WebName => _webname; /// - /// Gets the human-readable description of the current encoding. + /// Gets the human-readable description of the current encoding. /// - public override string EncodingName { - get { return _encodingname; } - } + public override string EncodingName => _encodingname; /// - /// Gets the Windows operating system code page that most closely corresponds to the current encoding. + /// Gets the Windows operating system code page that most closely corresponds to the current encoding. /// - public override int WindowsCodePage { - get { return _windowsCodepage; } - } + public override int WindowsCodePage => _windowsCodepage; /// - /// Calculates the number of bytes produced by encoding the characters in the specified . + /// Calculates the number of bytes produced by encoding the characters in the specified . /// /// The number of bytes produced by encoding the specified characters. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. public override int GetByteCount(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return s.Length; } /// - /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. + /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. /// /// The number of bytes produced by encoding the specified characters. /// The character array containing the set of characters to encode. @@ -154,36 +200,32 @@ namespace Claunia.Encoding /// The number of characters to encode. public override int GetByteCount(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0 || index >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0 || index >= chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0 || index + count > chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(count < 0 || index + count > chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); return count; } /// - /// Calculates the number of bytes produced by encoding all the characters in the specified character array. + /// Calculates the number of bytes produced by encoding all the characters in the specified character array. /// /// The number of bytes produced by encoding all the characters in the specified character array. /// The character array containing the characters to encode. public override int GetByteCount(char[] chars) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); return chars.Length; } /// - /// Encodes a set of characters from the specified into the specified byte array. + /// Encodes a set of characters from the specified into the specified byte array. /// /// The actual number of bytes written into bytes. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. /// The index of the first character to encode. /// The number of characters to encode. /// The byte array to contain the resulting sequence of bytes. @@ -194,20 +236,19 @@ namespace Claunia.Encoding } /// - /// Encodes all the characters in the specified string into a sequence of bytes. + /// Encodes all the characters in the specified string into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The string containing the characters to encode. public override byte[] GetBytes(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return GetBytes(s.ToCharArray(), 0, s.Length); } /// - /// Encodes a set of characters from the specified character array into the specified byte array. + /// Encodes a set of characters from the specified character array into the specified byte array. /// /// The actual number of bytes written into bytes. /// The character array containing the set of characters to encode. @@ -217,43 +258,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting sequence of bytes. public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount + charIndex > chars.Length) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount + charIndex > chars.Length) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteIndex + charCount > bytes.Length) - throw new ArgumentException(nameof(bytes)); + if(byteIndex + charCount > bytes.Length) throw new ArgumentException(nameof(bytes)); byte[] temp = GetBytes(chars, charIndex, charCount); - for(int i = 0; i < temp.Length; i++) - bytes[i + byteIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) bytes[i + byteIndex] = temp[i]; return charCount; } /// - /// Encodes a set of characters from the specified character array into a sequence of bytes. + /// Encodes a set of characters from the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the set of characters to encode. @@ -261,28 +292,23 @@ namespace Claunia.Encoding /// The number of characters to encode. public override byte[] GetBytes(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > chars.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > chars.Length) throw new ArgumentOutOfRangeException(nameof(count)); byte[] bytes = new byte[count]; - for(int i = 0; i < count; i++) - bytes[i] = GetByte(chars[index + i]); + for(int i = 0; i < count; i++) bytes[i] = GetByte(chars[index + i]); return bytes; } /// - /// Encodes all the characters in the specified character array into a sequence of bytes. + /// Encodes all the characters in the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the characters to encode. @@ -292,7 +318,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. + /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -302,7 +328,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. + /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -310,23 +336,19 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override int GetCharCount(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); return count; } /// - /// Decodes a sequence of bytes from the specified byte array into the specified character array. + /// Decodes a sequence of bytes from the specified byte array into the specified character array. /// /// The actual number of characters written into chars. /// The byte array containing the sequence of bytes to decode. @@ -336,43 +358,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting set of characters. public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount + byteIndex > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount + byteIndex > bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charIndex + byteCount > chars.Length) - throw new ArgumentException(nameof(chars)); + if(charIndex + byteCount > chars.Length) throw new ArgumentException(nameof(chars)); char[] temp = GetChars(bytes, byteIndex, byteCount); - for(int i = 0; i < temp.Length; i++) - chars[i + charIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) chars[i + charIndex] = temp[i]; return byteCount; } /// - /// Decodes all the bytes in the specified byte array into a set of characters. + /// Decodes all the bytes in the specified byte array into a set of characters. /// /// A character array containing the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -382,7 +394,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a set of characters. + /// Decodes a sequence of bytes from the specified byte array into a set of characters. /// /// The chars. /// The byte array containing the sequence of bytes to decode. @@ -390,54 +402,47 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override char[] GetChars(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); char[] chars = new char[count]; - for(int i = 0; i < count; i++) - chars[i] = GetChar(bytes[index + i]); + for(int i = 0; i < count; i++) chars[i] = GetChar(bytes[index + i]); return chars; } /// - /// Calculates the maximum number of bytes produced by encoding the specified number of characters. + /// Calculates the maximum number of bytes produced by encoding the specified number of characters. /// /// The maximum number of bytes produced by encoding the specified number of characters. /// The number of characters to encode. public override int GetMaxByteCount(int charCount) { - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); return charCount; } /// - /// Calculates the maximum number of characters produced by decoding the specified number of bytes. + /// Calculates the maximum number of characters produced by decoding the specified number of bytes. /// /// The maximum number of characters produced by decoding the specified number of bytes. /// The number of bytes to decode. public override int GetMaxCharCount(int byteCount) { - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); return byteCount; } /// - /// Returns a sequence of bytes that specifies the encoding used. + /// Returns a sequence of bytes that specifies the encoding used. /// /// A byte array of length zero, as a preamble is not required. public override byte[] GetPreamble() @@ -446,7 +451,7 @@ namespace Claunia.Encoding } /// - /// Decodes all the bytes in the specified byte array into a string. + /// Decodes all the bytes in the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -456,7 +461,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a string. + /// Decodes a sequence of bytes from the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -468,77 +473,7 @@ namespace Claunia.Encoding } /// - /// The Apple IIe to Unicode character map. - /// - static readonly char[] Apple2eTable = { - // 0x00 - '\u0020','\u0021','\u0022','\u0023','\u0024','\u0025','\u0026','\u0027', - // 0x08 - '\u0028','\u0029','\u002A','\u002B','\u002C','\u002D','\u002E','\u002F', - // 0x10 - '\u0030','\u0031','\u0032','\u0033','\u0034','\u0035','\u0036','\u0037', - // 0x18 - '\u0038','\u0039','\u003A','\u003B','\u003C','\u003D','\u003E','\u003F', - // 0x20 - '\u0040','\u0061','\u0062','\u0063','\u0064','\u0065','\u0066','\u0067', - // 0x28 - '\u0068','\u0069','\u006A','\u006B','\u006C','\u006D','\u006E','\u006F', - // 0x30 - '\u0070','\u0071','\u0072','\u0073','\u0074','\u0075','\u0076','\u0077', - // 0x38 - '\u0078','\u0079','\u007A','\u005B','\u005C','\u005D','\u005E','\u005F', - // 0x40 - '\u00A0','\u2575','\u2574','\u2577','\u2576','\u2518','\u2510','\u250C', - // 0x48 - '\u2514','\u2500','\u2502','\u2534','\u2524','\u252C','\u251C','\u253C', - // 0x50 - '\u25E4','\u25E5','\u2592','\u2598','\u259D','\u2580','\u2596','\u2597', - // 0x58 - '\u259A','\u258C','\u0000','\u0000','\u2190','\u2191','\u2192','\u2193', - // 0x60 - '\u03C0','\u0041','\u0042','\u0043','\u0044','\u0045','\u0046','\u0047', - // 0x68 - '\u0048','\u0049','\u004A','\u004B','\u004C','\u004D','\u004E','\u004F', - // 0x70 - '\u0050','\u0051','\u0052','\u0053','\u0054','\u0055','\u0056','\u0057', - // 0x78 - '\u0058','\u0059','\u005A','\u007B','\u007C','\u007D','\u007E','\u0000', - // 0x80 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0x88 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0x90 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0x98 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xA0 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xA8 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xB0 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xB8 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xC0 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xC8 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xD0 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xD8 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xE0 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xE8 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xF0 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xF8 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000' - }; - - /// - /// Converts a Apple IIe character to an Unicode character + /// Converts a Apple IIe character to an Unicode character /// /// Unicode character. /// Apple IIe character. @@ -548,267 +483,143 @@ namespace Claunia.Encoding } /// - /// Converts a Unicode character to an Apple IIe character + /// Converts a Unicode character to an Apple IIe character /// /// Apple IIe character. /// Unicode character. static byte GetByte(char character) { - switch(character) { - case '\u0020': - return 0x00; - case '\u0021': - return 0x01; - case '\u0022': - return 0x02; - case '\u0023': - return 0x03; - case '\u0024': - return 0x04; - case '\u0025': - return 0x05; - case '\u0026': - return 0x06; - case '\u0027': - return 0x07; - case '\u0028': - return 0x08; - case '\u0029': - return 0x09; - case '\u002A': - return 0x0A; - case '\u002B': - return 0x0B; - case '\u002C': - return 0x0C; - case '\u002D': - return 0x0D; - case '\u002E': - return 0x0E; - case '\u002F': - return 0x0F; - case '\u0030': - return 0x10; - case '\u0031': - return 0x11; - case '\u0032': - return 0x12; - case '\u0033': - return 0x13; - case '\u0034': - return 0x14; - case '\u0035': - return 0x15; - case '\u0036': - return 0x16; - case '\u0037': - return 0x17; - case '\u0038': - return 0x18; - case '\u0039': - return 0x19; - case '\u003A': - return 0x1A; - case '\u003B': - return 0x1B; - case '\u003C': - return 0x1C; - case '\u003D': - return 0x1D; - case '\u003E': - return 0x1E; - case '\u003F': - return 0x1F; - case '\u0040': - return 0x20; - case '\u0061': - return 0x21; - case '\u0062': - return 0x22; - case '\u0063': - return 0x23; - case '\u0064': - return 0x24; - case '\u0065': - return 0x25; - case '\u0066': - return 0x26; - case '\u0067': - return 0x27; - case '\u0068': - return 0x28; - case '\u0069': - return 0x29; - case '\u006A': - return 0x2A; - case '\u006B': - return 0x2B; - case '\u006C': - return 0x2C; - case '\u006D': - return 0x2D; - case '\u006E': - return 0x2E; - case '\u006F': - return 0x2F; - case '\u0070': - return 0x30; - case '\u0071': - return 0x31; - case '\u0072': - return 0x32; - case '\u0073': - return 0x33; - case '\u0074': - return 0x34; - case '\u0075': - return 0x35; - case '\u0076': - return 0x36; - case '\u0077': - return 0x37; - case '\u0078': - return 0x38; - case '\u0079': - return 0x39; - case '\u007A': - return 0x3A; - case '\u005B': - return 0x3B; - case '\u005C': - return 0x3C; - case '\u005D': - return 0x3D; - case '\u005E': - return 0x3E; - case '\u005F': - return 0x3F; - case '\u00A0': - return 0x40; - case '\u2575': - return 0x41; - case '\u2574': - return 0x42; - case '\u2577': - return 0x43; - case '\u2576': - return 0x44; - case '\u2518': - return 0x45; - case '\u2510': - return 0x46; - case '\u250C': - return 0x47; - case '\u2514': - return 0x48; - case '\u2500': - return 0x49; - case '\u2502': - return 0x4A; - case '\u2534': - return 0x4B; - case '\u2524': - return 0x4C; - case '\u252C': - return 0x4D; - case '\u251C': - return 0x4E; - case '\u253C': - return 0x4F; - case '\u25E4': - return 0x50; - case '\u25E5': - return 0x51; - case '\u2592': - return 0x52; - case '\u2598': - return 0x53; - case '\u259D': - return 0x54; - case '\u2580': - return 0x55; - case '\u2596': - return 0x56; - case '\u2597': - return 0x57; - case '\u259A': - return 0x58; - case '\u258C': - return 0x59; - case '\u2190': - return 0x5C; - case '\u2191': - return 0x5D; - case '\u2192': - return 0x5E; - case '\u2193': - return 0x5F; - case '\u03C0': - return 0x60; - case '\u0041': - return 0x61; - case '\u0042': - return 0x62; - case '\u0043': - return 0x63; - case '\u0044': - return 0x64; - case '\u0045': - return 0x65; - case '\u0046': - return 0x66; - case '\u0047': - return 0x67; - case '\u0048': - return 0x68; - case '\u0049': - return 0x69; - case '\u004A': - return 0x6A; - case '\u004B': - return 0x6B; - case '\u004C': - return 0x6C; - case '\u004D': - return 0x6D; - case '\u004E': - return 0x6E; - case '\u004F': - return 0x6F; - case '\u0050': - return 0x70; - case '\u0051': - return 0x71; - case '\u0052': - return 0x72; - case '\u0053': - return 0x73; - case '\u0054': - return 0x74; - case '\u0055': - return 0x75; - case '\u0056': - return 0x76; - case '\u0057': - return 0x77; - case '\u0058': - return 0x78; - case '\u0059': - return 0x79; - case '\u005A': - return 0x7A; - case '\u007B': - return 0x7B; - case '\u007C': - return 0x7C; - case '\u007D': - return 0x7D; - case '\u007E': - return 0x7E; + switch(character) + { + case '\u0020': return 0x00; + case '\u0021': return 0x01; + case '\u0022': return 0x02; + case '\u0023': return 0x03; + case '\u0024': return 0x04; + case '\u0025': return 0x05; + case '\u0026': return 0x06; + case '\u0027': return 0x07; + case '\u0028': return 0x08; + case '\u0029': return 0x09; + case '\u002A': return 0x0A; + case '\u002B': return 0x0B; + case '\u002C': return 0x0C; + case '\u002D': return 0x0D; + case '\u002E': return 0x0E; + case '\u002F': return 0x0F; + case '\u0030': return 0x10; + case '\u0031': return 0x11; + case '\u0032': return 0x12; + case '\u0033': return 0x13; + case '\u0034': return 0x14; + case '\u0035': return 0x15; + case '\u0036': return 0x16; + case '\u0037': return 0x17; + case '\u0038': return 0x18; + case '\u0039': return 0x19; + case '\u003A': return 0x1A; + case '\u003B': return 0x1B; + case '\u003C': return 0x1C; + case '\u003D': return 0x1D; + case '\u003E': return 0x1E; + case '\u003F': return 0x1F; + case '\u0040': return 0x20; + case '\u0061': return 0x21; + case '\u0062': return 0x22; + case '\u0063': return 0x23; + case '\u0064': return 0x24; + case '\u0065': return 0x25; + case '\u0066': return 0x26; + case '\u0067': return 0x27; + case '\u0068': return 0x28; + case '\u0069': return 0x29; + case '\u006A': return 0x2A; + case '\u006B': return 0x2B; + case '\u006C': return 0x2C; + case '\u006D': return 0x2D; + case '\u006E': return 0x2E; + case '\u006F': return 0x2F; + case '\u0070': return 0x30; + case '\u0071': return 0x31; + case '\u0072': return 0x32; + case '\u0073': return 0x33; + case '\u0074': return 0x34; + case '\u0075': return 0x35; + case '\u0076': return 0x36; + case '\u0077': return 0x37; + case '\u0078': return 0x38; + case '\u0079': return 0x39; + case '\u007A': return 0x3A; + case '\u005B': return 0x3B; + case '\u005C': return 0x3C; + case '\u005D': return 0x3D; + case '\u005E': return 0x3E; + case '\u005F': return 0x3F; + case '\u00A0': return 0x40; + case '\u2575': return 0x41; + case '\u2574': return 0x42; + case '\u2577': return 0x43; + case '\u2576': return 0x44; + case '\u2518': return 0x45; + case '\u2510': return 0x46; + case '\u250C': return 0x47; + case '\u2514': return 0x48; + case '\u2500': return 0x49; + case '\u2502': return 0x4A; + case '\u2534': return 0x4B; + case '\u2524': return 0x4C; + case '\u252C': return 0x4D; + case '\u251C': return 0x4E; + case '\u253C': return 0x4F; + case '\u25E4': return 0x50; + case '\u25E5': return 0x51; + case '\u2592': return 0x52; + case '\u2598': return 0x53; + case '\u259D': return 0x54; + case '\u2580': return 0x55; + case '\u2596': return 0x56; + case '\u2597': return 0x57; + case '\u259A': return 0x58; + case '\u258C': return 0x59; + case '\u2190': return 0x5C; + case '\u2191': return 0x5D; + case '\u2192': return 0x5E; + case '\u2193': return 0x5F; + case '\u03C0': return 0x60; + case '\u0041': return 0x61; + case '\u0042': return 0x62; + case '\u0043': return 0x63; + case '\u0044': return 0x64; + case '\u0045': return 0x65; + case '\u0046': return 0x66; + case '\u0047': return 0x67; + case '\u0048': return 0x68; + case '\u0049': return 0x69; + case '\u004A': return 0x6A; + case '\u004B': return 0x6B; + case '\u004C': return 0x6C; + case '\u004D': return 0x6D; + case '\u004E': return 0x6E; + case '\u004F': return 0x6F; + case '\u0050': return 0x70; + case '\u0051': return 0x71; + case '\u0052': return 0x72; + case '\u0053': return 0x73; + case '\u0054': return 0x74; + case '\u0055': return 0x75; + case '\u0056': return 0x76; + case '\u0057': return 0x77; + case '\u0058': return 0x78; + case '\u0059': return 0x79; + case '\u005A': return 0x7A; + case '\u007B': return 0x7B; + case '\u007C': return 0x7C; + case '\u007D': return 0x7D; + case '\u007E': return 0x7E; default: // Fallback to '?' return 0x3F; } } } -} +} \ No newline at end of file diff --git a/Claunia.Encoding/Apple2gs.cs b/Claunia.Encoding/Apple2gs.cs index 2a92b00..e9455e9 100644 --- a/Claunia.Encoding/Apple2gs.cs +++ b/Claunia.Encoding/Apple2gs.cs @@ -29,7 +29,7 @@ using System; namespace Claunia.Encoding { /// - /// Represents an Apple IIgs character encoding of Unicode characters. + /// Represents an Apple IIgs character encoding of Unicode characters. /// public class Apple2gs : Encoding { @@ -48,105 +48,152 @@ namespace Claunia.Encoding const bool singleByte = true; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. + /// The Apple IIgs to Unicode character map. + /// Inverted screen characters are mapped to normal characters. /// - public override bool IsBrowserDisplay { - get { return browserDisplay; } - } + static readonly char[] Apple2gsTable = + { + // 0x00 + '\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047', + // 0x08 + '\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F', + // 0x10 + '\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057', + // 0x18 + '\u0058', '\u0059', '\u005A', '\u005B', '\u005C', '\u005D', '\u005E', '\u0020', + // 0x20 + '\u2588', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027', + // 0x28 + '\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F', + // 0x30 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0x38 + '\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F', + // 0x40 + '\u0000', '\u0000', '\u0000', '\u231B', '\u2713', '\u0000', '\u0000', '\u0000', + // 0x48 + '\u2190', '\u2026', '\u2193', '\u2191', '\u0000', '\u21B5', '\u0000', '\u0000', + // 0x50 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u2192', '\u0000', '\u0000', + // 0x58 + '\u0000', '\u0000', '\u0000', '\u25C6', '\u0000', '\u0000', '\u0000', '\u0000', + // 0x60 + '\u0060', '\u0061', '\u0062', '\u0063', '\u0064', '\u0065', '\u0066', '\u0067', + // 0x68 + '\u0068', '\u0069', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F', + // 0x70 + '\u0070', '\u0071', '\u0072', '\u0073', '\u0074', '\u0075', '\u0076', '\u0077', + // 0x78 + '\u0078', '\u0079', '\u007A', '\u007B', '\u007C', '\u007D', '\u007E', '\u0000', + // 0x80 + '\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047', + // 0x88 + '\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F', + // 0x90 + '\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057', + // 0x98 + '\u0058', '\u0059', '\u005A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F', + // 0xA0 + '\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027', + // 0xA8 + '\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F', + // 0xB0 + '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', + // 0xB8 + '\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F', + // 0xC0 + '\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047', + // 0xC8 + '\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F', + // 0xD0 + '\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057', + // 0xD8 + '\u0058', '\u0059', '\u005A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F', + // 0xE0 + '\u0060', '\u0061', '\u0062', '\u0063', '\u0064', '\u0065', '\u0066', '\u0067', + // 0xE8 + '\u0068', '\u0069', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F', + // 0xF0 + '\u0070', '\u0071', '\u0072', '\u0073', '\u0074', '\u0075', '\u0076', '\u0077', + // 0xF8 + '\u0078', '\u0079', '\u007A', '\u007B', '\u007C', '\u007D', '\u007E', '\u0000' + }; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. + /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. /// - public override bool IsBrowserSave { - get { return browserSave; } - } + public override bool IsBrowserDisplay => browserDisplay; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. + /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. /// - public override bool IsMailNewsDisplay { - get { return mailNewsDisplay; } - } + public override bool IsBrowserSave => browserSave; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. /// - public override bool IsMailNewsSave { - get { return mailNewsSave; } - } + public override bool IsMailNewsDisplay => mailNewsDisplay; /// - /// Gets a value indicating whether the current encoding is read-only. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// + public override bool IsMailNewsSave => mailNewsSave; + + /// + /// Gets a value indicating whether the current encoding is read-only. /// /// The is single byte. - public override bool IsReadOnly { - get { return readOnly; } - } + public override bool IsReadOnly => readOnly; /// - /// Gets a value indicating whether the current encoding uses single-byte code points. + /// Gets a value indicating whether the current encoding uses single-byte code points. /// - public override bool IsSingleByte { - get { return singleByte; } - } + public override bool IsSingleByte => singleByte; /// - /// Gets the code page identifier of the current Encoding. + /// Gets the code page identifier of the current Encoding. /// - public override int CodePage { - get { return _codepage; } - } + public override int CodePage => _codepage; /// - /// Gets a name for the current encoding that can be used with mail agent body tags + /// Gets a name for the current encoding that can be used with mail agent body tags /// - public override string BodyName { - get { return _bodyname; } - } + public override string BodyName => _bodyname; /// - /// Gets a name for the current encoding that can be used with mail agent header tags + /// Gets a name for the current encoding that can be used with mail agent header tags /// - public override string HeaderName { - get { return _headername; } - } + public override string HeaderName => _headername; /// - /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. + /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. /// - public override string WebName { - get { return _webname; } - } + public override string WebName => _webname; /// - /// Gets the human-readable description of the current encoding. + /// Gets the human-readable description of the current encoding. /// - public override string EncodingName { - get { return _encodingname; } - } + public override string EncodingName => _encodingname; /// - /// Gets the Windows operating system code page that most closely corresponds to the current encoding. + /// Gets the Windows operating system code page that most closely corresponds to the current encoding. /// - public override int WindowsCodePage { - get { return _windowsCodepage; } - } + public override int WindowsCodePage => _windowsCodepage; /// - /// Calculates the number of bytes produced by encoding the characters in the specified . + /// Calculates the number of bytes produced by encoding the characters in the specified . /// /// The number of bytes produced by encoding the specified characters. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. public override int GetByteCount(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return s.Length; } /// - /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. + /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. /// /// The number of bytes produced by encoding the specified characters. /// The character array containing the set of characters to encode. @@ -154,36 +201,32 @@ namespace Claunia.Encoding /// The number of characters to encode. public override int GetByteCount(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0 || index >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0 || index >= chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0 || index + count > chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(count < 0 || index + count > chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); return count; } /// - /// Calculates the number of bytes produced by encoding all the characters in the specified character array. + /// Calculates the number of bytes produced by encoding all the characters in the specified character array. /// /// The number of bytes produced by encoding all the characters in the specified character array. /// The character array containing the characters to encode. public override int GetByteCount(char[] chars) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); return chars.Length; } /// - /// Encodes a set of characters from the specified into the specified byte array. + /// Encodes a set of characters from the specified into the specified byte array. /// /// The actual number of bytes written into bytes. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. /// The index of the first character to encode. /// The number of characters to encode. /// The byte array to contain the resulting sequence of bytes. @@ -194,20 +237,19 @@ namespace Claunia.Encoding } /// - /// Encodes all the characters in the specified string into a sequence of bytes. + /// Encodes all the characters in the specified string into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The string containing the characters to encode. public override byte[] GetBytes(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return GetBytes(s.ToCharArray(), 0, s.Length); } /// - /// Encodes a set of characters from the specified character array into the specified byte array. + /// Encodes a set of characters from the specified character array into the specified byte array. /// /// The actual number of bytes written into bytes. /// The character array containing the set of characters to encode. @@ -217,43 +259,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting sequence of bytes. public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount + charIndex > chars.Length) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount + charIndex > chars.Length) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteIndex + charCount > bytes.Length) - throw new ArgumentException(nameof(bytes)); + if(byteIndex + charCount > bytes.Length) throw new ArgumentException(nameof(bytes)); byte[] temp = GetBytes(chars, charIndex, charCount); - for(int i = 0; i < temp.Length; i++) - bytes[i + byteIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) bytes[i + byteIndex] = temp[i]; return charCount; } /// - /// Encodes a set of characters from the specified character array into a sequence of bytes. + /// Encodes a set of characters from the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the set of characters to encode. @@ -261,28 +293,23 @@ namespace Claunia.Encoding /// The number of characters to encode. public override byte[] GetBytes(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > chars.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > chars.Length) throw new ArgumentOutOfRangeException(nameof(count)); byte[] bytes = new byte[count]; - for(int i = 0; i < count; i++) - bytes[i] = GetByte(chars[index + i]); + for(int i = 0; i < count; i++) bytes[i] = GetByte(chars[index + i]); return bytes; } /// - /// Encodes all the characters in the specified character array into a sequence of bytes. + /// Encodes all the characters in the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the characters to encode. @@ -292,7 +319,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. + /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -302,7 +329,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. + /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -310,23 +337,19 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override int GetCharCount(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); return count; } /// - /// Decodes a sequence of bytes from the specified byte array into the specified character array. + /// Decodes a sequence of bytes from the specified byte array into the specified character array. /// /// The actual number of characters written into chars. /// The byte array containing the sequence of bytes to decode. @@ -336,43 +359,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting set of characters. public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount + byteIndex > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount + byteIndex > bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charIndex + byteCount > chars.Length) - throw new ArgumentException(nameof(chars)); + if(charIndex + byteCount > chars.Length) throw new ArgumentException(nameof(chars)); char[] temp = GetChars(bytes, byteIndex, byteCount); - for(int i = 0; i < temp.Length; i++) - chars[i + charIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) chars[i + charIndex] = temp[i]; return byteCount; } /// - /// Decodes all the bytes in the specified byte array into a set of characters. + /// Decodes all the bytes in the specified byte array into a set of characters. /// /// A character array containing the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -382,7 +395,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a set of characters. + /// Decodes a sequence of bytes from the specified byte array into a set of characters. /// /// The chars. /// The byte array containing the sequence of bytes to decode. @@ -390,54 +403,47 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override char[] GetChars(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); char[] chars = new char[count]; - for(int i = 0; i < count; i++) - chars[i] = GetChar(bytes[index + i]); + for(int i = 0; i < count; i++) chars[i] = GetChar(bytes[index + i]); return chars; } /// - /// Calculates the maximum number of bytes produced by encoding the specified number of characters. + /// Calculates the maximum number of bytes produced by encoding the specified number of characters. /// /// The maximum number of bytes produced by encoding the specified number of characters. /// The number of characters to encode. public override int GetMaxByteCount(int charCount) { - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); return charCount; } /// - /// Calculates the maximum number of characters produced by decoding the specified number of bytes. + /// Calculates the maximum number of characters produced by decoding the specified number of bytes. /// /// The maximum number of characters produced by decoding the specified number of bytes. /// The number of bytes to decode. public override int GetMaxCharCount(int byteCount) { - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); return byteCount; } /// - /// Returns a sequence of bytes that specifies the encoding used. + /// Returns a sequence of bytes that specifies the encoding used. /// /// A byte array of length zero, as a preamble is not required. public override byte[] GetPreamble() @@ -446,7 +452,7 @@ namespace Claunia.Encoding } /// - /// Decodes all the bytes in the specified byte array into a string. + /// Decodes all the bytes in the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -456,7 +462,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a string. + /// Decodes a sequence of bytes from the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -468,78 +474,7 @@ namespace Claunia.Encoding } /// - /// The Apple IIgs to Unicode character map. - /// Inverted screen characters are mapped to normal characters. - /// - static readonly char[] Apple2gsTable = { - // 0x00 - '\u0040','\u0041','\u0042','\u0043','\u0044','\u0045','\u0046','\u0047', - // 0x08 - '\u0048','\u0049','\u004A','\u004B','\u004C','\u004D','\u004E','\u004F', - // 0x10 - '\u0050','\u0051','\u0052','\u0053','\u0054','\u0055','\u0056','\u0057', - // 0x18 - '\u0058','\u0059','\u005A','\u005B','\u005C','\u005D','\u005E','\u0020', - // 0x20 - '\u2588','\u0021','\u0022','\u0023','\u0024','\u0025','\u0026','\u0027', - // 0x28 - '\u0028','\u0029','\u002A','\u002B','\u002C','\u002D','\u002E','\u002F', - // 0x30 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0x38 - '\u0038','\u0039','\u003A','\u003B','\u003C','\u003D','\u003E','\u003F', - // 0x40 - '\u0000','\u0000','\u0000','\u231B','\u2713','\u0000','\u0000','\u0000', - // 0x48 - '\u2190','\u2026','\u2193','\u2191','\u0000','\u21B5','\u0000','\u0000', - // 0x50 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u2192','\u0000','\u0000', - // 0x58 - '\u0000','\u0000','\u0000','\u25C6','\u0000','\u0000','\u0000','\u0000', - // 0x60 - '\u0060','\u0061','\u0062','\u0063','\u0064','\u0065','\u0066','\u0067', - // 0x68 - '\u0068','\u0069','\u006A','\u006B','\u006C','\u006D','\u006E','\u006F', - // 0x70 - '\u0070','\u0071','\u0072','\u0073','\u0074','\u0075','\u0076','\u0077', - // 0x78 - '\u0078','\u0079','\u007A','\u007B','\u007C','\u007D','\u007E','\u0000', - // 0x80 - '\u0040','\u0041','\u0042','\u0043','\u0044','\u0045','\u0046','\u0047', - // 0x88 - '\u0048','\u0049','\u004A','\u004B','\u004C','\u004D','\u004E','\u004F', - // 0x90 - '\u0050','\u0051','\u0052','\u0053','\u0054','\u0055','\u0056','\u0057', - // 0x98 - '\u0058','\u0059','\u005A','\u005B','\u005C','\u005D','\u005E','\u005F', - // 0xA0 - '\u0020','\u0021','\u0022','\u0023','\u0024','\u0025','\u0026','\u0027', - // 0xA8 - '\u0028','\u0029','\u002A','\u002B','\u002C','\u002D','\u002E','\u002F', - // 0xB0 - '\u0030','\u0031','\u0032','\u0033','\u0034','\u0035','\u0036','\u0037', - // 0xB8 - '\u0038','\u0039','\u003A','\u003B','\u003C','\u003D','\u003E','\u003F', - // 0xC0 - '\u0040','\u0041','\u0042','\u0043','\u0044','\u0045','\u0046','\u0047', - // 0xC8 - '\u0048','\u0049','\u004A','\u004B','\u004C','\u004D','\u004E','\u004F', - // 0xD0 - '\u0050','\u0051','\u0052','\u0053','\u0054','\u0055','\u0056','\u0057', - // 0xD8 - '\u0058','\u0059','\u005A','\u005B','\u005C','\u005D','\u005E','\u005F', - // 0xE0 - '\u0060','\u0061','\u0062','\u0063','\u0064','\u0065','\u0066','\u0067', - // 0xE8 - '\u0068','\u0069','\u006A','\u006B','\u006C','\u006D','\u006E','\u006F', - // 0xF0 - '\u0070','\u0071','\u0072','\u0073','\u0074','\u0075','\u0076','\u0077', - // 0xF8 - '\u0078','\u0079','\u007A','\u007B','\u007C','\u007D','\u007E','\u0000' - }; - - /// - /// Converts a Apple IIgs character to an Unicode character + /// Converts a Apple IIgs character to an Unicode character /// /// Unicode character. /// Apple IIgs character. @@ -549,227 +484,123 @@ namespace Claunia.Encoding } /// - /// Converts a Unicode character to an Apple IIgs character + /// Converts a Unicode character to an Apple IIgs character /// /// Apple IIgs character. /// Unicode character. static byte GetByte(char character) { - switch(character) { - case '\u2588': - return 0x20; - case '\u231B': - return 0x43; - case '\u2713': - return 0x44; - case '\u2190': - return 0x48; - case '\u2026': - return 0x49; - case '\u2193': - return 0x4A; - case '\u2191': - return 0x4B; - case '\u21B5': - return 0x4D; - case '\u2192': - return 0x55; - case '\u25C6': - return 0x5B; - case '\u0040': - return 0x80; - case '\u0041': - return 0x81; - case '\u0042': - return 0x82; - case '\u0043': - return 0x83; - case '\u0044': - return 0x84; - case '\u0045': - return 0x85; - case '\u0046': - return 0x86; - case '\u0047': - return 0x87; - case '\u0048': - return 0x88; - case '\u0049': - return 0x89; - case '\u004A': - return 0x8A; - case '\u004B': - return 0x8B; - case '\u004C': - return 0x8C; - case '\u004D': - return 0x8D; - case '\u004E': - return 0x8E; - case '\u004F': - return 0x8F; - case '\u0050': - return 0x90; - case '\u0051': - return 0x91; - case '\u0052': - return 0x92; - case '\u0053': - return 0x93; - case '\u0054': - return 0x94; - case '\u0055': - return 0x95; - case '\u0056': - return 0x96; - case '\u0057': - return 0x97; - case '\u0058': - return 0x98; - case '\u0059': - return 0x99; - case '\u005A': - return 0x9A; - case '\u005B': - return 0x9B; - case '\u005C': - return 0x9C; - case '\u005D': - return 0x9D; - case '\u005E': - return 0x9E; - case '\u005F': - return 0x9F; - case '\u0020': - return 0xA0; - case '\u0021': - return 0xA1; - case '\u0022': - return 0xA2; - case '\u0023': - return 0xA3; - case '\u0024': - return 0xA4; - case '\u2025': - return 0xA5; - case '\u0026': - return 0xA6; - case '\u0027': - return 0xA7; - case '\u0028': - return 0xA8; - case '\u0029': - return 0xA9; - case '\u002A': - return 0xAA; - case '\u002B': - return 0xAB; - case '\u002C': - return 0xAC; - case '\u002D': - return 0xAD; - case '\u002E': - return 0xAE; - case '\u002F': - return 0xAF; - case '\u0030': - return 0xB0; - case '\u0031': - return 0xB1; - case '\u0032': - return 0xB2; - case '\u0033': - return 0xB3; - case '\u0034': - return 0xB4; - case '\u0035': - return 0xB5; - case '\u0036': - return 0xB6; - case '\u0037': - return 0xB7; - case '\u0038': - return 0xB8; - case '\u0039': - return 0xB9; - case '\u003A': - return 0xBA; - case '\u003B': - return 0xBB; - case '\u003C': - return 0xBC; - case '\u003D': - return 0xBD; - case '\u003E': - return 0xBE; - case '\u003F': - return 0xBF; - case '\u0060': - return 0xE0; - case '\u0061': - return 0xE1; - case '\u0062': - return 0xE2; - case '\u0063': - return 0xE3; - case '\u0064': - return 0xE4; - case '\u0065': - return 0xE5; - case '\u0066': - return 0xE6; - case '\u0067': - return 0xE7; - case '\u0068': - return 0xE8; - case '\u0069': - return 0xE9; - case '\u006A': - return 0xEA; - case '\u006B': - return 0xEB; - case '\u006C': - return 0xEC; - case '\u006D': - return 0xED; - case '\u006E': - return 0xEE; - case '\u006F': - return 0xEF; - case '\u0070': - return 0xF0; - case '\u0071': - return 0xF1; - case '\u0072': - return 0xF2; - case '\u0073': - return 0xF3; - case '\u0074': - return 0xF4; - case '\u0075': - return 0xF5; - case '\u0076': - return 0xF6; - case '\u0077': - return 0xF7; - case '\u0078': - return 0xF8; - case '\u0079': - return 0xF9; - case '\u007A': - return 0xFA; - case '\u007B': - return 0xFB; - case '\u007C': - return 0xFC; - case '\u007D': - return 0xFD; - case '\u007E': - return 0xFE; + switch(character) + { + case '\u2588': return 0x20; + case '\u231B': return 0x43; + case '\u2713': return 0x44; + case '\u2190': return 0x48; + case '\u2026': return 0x49; + case '\u2193': return 0x4A; + case '\u2191': return 0x4B; + case '\u21B5': return 0x4D; + case '\u2192': return 0x55; + case '\u25C6': return 0x5B; + case '\u0040': return 0x80; + case '\u0041': return 0x81; + case '\u0042': return 0x82; + case '\u0043': return 0x83; + case '\u0044': return 0x84; + case '\u0045': return 0x85; + case '\u0046': return 0x86; + case '\u0047': return 0x87; + case '\u0048': return 0x88; + case '\u0049': return 0x89; + case '\u004A': return 0x8A; + case '\u004B': return 0x8B; + case '\u004C': return 0x8C; + case '\u004D': return 0x8D; + case '\u004E': return 0x8E; + case '\u004F': return 0x8F; + case '\u0050': return 0x90; + case '\u0051': return 0x91; + case '\u0052': return 0x92; + case '\u0053': return 0x93; + case '\u0054': return 0x94; + case '\u0055': return 0x95; + case '\u0056': return 0x96; + case '\u0057': return 0x97; + case '\u0058': return 0x98; + case '\u0059': return 0x99; + case '\u005A': return 0x9A; + case '\u005B': return 0x9B; + case '\u005C': return 0x9C; + case '\u005D': return 0x9D; + case '\u005E': return 0x9E; + case '\u005F': return 0x9F; + case '\u0020': return 0xA0; + case '\u0021': return 0xA1; + case '\u0022': return 0xA2; + case '\u0023': return 0xA3; + case '\u0024': return 0xA4; + case '\u2025': return 0xA5; + case '\u0026': return 0xA6; + case '\u0027': return 0xA7; + case '\u0028': return 0xA8; + case '\u0029': return 0xA9; + case '\u002A': return 0xAA; + case '\u002B': return 0xAB; + case '\u002C': return 0xAC; + case '\u002D': return 0xAD; + case '\u002E': return 0xAE; + case '\u002F': return 0xAF; + case '\u0030': return 0xB0; + case '\u0031': return 0xB1; + case '\u0032': return 0xB2; + case '\u0033': return 0xB3; + case '\u0034': return 0xB4; + case '\u0035': return 0xB5; + case '\u0036': return 0xB6; + case '\u0037': return 0xB7; + case '\u0038': return 0xB8; + case '\u0039': return 0xB9; + case '\u003A': return 0xBA; + case '\u003B': return 0xBB; + case '\u003C': return 0xBC; + case '\u003D': return 0xBD; + case '\u003E': return 0xBE; + case '\u003F': return 0xBF; + case '\u0060': return 0xE0; + case '\u0061': return 0xE1; + case '\u0062': return 0xE2; + case '\u0063': return 0xE3; + case '\u0064': return 0xE4; + case '\u0065': return 0xE5; + case '\u0066': return 0xE6; + case '\u0067': return 0xE7; + case '\u0068': return 0xE8; + case '\u0069': return 0xE9; + case '\u006A': return 0xEA; + case '\u006B': return 0xEB; + case '\u006C': return 0xEC; + case '\u006D': return 0xED; + case '\u006E': return 0xEE; + case '\u006F': return 0xEF; + case '\u0070': return 0xF0; + case '\u0071': return 0xF1; + case '\u0072': return 0xF2; + case '\u0073': return 0xF3; + case '\u0074': return 0xF4; + case '\u0075': return 0xF5; + case '\u0076': return 0xF6; + case '\u0077': return 0xF7; + case '\u0078': return 0xF8; + case '\u0079': return 0xF9; + case '\u007A': return 0xFA; + case '\u007B': return 0xFB; + case '\u007C': return 0xFC; + case '\u007D': return 0xFD; + case '\u007E': return 0xFE; default: // Fallback to '?' return 0xBF; } } } -} +} \ No newline at end of file diff --git a/Claunia.Encoding/AtariST.cs b/Claunia.Encoding/AtariST.cs index 1ae3e84..870a6dd 100644 --- a/Claunia.Encoding/AtariST.cs +++ b/Claunia.Encoding/AtariST.cs @@ -29,7 +29,7 @@ using System; namespace Claunia.Encoding { /// - /// Represents an Atari ST character encoding of Unicode characters. + /// Represents an Atari ST character encoding of Unicode characters. /// // TODO: 0x09 => U+1F552, 0x0A => U+1F514 public class AtariST : Encoding @@ -49,105 +49,151 @@ namespace Claunia.Encoding const bool singleByte = true; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. + /// The Atari ST to Unicode character map. /// - public override bool IsBrowserDisplay { - get { return browserDisplay; } - } + static readonly char[] AtariSTTable = + { + // 0x00 + '\u0000', '\u21E7', '\u21E9', '\u21E8', '\u21E6', '\u274E', '\uFFFD', '\uFFFD', + // 0x08 + '\u2713', '\uFFFD', '\uFFFD', '\u266A', '\u000C', '\u000D', '\uFFFD', '\uFFFD', + // 0x10 + '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', + // 0x18 + '\uFFFD', '\uFFFD', '\u0259', '\u001B', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', + // 0x20 + '\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027', + // 0x28 + '\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F', + // 0x30 + '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', + // 0x38 + '\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F', + // 0x40 + '\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047', + // 0x48 + '\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F', + // 0x50 + '\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057', + // 0x58 + '\u0058', '\u0059', '\u005A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F', + // 0x60 + '\u0060', '\u0061', '\u0062', '\u0063', '\u0064', '\u0065', '\u0066', '\u0067', + // 0x68 + '\u0068', '\u0069', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F', + // 0x70 + '\u0070', '\u0071', '\u0072', '\u0073', '\u0074', '\u0075', '\u0076', '\u0077', + // 0x78 + '\u0078', '\u0079', '\u007A', '\u007B', '\u007C', '\u007D', '\u007E', '\u2302', + // 0x80 + '\u00C7', '\u00FC', '\u00E9', '\u00E2', '\u00E4', '\u00E0', '\u00E5', '\u00E7', + // 0x88 + '\u00EA', '\u00EB', '\u00E8', '\u00EF', '\u00EE', '\u00EC', '\u00C4', '\u00C5', + // 0x90 + '\u00C9', '\u00E6', '\u00C6', '\u00F4', '\u00F6', '\u00F2', '\u00FB', '\u00F9', + // 0x98 + '\u00FF', '\u00D6', '\u00DC', '\u00A2', '\u00A3', '\u00A5', '\u00DF', '\u0192', + // 0xA0 + '\u00E1', '\u00ED', '\u00F3', '\u00FA', '\u00F1', '\u00D1', '\u00AA', '\u00BA', + // 0xA8 + '\u00BF', '\u2310', '\u00AC', '\u00BD', '\u00BC', '\u00A1', '\u00AB', '\u00BB', + // 0xB0 + '\u00E3', '\u00F5', '\u00D8', '\u00F8', '\u0153', '\u0152', '\u00C0', '\u00C3', + // 0xB8 + '\u00D5', '\u00A8', '\u00B4', '\u2020', '\u00B6', '\u00A9', '\u00AE', '\u2122', + // 0xC0 + '\u0133', '\u0132', '\u05D0', '\u05D1', '\u05D2', '\u05D3', '\u05D4', '\u05D5', + // 0xC8 + '\u05D6', '\u05D7', '\u05D8', '\u05D9', '\u05DB', '\u05DC', '\u05DE', '\u05E0', + // 0xD0 + '\u05E1', '\u05E2', '\u05E4', '\u05E6', '\u05E7', '\u05E8', '\u05E9', '\u05EA', + // 0xD8 + '\u05DF', '\u05DA', '\u05DD', '\u05E3', '\u05E5', '\u00A7', '\u2227', '\u221E', + // 0xE0 + '\u03B1', '\u03B2', '\u0393', '\u03C0', '\u03A3', '\u03C3', '\u00B5', '\u03C4', + // 0xE8 + '\u03A6', '\u0398', '\u03A9', '\u03B4', '\u222E', '\u03D5', '\u2208', '\u2229', + // 0xF0 + '\u2261', '\u00B1', '\u2265', '\u2264', '\u2320', '\u2321', '\u00F7', '\u2248', + // 0xF8 + '\u00B0', '\u2219', '\u00B7', '\u221A', '\u207F', '\u00B2', '\u00B3', '\u00AF' + }; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. + /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. /// - public override bool IsBrowserSave { - get { return browserSave; } - } + public override bool IsBrowserDisplay => browserDisplay; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. + /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. /// - public override bool IsMailNewsDisplay { - get { return mailNewsDisplay; } - } + public override bool IsBrowserSave => browserSave; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. /// - public override bool IsMailNewsSave { - get { return mailNewsSave; } - } + public override bool IsMailNewsDisplay => mailNewsDisplay; /// - /// Gets a value indicating whether the current encoding is read-only. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// + public override bool IsMailNewsSave => mailNewsSave; + + /// + /// Gets a value indicating whether the current encoding is read-only. /// /// The is single byte. - public override bool IsReadOnly { - get { return readOnly; } - } + public override bool IsReadOnly => readOnly; /// - /// Gets a value indicating whether the current encoding uses single-byte code points. + /// Gets a value indicating whether the current encoding uses single-byte code points. /// - public override bool IsSingleByte { - get { return singleByte; } - } + public override bool IsSingleByte => singleByte; /// - /// Gets the code page identifier of the current Encoding. + /// Gets the code page identifier of the current Encoding. /// - public override int CodePage { - get { return _codepage; } - } + public override int CodePage => _codepage; /// - /// Gets a name for the current encoding that can be used with mail agent body tags + /// Gets a name for the current encoding that can be used with mail agent body tags /// - public override string BodyName { - get { return _bodyname; } - } + public override string BodyName => _bodyname; /// - /// Gets a name for the current encoding that can be used with mail agent header tags + /// Gets a name for the current encoding that can be used with mail agent header tags /// - public override string HeaderName { - get { return _headername; } - } + public override string HeaderName => _headername; /// - /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. + /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. /// - public override string WebName { - get { return _webname; } - } + public override string WebName => _webname; /// - /// Gets the human-readable description of the current encoding. + /// Gets the human-readable description of the current encoding. /// - public override string EncodingName { - get { return _encodingname; } - } + public override string EncodingName => _encodingname; /// - /// Gets the Windows operating system code page that most closely corresponds to the current encoding. + /// Gets the Windows operating system code page that most closely corresponds to the current encoding. /// - public override int WindowsCodePage { - get { return _windowsCodepage; } - } + public override int WindowsCodePage => _windowsCodepage; /// - /// Calculates the number of bytes produced by encoding the characters in the specified . + /// Calculates the number of bytes produced by encoding the characters in the specified . /// /// The number of bytes produced by encoding the specified characters. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. public override int GetByteCount(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return s.Length; } /// - /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. + /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. /// /// The number of bytes produced by encoding the specified characters. /// The character array containing the set of characters to encode. @@ -155,36 +201,32 @@ namespace Claunia.Encoding /// The number of characters to encode. public override int GetByteCount(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0 || index >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0 || index >= chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0 || index + count > chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(count < 0 || index + count > chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); return count; } /// - /// Calculates the number of bytes produced by encoding all the characters in the specified character array. + /// Calculates the number of bytes produced by encoding all the characters in the specified character array. /// /// The number of bytes produced by encoding all the characters in the specified character array. /// The character array containing the characters to encode. public override int GetByteCount(char[] chars) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); return chars.Length; } /// - /// Encodes a set of characters from the specified into the specified byte array. + /// Encodes a set of characters from the specified into the specified byte array. /// /// The actual number of bytes written into bytes. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. /// The index of the first character to encode. /// The number of characters to encode. /// The byte array to contain the resulting sequence of bytes. @@ -195,20 +237,19 @@ namespace Claunia.Encoding } /// - /// Encodes all the characters in the specified string into a sequence of bytes. + /// Encodes all the characters in the specified string into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The string containing the characters to encode. public override byte[] GetBytes(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return GetBytes(s.ToCharArray(), 0, s.Length); } /// - /// Encodes a set of characters from the specified character array into the specified byte array. + /// Encodes a set of characters from the specified character array into the specified byte array. /// /// The actual number of bytes written into bytes. /// The character array containing the set of characters to encode. @@ -218,43 +259,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting sequence of bytes. public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount + charIndex > chars.Length) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount + charIndex > chars.Length) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteIndex + charCount > bytes.Length) - throw new ArgumentException(nameof(bytes)); + if(byteIndex + charCount > bytes.Length) throw new ArgumentException(nameof(bytes)); byte[] temp = GetBytes(chars, charIndex, charCount); - for(int i = 0; i < temp.Length; i++) - bytes[i + byteIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) bytes[i + byteIndex] = temp[i]; return charCount; } /// - /// Encodes a set of characters from the specified character array into a sequence of bytes. + /// Encodes a set of characters from the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the set of characters to encode. @@ -262,28 +293,23 @@ namespace Claunia.Encoding /// The number of characters to encode. public override byte[] GetBytes(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > chars.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > chars.Length) throw new ArgumentOutOfRangeException(nameof(count)); byte[] bytes = new byte[count]; - for(int i = 0; i < count; i++) - bytes[i] = GetByte(chars[index + i]); + for(int i = 0; i < count; i++) bytes[i] = GetByte(chars[index + i]); return bytes; } /// - /// Encodes all the characters in the specified character array into a sequence of bytes. + /// Encodes all the characters in the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the characters to encode. @@ -293,7 +319,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. + /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -303,7 +329,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. + /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -311,23 +337,19 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override int GetCharCount(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); return count; } /// - /// Decodes a sequence of bytes from the specified byte array into the specified character array. + /// Decodes a sequence of bytes from the specified byte array into the specified character array. /// /// The actual number of characters written into chars. /// The byte array containing the sequence of bytes to decode. @@ -337,43 +359,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting set of characters. public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount + byteIndex > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount + byteIndex > bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charIndex + byteCount > chars.Length) - throw new ArgumentException(nameof(chars)); + if(charIndex + byteCount > chars.Length) throw new ArgumentException(nameof(chars)); char[] temp = GetChars(bytes, byteIndex, byteCount); - for(int i = 0; i < temp.Length; i++) - chars[i + charIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) chars[i + charIndex] = temp[i]; return byteCount; } /// - /// Decodes all the bytes in the specified byte array into a set of characters. + /// Decodes all the bytes in the specified byte array into a set of characters. /// /// A character array containing the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -383,7 +395,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a set of characters. + /// Decodes a sequence of bytes from the specified byte array into a set of characters. /// /// The chars. /// The byte array containing the sequence of bytes to decode. @@ -391,54 +403,47 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override char[] GetChars(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); char[] chars = new char[count]; - for(int i = 0; i < count; i++) - chars[i] = GetChar(bytes[index + i]); + for(int i = 0; i < count; i++) chars[i] = GetChar(bytes[index + i]); return chars; } /// - /// Calculates the maximum number of bytes produced by encoding the specified number of characters. + /// Calculates the maximum number of bytes produced by encoding the specified number of characters. /// /// The maximum number of bytes produced by encoding the specified number of characters. /// The number of characters to encode. public override int GetMaxByteCount(int charCount) { - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); return charCount; } /// - /// Calculates the maximum number of characters produced by decoding the specified number of bytes. + /// Calculates the maximum number of characters produced by decoding the specified number of bytes. /// /// The maximum number of characters produced by decoding the specified number of bytes. /// The number of bytes to decode. public override int GetMaxCharCount(int byteCount) { - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); return byteCount; } /// - /// Returns a sequence of bytes that specifies the encoding used. + /// Returns a sequence of bytes that specifies the encoding used. /// /// A byte array of length zero, as a preamble is not required. public override byte[] GetPreamble() @@ -447,7 +452,7 @@ namespace Claunia.Encoding } /// - /// Decodes all the bytes in the specified byte array into a string. + /// Decodes all the bytes in the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -457,7 +462,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a string. + /// Decodes a sequence of bytes from the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -469,77 +474,7 @@ namespace Claunia.Encoding } /// - /// The Atari ST to Unicode character map. - /// - static readonly char[] AtariSTTable = { - // 0x00 - '\u0000','\u21E7','\u21E9','\u21E8','\u21E6','\u274E','\uFFFD','\uFFFD', - // 0x08 - '\u2713','\uFFFD','\uFFFD','\u266A','\u000C','\u000D','\uFFFD','\uFFFD', - // 0x10 - '\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD', - // 0x18 - '\uFFFD','\uFFFD','\u0259','\u001B','\uFFFD','\uFFFD','\uFFFD','\uFFFD', - // 0x20 - '\u0020','\u0021','\u0022','\u0023','\u0024','\u0025','\u0026','\u0027', - // 0x28 - '\u0028','\u0029','\u002A','\u002B','\u002C','\u002D','\u002E','\u002F', - // 0x30 - '\u0030','\u0031','\u0032','\u0033','\u0034','\u0035','\u0036','\u0037', - // 0x38 - '\u0038','\u0039','\u003A','\u003B','\u003C','\u003D','\u003E','\u003F', - // 0x40 - '\u0040','\u0041','\u0042','\u0043','\u0044','\u0045','\u0046','\u0047', - // 0x48 - '\u0048','\u0049','\u004A','\u004B','\u004C','\u004D','\u004E','\u004F', - // 0x50 - '\u0050','\u0051','\u0052','\u0053','\u0054','\u0055','\u0056','\u0057', - // 0x58 - '\u0058','\u0059','\u005A','\u005B','\u005C','\u005D','\u005E','\u005F', - // 0x60 - '\u0060','\u0061','\u0062','\u0063','\u0064','\u0065','\u0066','\u0067', - // 0x68 - '\u0068','\u0069','\u006A','\u006B','\u006C','\u006D','\u006E','\u006F', - // 0x70 - '\u0070','\u0071','\u0072','\u0073','\u0074','\u0075','\u0076','\u0077', - // 0x78 - '\u0078','\u0079','\u007A','\u007B','\u007C','\u007D','\u007E','\u2302', - // 0x80 - '\u00C7','\u00FC','\u00E9','\u00E2','\u00E4','\u00E0','\u00E5','\u00E7', - // 0x88 - '\u00EA','\u00EB','\u00E8','\u00EF','\u00EE','\u00EC','\u00C4','\u00C5', - // 0x90 - '\u00C9','\u00E6','\u00C6','\u00F4','\u00F6','\u00F2','\u00FB','\u00F9', - // 0x98 - '\u00FF','\u00D6','\u00DC','\u00A2','\u00A3','\u00A5','\u00DF','\u0192', - // 0xA0 - '\u00E1','\u00ED','\u00F3','\u00FA','\u00F1','\u00D1','\u00AA','\u00BA', - // 0xA8 - '\u00BF','\u2310','\u00AC','\u00BD','\u00BC','\u00A1','\u00AB','\u00BB', - // 0xB0 - '\u00E3','\u00F5','\u00D8','\u00F8','\u0153','\u0152','\u00C0','\u00C3', - // 0xB8 - '\u00D5','\u00A8','\u00B4','\u2020','\u00B6','\u00A9','\u00AE','\u2122', - // 0xC0 - '\u0133','\u0132','\u05D0','\u05D1','\u05D2','\u05D3','\u05D4','\u05D5', - // 0xC8 - '\u05D6','\u05D7','\u05D8','\u05D9','\u05DB','\u05DC','\u05DE','\u05E0', - // 0xD0 - '\u05E1','\u05E2','\u05E4','\u05E6','\u05E7','\u05E8','\u05E9','\u05EA', - // 0xD8 - '\u05DF','\u05DA','\u05DD','\u05E3','\u05E5','\u00A7','\u2227','\u221E', - // 0xE0 - '\u03B1','\u03B2','\u0393','\u03C0','\u03A3','\u03C3','\u00B5','\u03C4', - // 0xE8 - '\u03A6','\u0398','\u03A9','\u03B4','\u222E','\u03D5','\u2208','\u2229', - // 0xF0 - '\u2261','\u00B1','\u2265','\u2264','\u2320','\u2321','\u00F7','\u2248', - // 0xF8 - '\u00B0','\u2219','\u00B7','\u221A','\u207F','\u00B2','\u00B3','\u00AF' - }; - - /// - /// Converts a Atari ST character to an Unicode character + /// Converts a Atari ST character to an Unicode character /// /// Unicode character. /// Atari ST character. @@ -549,485 +484,250 @@ namespace Claunia.Encoding } /// - /// Converts a Unicode character to an Atari ST character + /// Converts a Unicode character to an Atari ST character /// /// Atari ST character. /// Unicode character. static byte GetByte(char character) { - switch(character) { - case '\u0000': - return 0x00; - case '\u21E7': - return 0x01; - case '\u21E9': - return 0x02; - case '\u21E8': - return 0x03; - case '\u21E6': - return 0x04; - case '\u274E': - return 0x05; - case '\u2713': - return 0x08; - case '\u266A': - return 0x0B; - case '\u000C': - return 0x0C; - case '\u000D': - return 0x0D; - case '\u0259': - return 0x1A; - case '\u001B': - return 0x1B; - case '\u0020': - return 0x20; - case '\u0021': - return 0x21; - case '\u0022': - return 0x22; - case '\u0023': - return 0x23; - case '\u0024': - return 0x24; - case '\u0025': - return 0x25; - case '\u0026': - return 0x26; - case '\u0027': - return 0x27; - case '\u0028': - return 0x28; - case '\u0029': - return 0x29; - case '\u002A': - return 0x2A; - case '\u002B': - return 0x2B; - case '\u002C': - return 0x2C; - case '\u002D': - return 0x2D; - case '\u002E': - return 0x2E; - case '\u002F': - return 0x2F; - case '\u0030': - return 0x30; - case '\u0031': - return 0x31; - case '\u0032': - return 0x32; - case '\u0033': - return 0x33; - case '\u0034': - return 0x34; - case '\u0035': - return 0x35; - case '\u0036': - return 0x36; - case '\u0037': - return 0x37; - case '\u0038': - return 0x38; - case '\u0039': - return 0x39; - case '\u003A': - return 0x3A; - case '\u003B': - return 0x3B; - case '\u003C': - return 0x3C; - case '\u003D': - return 0x3D; - case '\u003E': - return 0x3E; - case '\u003F': - return 0x3F; - case '\u0040': - return 0x40; - case '\u0041': - return 0x41; - case '\u0042': - return 0x42; - case '\u0043': - return 0x43; - case '\u0044': - return 0x44; - case '\u0045': - return 0x45; - case '\u0046': - return 0x46; - case '\u0047': - return 0x47; - case '\u0048': - return 0x48; - case '\u0049': - return 0x49; - case '\u004A': - return 0x4A; - case '\u004B': - return 0x4B; - case '\u004C': - return 0x4C; - case '\u004D': - return 0x4D; - case '\u004E': - return 0x4E; - case '\u004F': - return 0x4F; - case '\u0050': - return 0x50; - case '\u0051': - return 0x51; - case '\u0052': - return 0x52; - case '\u0053': - return 0x53; - case '\u0054': - return 0x54; - case '\u0055': - return 0x55; - case '\u0056': - return 0x56; - case '\u0057': - return 0x57; - case '\u0058': - return 0x58; - case '\u0059': - return 0x59; - case '\u005A': - return 0x5A; - case '\u005B': - return 0x5B; - case '\u005C': - return 0x5C; - case '\u005D': - return 0x5D; - case '\u005E': - return 0x5E; - case '\u005F': - return 0x5F; - case '\u0060': - return 0x60; - case '\u0061': - return 0x61; - case '\u0062': - return 0x62; - case '\u0063': - return 0x63; - case '\u0064': - return 0x64; - case '\u0065': - return 0x65; - case '\u0066': - return 0x66; - case '\u0067': - return 0x67; - case '\u0068': - return 0x68; - case '\u0069': - return 0x69; - case '\u006A': - return 0x6A; - case '\u006B': - return 0x6B; - case '\u006C': - return 0x6C; - case '\u006D': - return 0x6D; - case '\u006E': - return 0x6E; - case '\u006F': - return 0x6F; - case '\u0070': - return 0x70; - case '\u0071': - return 0x71; - case '\u0072': - return 0x72; - case '\u0073': - return 0x73; - case '\u0074': - return 0x74; - case '\u0075': - return 0x75; - case '\u0076': - return 0x76; - case '\u0077': - return 0x77; - case '\u0078': - return 0x78; - case '\u0079': - return 0x79; - case '\u007A': - return 0x7A; - case '\u007B': - return 0x7B; - case '\u007C': - return 0x7C; - case '\u007D': - return 0x7D; - case '\u007E': - return 0x7E; - case '\u2302': - return 0x7F; - case '\u00C7': - return 0x80; - case '\u00FC': - return 0x81; - case '\u00E9': - return 0x82; - case '\u00E2': - return 0x83; - case '\u00E4': - return 0x84; - case '\u00E0': - return 0x85; - case '\u00E5': - return 0x86; - case '\u00E7': - return 0x87; - case '\u00EA': - return 0x88; - case '\u00EB': - return 0x89; - case '\u00E8': - return 0x8A; - case '\u00EF': - return 0x8B; - case '\u00EE': - return 0x8C; - case '\u00EC': - return 0x8D; - case '\u00C4': - return 0x8E; - case '\u00C5': - return 0x8F; - case '\u00C9': - return 0x90; - case '\u00E6': - return 0x91; - case '\u00C6': - return 0x92; - case '\u00F4': - return 0x93; - case '\u00F6': - return 0x94; - case '\u00F2': - return 0x95; - case '\u00FB': - return 0x96; - case '\u00F9': - return 0x97; - case '\u00FF': - return 0x98; - case '\u00D6': - return 0x99; - case '\u00DC': - return 0x9A; - case '\u00A2': - return 0x9B; - case '\u00A3': - return 0x9C; - case '\u00A5': - return 0x9D; - case '\u00DF': - return 0x9E; - case '\u0192': - return 0x9F; - case '\u00E1': - return 0xA0; - case '\u00ED': - return 0xA1; - case '\u00F3': - return 0xA2; - case '\u00FA': - return 0xA3; - case '\u00F1': - return 0xA4; - case '\u00D1': - return 0xA5; - case '\u00AA': - return 0xA6; - case '\u00BA': - return 0xA7; - case '\u00BF': - return 0xA8; - case '\u2310': - return 0xA9; - case '\u00AC': - return 0xAA; - case '\u00BD': - return 0xAB; - case '\u00BC': - return 0xAC; - case '\u00A1': - return 0xAD; - case '\u00AB': - return 0xAE; - case '\u00BB': - return 0xAF; - case '\u00E3': - return 0xB0; - case '\u00F5': - return 0xB1; - case '\u00D8': - return 0xB2; - case '\u00F8': - return 0xB3; - case '\u0153': - return 0xB4; - case '\u0152': - return 0xB5; - case '\u00C0': - return 0xB6; - case '\u00C3': - return 0xB7; - case '\u00D5': - return 0xB8; - case '\u00A8': - return 0xB9; - case '\u00B4': - return 0xBA; - case '\u2020': - return 0xBB; - case '\u00B6': - return 0xBC; - case '\u00A9': - return 0xBD; - case '\u00AE': - return 0xBE; - case '\u2122': - return 0xBF; - case '\u0133': - return 0xC0; - case '\u0132': - return 0xC1; - case '\u05D0': - return 0xC2; - case '\u05D1': - return 0xC3; - case '\u05D2': - return 0xC4; - case '\u05D3': - return 0xC5; - case '\u05D4': - return 0xC6; - case '\u05D5': - return 0xC7; - case '\u05D6': - return 0xC8; - case '\u05D7': - return 0xC9; - case '\u05D8': - return 0xCA; - case '\u05D9': - return 0xCB; - case '\u05DB': - return 0xCC; - case '\u05DC': - return 0xCD; - case '\u05DE': - return 0xCE; - case '\u05E0': - return 0xCF; - case '\u05E1': - return 0xD0; - case '\u05E2': - return 0xD1; - case '\u05E4': - return 0xD2; - case '\u05E6': - return 0xD3; - case '\u05E7': - return 0xD4; - case '\u05E8': - return 0xD5; - case '\u05E9': - return 0xD6; - case '\u05EA': - return 0xD7; - case '\u05DF': - return 0xD8; - case '\u05DA': - return 0xD9; - case '\u05DD': - return 0xDA; - case '\u05E3': - return 0xDB; - case '\u05E5': - return 0xDC; - case '\u00A7': - return 0xDD; - case '\u2227': - return 0xDE; - case '\u221E': - return 0xDF; - case '\u03B1': - return 0xE0; - case '\u03B2': - return 0xE1; - case '\u0393': - return 0xE2; - case '\u03C0': - return 0xE3; - case '\u03A3': - return 0xE4; - case '\u03C3': - return 0xE5; - case '\u00B5': - return 0xE6; - case '\u03C4': - return 0xE7; - case '\u03A6': - return 0xE8; - case '\u0398': - return 0xE9; - case '\u03A9': - return 0xEA; - case '\u03B4': - return 0xEB; - case '\u222E': - return 0xEC; - case '\u03D5': - return 0xED; - case '\u2208': - return 0xEE; - case '\u2229': - return 0xEF; - case '\u2261': - return 0xF0; - case '\u00B1': - return 0xF1; - case '\u2265': - return 0xF2; - case '\u2264': - return 0xF3; - case '\u2320': - return 0xF4; - case '\u2321': - return 0xF5; - case '\u00F7': - return 0xF6; - case '\u2248': - return 0xF7; - case '\u00B0': - return 0xF8; - case '\u2219': - return 0xF9; - case '\u00B7': - return 0xFA; - case '\u221A': - return 0xFB; - case '\u207F': - return 0xFC; - case '\u00B2': - return 0xFD; - case '\u00B3': - return 0xFE; - case '\u00AF': - return 0xFF; + switch(character) + { + case '\u0000': return 0x00; + case '\u21E7': return 0x01; + case '\u21E9': return 0x02; + case '\u21E8': return 0x03; + case '\u21E6': return 0x04; + case '\u274E': return 0x05; + case '\u2713': return 0x08; + case '\u266A': return 0x0B; + case '\u000C': return 0x0C; + case '\u000D': return 0x0D; + case '\u0259': return 0x1A; + case '\u001B': return 0x1B; + case '\u0020': return 0x20; + case '\u0021': return 0x21; + case '\u0022': return 0x22; + case '\u0023': return 0x23; + case '\u0024': return 0x24; + case '\u0025': return 0x25; + case '\u0026': return 0x26; + case '\u0027': return 0x27; + case '\u0028': return 0x28; + case '\u0029': return 0x29; + case '\u002A': return 0x2A; + case '\u002B': return 0x2B; + case '\u002C': return 0x2C; + case '\u002D': return 0x2D; + case '\u002E': return 0x2E; + case '\u002F': return 0x2F; + case '\u0030': return 0x30; + case '\u0031': return 0x31; + case '\u0032': return 0x32; + case '\u0033': return 0x33; + case '\u0034': return 0x34; + case '\u0035': return 0x35; + case '\u0036': return 0x36; + case '\u0037': return 0x37; + case '\u0038': return 0x38; + case '\u0039': return 0x39; + case '\u003A': return 0x3A; + case '\u003B': return 0x3B; + case '\u003C': return 0x3C; + case '\u003D': return 0x3D; + case '\u003E': return 0x3E; + case '\u003F': return 0x3F; + case '\u0040': return 0x40; + case '\u0041': return 0x41; + case '\u0042': return 0x42; + case '\u0043': return 0x43; + case '\u0044': return 0x44; + case '\u0045': return 0x45; + case '\u0046': return 0x46; + case '\u0047': return 0x47; + case '\u0048': return 0x48; + case '\u0049': return 0x49; + case '\u004A': return 0x4A; + case '\u004B': return 0x4B; + case '\u004C': return 0x4C; + case '\u004D': return 0x4D; + case '\u004E': return 0x4E; + case '\u004F': return 0x4F; + case '\u0050': return 0x50; + case '\u0051': return 0x51; + case '\u0052': return 0x52; + case '\u0053': return 0x53; + case '\u0054': return 0x54; + case '\u0055': return 0x55; + case '\u0056': return 0x56; + case '\u0057': return 0x57; + case '\u0058': return 0x58; + case '\u0059': return 0x59; + case '\u005A': return 0x5A; + case '\u005B': return 0x5B; + case '\u005C': return 0x5C; + case '\u005D': return 0x5D; + case '\u005E': return 0x5E; + case '\u005F': return 0x5F; + case '\u0060': return 0x60; + case '\u0061': return 0x61; + case '\u0062': return 0x62; + case '\u0063': return 0x63; + case '\u0064': return 0x64; + case '\u0065': return 0x65; + case '\u0066': return 0x66; + case '\u0067': return 0x67; + case '\u0068': return 0x68; + case '\u0069': return 0x69; + case '\u006A': return 0x6A; + case '\u006B': return 0x6B; + case '\u006C': return 0x6C; + case '\u006D': return 0x6D; + case '\u006E': return 0x6E; + case '\u006F': return 0x6F; + case '\u0070': return 0x70; + case '\u0071': return 0x71; + case '\u0072': return 0x72; + case '\u0073': return 0x73; + case '\u0074': return 0x74; + case '\u0075': return 0x75; + case '\u0076': return 0x76; + case '\u0077': return 0x77; + case '\u0078': return 0x78; + case '\u0079': return 0x79; + case '\u007A': return 0x7A; + case '\u007B': return 0x7B; + case '\u007C': return 0x7C; + case '\u007D': return 0x7D; + case '\u007E': return 0x7E; + case '\u2302': return 0x7F; + case '\u00C7': return 0x80; + case '\u00FC': return 0x81; + case '\u00E9': return 0x82; + case '\u00E2': return 0x83; + case '\u00E4': return 0x84; + case '\u00E0': return 0x85; + case '\u00E5': return 0x86; + case '\u00E7': return 0x87; + case '\u00EA': return 0x88; + case '\u00EB': return 0x89; + case '\u00E8': return 0x8A; + case '\u00EF': return 0x8B; + case '\u00EE': return 0x8C; + case '\u00EC': return 0x8D; + case '\u00C4': return 0x8E; + case '\u00C5': return 0x8F; + case '\u00C9': return 0x90; + case '\u00E6': return 0x91; + case '\u00C6': return 0x92; + case '\u00F4': return 0x93; + case '\u00F6': return 0x94; + case '\u00F2': return 0x95; + case '\u00FB': return 0x96; + case '\u00F9': return 0x97; + case '\u00FF': return 0x98; + case '\u00D6': return 0x99; + case '\u00DC': return 0x9A; + case '\u00A2': return 0x9B; + case '\u00A3': return 0x9C; + case '\u00A5': return 0x9D; + case '\u00DF': return 0x9E; + case '\u0192': return 0x9F; + case '\u00E1': return 0xA0; + case '\u00ED': return 0xA1; + case '\u00F3': return 0xA2; + case '\u00FA': return 0xA3; + case '\u00F1': return 0xA4; + case '\u00D1': return 0xA5; + case '\u00AA': return 0xA6; + case '\u00BA': return 0xA7; + case '\u00BF': return 0xA8; + case '\u2310': return 0xA9; + case '\u00AC': return 0xAA; + case '\u00BD': return 0xAB; + case '\u00BC': return 0xAC; + case '\u00A1': return 0xAD; + case '\u00AB': return 0xAE; + case '\u00BB': return 0xAF; + case '\u00E3': return 0xB0; + case '\u00F5': return 0xB1; + case '\u00D8': return 0xB2; + case '\u00F8': return 0xB3; + case '\u0153': return 0xB4; + case '\u0152': return 0xB5; + case '\u00C0': return 0xB6; + case '\u00C3': return 0xB7; + case '\u00D5': return 0xB8; + case '\u00A8': return 0xB9; + case '\u00B4': return 0xBA; + case '\u2020': return 0xBB; + case '\u00B6': return 0xBC; + case '\u00A9': return 0xBD; + case '\u00AE': return 0xBE; + case '\u2122': return 0xBF; + case '\u0133': return 0xC0; + case '\u0132': return 0xC1; + case '\u05D0': return 0xC2; + case '\u05D1': return 0xC3; + case '\u05D2': return 0xC4; + case '\u05D3': return 0xC5; + case '\u05D4': return 0xC6; + case '\u05D5': return 0xC7; + case '\u05D6': return 0xC8; + case '\u05D7': return 0xC9; + case '\u05D8': return 0xCA; + case '\u05D9': return 0xCB; + case '\u05DB': return 0xCC; + case '\u05DC': return 0xCD; + case '\u05DE': return 0xCE; + case '\u05E0': return 0xCF; + case '\u05E1': return 0xD0; + case '\u05E2': return 0xD1; + case '\u05E4': return 0xD2; + case '\u05E6': return 0xD3; + case '\u05E7': return 0xD4; + case '\u05E8': return 0xD5; + case '\u05E9': return 0xD6; + case '\u05EA': return 0xD7; + case '\u05DF': return 0xD8; + case '\u05DA': return 0xD9; + case '\u05DD': return 0xDA; + case '\u05E3': return 0xDB; + case '\u05E5': return 0xDC; + case '\u00A7': return 0xDD; + case '\u2227': return 0xDE; + case '\u221E': return 0xDF; + case '\u03B1': return 0xE0; + case '\u03B2': return 0xE1; + case '\u0393': return 0xE2; + case '\u03C0': return 0xE3; + case '\u03A3': return 0xE4; + case '\u03C3': return 0xE5; + case '\u00B5': return 0xE6; + case '\u03C4': return 0xE7; + case '\u03A6': return 0xE8; + case '\u0398': return 0xE9; + case '\u03A9': return 0xEA; + case '\u03B4': return 0xEB; + case '\u222E': return 0xEC; + case '\u03D5': return 0xED; + case '\u2208': return 0xEE; + case '\u2229': return 0xEF; + case '\u2261': return 0xF0; + case '\u00B1': return 0xF1; + case '\u2265': return 0xF2; + case '\u2264': return 0xF3; + case '\u2320': return 0xF4; + case '\u2321': return 0xF5; + case '\u00F7': return 0xF6; + case '\u2248': return 0xF7; + case '\u00B0': return 0xF8; + case '\u2219': return 0xF9; + case '\u00B7': return 0xFA; + case '\u221A': return 0xFB; + case '\u207F': return 0xFC; + case '\u00B2': return 0xFD; + case '\u00B3': return 0xFE; + case '\u00AF': return 0xFF; default: // Fallback to '?' return 0x3F; diff --git a/Claunia.Encoding/Encoding.cs b/Claunia.Encoding/Encoding.cs index e3673b8..3ac2d32 100644 --- a/Claunia.Encoding/Encoding.cs +++ b/Claunia.Encoding/Encoding.cs @@ -24,130 +24,127 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -using System; +using System; using System.Collections.Generic; +using System.Linq; using System.Reflection; namespace Claunia.Encoding { /// - /// This class contains static instances of the supported encodings. + /// This class contains static instances of the supported encodings. /// public abstract class Encoding : System.Text.Encoding { /// - /// Static instance for the LisaRoman encoding + /// Static instance for the LisaRoman encoding /// public static System.Text.Encoding LisaEncoding = new LisaRoman(); /// - /// Static instance for the ATASCII encoding + /// Static instance for the ATASCII encoding /// public static System.Text.Encoding AtariEncoding = new ATASCII(); /// - /// Static instance for the Atari ST encoding + /// Static instance for the Atari ST encoding /// public static System.Text.Encoding AtariSTEncoding = new AtariST(); /// - /// Static instance for the PETSCII encoding + /// Static instance for the PETSCII encoding /// public static System.Text.Encoding PETEncoding = new PETSCII(); /// - /// Returns an array that contains all encodings. - /// - /// An array that contains all encodings. - public static EncodingInfo[] GetEncodings() - { - List encodings = new List(); - - foreach(Type type in Assembly.GetExecutingAssembly().GetTypes()) { - if(type.IsSubclassOf(typeof(Encoding))) { - Encoding encoding = (Encoding)type.GetConstructor(new Type[] {}).Invoke(new object[] { }); - encodings.Add(new EncodingInfo(encoding.CodePage, encoding.BodyName, encoding.EncodingName, false, type)); - } - } - - return encodings.ToArray(); - } - - /// - /// Returns the encoding associated with the specified code page name. - /// - /// The encoding associated with the specified code page. - /// The code page name of the preferred encoding. Any value returned by the WebName property is valid. Possible values are listed in the Name column of the table that appears in the Encoding class topic. - public static System.Text.Encoding GetEncoding(string name) - { - foreach(Type type in Assembly.GetExecutingAssembly().GetTypes()) { - if(type.IsSubclassOf(typeof(Encoding))) { - Encoding encoding = (Encoding)type.GetConstructor(new Type[] { }).Invoke(new object[] { }); - if(encoding.BodyName == name.ToLowerInvariant()) - return encoding; - } - } - - return System.Text.Encoding.GetEncoding(name); - } - - /// - /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. + /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. /// public abstract bool IsBrowserDisplay { get; } /// - /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. + /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. /// - public abstract bool IsBrowserSave{ get; } + public abstract bool IsBrowserSave { get; } /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. /// - public abstract bool IsMailNewsDisplay{ get; } + public abstract bool IsMailNewsDisplay { get; } /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. /// - public abstract bool IsMailNewsSave{ get; } + public abstract bool IsMailNewsSave { get; } /// - /// Gets a value indicating whether the current encoding is read-only. + /// Gets a value indicating whether the current encoding is read-only. /// /// The is single byte. - public abstract bool IsReadOnly{ get; } + public abstract bool IsReadOnly { get; } /// - /// Gets a value indicating whether the current encoding uses single-byte code points. + /// Gets a value indicating whether the current encoding uses single-byte code points. /// - public abstract bool IsSingleByte{ get; } + public abstract bool IsSingleByte { get; } /// - /// Gets the code page identifier of the current Encoding. + /// Gets the code page identifier of the current Encoding. /// - public abstract int CodePage{ get; } + public abstract int CodePage { get; } /// - /// Gets a name for the current encoding that can be used with mail agent body tags + /// Gets a name for the current encoding that can be used with mail agent body tags /// - public abstract string BodyName{ get; } + public abstract string BodyName { get; } /// - /// Gets a name for the current encoding that can be used with mail agent header tags + /// Gets a name for the current encoding that can be used with mail agent header tags /// - public abstract string HeaderName{ get; } + public abstract string HeaderName { get; } /// - /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. + /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. /// - public abstract override string WebName{ get; } + public abstract override string WebName { get; } /// - /// Gets the human-readable description of the current encoding. + /// Gets the human-readable description of the current encoding. /// - public abstract string EncodingName{ get; } + public abstract string EncodingName { get; } /// - /// Gets the Windows operating system code page that most closely corresponds to the current encoding. + /// Gets the Windows operating system code page that most closely corresponds to the current encoding. /// - public abstract int WindowsCodePage{ get; } + public abstract int WindowsCodePage { get; } + + /// + /// Returns an array that contains all encodings. + /// + /// An array that contains all encodings. + public static IEnumerable GetEncodings() + { + return (from type in Assembly.GetExecutingAssembly().GetTypes() + where type.IsSubclassOf(typeof(Encoding)) + let encoding = (Encoding)type.GetConstructor(new Type[] { }).Invoke(new object[] { }) + select new EncodingInfo(encoding.CodePage, encoding.BodyName, encoding.EncodingName, false, type)) + .ToArray(); + } + + /// + /// Returns the encoding associated with the specified code page name. + /// + /// The encoding associated with the specified code page. + /// + /// The code page name of the preferred encoding. Any value returned by the WebName property is valid. + /// Possible values are listed in the Name column of the table that appears in the Encoding class topic. + /// + public static System.Text.Encoding GetEncoding(string name) + { + foreach(Type type in Assembly.GetExecutingAssembly().GetTypes()) + if(type.IsSubclassOf(typeof(Encoding))) + { + Encoding encoding = (Encoding)type.GetConstructor(new Type[] { }).Invoke(new object[] { }); + if(encoding.BodyName == name.ToLowerInvariant()) return encoding; + } + + return System.Text.Encoding.GetEncoding(name); + } } -} - +} \ No newline at end of file diff --git a/Claunia.Encoding/EncodingInfo.cs b/Claunia.Encoding/EncodingInfo.cs index f7866fe..110a440 100644 --- a/Claunia.Encoding/EncodingInfo.cs +++ b/Claunia.Encoding/EncodingInfo.cs @@ -7,85 +7,73 @@ using System; namespace Claunia.Encoding { /// - /// Provides basic information about an encoding. + /// Provides basic information about an encoding. /// public sealed class EncodingInfo { - private int iCodePage; // Code Page # - private string strEncodingName; // Short name (web name) - private string strDisplayName; // Full localized name - private bool isSystem; - private Type thisType; + bool isSystem; + Type thisType; - internal EncodingInfo(int codePage, string name, string displayName, bool system = true, Type internalType = null) + internal EncodingInfo(int codePage, string name, string displayName, bool system = true, + Type internalType = null) { - iCodePage = codePage; - strEncodingName = name; - strDisplayName = displayName; + CodePage = codePage; + Name = name; + DisplayName = displayName; isSystem = system; thisType = internalType; } /// - /// Gets the code page identifier of the encoding. + /// Gets the code page identifier of the encoding. /// /// The code page identifier of the encoding. - public int CodePage { - get { - return iCodePage; - } - } + public int CodePage { get; } /// - /// Gets the name registered with the Internet Assigned Numbers Authority (IANA) for the encoding. + /// Gets the name registered with the Internet Assigned Numbers Authority (IANA) for the encoding. /// /// The IANA name for the encoding. For more information about the IANA, see www.iana.org. - public string Name { - get { - return strEncodingName; - } - } + public string Name { get; } /// - /// Gets the human-readable description of the encoding. + /// Gets the human-readable description of the encoding. /// /// The human-readable description of the encoding. - public string DisplayName { - get { - return strDisplayName; - } - } + public string DisplayName { get; } /// - /// Returns a Encoding object that corresponds to the current EncodingInfo object. + /// Returns a Encoding object that corresponds to the current EncodingInfo object. /// - /// A object that corresponds to the current object. + /// + /// A object that corresponds to the current + /// object. + /// public Encoding GetEncoding() { return (Encoding)thisType.GetConstructor(new Type[] { }).Invoke(new object[] { }); } /// - /// Gets a value indicating whether the specified object is equal to the current EncodingInfo object. + /// Gets a value indicating whether the specified object is equal to the current EncodingInfo object. /// - /// An object to compare to the current object. - /// true if value is a and is equal to the current ; otherwise, false. - public override bool Equals(Object value) + /// An object to compare to the current object. + /// + /// true if value is a and is equal to the current + /// ; otherwise, false. + /// + public override bool Equals(object value) { - EncodingInfo that = value as EncodingInfo; - if(that != null) { - return (this.CodePage == that.CodePage); - } - return (false); + return value is EncodingInfo that && CodePage == that.CodePage; } /// - /// Returns the hash code for the current EncodingInfo object. + /// Returns the hash code for the current EncodingInfo object. /// /// A 32-bit signed integer hash code. public override int GetHashCode() { - return this.CodePage; + return CodePage; } } } \ No newline at end of file diff --git a/Claunia.Encoding/LisaRoman.cs b/Claunia.Encoding/LisaRoman.cs index da18203..06525aa 100644 --- a/Claunia.Encoding/LisaRoman.cs +++ b/Claunia.Encoding/LisaRoman.cs @@ -29,7 +29,7 @@ using System; namespace Claunia.Encoding { /// - /// Represents an Apple Lisa character encoding of Unicode characters. + /// Represents an Apple Lisa character encoding of Unicode characters. /// public class LisaRoman : Encoding { @@ -48,105 +48,152 @@ namespace Claunia.Encoding const bool singleByte = true; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. + /// The Lisa to Unicode character map. + /// MacRoman is a superset of LisaRoman. /// - public override bool IsBrowserDisplay { - get { return browserDisplay; } - } + static readonly char[] LisaRomanTable = + { + // 0x00 + '\u0000', '\u0001', '\u0002', '\u0003', '\u0004', '\u0005', '\u0006', '\u0007', + // 0x08 + '\u0008', '\u0009', '\u000A', '\u000B', '\u000C', '\u000D', '\u000E', '\u000F', + // 0x10 + '\u0010', '\u0011', '\u0012', '\u0013', '\u0014', '\u0015', '\u0016', '\u0017', + // 0x18 + '\u0018', '\u0019', '\u001A', '\u001B', '\u001C', '\u001D', '\u001E', '\u001F', + // 0x20 + '\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027', + // 0x28 + '\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F', + // 0x30 + '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', + // 0x38 + '\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F', + // 0x40 + '\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047', + // 0x48 + '\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F', + // 0x50 + '\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057', + // 0x58 + '\u0058', '\u0059', '\u005A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F', + // 0x60 + '\u0060', '\u0061', '\u0062', '\u0063', '\u0064', '\u0065', '\u0066', '\u0067', + // 0x68 + '\u0068', '\u0069', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F', + // 0x70 + '\u0070', '\u0071', '\u0072', '\u0073', '\u0074', '\u0075', '\u0076', '\u0077', + // 0x78 + '\u0078', '\u0079', '\u007A', '\u007B', '\u007C', '\u007D', '\u007E', '\u2588', + // 0x80 + '\u00C4', '\u00C5', '\u00C7', '\u00C9', '\u00D1', '\u00D6', '\u00DC', '\u00E1', + // 0x88 + '\u00E0', '\u00E2', '\u00E4', '\u00E3', '\u00E5', '\u00E7', '\u00E9', '\u00E8', + // 0x90 + '\u00EA', '\u00EB', '\u00ED', '\u00EC', '\u00EE', '\u00EF', '\u00F1', '\u00F3', + // 0x98 + '\u00F2', '\u00F4', '\u00F6', '\u00F5', '\u00FA', '\u00F9', '\u00FB', '\u00FC', + // 0xA0 + '\u2020', '\u00B0', '\u00A2', '\u00A3', '\u00A7', '\u2022', '\u00B6', '\u00DF', + // 0xA8 + '\u00AE', '\u00A9', '\u2122', '\u00B4', '\u00A8', '\u2260', '\u00C6', '\u00D8', + // 0xB0 + '\u221E', '\u00B1', '\u2264', '\u2265', '\u00A5', '\u00B5', '\u2202', '\u2211', + // 0xB8 + '\u220F', '\u03C0', '\u222B', '\u00AA', '\u00BA', '\u03A9', '\u00E6', '\u00F8', + // 0xC0 + '\u00BF', '\u00A1', '\u00AC', '\u221A', '\u0192', '\u2248', '\u2206', '\u00AB', + // 0xC8 + '\u00BB', '\u2026', '\u00A0', '\u00C0', '\u00C3', '\u00D5', '\u0152', '\u0153', + // 0xD0 + '\u2013', '\u2014', '\u201C', '\u201D', '\u2018', '\u2019', '\u00F7', '\u25CA', + // 0xD8 + '\u00FF', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xE0 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xE8 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xF0 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xF8 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000' + }; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. + /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. /// - public override bool IsBrowserSave { - get { return browserSave; } - } + public override bool IsBrowserDisplay => browserDisplay; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. + /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. /// - public override bool IsMailNewsDisplay { - get { return mailNewsDisplay; } - } + public override bool IsBrowserSave => browserSave; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. /// - public override bool IsMailNewsSave { - get { return mailNewsSave; } - } + public override bool IsMailNewsDisplay => mailNewsDisplay; /// - /// Gets a value indicating whether the current encoding is read-only. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// + public override bool IsMailNewsSave => mailNewsSave; + + /// + /// Gets a value indicating whether the current encoding is read-only. /// /// The is single byte. - public override bool IsReadOnly { - get { return readOnly; } - } + public override bool IsReadOnly => readOnly; /// - /// Gets a value indicating whether the current encoding uses single-byte code points. + /// Gets a value indicating whether the current encoding uses single-byte code points. /// - public override bool IsSingleByte { - get { return singleByte; } - } + public override bool IsSingleByte => singleByte; /// - /// Gets the code page identifier of the current Encoding. + /// Gets the code page identifier of the current Encoding. /// - public override int CodePage { - get { return _codepage; } - } + public override int CodePage => _codepage; /// - /// Gets a name for the current encoding that can be used with mail agent body tags + /// Gets a name for the current encoding that can be used with mail agent body tags /// - public override string BodyName { - get { return _bodyname; } - } + public override string BodyName => _bodyname; /// - /// Gets a name for the current encoding that can be used with mail agent header tags + /// Gets a name for the current encoding that can be used with mail agent header tags /// - public override string HeaderName { - get { return _headername; } - } + public override string HeaderName => _headername; /// - /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. + /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. /// - public override string WebName { - get { return _webname; } - } + public override string WebName => _webname; /// - /// Gets the human-readable description of the current encoding. + /// Gets the human-readable description of the current encoding. /// - public override string EncodingName { - get { return _encodingname; } - } + public override string EncodingName => _encodingname; /// - /// Gets the Windows operating system code page that most closely corresponds to the current encoding. + /// Gets the Windows operating system code page that most closely corresponds to the current encoding. /// - public override int WindowsCodePage { - get { return _windowsCodepage; } - } + public override int WindowsCodePage => _windowsCodepage; /// - /// Calculates the number of bytes produced by encoding the characters in the specified . + /// Calculates the number of bytes produced by encoding the characters in the specified . /// /// The number of bytes produced by encoding the specified characters. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. public override int GetByteCount(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return s.Length; } /// - /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. + /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. /// /// The number of bytes produced by encoding the specified characters. /// The character array containing the set of characters to encode. @@ -154,36 +201,32 @@ namespace Claunia.Encoding /// The number of characters to encode. public override int GetByteCount(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0 || index >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0 || index >= chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0 || index + count > chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(count < 0 || index + count > chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); return count; } /// - /// Calculates the number of bytes produced by encoding all the characters in the specified character array. + /// Calculates the number of bytes produced by encoding all the characters in the specified character array. /// /// The number of bytes produced by encoding all the characters in the specified character array. /// The character array containing the characters to encode. public override int GetByteCount(char[] chars) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); return chars.Length; } /// - /// Encodes a set of characters from the specified into the specified byte array. + /// Encodes a set of characters from the specified into the specified byte array. /// /// The actual number of bytes written into bytes. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. /// The index of the first character to encode. /// The number of characters to encode. /// The byte array to contain the resulting sequence of bytes. @@ -194,20 +237,19 @@ namespace Claunia.Encoding } /// - /// Encodes all the characters in the specified string into a sequence of bytes. + /// Encodes all the characters in the specified string into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The string containing the characters to encode. public override byte[] GetBytes(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return GetBytes(s.ToCharArray(), 0, s.Length); } /// - /// Encodes a set of characters from the specified character array into the specified byte array. + /// Encodes a set of characters from the specified character array into the specified byte array. /// /// The actual number of bytes written into bytes. /// The character array containing the set of characters to encode. @@ -217,43 +259,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting sequence of bytes. public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount + charIndex > chars.Length) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount + charIndex > chars.Length) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteIndex + charCount > bytes.Length) - throw new ArgumentException(nameof(bytes)); + if(byteIndex + charCount > bytes.Length) throw new ArgumentException(nameof(bytes)); byte[] temp = GetBytes(chars, charIndex, charCount); - for(int i = 0; i < temp.Length; i++) - bytes[i + byteIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) bytes[i + byteIndex] = temp[i]; return charCount; } /// - /// Encodes a set of characters from the specified character array into a sequence of bytes. + /// Encodes a set of characters from the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the set of characters to encode. @@ -261,28 +293,23 @@ namespace Claunia.Encoding /// The number of characters to encode. public override byte[] GetBytes(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > chars.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > chars.Length) throw new ArgumentOutOfRangeException(nameof(count)); byte[] bytes = new byte[count]; - for(int i = 0; i < count; i++) - bytes[i] = GetByte(chars[index + i]); + for(int i = 0; i < count; i++) bytes[i] = GetByte(chars[index + i]); return bytes; } /// - /// Encodes all the characters in the specified character array into a sequence of bytes. + /// Encodes all the characters in the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the characters to encode. @@ -292,7 +319,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. + /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -302,7 +329,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. + /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -310,23 +337,19 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override int GetCharCount(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); return count; } /// - /// Decodes a sequence of bytes from the specified byte array into the specified character array. + /// Decodes a sequence of bytes from the specified byte array into the specified character array. /// /// The actual number of characters written into chars. /// The byte array containing the sequence of bytes to decode. @@ -336,43 +359,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting set of characters. public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount + byteIndex > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount + byteIndex > bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charIndex + byteCount > chars.Length) - throw new ArgumentException(nameof(chars)); + if(charIndex + byteCount > chars.Length) throw new ArgumentException(nameof(chars)); char[] temp = GetChars(bytes, byteIndex, byteCount); - for(int i = 0; i < temp.Length; i++) - chars[i + charIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) chars[i + charIndex] = temp[i]; return byteCount; } /// - /// Decodes all the bytes in the specified byte array into a set of characters. + /// Decodes all the bytes in the specified byte array into a set of characters. /// /// A character array containing the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -382,7 +395,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a set of characters. + /// Decodes a sequence of bytes from the specified byte array into a set of characters. /// /// The chars. /// The byte array containing the sequence of bytes to decode. @@ -390,54 +403,47 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override char[] GetChars(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); char[] chars = new char[count]; - for(int i = 0; i < count; i++) - chars[i] = GetChar(bytes[index + i]); + for(int i = 0; i < count; i++) chars[i] = GetChar(bytes[index + i]); return chars; } /// - /// Calculates the maximum number of bytes produced by encoding the specified number of characters. + /// Calculates the maximum number of bytes produced by encoding the specified number of characters. /// /// The maximum number of bytes produced by encoding the specified number of characters. /// The number of characters to encode. public override int GetMaxByteCount(int charCount) { - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); return charCount; } /// - /// Calculates the maximum number of characters produced by decoding the specified number of bytes. + /// Calculates the maximum number of characters produced by decoding the specified number of bytes. /// /// The maximum number of characters produced by decoding the specified number of bytes. /// The number of bytes to decode. public override int GetMaxCharCount(int byteCount) { - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); return byteCount; } /// - /// Returns a sequence of bytes that specifies the encoding used. + /// Returns a sequence of bytes that specifies the encoding used. /// /// A byte array of length zero, as a preamble is not required. public override byte[] GetPreamble() @@ -446,7 +452,7 @@ namespace Claunia.Encoding } /// - /// Decodes all the bytes in the specified byte array into a string. + /// Decodes all the bytes in the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -456,7 +462,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a string. + /// Decodes a sequence of bytes from the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -468,78 +474,7 @@ namespace Claunia.Encoding } /// - /// The Lisa to Unicode character map. - /// MacRoman is a superset of LisaRoman. - /// - static readonly char[] LisaRomanTable = { - // 0x00 - '\u0000','\u0001','\u0002','\u0003','\u0004','\u0005','\u0006','\u0007', - // 0x08 - '\u0008','\u0009','\u000A','\u000B','\u000C','\u000D','\u000E','\u000F', - // 0x10 - '\u0010','\u0011','\u0012','\u0013','\u0014','\u0015','\u0016','\u0017', - // 0x18 - '\u0018','\u0019','\u001A','\u001B','\u001C','\u001D','\u001E','\u001F', - // 0x20 - '\u0020','\u0021','\u0022','\u0023','\u0024','\u0025','\u0026','\u0027', - // 0x28 - '\u0028','\u0029','\u002A','\u002B','\u002C','\u002D','\u002E','\u002F', - // 0x30 - '\u0030','\u0031','\u0032','\u0033','\u0034','\u0035','\u0036','\u0037', - // 0x38 - '\u0038','\u0039','\u003A','\u003B','\u003C','\u003D','\u003E','\u003F', - // 0x40 - '\u0040','\u0041','\u0042','\u0043','\u0044','\u0045','\u0046','\u0047', - // 0x48 - '\u0048','\u0049','\u004A','\u004B','\u004C','\u004D','\u004E','\u004F', - // 0x50 - '\u0050','\u0051','\u0052','\u0053','\u0054','\u0055','\u0056','\u0057', - // 0x58 - '\u0058','\u0059','\u005A','\u005B','\u005C','\u005D','\u005E','\u005F', - // 0x60 - '\u0060','\u0061','\u0062','\u0063','\u0064','\u0065','\u0066','\u0067', - // 0x68 - '\u0068','\u0069','\u006A','\u006B','\u006C','\u006D','\u006E','\u006F', - // 0x70 - '\u0070','\u0071','\u0072','\u0073','\u0074','\u0075','\u0076','\u0077', - // 0x78 - '\u0078','\u0079','\u007A','\u007B','\u007C','\u007D','\u007E','\u2588', - // 0x80 - '\u00C4','\u00C5','\u00C7','\u00C9','\u00D1','\u00D6','\u00DC','\u00E1', - // 0x88 - '\u00E0','\u00E2','\u00E4','\u00E3','\u00E5','\u00E7','\u00E9','\u00E8', - // 0x90 - '\u00EA','\u00EB','\u00ED','\u00EC','\u00EE','\u00EF','\u00F1','\u00F3', - // 0x98 - '\u00F2','\u00F4','\u00F6','\u00F5','\u00FA','\u00F9','\u00FB','\u00FC', - // 0xA0 - '\u2020','\u00B0','\u00A2','\u00A3','\u00A7','\u2022','\u00B6','\u00DF', - // 0xA8 - '\u00AE','\u00A9','\u2122','\u00B4','\u00A8','\u2260','\u00C6','\u00D8', - // 0xB0 - '\u221E','\u00B1','\u2264','\u2265','\u00A5','\u00B5','\u2202','\u2211', - // 0xB8 - '\u220F','\u03C0','\u222B','\u00AA','\u00BA','\u03A9','\u00E6','\u00F8', - // 0xC0 - '\u00BF','\u00A1','\u00AC','\u221A','\u0192','\u2248','\u2206','\u00AB', - // 0xC8 - '\u00BB','\u2026','\u00A0','\u00C0','\u00C3','\u00D5','\u0152','\u0153', - // 0xD0 - '\u2013','\u2014','\u201C','\u201D','\u2018','\u2019','\u00F7','\u25CA', - // 0xD8 - '\u00FF','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xE0 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xE8 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xF0 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xF8 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000' - }; - - /// - /// Converts a LisaRoman character to an Unicode character + /// Converts a LisaRoman character to an Unicode character /// /// Unicode character. /// LisaRoman character. @@ -549,451 +484,235 @@ namespace Claunia.Encoding } /// - /// Converts a Unicode character to an LisaRoman character + /// Converts a Unicode character to an LisaRoman character /// /// LisaRoman character. /// Unicode character. static byte GetByte(char character) { - switch(character) { - case '\u0000': - return 0x00; - case '\u0001': - return 0x01; - case '\u0002': - return 0x02; - case '\u0003': - return 0x03; - case '\u0004': - return 0x04; - case '\u0005': - return 0x05; - case '\u0006': - return 0x06; - case '\u0007': - return 0x07; - case '\u0008': - return 0x08; - case '\u0009': - return 0x09; - case '\u000A': - return 0x0A; - case '\u000B': - return 0x0B; - case '\u000C': - return 0x0C; - case '\u000D': - return 0x0D; - case '\u000E': - return 0x0E; - case '\u000F': - return 0x0F; - case '\u0010': - return 0x10; - case '\u0011': - return 0x11; - case '\u0012': - return 0x12; - case '\u0013': - return 0x13; - case '\u0014': - return 0x14; - case '\u0015': - return 0x15; - case '\u0016': - return 0x16; - case '\u0017': - return 0x17; - case '\u0018': - return 0x18; - case '\u0019': - return 0x19; - case '\u001A': - return 0x1A; - case '\u001B': - return 0x1B; - case '\u001C': - return 0x1C; - case '\u001D': - return 0x1D; - case '\u001E': - return 0x1E; - case '\u001F': - return 0x1F; - case '\u0020': - return 0x20; - case '\u0021': - return 0x21; - case '\u0022': - return 0x22; - case '\u0023': - return 0x23; - case '\u0024': - return 0x24; - case '\u0025': - return 0x25; - case '\u0026': - return 0x26; - case '\u0027': - return 0x27; - case '\u0028': - return 0x28; - case '\u0029': - return 0x29; - case '\u002A': - return 0x2A; - case '\u002B': - return 0x2B; - case '\u002C': - return 0x2C; - case '\u002D': - return 0x2D; - case '\u002E': - return 0x2E; - case '\u002F': - return 0x2F; - case '\u0030': - return 0x30; - case '\u0031': - return 0x31; - case '\u0032': - return 0x32; - case '\u0033': - return 0x33; - case '\u0034': - return 0x34; - case '\u0035': - return 0x35; - case '\u0036': - return 0x36; - case '\u0037': - return 0x37; - case '\u0038': - return 0x38; - case '\u0039': - return 0x39; - case '\u003A': - return 0x3A; - case '\u003B': - return 0x3B; - case '\u003C': - return 0x3C; - case '\u003D': - return 0x3D; - case '\u003E': - return 0x3E; - case '\u003F': - return 0x3F; - case '\u0040': - return 0x40; - case '\u0041': - return 0x41; - case '\u0042': - return 0x42; - case '\u0043': - return 0x43; - case '\u0044': - return 0x44; - case '\u0045': - return 0x45; - case '\u0046': - return 0x46; - case '\u0047': - return 0x47; - case '\u0048': - return 0x48; - case '\u0049': - return 0x49; - case '\u004A': - return 0x4A; - case '\u004B': - return 0x4B; - case '\u004C': - return 0x4C; - case '\u004D': - return 0x4D; - case '\u004E': - return 0x4E; - case '\u004F': - return 0x4F; - case '\u0050': - return 0x50; - case '\u0051': - return 0x51; - case '\u0052': - return 0x52; - case '\u0053': - return 0x53; - case '\u0054': - return 0x54; - case '\u0055': - return 0x55; - case '\u0056': - return 0x56; - case '\u0057': - return 0x57; - case '\u0058': - return 0x58; - case '\u0059': - return 0x59; - case '\u005A': - return 0x5A; - case '\u005B': - return 0x5B; - case '\u005C': - return 0x5C; - case '\u005D': - return 0x5D; - case '\u005E': - return 0x5E; - case '\u005F': - return 0x5F; - case '\u0060': - return 0x60; - case '\u0061': - return 0x61; - case '\u0062': - return 0x62; - case '\u0063': - return 0x63; - case '\u0064': - return 0x64; - case '\u0065': - return 0x65; - case '\u0066': - return 0x66; - case '\u0067': - return 0x67; - case '\u0068': - return 0x68; - case '\u0069': - return 0x69; - case '\u006A': - return 0x6A; - case '\u006B': - return 0x6B; - case '\u006C': - return 0x6C; - case '\u006D': - return 0x6D; - case '\u006E': - return 0x6E; - case '\u006F': - return 0x6F; - case '\u0070': - return 0x70; - case '\u0071': - return 0x71; - case '\u0072': - return 0x72; - case '\u0073': - return 0x73; - case '\u0074': - return 0x74; - case '\u0075': - return 0x75; - case '\u0076': - return 0x76; - case '\u0077': - return 0x77; - case '\u0078': - return 0x78; - case '\u0079': - return 0x79; - case '\u007A': - return 0x7A; - case '\u007B': - return 0x7B; - case '\u007C': - return 0x7C; - case '\u007D': - return 0x7D; - case '\u007E': - return 0x7E; - case '\u2588': - return 0x7F; - case '\u00C4': - return 0x80; - case '\u00C5': - return 0x81; - case '\u00C7': - return 0x82; - case '\u00C9': - return 0x83; - case '\u00D1': - return 0x84; - case '\u00D6': - return 0x85; - case '\u00DC': - return 0x86; - case '\u00E1': - return 0x87; - case '\u00E0': - return 0x88; - case '\u00E2': - return 0x89; - case '\u00E4': - return 0x8A; - case '\u00E3': - return 0x8B; - case '\u00E5': - return 0x8C; - case '\u00E7': - return 0x8D; - case '\u00E9': - return 0x8E; - case '\u00E8': - return 0x8F; - case '\u00EA': - return 0x90; - case '\u00EB': - return 0x91; - case '\u00ED': - return 0x92; - case '\u00EC': - return 0x93; - case '\u00EE': - return 0x94; - case '\u00EF': - return 0x95; - case '\u00F1': - return 0x96; - case '\u00F3': - return 0x97; - case '\u00F2': - return 0x98; - case '\u00F4': - return 0x99; - case '\u00F6': - return 0x9A; - case '\u00F5': - return 0x9B; - case '\u00FA': - return 0x9C; - case '\u00F9': - return 0x9D; - case '\u00FB': - return 0x9E; - case '\u00FC': - return 0x9F; - case '\u2020': - return 0xA0; - case '\u00B0': - return 0xA1; - case '\u00A2': - return 0xA2; - case '\u00A3': - return 0xA3; - case '\u00A7': - return 0xA4; - case '\u2022': - return 0xA5; - case '\u00B6': - return 0xA6; - case '\u00DF': - return 0xA7; - case '\u00AE': - return 0xA8; - case '\u00A9': - return 0xA9; - case '\u2122': - return 0xAA; - case '\u00B4': - return 0xAB; - case '\u00A8': - return 0xAC; - case '\u2260': - return 0xAD; - case '\u00C6': - return 0xAE; - case '\u00D8': - return 0xAF; - case '\u221E': - return 0xB0; - case '\u00B1': - return 0xB1; - case '\u2264': - return 0xB2; - case '\u2265': - return 0xB3; - case '\u00A5': - return 0xB4; - case '\u00B5': - return 0xB5; - case '\u2202': - return 0xB6; - case '\u2211': - return 0xB7; - case '\u220F': - return 0xB8; - case '\u03C0': - return 0xB9; - case '\u222B': - return 0xBA; - case '\u00AA': - return 0xBB; - case '\u00BA': - return 0xBC; - case '\u03A9': - return 0xBD; - case '\u00E6': - return 0xBE; - case '\u00F8': - return 0xBF; - case '\u00BF': - return 0xC0; - case '\u00A1': - return 0xC1; - case '\u00AC': - return 0xC2; - case '\u221A': - return 0xC3; - case '\u0192': - return 0xC4; - case '\u2248': - return 0xC5; - case '\u2206': - return 0xC6; - case '\u00AB': - return 0xC7; - case '\u00BB': - return 0xC8; - case '\u2026': - return 0xC9; - case '\u00A0': - return 0xCA; - case '\u00C0': - return 0xCB; - case '\u00C3': - return 0xCC; - case '\u00D5': - return 0xCD; - case '\u0152': - return 0xCE; - case '\u0153': - return 0xCF; - case '\u2013': - return 0xD0; - case '\u2014': - return 0xD1; - case '\u201C': - return 0xD2; - case '\u201D': - return 0xD3; - case '\u2018': - return 0xD4; - case '\u2019': - return 0xD5; - case '\u00F7': - return 0xD6; - case '\u25CA': - return 0xD7; - case '\u00FF': - return 0xD8; + switch(character) + { + case '\u0000': return 0x00; + case '\u0001': return 0x01; + case '\u0002': return 0x02; + case '\u0003': return 0x03; + case '\u0004': return 0x04; + case '\u0005': return 0x05; + case '\u0006': return 0x06; + case '\u0007': return 0x07; + case '\u0008': return 0x08; + case '\u0009': return 0x09; + case '\u000A': return 0x0A; + case '\u000B': return 0x0B; + case '\u000C': return 0x0C; + case '\u000D': return 0x0D; + case '\u000E': return 0x0E; + case '\u000F': return 0x0F; + case '\u0010': return 0x10; + case '\u0011': return 0x11; + case '\u0012': return 0x12; + case '\u0013': return 0x13; + case '\u0014': return 0x14; + case '\u0015': return 0x15; + case '\u0016': return 0x16; + case '\u0017': return 0x17; + case '\u0018': return 0x18; + case '\u0019': return 0x19; + case '\u001A': return 0x1A; + case '\u001B': return 0x1B; + case '\u001C': return 0x1C; + case '\u001D': return 0x1D; + case '\u001E': return 0x1E; + case '\u001F': return 0x1F; + case '\u0020': return 0x20; + case '\u0021': return 0x21; + case '\u0022': return 0x22; + case '\u0023': return 0x23; + case '\u0024': return 0x24; + case '\u0025': return 0x25; + case '\u0026': return 0x26; + case '\u0027': return 0x27; + case '\u0028': return 0x28; + case '\u0029': return 0x29; + case '\u002A': return 0x2A; + case '\u002B': return 0x2B; + case '\u002C': return 0x2C; + case '\u002D': return 0x2D; + case '\u002E': return 0x2E; + case '\u002F': return 0x2F; + case '\u0030': return 0x30; + case '\u0031': return 0x31; + case '\u0032': return 0x32; + case '\u0033': return 0x33; + case '\u0034': return 0x34; + case '\u0035': return 0x35; + case '\u0036': return 0x36; + case '\u0037': return 0x37; + case '\u0038': return 0x38; + case '\u0039': return 0x39; + case '\u003A': return 0x3A; + case '\u003B': return 0x3B; + case '\u003C': return 0x3C; + case '\u003D': return 0x3D; + case '\u003E': return 0x3E; + case '\u003F': return 0x3F; + case '\u0040': return 0x40; + case '\u0041': return 0x41; + case '\u0042': return 0x42; + case '\u0043': return 0x43; + case '\u0044': return 0x44; + case '\u0045': return 0x45; + case '\u0046': return 0x46; + case '\u0047': return 0x47; + case '\u0048': return 0x48; + case '\u0049': return 0x49; + case '\u004A': return 0x4A; + case '\u004B': return 0x4B; + case '\u004C': return 0x4C; + case '\u004D': return 0x4D; + case '\u004E': return 0x4E; + case '\u004F': return 0x4F; + case '\u0050': return 0x50; + case '\u0051': return 0x51; + case '\u0052': return 0x52; + case '\u0053': return 0x53; + case '\u0054': return 0x54; + case '\u0055': return 0x55; + case '\u0056': return 0x56; + case '\u0057': return 0x57; + case '\u0058': return 0x58; + case '\u0059': return 0x59; + case '\u005A': return 0x5A; + case '\u005B': return 0x5B; + case '\u005C': return 0x5C; + case '\u005D': return 0x5D; + case '\u005E': return 0x5E; + case '\u005F': return 0x5F; + case '\u0060': return 0x60; + case '\u0061': return 0x61; + case '\u0062': return 0x62; + case '\u0063': return 0x63; + case '\u0064': return 0x64; + case '\u0065': return 0x65; + case '\u0066': return 0x66; + case '\u0067': return 0x67; + case '\u0068': return 0x68; + case '\u0069': return 0x69; + case '\u006A': return 0x6A; + case '\u006B': return 0x6B; + case '\u006C': return 0x6C; + case '\u006D': return 0x6D; + case '\u006E': return 0x6E; + case '\u006F': return 0x6F; + case '\u0070': return 0x70; + case '\u0071': return 0x71; + case '\u0072': return 0x72; + case '\u0073': return 0x73; + case '\u0074': return 0x74; + case '\u0075': return 0x75; + case '\u0076': return 0x76; + case '\u0077': return 0x77; + case '\u0078': return 0x78; + case '\u0079': return 0x79; + case '\u007A': return 0x7A; + case '\u007B': return 0x7B; + case '\u007C': return 0x7C; + case '\u007D': return 0x7D; + case '\u007E': return 0x7E; + case '\u2588': return 0x7F; + case '\u00C4': return 0x80; + case '\u00C5': return 0x81; + case '\u00C7': return 0x82; + case '\u00C9': return 0x83; + case '\u00D1': return 0x84; + case '\u00D6': return 0x85; + case '\u00DC': return 0x86; + case '\u00E1': return 0x87; + case '\u00E0': return 0x88; + case '\u00E2': return 0x89; + case '\u00E4': return 0x8A; + case '\u00E3': return 0x8B; + case '\u00E5': return 0x8C; + case '\u00E7': return 0x8D; + case '\u00E9': return 0x8E; + case '\u00E8': return 0x8F; + case '\u00EA': return 0x90; + case '\u00EB': return 0x91; + case '\u00ED': return 0x92; + case '\u00EC': return 0x93; + case '\u00EE': return 0x94; + case '\u00EF': return 0x95; + case '\u00F1': return 0x96; + case '\u00F3': return 0x97; + case '\u00F2': return 0x98; + case '\u00F4': return 0x99; + case '\u00F6': return 0x9A; + case '\u00F5': return 0x9B; + case '\u00FA': return 0x9C; + case '\u00F9': return 0x9D; + case '\u00FB': return 0x9E; + case '\u00FC': return 0x9F; + case '\u2020': return 0xA0; + case '\u00B0': return 0xA1; + case '\u00A2': return 0xA2; + case '\u00A3': return 0xA3; + case '\u00A7': return 0xA4; + case '\u2022': return 0xA5; + case '\u00B6': return 0xA6; + case '\u00DF': return 0xA7; + case '\u00AE': return 0xA8; + case '\u00A9': return 0xA9; + case '\u2122': return 0xAA; + case '\u00B4': return 0xAB; + case '\u00A8': return 0xAC; + case '\u2260': return 0xAD; + case '\u00C6': return 0xAE; + case '\u00D8': return 0xAF; + case '\u221E': return 0xB0; + case '\u00B1': return 0xB1; + case '\u2264': return 0xB2; + case '\u2265': return 0xB3; + case '\u00A5': return 0xB4; + case '\u00B5': return 0xB5; + case '\u2202': return 0xB6; + case '\u2211': return 0xB7; + case '\u220F': return 0xB8; + case '\u03C0': return 0xB9; + case '\u222B': return 0xBA; + case '\u00AA': return 0xBB; + case '\u00BA': return 0xBC; + case '\u03A9': return 0xBD; + case '\u00E6': return 0xBE; + case '\u00F8': return 0xBF; + case '\u00BF': return 0xC0; + case '\u00A1': return 0xC1; + case '\u00AC': return 0xC2; + case '\u221A': return 0xC3; + case '\u0192': return 0xC4; + case '\u2248': return 0xC5; + case '\u2206': return 0xC6; + case '\u00AB': return 0xC7; + case '\u00BB': return 0xC8; + case '\u2026': return 0xC9; + case '\u00A0': return 0xCA; + case '\u00C0': return 0xCB; + case '\u00C3': return 0xCC; + case '\u00D5': return 0xCD; + case '\u0152': return 0xCE; + case '\u0153': return 0xCF; + case '\u2013': return 0xD0; + case '\u2014': return 0xD1; + case '\u201C': return 0xD2; + case '\u201D': return 0xD3; + case '\u2018': return 0xD4; + case '\u2019': return 0xD5; + case '\u00F7': return 0xD6; + case '\u25CA': return 0xD7; + case '\u00FF': return 0xD8; default: // Fallback to '?' return 0x3F; } } } -} +} \ No newline at end of file diff --git a/Claunia.Encoding/MacArabic.cs b/Claunia.Encoding/MacArabic.cs index ce1ca3a..8a477a3 100644 --- a/Claunia.Encoding/MacArabic.cs +++ b/Claunia.Encoding/MacArabic.cs @@ -29,7 +29,7 @@ using System; namespace Claunia.Encoding { /// - /// Represents an Mac Arabic character encoding of Unicode characters. + /// Represents an Mac Arabic character encoding of Unicode characters. /// public class MacArabic : Encoding { @@ -48,105 +48,151 @@ namespace Claunia.Encoding const bool singleByte = true; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. + /// The Macintosh Arabic to Unicode character map. /// - public override bool IsBrowserDisplay { - get { return browserDisplay; } - } + static readonly char[] MacArabicTable = + { + // 0x00 + '\u0000', '\u0001', '\u0002', '\u0003', '\u0004', '\u0005', '\u0006', '\u0007', + // 0x08 + '\u0008', '\u0009', '\u000A', '\u000B', '\u000C', '\u000D', '\u000E', '\u000F', + // 0x10 + '\u0010', '\u0011', '\u0012', '\u0013', '\u0014', '\u0015', '\u0016', '\u0017', + // 0x18 + '\u0018', '\u0019', '\u001A', '\u001B', '\u001C', '\u001D', '\u001E', '\u001F', + // 0x20 + '\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027', + // 0x28 + '\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F', + // 0x30 + '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', + // 0x38 + '\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F', + // 0x40 + '\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047', + // 0x48 + '\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F', + // 0x50 + '\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057', + // 0x58 + '\u0058', '\u0059', '\u005A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F', + // 0x60 + '\u0060', '\u0061', '\u0062', '\u0063', '\u0064', '\u0065', '\u0066', '\u0067', + // 0x68 + '\u0068', '\u0069', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F', + // 0x70 + '\u0070', '\u0071', '\u0072', '\u0073', '\u0074', '\u0075', '\u0076', '\u0077', + // 0x78 + '\u0078', '\u0079', '\u007A', '\u007B', '\u007C', '\u007D', '\u007E', '\u007F', + // 0x80 + '\u00C4', '\u00A0', '\u00C7', '\u00C9', '\u00D1', '\u00D6', '\u00DC', '\u00E1', + // 0x88 + '\u00E0', '\u00E2', '\u00E4', '\u06BA', '\u00AB', '\u00E7', '\u00E9', '\u00E8', + // 0x90 + '\u00EA', '\u00EB', '\u00ED', '\u2026', '\u00EE', '\u00EF', '\u00F1', '\u00F3', + // 0x98 + '\u00BB', '\u00F4', '\u00F6', '\u00F7', '\u00FA', '\u00F9', '\u00FB', '\u00FC', + // 0xA0 + '\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u066A', '\u0026', '\u0027', + // 0xA8 + '\u0028', '\u0029', '\u002A', '\u002B', '\u060C', '\u002D', '\u002E', '\u002F', + // 0xB0 + '\u0660', '\u0661', '\u0662', '\u0663', '\u0664', '\u0665', '\u0666', '\u0667', + // 0xB8 + '\u0668', '\u0669', '\u003A', '\u061B', '\u003C', '\u003D', '\u003E', '\u061F', + // 0xC0 + '\u274A', '\u0621', '\u0622', '\u0623', '\u0624', '\u0625', '\u0626', '\u0627', + // 0xC8 + '\u0628', '\u0629', '\u062A', '\u062B', '\u062C', '\u062D', '\u062E', '\u062F', + // 0xD0 + '\u0630', '\u0631', '\u0632', '\u0633', '\u0634', '\u0635', '\u0636', '\u0637', + // 0xD8 + '\u0638', '\u0639', '\u063A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F', + // 0xE0 + '\u0640', '\u0641', '\u0642', '\u0643', '\u0644', '\u0645', '\u0646', '\u0647', + // 0xE8 + '\u0648', '\u0649', '\u064A', '\u064B', '\u064C', '\u064D', '\u064E', '\u064F', + // 0xF0 + '\u0650', '\u0651', '\u0652', '\u067E', '\u0679', '\u0686', '\u06D5', '\u06A4', + // 0xF8 + '\u06AF', '\u0688', '\u0691', '\u007B', '\u007C', '\u007D', '\u0698', '\u06D2' + }; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. + /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. /// - public override bool IsBrowserSave { - get { return browserSave; } - } + public override bool IsBrowserDisplay => browserDisplay; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. + /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. /// - public override bool IsMailNewsDisplay { - get { return mailNewsDisplay; } - } + public override bool IsBrowserSave => browserSave; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. /// - public override bool IsMailNewsSave { - get { return mailNewsSave; } - } + public override bool IsMailNewsDisplay => mailNewsDisplay; /// - /// Gets a value indicating whether the current encoding is read-only. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// + public override bool IsMailNewsSave => mailNewsSave; + + /// + /// Gets a value indicating whether the current encoding is read-only. /// /// The is single byte. - public override bool IsReadOnly { - get { return readOnly; } - } + public override bool IsReadOnly => readOnly; /// - /// Gets a value indicating whether the current encoding uses single-byte code points. + /// Gets a value indicating whether the current encoding uses single-byte code points. /// - public override bool IsSingleByte { - get { return singleByte; } - } + public override bool IsSingleByte => singleByte; /// - /// Gets the code page identifier of the current Encoding. + /// Gets the code page identifier of the current Encoding. /// - public override int CodePage { - get { return _codepage; } - } + public override int CodePage => _codepage; /// - /// Gets a name for the current encoding that can be used with mail agent body tags + /// Gets a name for the current encoding that can be used with mail agent body tags /// - public override string BodyName { - get { return _bodyname; } - } + public override string BodyName => _bodyname; /// - /// Gets a name for the current encoding that can be used with mail agent header tags + /// Gets a name for the current encoding that can be used with mail agent header tags /// - public override string HeaderName { - get { return _headername; } - } + public override string HeaderName => _headername; /// - /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. + /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. /// - public override string WebName { - get { return _webname; } - } + public override string WebName => _webname; /// - /// Gets the human-readable description of the current encoding. + /// Gets the human-readable description of the current encoding. /// - public override string EncodingName { - get { return _encodingname; } - } + public override string EncodingName => _encodingname; /// - /// Gets the Windows operating system code page that most closely corresponds to the current encoding. + /// Gets the Windows operating system code page that most closely corresponds to the current encoding. /// - public override int WindowsCodePage { - get { return _windowsCodepage; } - } + public override int WindowsCodePage => _windowsCodepage; /// - /// Calculates the number of bytes produced by encoding the characters in the specified . + /// Calculates the number of bytes produced by encoding the characters in the specified . /// /// The number of bytes produced by encoding the specified characters. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. public override int GetByteCount(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return s.Length; } /// - /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. + /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. /// /// The number of bytes produced by encoding the specified characters. /// The character array containing the set of characters to encode. @@ -154,36 +200,32 @@ namespace Claunia.Encoding /// The number of characters to encode. public override int GetByteCount(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0 || index >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0 || index >= chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0 || index + count > chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(count < 0 || index + count > chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); return count; } /// - /// Calculates the number of bytes produced by encoding all the characters in the specified character array. + /// Calculates the number of bytes produced by encoding all the characters in the specified character array. /// /// The number of bytes produced by encoding all the characters in the specified character array. /// The character array containing the characters to encode. public override int GetByteCount(char[] chars) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); return chars.Length; } /// - /// Encodes a set of characters from the specified into the specified byte array. + /// Encodes a set of characters from the specified into the specified byte array. /// /// The actual number of bytes written into bytes. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. /// The index of the first character to encode. /// The number of characters to encode. /// The byte array to contain the resulting sequence of bytes. @@ -194,20 +236,19 @@ namespace Claunia.Encoding } /// - /// Encodes all the characters in the specified string into a sequence of bytes. + /// Encodes all the characters in the specified string into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The string containing the characters to encode. public override byte[] GetBytes(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return GetBytes(s.ToCharArray(), 0, s.Length); } /// - /// Encodes a set of characters from the specified character array into the specified byte array. + /// Encodes a set of characters from the specified character array into the specified byte array. /// /// The actual number of bytes written into bytes. /// The character array containing the set of characters to encode. @@ -217,43 +258,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting sequence of bytes. public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount + charIndex > chars.Length) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount + charIndex > chars.Length) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteIndex + charCount > bytes.Length) - throw new ArgumentException(nameof(bytes)); + if(byteIndex + charCount > bytes.Length) throw new ArgumentException(nameof(bytes)); byte[] temp = GetBytes(chars, charIndex, charCount); - for(int i = 0; i < temp.Length; i++) - bytes[i + byteIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) bytes[i + byteIndex] = temp[i]; return charCount; } /// - /// Encodes a set of characters from the specified character array into a sequence of bytes. + /// Encodes a set of characters from the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the set of characters to encode. @@ -261,28 +292,23 @@ namespace Claunia.Encoding /// The number of characters to encode. public override byte[] GetBytes(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > chars.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > chars.Length) throw new ArgumentOutOfRangeException(nameof(count)); byte[] bytes = new byte[count]; - for(int i = 0; i < count; i++) - bytes[i] = GetByte(chars[index + i]); + for(int i = 0; i < count; i++) bytes[i] = GetByte(chars[index + i]); return bytes; } /// - /// Encodes all the characters in the specified character array into a sequence of bytes. + /// Encodes all the characters in the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the characters to encode. @@ -292,7 +318,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. + /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -302,7 +328,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. + /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -310,23 +336,19 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override int GetCharCount(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); return count; } /// - /// Decodes a sequence of bytes from the specified byte array into the specified character array. + /// Decodes a sequence of bytes from the specified byte array into the specified character array. /// /// The actual number of characters written into chars. /// The byte array containing the sequence of bytes to decode. @@ -336,43 +358,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting set of characters. public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount + byteIndex > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount + byteIndex > bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charIndex + byteCount > chars.Length) - throw new ArgumentException(nameof(chars)); + if(charIndex + byteCount > chars.Length) throw new ArgumentException(nameof(chars)); char[] temp = GetChars(bytes, byteIndex, byteCount); - for(int i = 0; i < temp.Length; i++) - chars[i + charIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) chars[i + charIndex] = temp[i]; return byteCount; } /// - /// Decodes all the bytes in the specified byte array into a set of characters. + /// Decodes all the bytes in the specified byte array into a set of characters. /// /// A character array containing the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -382,7 +394,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a set of characters. + /// Decodes a sequence of bytes from the specified byte array into a set of characters. /// /// The chars. /// The byte array containing the sequence of bytes to decode. @@ -390,54 +402,47 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override char[] GetChars(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); char[] chars = new char[count]; - for(int i = 0; i < count; i++) - chars[i] = GetChar(bytes[index + i]); + for(int i = 0; i < count; i++) chars[i] = GetChar(bytes[index + i]); return chars; } /// - /// Calculates the maximum number of bytes produced by encoding the specified number of characters. + /// Calculates the maximum number of bytes produced by encoding the specified number of characters. /// /// The maximum number of bytes produced by encoding the specified number of characters. /// The number of characters to encode. public override int GetMaxByteCount(int charCount) { - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); return charCount; } /// - /// Calculates the maximum number of characters produced by decoding the specified number of bytes. + /// Calculates the maximum number of characters produced by decoding the specified number of bytes. /// /// The maximum number of characters produced by decoding the specified number of bytes. /// The number of bytes to decode. public override int GetMaxCharCount(int byteCount) { - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); return byteCount; } /// - /// Returns a sequence of bytes that specifies the encoding used. + /// Returns a sequence of bytes that specifies the encoding used. /// /// A byte array of length zero, as a preamble is not required. public override byte[] GetPreamble() @@ -446,7 +451,7 @@ namespace Claunia.Encoding } /// - /// Decodes all the bytes in the specified byte array into a string. + /// Decodes all the bytes in the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -456,7 +461,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a string. + /// Decodes a sequence of bytes from the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -468,77 +473,7 @@ namespace Claunia.Encoding } /// - /// The Macintosh Arabic to Unicode character map. - /// - static readonly char[] MacArabicTable = { - // 0x00 - '\u0000','\u0001','\u0002','\u0003','\u0004','\u0005','\u0006','\u0007', - // 0x08 - '\u0008','\u0009','\u000A','\u000B','\u000C','\u000D','\u000E','\u000F', - // 0x10 - '\u0010','\u0011','\u0012','\u0013','\u0014','\u0015','\u0016','\u0017', - // 0x18 - '\u0018','\u0019','\u001A','\u001B','\u001C','\u001D','\u001E','\u001F', - // 0x20 - '\u0020','\u0021','\u0022','\u0023','\u0024','\u0025','\u0026','\u0027', - // 0x28 - '\u0028','\u0029','\u002A','\u002B','\u002C','\u002D','\u002E','\u002F', - // 0x30 - '\u0030','\u0031','\u0032','\u0033','\u0034','\u0035','\u0036','\u0037', - // 0x38 - '\u0038','\u0039','\u003A','\u003B','\u003C','\u003D','\u003E','\u003F', - // 0x40 - '\u0040','\u0041','\u0042','\u0043','\u0044','\u0045','\u0046','\u0047', - // 0x48 - '\u0048','\u0049','\u004A','\u004B','\u004C','\u004D','\u004E','\u004F', - // 0x50 - '\u0050','\u0051','\u0052','\u0053','\u0054','\u0055','\u0056','\u0057', - // 0x58 - '\u0058','\u0059','\u005A','\u005B','\u005C','\u005D','\u005E','\u005F', - // 0x60 - '\u0060','\u0061','\u0062','\u0063','\u0064','\u0065','\u0066','\u0067', - // 0x68 - '\u0068','\u0069','\u006A','\u006B','\u006C','\u006D','\u006E','\u006F', - // 0x70 - '\u0070','\u0071','\u0072','\u0073','\u0074','\u0075','\u0076','\u0077', - // 0x78 - '\u0078','\u0079','\u007A','\u007B','\u007C','\u007D','\u007E','\u007F', - // 0x80 - '\u00C4','\u00A0','\u00C7','\u00C9','\u00D1','\u00D6','\u00DC','\u00E1', - // 0x88 - '\u00E0','\u00E2','\u00E4','\u06BA','\u00AB','\u00E7','\u00E9','\u00E8', - // 0x90 - '\u00EA','\u00EB','\u00ED','\u2026','\u00EE','\u00EF','\u00F1','\u00F3', - // 0x98 - '\u00BB','\u00F4','\u00F6','\u00F7','\u00FA','\u00F9','\u00FB','\u00FC', - // 0xA0 - '\u0020','\u0021','\u0022','\u0023','\u0024','\u066A','\u0026','\u0027', - // 0xA8 - '\u0028','\u0029','\u002A','\u002B','\u060C','\u002D','\u002E','\u002F', - // 0xB0 - '\u0660','\u0661','\u0662','\u0663','\u0664','\u0665','\u0666','\u0667', - // 0xB8 - '\u0668','\u0669','\u003A','\u061B','\u003C','\u003D','\u003E','\u061F', - // 0xC0 - '\u274A','\u0621','\u0622','\u0623','\u0624','\u0625','\u0626','\u0627', - // 0xC8 - '\u0628','\u0629','\u062A','\u062B','\u062C','\u062D','\u062E','\u062F', - // 0xD0 - '\u0630','\u0631','\u0632','\u0633','\u0634','\u0635','\u0636','\u0637', - // 0xD8 - '\u0638','\u0639','\u063A','\u005B','\u005C','\u005D','\u005E','\u005F', - // 0xE0 - '\u0640','\u0641','\u0642','\u0643','\u0644','\u0645','\u0646','\u0647', - // 0xE8 - '\u0648','\u0649','\u064A','\u064B','\u064C','\u064D','\u064E','\u064F', - // 0xF0 - '\u0650','\u0651','\u0652','\u067E','\u0679','\u0686','\u06D5','\u06A4', - // 0xF8 - '\u06AF','\u0688','\u0691','\u007B','\u007C','\u007D','\u0698','\u06D2' - }; - - /// - /// Converts a Mac Arabic character to an Unicode character + /// Converts a Mac Arabic character to an Unicode character /// /// Unicode character. /// Mac Arabic character. @@ -548,473 +483,244 @@ namespace Claunia.Encoding } /// - /// Converts a Unicode character to an Mac Arabic character + /// Converts a Unicode character to an Mac Arabic character /// /// Mac Arabic character. /// Unicode character. static byte GetByte(char character) { - switch(character) { - case '\u0000': - return 0x00; - case '\u0001': - return 0x01; - case '\u0002': - return 0x02; - case '\u0003': - return 0x03; - case '\u0004': - return 0x04; - case '\u0005': - return 0x05; - case '\u0006': - return 0x06; - case '\u0007': - return 0x07; - case '\u0008': - return 0x08; - case '\u0009': - return 0x09; - case '\u000A': - return 0x0A; - case '\u000B': - return 0x0B; - case '\u000C': - return 0x0C; - case '\u000D': - return 0x0D; - case '\u000E': - return 0x0E; - case '\u000F': - return 0x0F; - case '\u0010': - return 0x10; - case '\u0011': - return 0x11; - case '\u0012': - return 0x12; - case '\u0013': - return 0x13; - case '\u0014': - return 0x14; - case '\u0015': - return 0x15; - case '\u0016': - return 0x16; - case '\u0017': - return 0x17; - case '\u0018': - return 0x18; - case '\u0019': - return 0x19; - case '\u001A': - return 0x1A; - case '\u001B': - return 0x1B; - case '\u001C': - return 0x1C; - case '\u001D': - return 0x1D; - case '\u001E': - return 0x1E; - case '\u001F': - return 0x1F; - case '\u0020': - return 0x20; - case '\u0021': - return 0x21; - case '\u0022': - return 0x22; - case '\u0023': - return 0x23; - case '\u0024': - return 0x24; - case '\u0025': - return 0x25; - case '\u0026': - return 0x26; - case '\u0027': - return 0x27; - case '\u0028': - return 0x28; - case '\u0029': - return 0x29; - case '\u002A': - return 0x2A; - case '\u002B': - return 0x2B; - case '\u002C': - return 0x2C; - case '\u002D': - return 0x2D; - case '\u002E': - return 0x2E; - case '\u002F': - return 0x2F; - case '\u0030': - return 0x30; - case '\u0031': - return 0x31; - case '\u0032': - return 0x32; - case '\u0033': - return 0x33; - case '\u0034': - return 0x34; - case '\u0035': - return 0x35; - case '\u0036': - return 0x36; - case '\u0037': - return 0x37; - case '\u0038': - return 0x38; - case '\u0039': - return 0x39; - case '\u003A': - return 0x3A; - case '\u003B': - return 0x3B; - case '\u003C': - return 0x3C; - case '\u003D': - return 0x3D; - case '\u003E': - return 0x3E; - case '\u003F': - return 0x3F; - case '\u0040': - return 0x40; - case '\u0041': - return 0x41; - case '\u0042': - return 0x42; - case '\u0043': - return 0x43; - case '\u0044': - return 0x44; - case '\u0045': - return 0x45; - case '\u0046': - return 0x46; - case '\u0047': - return 0x47; - case '\u0048': - return 0x48; - case '\u0049': - return 0x49; - case '\u004A': - return 0x4A; - case '\u004B': - return 0x4B; - case '\u004C': - return 0x4C; - case '\u004D': - return 0x4D; - case '\u004E': - return 0x4E; - case '\u004F': - return 0x4F; - case '\u0050': - return 0x50; - case '\u0051': - return 0x51; - case '\u0052': - return 0x52; - case '\u0053': - return 0x53; - case '\u0054': - return 0x54; - case '\u0055': - return 0x55; - case '\u0056': - return 0x56; - case '\u0057': - return 0x57; - case '\u0058': - return 0x58; - case '\u0059': - return 0x59; - case '\u005A': - return 0x5A; - case '\u005B': - return 0x5B; - case '\u005C': - return 0x5C; - case '\u005D': - return 0x5D; - case '\u005E': - return 0x5E; - case '\u005F': - return 0x5F; - case '\u0060': - return 0x60; - case '\u0061': - return 0x61; - case '\u0062': - return 0x62; - case '\u0063': - return 0x63; - case '\u0064': - return 0x64; - case '\u0065': - return 0x65; - case '\u0066': - return 0x66; - case '\u0067': - return 0x67; - case '\u0068': - return 0x68; - case '\u0069': - return 0x69; - case '\u006A': - return 0x6A; - case '\u006B': - return 0x6B; - case '\u006C': - return 0x6C; - case '\u006D': - return 0x6D; - case '\u006E': - return 0x6E; - case '\u006F': - return 0x6F; - case '\u0070': - return 0x70; - case '\u0071': - return 0x71; - case '\u0072': - return 0x72; - case '\u0073': - return 0x73; - case '\u0074': - return 0x74; - case '\u0075': - return 0x75; - case '\u0076': - return 0x76; - case '\u0077': - return 0x77; - case '\u0078': - return 0x78; - case '\u0079': - return 0x79; - case '\u007A': - return 0x7A; - case '\u007B': - return 0x7B; - case '\u007C': - return 0x7C; - case '\u007D': - return 0x7D; - case '\u007E': - return 0x7E; - case '\u007F': - return 0x7F; - case '\u00C4': - return 0x80; - case '\u00A0': - return 0x81; - case '\u00C7': - return 0x82; - case '\u00C9': - return 0x83; - case '\u00D1': - return 0x84; - case '\u00D6': - return 0x85; - case '\u00DC': - return 0x86; - case '\u00E1': - return 0x87; - case '\u00E0': - return 0x88; - case '\u00E2': - return 0x89; - case '\u00E4': - return 0x8A; - case '\u06BA': - return 0x8B; - case '\u00AB': - return 0x8C; - case '\u00E7': - return 0x8D; - case '\u00E9': - return 0x8E; - case '\u00E8': - return 0x8F; - case '\u00EA': - return 0x90; - case '\u00EB': - return 0x91; - case '\u00ED': - return 0x92; - case '\u2026': - return 0x93; - case '\u00EE': - return 0x94; - case '\u00EF': - return 0x95; - case '\u00F1': - return 0x96; - case '\u00F3': - return 0x97; - case '\u00BB': - return 0x98; - case '\u00F4': - return 0x99; - case '\u00F6': - return 0x9A; - case '\u00F7': - return 0x9B; - case '\u00FA': - return 0x9C; - case '\u00F9': - return 0x9D; - case '\u00FB': - return 0x9E; - case '\u00FC': - return 0x9F; - case '\u066A': - return 0xA5; - case '\u060C': - return 0xAC; - case '\u0660': - return 0xB0; - case '\u0661': - return 0xB1; - case '\u0662': - return 0xB2; - case '\u0663': - return 0xB3; - case '\u0664': - return 0xB4; - case '\u0665': - return 0xB5; - case '\u0666': - return 0xB6; - case '\u0667': - return 0xB7; - case '\u0668': - return 0xB8; - case '\u0669': - return 0xB9; - case '\u061B': - return 0xBB; - case '\u061F': - return 0xBF; - case '\u274A': - return 0xC0; - case '\u0621': - return 0xC1; - case '\u0622': - return 0xC2; - case '\u0623': - return 0xC3; - case '\u0624': - return 0xC4; - case '\u0625': - return 0xC5; - case '\u0626': - return 0xC6; - case '\u0627': - return 0xC7; - case '\u0628': - return 0xC8; - case '\u0629': - return 0xC9; - case '\u062A': - return 0xCA; - case '\u062B': - return 0xCB; - case '\u062C': - return 0xCC; - case '\u062D': - return 0xCD; - case '\u062E': - return 0xCE; - case '\u062F': - return 0xCF; - case '\u0630': - return 0xD0; - case '\u0631': - return 0xD1; - case '\u0632': - return 0xD2; - case '\u0633': - return 0xD3; - case '\u0634': - return 0xD4; - case '\u0635': - return 0xD5; - case '\u0636': - return 0xD6; - case '\u0637': - return 0xD7; - case '\u0638': - return 0xD8; - case '\u0639': - return 0xD9; - case '\u063A': - return 0xDA; - case '\u0640': - return 0xE0; - case '\u0641': - return 0xE1; - case '\u0642': - return 0xE2; - case '\u0643': - return 0xE3; - case '\u0644': - return 0xE4; - case '\u0645': - return 0xE5; - case '\u0646': - return 0xE6; - case '\u0647': - return 0xE7; - case '\u0648': - return 0xE8; - case '\u0649': - return 0xE9; - case '\u064A': - return 0xEA; - case '\u064B': - return 0xEB; - case '\u064C': - return 0xEC; - case '\u064D': - return 0xED; - case '\u064E': - return 0xEE; - case '\u064F': - return 0xEF; - case '\u0650': - return 0xF0; - case '\u0651': - return 0xF1; - case '\u0652': - return 0xF2; - case '\u067E': - return 0xF3; - case '\u0679': - return 0xF4; - case '\u0686': - return 0xF5; - case '\u06D5': - return 0xF6; - case '\u06A4': - return 0xF7; - case '\u06AF': - return 0xF8; - case '\u0688': - return 0xF9; - case '\u0691': - return 0xFA; - case '\u0698': - return 0xFE; - case '\u06D2': - return 0xFF; + switch(character) + { + case '\u0000': return 0x00; + case '\u0001': return 0x01; + case '\u0002': return 0x02; + case '\u0003': return 0x03; + case '\u0004': return 0x04; + case '\u0005': return 0x05; + case '\u0006': return 0x06; + case '\u0007': return 0x07; + case '\u0008': return 0x08; + case '\u0009': return 0x09; + case '\u000A': return 0x0A; + case '\u000B': return 0x0B; + case '\u000C': return 0x0C; + case '\u000D': return 0x0D; + case '\u000E': return 0x0E; + case '\u000F': return 0x0F; + case '\u0010': return 0x10; + case '\u0011': return 0x11; + case '\u0012': return 0x12; + case '\u0013': return 0x13; + case '\u0014': return 0x14; + case '\u0015': return 0x15; + case '\u0016': return 0x16; + case '\u0017': return 0x17; + case '\u0018': return 0x18; + case '\u0019': return 0x19; + case '\u001A': return 0x1A; + case '\u001B': return 0x1B; + case '\u001C': return 0x1C; + case '\u001D': return 0x1D; + case '\u001E': return 0x1E; + case '\u001F': return 0x1F; + case '\u0020': return 0x20; + case '\u0021': return 0x21; + case '\u0022': return 0x22; + case '\u0023': return 0x23; + case '\u0024': return 0x24; + case '\u0025': return 0x25; + case '\u0026': return 0x26; + case '\u0027': return 0x27; + case '\u0028': return 0x28; + case '\u0029': return 0x29; + case '\u002A': return 0x2A; + case '\u002B': return 0x2B; + case '\u002C': return 0x2C; + case '\u002D': return 0x2D; + case '\u002E': return 0x2E; + case '\u002F': return 0x2F; + case '\u0030': return 0x30; + case '\u0031': return 0x31; + case '\u0032': return 0x32; + case '\u0033': return 0x33; + case '\u0034': return 0x34; + case '\u0035': return 0x35; + case '\u0036': return 0x36; + case '\u0037': return 0x37; + case '\u0038': return 0x38; + case '\u0039': return 0x39; + case '\u003A': return 0x3A; + case '\u003B': return 0x3B; + case '\u003C': return 0x3C; + case '\u003D': return 0x3D; + case '\u003E': return 0x3E; + case '\u003F': return 0x3F; + case '\u0040': return 0x40; + case '\u0041': return 0x41; + case '\u0042': return 0x42; + case '\u0043': return 0x43; + case '\u0044': return 0x44; + case '\u0045': return 0x45; + case '\u0046': return 0x46; + case '\u0047': return 0x47; + case '\u0048': return 0x48; + case '\u0049': return 0x49; + case '\u004A': return 0x4A; + case '\u004B': return 0x4B; + case '\u004C': return 0x4C; + case '\u004D': return 0x4D; + case '\u004E': return 0x4E; + case '\u004F': return 0x4F; + case '\u0050': return 0x50; + case '\u0051': return 0x51; + case '\u0052': return 0x52; + case '\u0053': return 0x53; + case '\u0054': return 0x54; + case '\u0055': return 0x55; + case '\u0056': return 0x56; + case '\u0057': return 0x57; + case '\u0058': return 0x58; + case '\u0059': return 0x59; + case '\u005A': return 0x5A; + case '\u005B': return 0x5B; + case '\u005C': return 0x5C; + case '\u005D': return 0x5D; + case '\u005E': return 0x5E; + case '\u005F': return 0x5F; + case '\u0060': return 0x60; + case '\u0061': return 0x61; + case '\u0062': return 0x62; + case '\u0063': return 0x63; + case '\u0064': return 0x64; + case '\u0065': return 0x65; + case '\u0066': return 0x66; + case '\u0067': return 0x67; + case '\u0068': return 0x68; + case '\u0069': return 0x69; + case '\u006A': return 0x6A; + case '\u006B': return 0x6B; + case '\u006C': return 0x6C; + case '\u006D': return 0x6D; + case '\u006E': return 0x6E; + case '\u006F': return 0x6F; + case '\u0070': return 0x70; + case '\u0071': return 0x71; + case '\u0072': return 0x72; + case '\u0073': return 0x73; + case '\u0074': return 0x74; + case '\u0075': return 0x75; + case '\u0076': return 0x76; + case '\u0077': return 0x77; + case '\u0078': return 0x78; + case '\u0079': return 0x79; + case '\u007A': return 0x7A; + case '\u007B': return 0x7B; + case '\u007C': return 0x7C; + case '\u007D': return 0x7D; + case '\u007E': return 0x7E; + case '\u007F': return 0x7F; + case '\u00C4': return 0x80; + case '\u00A0': return 0x81; + case '\u00C7': return 0x82; + case '\u00C9': return 0x83; + case '\u00D1': return 0x84; + case '\u00D6': return 0x85; + case '\u00DC': return 0x86; + case '\u00E1': return 0x87; + case '\u00E0': return 0x88; + case '\u00E2': return 0x89; + case '\u00E4': return 0x8A; + case '\u06BA': return 0x8B; + case '\u00AB': return 0x8C; + case '\u00E7': return 0x8D; + case '\u00E9': return 0x8E; + case '\u00E8': return 0x8F; + case '\u00EA': return 0x90; + case '\u00EB': return 0x91; + case '\u00ED': return 0x92; + case '\u2026': return 0x93; + case '\u00EE': return 0x94; + case '\u00EF': return 0x95; + case '\u00F1': return 0x96; + case '\u00F3': return 0x97; + case '\u00BB': return 0x98; + case '\u00F4': return 0x99; + case '\u00F6': return 0x9A; + case '\u00F7': return 0x9B; + case '\u00FA': return 0x9C; + case '\u00F9': return 0x9D; + case '\u00FB': return 0x9E; + case '\u00FC': return 0x9F; + case '\u066A': return 0xA5; + case '\u060C': return 0xAC; + case '\u0660': return 0xB0; + case '\u0661': return 0xB1; + case '\u0662': return 0xB2; + case '\u0663': return 0xB3; + case '\u0664': return 0xB4; + case '\u0665': return 0xB5; + case '\u0666': return 0xB6; + case '\u0667': return 0xB7; + case '\u0668': return 0xB8; + case '\u0669': return 0xB9; + case '\u061B': return 0xBB; + case '\u061F': return 0xBF; + case '\u274A': return 0xC0; + case '\u0621': return 0xC1; + case '\u0622': return 0xC2; + case '\u0623': return 0xC3; + case '\u0624': return 0xC4; + case '\u0625': return 0xC5; + case '\u0626': return 0xC6; + case '\u0627': return 0xC7; + case '\u0628': return 0xC8; + case '\u0629': return 0xC9; + case '\u062A': return 0xCA; + case '\u062B': return 0xCB; + case '\u062C': return 0xCC; + case '\u062D': return 0xCD; + case '\u062E': return 0xCE; + case '\u062F': return 0xCF; + case '\u0630': return 0xD0; + case '\u0631': return 0xD1; + case '\u0632': return 0xD2; + case '\u0633': return 0xD3; + case '\u0634': return 0xD4; + case '\u0635': return 0xD5; + case '\u0636': return 0xD6; + case '\u0637': return 0xD7; + case '\u0638': return 0xD8; + case '\u0639': return 0xD9; + case '\u063A': return 0xDA; + case '\u0640': return 0xE0; + case '\u0641': return 0xE1; + case '\u0642': return 0xE2; + case '\u0643': return 0xE3; + case '\u0644': return 0xE4; + case '\u0645': return 0xE5; + case '\u0646': return 0xE6; + case '\u0647': return 0xE7; + case '\u0648': return 0xE8; + case '\u0649': return 0xE9; + case '\u064A': return 0xEA; + case '\u064B': return 0xEB; + case '\u064C': return 0xEC; + case '\u064D': return 0xED; + case '\u064E': return 0xEE; + case '\u064F': return 0xEF; + case '\u0650': return 0xF0; + case '\u0651': return 0xF1; + case '\u0652': return 0xF2; + case '\u067E': return 0xF3; + case '\u0679': return 0xF4; + case '\u0686': return 0xF5; + case '\u06D5': return 0xF6; + case '\u06A4': return 0xF7; + case '\u06AF': return 0xF8; + case '\u0688': return 0xF9; + case '\u0691': return 0xFA; + case '\u0698': return 0xFE; + case '\u06D2': return 0xFF; default: // Fallback to '?' return 0x3F; diff --git a/Claunia.Encoding/MacCentralEuropean.cs b/Claunia.Encoding/MacCentralEuropean.cs index 578e748..e273d5a 100644 --- a/Claunia.Encoding/MacCentralEuropean.cs +++ b/Claunia.Encoding/MacCentralEuropean.cs @@ -29,7 +29,7 @@ using System; namespace Claunia.Encoding { /// - /// Represents an Mac CentralEuropean character encoding of Unicode characters. + /// Represents an Mac CentralEuropean character encoding of Unicode characters. /// public class MacCentralEuropean : Encoding { @@ -48,105 +48,151 @@ namespace Claunia.Encoding const bool singleByte = true; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. + /// The Macintosh CentralEuropean to Unicode character map. /// - public override bool IsBrowserDisplay { - get { return browserDisplay; } - } + static readonly char[] MacCentralEuropeanTable = + { + // 0x00 + '\u0000', '\u0001', '\u0002', '\u0003', '\u0004', '\u0005', '\u0006', '\u0007', + // 0x08 + '\u0008', '\u0009', '\u000A', '\u000B', '\u000C', '\u000D', '\u000E', '\u000F', + // 0x10 + '\u0010', '\u0011', '\u0012', '\u0013', '\u0014', '\u0015', '\u0016', '\u0017', + // 0x18 + '\u0018', '\u0019', '\u001A', '\u001B', '\u001C', '\u001D', '\u001E', '\u001F', + // 0x20 + '\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027', + // 0x28 + '\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F', + // 0x30 + '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', + // 0x38 + '\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F', + // 0x40 + '\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047', + // 0x48 + '\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F', + // 0x50 + '\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057', + // 0x58 + '\u0058', '\u0059', '\u005A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F', + // 0x60 + '\u0060', '\u0061', '\u0062', '\u0063', '\u0064', '\u0065', '\u0066', '\u0067', + // 0x68 + '\u0068', '\u0069', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F', + // 0x70 + '\u0070', '\u0071', '\u0072', '\u0073', '\u0074', '\u0075', '\u0076', '\u0077', + // 0x78 + '\u0078', '\u0079', '\u007A', '\u007B', '\u007C', '\u007D', '\u007E', '\u007F', + // 0x80 + '\u00C4', '\u0100', '\u0101', '\u00C9', '\u0104', '\u00D6', '\u00DC', '\u00E1', + // 0x88 + '\u0105', '\u010C', '\u00E4', '\u010D', '\u0106', '\u0107', '\u00E9', '\u0179', + // 0x90 + '\u017A', '\u010E', '\u00ED', '\u010F', '\u0112', '\u0113', '\u0116', '\u00F3', + // 0x98 + '\u0117', '\u00F4', '\u00F6', '\u00F5', '\u00FA', '\u011A', '\u011B', '\u00FC', + // 0xA0 + '\u2020', '\u00B0', '\u0118', '\u00A3', '\u00A7', '\u2022', '\u00B6', '\u00DF', + // 0xA8 + '\u00AE', '\u00A9', '\u2122', '\u0119', '\u00A8', '\u2260', '\u0123', '\u012E', + // 0xB0 + '\u012F', '\u012A', '\u2264', '\u2265', '\u012B', '\u0136', '\u2202', '\u2211', + // 0xB8 + '\u0142', '\u013B', '\u013C', '\u013D', '\u013E', '\u0139', '\u013A', '\u0145', + // 0xC0 + '\u0146', '\u0143', '\u00AC', '\u221A', '\u0144', '\u0147', '\u2206', '\u00AB', + // 0xC8 + '\u00BB', '\u2026', '\u00A0', '\u0148', '\u0150', '\u00D5', '\u0151', '\u014C', + // 0xD0 + '\u2013', '\u2014', '\u201C', '\u201D', '\u2018', '\u2019', '\u00F7', '\u25CA', + // 0xD8 + '\u014D', '\u0154', '\u0155', '\u0158', '\u2039', '\u203A', '\u0159', '\u0156', + // 0xE0 + '\u0157', '\u0160', '\u201A', '\u201E', '\u0161', '\u015A', '\u015B', '\u00C1', + // 0xE8 + '\u0164', '\u0165', '\u00CD', '\u017D', '\u017E', '\u016A', '\u00D3', '\u00D4', + // 0xF0 + '\u016B', '\u016E', '\u00DA', '\u016F', '\u0170', '\u0171', '\u0172', '\u0173', + // 0xF8 + '\u00DD', '\u00FD', '\u0137', '\u017B', '\u0141', '\u017C', '\u0122', '\u02C7' + }; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. + /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. /// - public override bool IsBrowserSave { - get { return browserSave; } - } + public override bool IsBrowserDisplay => browserDisplay; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. + /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. /// - public override bool IsMailNewsDisplay { - get { return mailNewsDisplay; } - } + public override bool IsBrowserSave => browserSave; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. /// - public override bool IsMailNewsSave { - get { return mailNewsSave; } - } + public override bool IsMailNewsDisplay => mailNewsDisplay; /// - /// Gets a value indicating whether the current encoding is read-only. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// + public override bool IsMailNewsSave => mailNewsSave; + + /// + /// Gets a value indicating whether the current encoding is read-only. /// /// The is single byte. - public override bool IsReadOnly { - get { return readOnly; } - } + public override bool IsReadOnly => readOnly; /// - /// Gets a value indicating whether the current encoding uses single-byte code points. + /// Gets a value indicating whether the current encoding uses single-byte code points. /// - public override bool IsSingleByte { - get { return singleByte; } - } + public override bool IsSingleByte => singleByte; /// - /// Gets the code page identifier of the current Encoding. + /// Gets the code page identifier of the current Encoding. /// - public override int CodePage { - get { return _codepage; } - } + public override int CodePage => _codepage; /// - /// Gets a name for the current encoding that can be used with mail agent body tags + /// Gets a name for the current encoding that can be used with mail agent body tags /// - public override string BodyName { - get { return _bodyname; } - } + public override string BodyName => _bodyname; /// - /// Gets a name for the current encoding that can be used with mail agent header tags + /// Gets a name for the current encoding that can be used with mail agent header tags /// - public override string HeaderName { - get { return _headername; } - } + public override string HeaderName => _headername; /// - /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. + /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. /// - public override string WebName { - get { return _webname; } - } + public override string WebName => _webname; /// - /// Gets the human-readable description of the current encoding. + /// Gets the human-readable description of the current encoding. /// - public override string EncodingName { - get { return _encodingname; } - } + public override string EncodingName => _encodingname; /// - /// Gets the Windows operating system code page that most closely corresponds to the current encoding. + /// Gets the Windows operating system code page that most closely corresponds to the current encoding. /// - public override int WindowsCodePage { - get { return _windowsCodepage; } - } + public override int WindowsCodePage => _windowsCodepage; /// - /// Calculates the number of bytes produced by encoding the characters in the specified . + /// Calculates the number of bytes produced by encoding the characters in the specified . /// /// The number of bytes produced by encoding the specified characters. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. public override int GetByteCount(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return s.Length; } /// - /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. + /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. /// /// The number of bytes produced by encoding the specified characters. /// The character array containing the set of characters to encode. @@ -154,36 +200,32 @@ namespace Claunia.Encoding /// The number of characters to encode. public override int GetByteCount(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0 || index >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0 || index >= chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0 || index + count > chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(count < 0 || index + count > chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); return count; } /// - /// Calculates the number of bytes produced by encoding all the characters in the specified character array. + /// Calculates the number of bytes produced by encoding all the characters in the specified character array. /// /// The number of bytes produced by encoding all the characters in the specified character array. /// The character array containing the characters to encode. public override int GetByteCount(char[] chars) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); return chars.Length; } /// - /// Encodes a set of characters from the specified into the specified byte array. + /// Encodes a set of characters from the specified into the specified byte array. /// /// The actual number of bytes written into bytes. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. /// The index of the first character to encode. /// The number of characters to encode. /// The byte array to contain the resulting sequence of bytes. @@ -194,20 +236,19 @@ namespace Claunia.Encoding } /// - /// Encodes all the characters in the specified string into a sequence of bytes. + /// Encodes all the characters in the specified string into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The string containing the characters to encode. public override byte[] GetBytes(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return GetBytes(s.ToCharArray(), 0, s.Length); } /// - /// Encodes a set of characters from the specified character array into the specified byte array. + /// Encodes a set of characters from the specified character array into the specified byte array. /// /// The actual number of bytes written into bytes. /// The character array containing the set of characters to encode. @@ -217,43 +258,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting sequence of bytes. public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount + charIndex > chars.Length) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount + charIndex > chars.Length) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteIndex + charCount > bytes.Length) - throw new ArgumentException(nameof(bytes)); + if(byteIndex + charCount > bytes.Length) throw new ArgumentException(nameof(bytes)); byte[] temp = GetBytes(chars, charIndex, charCount); - for(int i = 0; i < temp.Length; i++) - bytes[i + byteIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) bytes[i + byteIndex] = temp[i]; return charCount; } /// - /// Encodes a set of characters from the specified character array into a sequence of bytes. + /// Encodes a set of characters from the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the set of characters to encode. @@ -261,28 +292,23 @@ namespace Claunia.Encoding /// The number of characters to encode. public override byte[] GetBytes(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > chars.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > chars.Length) throw new ArgumentOutOfRangeException(nameof(count)); byte[] bytes = new byte[count]; - for(int i = 0; i < count; i++) - bytes[i] = GetByte(chars[index + i]); + for(int i = 0; i < count; i++) bytes[i] = GetByte(chars[index + i]); return bytes; } /// - /// Encodes all the characters in the specified character array into a sequence of bytes. + /// Encodes all the characters in the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the characters to encode. @@ -292,7 +318,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. + /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -302,7 +328,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. + /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -310,23 +336,19 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override int GetCharCount(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); return count; } /// - /// Decodes a sequence of bytes from the specified byte array into the specified character array. + /// Decodes a sequence of bytes from the specified byte array into the specified character array. /// /// The actual number of characters written into chars. /// The byte array containing the sequence of bytes to decode. @@ -336,43 +358,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting set of characters. public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount + byteIndex > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount + byteIndex > bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charIndex + byteCount > chars.Length) - throw new ArgumentException(nameof(chars)); + if(charIndex + byteCount > chars.Length) throw new ArgumentException(nameof(chars)); char[] temp = GetChars(bytes, byteIndex, byteCount); - for(int i = 0; i < temp.Length; i++) - chars[i + charIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) chars[i + charIndex] = temp[i]; return byteCount; } /// - /// Decodes all the bytes in the specified byte array into a set of characters. + /// Decodes all the bytes in the specified byte array into a set of characters. /// /// A character array containing the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -382,7 +394,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a set of characters. + /// Decodes a sequence of bytes from the specified byte array into a set of characters. /// /// The chars. /// The byte array containing the sequence of bytes to decode. @@ -390,54 +402,47 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override char[] GetChars(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); char[] chars = new char[count]; - for(int i = 0; i < count; i++) - chars[i] = GetChar(bytes[index + i]); + for(int i = 0; i < count; i++) chars[i] = GetChar(bytes[index + i]); return chars; } /// - /// Calculates the maximum number of bytes produced by encoding the specified number of characters. + /// Calculates the maximum number of bytes produced by encoding the specified number of characters. /// /// The maximum number of bytes produced by encoding the specified number of characters. /// The number of characters to encode. public override int GetMaxByteCount(int charCount) { - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); return charCount; } /// - /// Calculates the maximum number of characters produced by decoding the specified number of bytes. + /// Calculates the maximum number of characters produced by decoding the specified number of bytes. /// /// The maximum number of characters produced by decoding the specified number of bytes. /// The number of bytes to decode. public override int GetMaxCharCount(int byteCount) { - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); return byteCount; } /// - /// Returns a sequence of bytes that specifies the encoding used. + /// Returns a sequence of bytes that specifies the encoding used. /// /// A byte array of length zero, as a preamble is not required. public override byte[] GetPreamble() @@ -446,7 +451,7 @@ namespace Claunia.Encoding } /// - /// Decodes all the bytes in the specified byte array into a string. + /// Decodes all the bytes in the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -456,7 +461,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a string. + /// Decodes a sequence of bytes from the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -468,77 +473,7 @@ namespace Claunia.Encoding } /// - /// The Macintosh CentralEuropean to Unicode character map. - /// - static readonly char[] MacCentralEuropeanTable = { - // 0x00 - '\u0000','\u0001','\u0002','\u0003','\u0004','\u0005','\u0006','\u0007', - // 0x08 - '\u0008','\u0009','\u000A','\u000B','\u000C','\u000D','\u000E','\u000F', - // 0x10 - '\u0010','\u0011','\u0012','\u0013','\u0014','\u0015','\u0016','\u0017', - // 0x18 - '\u0018','\u0019','\u001A','\u001B','\u001C','\u001D','\u001E','\u001F', - // 0x20 - '\u0020','\u0021','\u0022','\u0023','\u0024','\u0025','\u0026','\u0027', - // 0x28 - '\u0028','\u0029','\u002A','\u002B','\u002C','\u002D','\u002E','\u002F', - // 0x30 - '\u0030','\u0031','\u0032','\u0033','\u0034','\u0035','\u0036','\u0037', - // 0x38 - '\u0038','\u0039','\u003A','\u003B','\u003C','\u003D','\u003E','\u003F', - // 0x40 - '\u0040','\u0041','\u0042','\u0043','\u0044','\u0045','\u0046','\u0047', - // 0x48 - '\u0048','\u0049','\u004A','\u004B','\u004C','\u004D','\u004E','\u004F', - // 0x50 - '\u0050','\u0051','\u0052','\u0053','\u0054','\u0055','\u0056','\u0057', - // 0x58 - '\u0058','\u0059','\u005A','\u005B','\u005C','\u005D','\u005E','\u005F', - // 0x60 - '\u0060','\u0061','\u0062','\u0063','\u0064','\u0065','\u0066','\u0067', - // 0x68 - '\u0068','\u0069','\u006A','\u006B','\u006C','\u006D','\u006E','\u006F', - // 0x70 - '\u0070','\u0071','\u0072','\u0073','\u0074','\u0075','\u0076','\u0077', - // 0x78 - '\u0078','\u0079','\u007A','\u007B','\u007C','\u007D','\u007E','\u007F', - // 0x80 - '\u00C4','\u0100','\u0101','\u00C9','\u0104','\u00D6','\u00DC','\u00E1', - // 0x88 - '\u0105','\u010C','\u00E4','\u010D','\u0106','\u0107','\u00E9','\u0179', - // 0x90 - '\u017A','\u010E','\u00ED','\u010F','\u0112','\u0113','\u0116','\u00F3', - // 0x98 - '\u0117','\u00F4','\u00F6','\u00F5','\u00FA','\u011A','\u011B','\u00FC', - // 0xA0 - '\u2020','\u00B0','\u0118','\u00A3','\u00A7','\u2022','\u00B6','\u00DF', - // 0xA8 - '\u00AE','\u00A9','\u2122','\u0119','\u00A8','\u2260','\u0123','\u012E', - // 0xB0 - '\u012F','\u012A','\u2264','\u2265','\u012B','\u0136','\u2202','\u2211', - // 0xB8 - '\u0142','\u013B','\u013C','\u013D','\u013E','\u0139','\u013A','\u0145', - // 0xC0 - '\u0146','\u0143','\u00AC','\u221A','\u0144','\u0147','\u2206','\u00AB', - // 0xC8 - '\u00BB','\u2026','\u00A0','\u0148','\u0150','\u00D5','\u0151','\u014C', - // 0xD0 - '\u2013','\u2014','\u201C','\u201D','\u2018','\u2019','\u00F7','\u25CA', - // 0xD8 - '\u014D','\u0154','\u0155','\u0158','\u2039','\u203A','\u0159','\u0156', - // 0xE0 - '\u0157','\u0160','\u201A','\u201E','\u0161','\u015A','\u015B','\u00C1', - // 0xE8 - '\u0164','\u0165','\u00CD','\u017D','\u017E','\u016A','\u00D3','\u00D4', - // 0xF0 - '\u016B','\u016E','\u00DA','\u016F','\u0170','\u0171','\u0172','\u0173', - // 0xF8 - '\u00DD','\u00FD','\u0137','\u017B','\u0141','\u017C','\u0122','\u02C7' - }; - - /// - /// Converts a Mac CentralEuropean character to an Unicode character + /// Converts a Mac CentralEuropean character to an Unicode character /// /// Unicode character. /// Mac CentralEuropean character. @@ -548,525 +483,270 @@ namespace Claunia.Encoding } /// - /// Converts a Unicode character to an Mac CentralEuropean character + /// Converts a Unicode character to an Mac CentralEuropean character /// /// Mac CentralEuropean character. /// Unicode character. static byte GetByte(char character) { - switch(character) { - case '\u0000': - return 0x00; - case '\u0001': - return 0x01; - case '\u0002': - return 0x02; - case '\u0003': - return 0x03; - case '\u0004': - return 0x04; - case '\u0005': - return 0x05; - case '\u0006': - return 0x06; - case '\u0007': - return 0x07; - case '\u0008': - return 0x08; - case '\u0009': - return 0x09; - case '\u000A': - return 0x0A; - case '\u000B': - return 0x0B; - case '\u000C': - return 0x0C; - case '\u000D': - return 0x0D; - case '\u000E': - return 0x0E; - case '\u000F': - return 0x0F; - case '\u0010': - return 0x10; - case '\u0011': - return 0x11; - case '\u0012': - return 0x12; - case '\u0013': - return 0x13; - case '\u0014': - return 0x14; - case '\u0015': - return 0x15; - case '\u0016': - return 0x16; - case '\u0017': - return 0x17; - case '\u0018': - return 0x18; - case '\u0019': - return 0x19; - case '\u001A': - return 0x1A; - case '\u001B': - return 0x1B; - case '\u001C': - return 0x1C; - case '\u001D': - return 0x1D; - case '\u001E': - return 0x1E; - case '\u001F': - return 0x1F; - case '\u0020': - return 0x20; - case '\u0021': - return 0x21; - case '\u0022': - return 0x22; - case '\u0023': - return 0x23; - case '\u0024': - return 0x24; - case '\u0025': - return 0x25; - case '\u0026': - return 0x26; - case '\u0027': - return 0x27; - case '\u0028': - return 0x28; - case '\u0029': - return 0x29; - case '\u002A': - return 0x2A; - case '\u002B': - return 0x2B; - case '\u002C': - return 0x2C; - case '\u002D': - return 0x2D; - case '\u002E': - return 0x2E; - case '\u002F': - return 0x2F; - case '\u0030': - return 0x30; - case '\u0031': - return 0x31; - case '\u0032': - return 0x32; - case '\u0033': - return 0x33; - case '\u0034': - return 0x34; - case '\u0035': - return 0x35; - case '\u0036': - return 0x36; - case '\u0037': - return 0x37; - case '\u0038': - return 0x38; - case '\u0039': - return 0x39; - case '\u003A': - return 0x3A; - case '\u003B': - return 0x3B; - case '\u003C': - return 0x3C; - case '\u003D': - return 0x3D; - case '\u003E': - return 0x3E; - case '\u003F': - return 0x3F; - case '\u0040': - return 0x40; - case '\u0041': - return 0x41; - case '\u0042': - return 0x42; - case '\u0043': - return 0x43; - case '\u0044': - return 0x44; - case '\u0045': - return 0x45; - case '\u0046': - return 0x46; - case '\u0047': - return 0x47; - case '\u0048': - return 0x48; - case '\u0049': - return 0x49; - case '\u004A': - return 0x4A; - case '\u004B': - return 0x4B; - case '\u004C': - return 0x4C; - case '\u004D': - return 0x4D; - case '\u004E': - return 0x4E; - case '\u004F': - return 0x4F; - case '\u0050': - return 0x50; - case '\u0051': - return 0x51; - case '\u0052': - return 0x52; - case '\u0053': - return 0x53; - case '\u0054': - return 0x54; - case '\u0055': - return 0x55; - case '\u0056': - return 0x56; - case '\u0057': - return 0x57; - case '\u0058': - return 0x58; - case '\u0059': - return 0x59; - case '\u005A': - return 0x5A; - case '\u005B': - return 0x5B; - case '\u005C': - return 0x5C; - case '\u005D': - return 0x5D; - case '\u005E': - return 0x5E; - case '\u005F': - return 0x5F; - case '\u0060': - return 0x60; - case '\u0061': - return 0x61; - case '\u0062': - return 0x62; - case '\u0063': - return 0x63; - case '\u0064': - return 0x64; - case '\u0065': - return 0x65; - case '\u0066': - return 0x66; - case '\u0067': - return 0x67; - case '\u0068': - return 0x68; - case '\u0069': - return 0x69; - case '\u006A': - return 0x6A; - case '\u006B': - return 0x6B; - case '\u006C': - return 0x6C; - case '\u006D': - return 0x6D; - case '\u006E': - return 0x6E; - case '\u006F': - return 0x6F; - case '\u0070': - return 0x70; - case '\u0071': - return 0x71; - case '\u0072': - return 0x72; - case '\u0073': - return 0x73; - case '\u0074': - return 0x74; - case '\u0075': - return 0x75; - case '\u0076': - return 0x76; - case '\u0077': - return 0x77; - case '\u0078': - return 0x78; - case '\u0079': - return 0x79; - case '\u007A': - return 0x7A; - case '\u007B': - return 0x7B; - case '\u007C': - return 0x7C; - case '\u007D': - return 0x7D; - case '\u007E': - return 0x7E; - case '\u007F': - return 0x7F; - case '\u00C4': - return 0x80; - case '\u0100': - return 0x81; - case '\u0101': - return 0x82; - case '\u00C9': - return 0x83; - case '\u0104': - return 0x84; - case '\u00D6': - return 0x85; - case '\u00DC': - return 0x86; - case '\u00E1': - return 0x87; - case '\u0105': - return 0x88; - case '\u010C': - return 0x89; - case '\u00E4': - return 0x8A; - case '\u010D': - return 0x8B; - case '\u0106': - return 0x8C; - case '\u0107': - return 0x8D; - case '\u00E9': - return 0x8E; - case '\u0179': - return 0x8F; - case '\u017A': - return 0x90; - case '\u010E': - return 0x91; - case '\u00ED': - return 0x92; - case '\u010F': - return 0x93; - case '\u0112': - return 0x94; - case '\u0113': - return 0x95; - case '\u0116': - return 0x96; - case '\u00F3': - return 0x97; - case '\u0117': - return 0x98; - case '\u00F4': - return 0x99; - case '\u00F6': - return 0x9A; - case '\u00F5': - return 0x9B; - case '\u00FA': - return 0x9C; - case '\u011A': - return 0x9D; - case '\u011B': - return 0x9E; - case '\u00FC': - return 0x9F; - case '\u2020': - return 0xA0; - case '\u00B0': - return 0xA1; - case '\u0118': - return 0xA2; - case '\u00A3': - return 0xA3; - case '\u00A7': - return 0xA4; - case '\u2022': - return 0xA5; - case '\u00B6': - return 0xA6; - case '\u00DF': - return 0xA7; - case '\u00AE': - return 0xA8; - case '\u00A9': - return 0xA9; - case '\u2122': - return 0xAA; - case '\u0119': - return 0xAB; - case '\u00A8': - return 0xAC; - case '\u2260': - return 0xAD; - case '\u0123': - return 0xAE; - case '\u012E': - return 0xAF; - case '\u012F': - return 0xB0; - case '\u012A': - return 0xB1; - case '\u2264': - return 0xB2; - case '\u2265': - return 0xB3; - case '\u012B': - return 0xB4; - case '\u0136': - return 0xB5; - case '\u2202': - return 0xB6; - case '\u2211': - return 0xB7; - case '\u0142': - return 0xB8; - case '\u013B': - return 0xB9; - case '\u013C': - return 0xBA; - case '\u013D': - return 0xBB; - case '\u013E': - return 0xBC; - case '\u0139': - return 0xBD; - case '\u013A': - return 0xBE; - case '\u0145': - return 0xBF; - case '\u0146': - return 0xC0; - case '\u0143': - return 0xC1; - case '\u00AC': - return 0xC2; - case '\u221A': - return 0xC3; - case '\u0144': - return 0xC4; - case '\u0147': - return 0xC5; - case '\u2206': - return 0xC6; - case '\u00AB': - return 0xC7; - case '\u00BB': - return 0xC8; - case '\u2026': - return 0xC9; - case '\u00A0': - return 0xCA; - case '\u0148': - return 0xCB; - case '\u0150': - return 0xCC; - case '\u00D5': - return 0xCD; - case '\u0151': - return 0xCE; - case '\u014C': - return 0xCF; - case '\u2013': - return 0xD0; - case '\u2014': - return 0xD1; - case '\u201C': - return 0xD2; - case '\u201D': - return 0xD3; - case '\u2018': - return 0xD4; - case '\u2019': - return 0xD5; - case '\u00F7': - return 0xD6; - case '\u05CA': - return 0xD7; - case '\u014D': - return 0xD8; - case '\u0154': - return 0xD9; - case '\u0155': - return 0xDA; - case '\u0158': - return 0xDB; - case '\u2039': - return 0xDC; - case '\u203A': - return 0xDD; - case '\u0159': - return 0xDE; - case '\u0156': - return 0xDF; - case '\u0157': - return 0xE0; - case '\u0160': - return 0xE1; - case '\u201A': - return 0xE2; - case '\u201E': - return 0xE3; - case '\u0161': - return 0xE4; - case '\u015A': - return 0xE5; - case '\u015B': - return 0xE6; - case '\u00C1': - return 0xE7; - case '\u0164': - return 0xE8; - case '\u0165': - return 0xE9; - case '\u00CD': - return 0xEA; - case '\u017D': - return 0xEB; - case '\u017E': - return 0xEC; - case '\u016A': - return 0xED; - case '\u00D3': - return 0xEE; - case '\u00D4': - return 0xEF; - case '\u016B': - return 0xF0; - case '\u016E': - return 0xF1; - case '\u00DA': - return 0xF2; - case '\u016F': - return 0xF3; - case '\u0170': - return 0xF4; - case '\u0171': - return 0xF5; - case '\u0172': - return 0xF6; - case '\u0173': - return 0xF7; - case '\u00DD': - return 0xF8; - case '\u00FD': - return 0xF9; - case '\u0137': - return 0xFA; - case '\u017B': - return 0xFB; - case '\u0141': - return 0xFC; - case '\u017C': - return 0xFD; - case '\u0122': - return 0xFE; - case '\u02C7': - return 0xFF; + switch(character) + { + case '\u0000': return 0x00; + case '\u0001': return 0x01; + case '\u0002': return 0x02; + case '\u0003': return 0x03; + case '\u0004': return 0x04; + case '\u0005': return 0x05; + case '\u0006': return 0x06; + case '\u0007': return 0x07; + case '\u0008': return 0x08; + case '\u0009': return 0x09; + case '\u000A': return 0x0A; + case '\u000B': return 0x0B; + case '\u000C': return 0x0C; + case '\u000D': return 0x0D; + case '\u000E': return 0x0E; + case '\u000F': return 0x0F; + case '\u0010': return 0x10; + case '\u0011': return 0x11; + case '\u0012': return 0x12; + case '\u0013': return 0x13; + case '\u0014': return 0x14; + case '\u0015': return 0x15; + case '\u0016': return 0x16; + case '\u0017': return 0x17; + case '\u0018': return 0x18; + case '\u0019': return 0x19; + case '\u001A': return 0x1A; + case '\u001B': return 0x1B; + case '\u001C': return 0x1C; + case '\u001D': return 0x1D; + case '\u001E': return 0x1E; + case '\u001F': return 0x1F; + case '\u0020': return 0x20; + case '\u0021': return 0x21; + case '\u0022': return 0x22; + case '\u0023': return 0x23; + case '\u0024': return 0x24; + case '\u0025': return 0x25; + case '\u0026': return 0x26; + case '\u0027': return 0x27; + case '\u0028': return 0x28; + case '\u0029': return 0x29; + case '\u002A': return 0x2A; + case '\u002B': return 0x2B; + case '\u002C': return 0x2C; + case '\u002D': return 0x2D; + case '\u002E': return 0x2E; + case '\u002F': return 0x2F; + case '\u0030': return 0x30; + case '\u0031': return 0x31; + case '\u0032': return 0x32; + case '\u0033': return 0x33; + case '\u0034': return 0x34; + case '\u0035': return 0x35; + case '\u0036': return 0x36; + case '\u0037': return 0x37; + case '\u0038': return 0x38; + case '\u0039': return 0x39; + case '\u003A': return 0x3A; + case '\u003B': return 0x3B; + case '\u003C': return 0x3C; + case '\u003D': return 0x3D; + case '\u003E': return 0x3E; + case '\u003F': return 0x3F; + case '\u0040': return 0x40; + case '\u0041': return 0x41; + case '\u0042': return 0x42; + case '\u0043': return 0x43; + case '\u0044': return 0x44; + case '\u0045': return 0x45; + case '\u0046': return 0x46; + case '\u0047': return 0x47; + case '\u0048': return 0x48; + case '\u0049': return 0x49; + case '\u004A': return 0x4A; + case '\u004B': return 0x4B; + case '\u004C': return 0x4C; + case '\u004D': return 0x4D; + case '\u004E': return 0x4E; + case '\u004F': return 0x4F; + case '\u0050': return 0x50; + case '\u0051': return 0x51; + case '\u0052': return 0x52; + case '\u0053': return 0x53; + case '\u0054': return 0x54; + case '\u0055': return 0x55; + case '\u0056': return 0x56; + case '\u0057': return 0x57; + case '\u0058': return 0x58; + case '\u0059': return 0x59; + case '\u005A': return 0x5A; + case '\u005B': return 0x5B; + case '\u005C': return 0x5C; + case '\u005D': return 0x5D; + case '\u005E': return 0x5E; + case '\u005F': return 0x5F; + case '\u0060': return 0x60; + case '\u0061': return 0x61; + case '\u0062': return 0x62; + case '\u0063': return 0x63; + case '\u0064': return 0x64; + case '\u0065': return 0x65; + case '\u0066': return 0x66; + case '\u0067': return 0x67; + case '\u0068': return 0x68; + case '\u0069': return 0x69; + case '\u006A': return 0x6A; + case '\u006B': return 0x6B; + case '\u006C': return 0x6C; + case '\u006D': return 0x6D; + case '\u006E': return 0x6E; + case '\u006F': return 0x6F; + case '\u0070': return 0x70; + case '\u0071': return 0x71; + case '\u0072': return 0x72; + case '\u0073': return 0x73; + case '\u0074': return 0x74; + case '\u0075': return 0x75; + case '\u0076': return 0x76; + case '\u0077': return 0x77; + case '\u0078': return 0x78; + case '\u0079': return 0x79; + case '\u007A': return 0x7A; + case '\u007B': return 0x7B; + case '\u007C': return 0x7C; + case '\u007D': return 0x7D; + case '\u007E': return 0x7E; + case '\u007F': return 0x7F; + case '\u00C4': return 0x80; + case '\u0100': return 0x81; + case '\u0101': return 0x82; + case '\u00C9': return 0x83; + case '\u0104': return 0x84; + case '\u00D6': return 0x85; + case '\u00DC': return 0x86; + case '\u00E1': return 0x87; + case '\u0105': return 0x88; + case '\u010C': return 0x89; + case '\u00E4': return 0x8A; + case '\u010D': return 0x8B; + case '\u0106': return 0x8C; + case '\u0107': return 0x8D; + case '\u00E9': return 0x8E; + case '\u0179': return 0x8F; + case '\u017A': return 0x90; + case '\u010E': return 0x91; + case '\u00ED': return 0x92; + case '\u010F': return 0x93; + case '\u0112': return 0x94; + case '\u0113': return 0x95; + case '\u0116': return 0x96; + case '\u00F3': return 0x97; + case '\u0117': return 0x98; + case '\u00F4': return 0x99; + case '\u00F6': return 0x9A; + case '\u00F5': return 0x9B; + case '\u00FA': return 0x9C; + case '\u011A': return 0x9D; + case '\u011B': return 0x9E; + case '\u00FC': return 0x9F; + case '\u2020': return 0xA0; + case '\u00B0': return 0xA1; + case '\u0118': return 0xA2; + case '\u00A3': return 0xA3; + case '\u00A7': return 0xA4; + case '\u2022': return 0xA5; + case '\u00B6': return 0xA6; + case '\u00DF': return 0xA7; + case '\u00AE': return 0xA8; + case '\u00A9': return 0xA9; + case '\u2122': return 0xAA; + case '\u0119': return 0xAB; + case '\u00A8': return 0xAC; + case '\u2260': return 0xAD; + case '\u0123': return 0xAE; + case '\u012E': return 0xAF; + case '\u012F': return 0xB0; + case '\u012A': return 0xB1; + case '\u2264': return 0xB2; + case '\u2265': return 0xB3; + case '\u012B': return 0xB4; + case '\u0136': return 0xB5; + case '\u2202': return 0xB6; + case '\u2211': return 0xB7; + case '\u0142': return 0xB8; + case '\u013B': return 0xB9; + case '\u013C': return 0xBA; + case '\u013D': return 0xBB; + case '\u013E': return 0xBC; + case '\u0139': return 0xBD; + case '\u013A': return 0xBE; + case '\u0145': return 0xBF; + case '\u0146': return 0xC0; + case '\u0143': return 0xC1; + case '\u00AC': return 0xC2; + case '\u221A': return 0xC3; + case '\u0144': return 0xC4; + case '\u0147': return 0xC5; + case '\u2206': return 0xC6; + case '\u00AB': return 0xC7; + case '\u00BB': return 0xC8; + case '\u2026': return 0xC9; + case '\u00A0': return 0xCA; + case '\u0148': return 0xCB; + case '\u0150': return 0xCC; + case '\u00D5': return 0xCD; + case '\u0151': return 0xCE; + case '\u014C': return 0xCF; + case '\u2013': return 0xD0; + case '\u2014': return 0xD1; + case '\u201C': return 0xD2; + case '\u201D': return 0xD3; + case '\u2018': return 0xD4; + case '\u2019': return 0xD5; + case '\u00F7': return 0xD6; + case '\u05CA': return 0xD7; + case '\u014D': return 0xD8; + case '\u0154': return 0xD9; + case '\u0155': return 0xDA; + case '\u0158': return 0xDB; + case '\u2039': return 0xDC; + case '\u203A': return 0xDD; + case '\u0159': return 0xDE; + case '\u0156': return 0xDF; + case '\u0157': return 0xE0; + case '\u0160': return 0xE1; + case '\u201A': return 0xE2; + case '\u201E': return 0xE3; + case '\u0161': return 0xE4; + case '\u015A': return 0xE5; + case '\u015B': return 0xE6; + case '\u00C1': return 0xE7; + case '\u0164': return 0xE8; + case '\u0165': return 0xE9; + case '\u00CD': return 0xEA; + case '\u017D': return 0xEB; + case '\u017E': return 0xEC; + case '\u016A': return 0xED; + case '\u00D3': return 0xEE; + case '\u00D4': return 0xEF; + case '\u016B': return 0xF0; + case '\u016E': return 0xF1; + case '\u00DA': return 0xF2; + case '\u016F': return 0xF3; + case '\u0170': return 0xF4; + case '\u0171': return 0xF5; + case '\u0172': return 0xF6; + case '\u0173': return 0xF7; + case '\u00DD': return 0xF8; + case '\u00FD': return 0xF9; + case '\u0137': return 0xFA; + case '\u017B': return 0xFB; + case '\u0141': return 0xFC; + case '\u017C': return 0xFD; + case '\u0122': return 0xFE; + case '\u02C7': return 0xFF; default: // Fallback to '?' return 0x3F; diff --git a/Claunia.Encoding/MacCroatian.cs b/Claunia.Encoding/MacCroatian.cs index da6f950..a26b022 100644 --- a/Claunia.Encoding/MacCroatian.cs +++ b/Claunia.Encoding/MacCroatian.cs @@ -29,7 +29,7 @@ using System; namespace Claunia.Encoding { /// - /// Represents an Mac Croatian character encoding of Unicode characters. + /// Represents an Mac Croatian character encoding of Unicode characters. /// public class MacCroatian : Encoding { @@ -48,105 +48,151 @@ namespace Claunia.Encoding const bool singleByte = true; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. + /// The Macintosh Croatian to Unicode character map. /// - public override bool IsBrowserDisplay { - get { return browserDisplay; } - } + static readonly char[] MacCroatianTable = + { + // 0x00 + '\u0000', '\u0001', '\u0002', '\u0003', '\u0004', '\u0005', '\u0006', '\u0007', + // 0x08 + '\u0008', '\u0009', '\u000A', '\u000B', '\u000C', '\u000D', '\u000E', '\u000F', + // 0x10 + '\u0010', '\u0011', '\u0012', '\u0013', '\u0014', '\u0015', '\u0016', '\u0017', + // 0x18 + '\u0018', '\u0019', '\u001A', '\u001B', '\u001C', '\u001D', '\u001E', '\u001F', + // 0x20 + '\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027', + // 0x28 + '\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F', + // 0x30 + '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', + // 0x38 + '\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F', + // 0x40 + '\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047', + // 0x48 + '\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F', + // 0x50 + '\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057', + // 0x58 + '\u0058', '\u0059', '\u005A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F', + // 0x60 + '\u0060', '\u0061', '\u0062', '\u0063', '\u0064', '\u0065', '\u0066', '\u0067', + // 0x68 + '\u0068', '\u0069', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F', + // 0x70 + '\u0070', '\u0071', '\u0072', '\u0073', '\u0074', '\u0075', '\u0076', '\u0077', + // 0x78 + '\u0078', '\u0079', '\u007A', '\u007B', '\u007C', '\u007D', '\u007E', '\u007F', + // 0x80 + '\u00C4', '\u00C5', '\u00C7', '\u00C9', '\u00D1', '\u00D6', '\u00DC', '\u00E1', + // 0x88 + '\u00E0', '\u00E2', '\u00E4', '\u00E3', '\u00E5', '\u00E7', '\u00E9', '\u00E8', + // 0x90 + '\u00EA', '\u00EB', '\u00ED', '\u00EC', '\u00EE', '\u00EF', '\u00F1', '\u00F3', + // 0x98 + '\u00F2', '\u00F4', '\u00F6', '\u00F5', '\u00FA', '\u00F9', '\u00FB', '\u00FC', + // 0xA0 + '\u2020', '\u00B0', '\u00A2', '\u00A3', '\u00A7', '\u2022', '\u00B6', '\u00DF', + // 0xA8 + '\u00AE', '\u0160', '\u2122', '\u00B4', '\u00A8', '\u2260', '\u017D', '\u00D8', + // 0xB0 + '\u221E', '\u00B1', '\u2264', '\u2265', '\u2206', '\u00B5', '\u2202', '\u2211', + // 0xB8 + '\u220F', '\u0161', '\u222B', '\u00AA', '\u00BA', '\u03A9', '\u017E', '\u00F8', + // 0xC0 + '\u00BF', '\u00A1', '\u00AC', '\u221A', '\u0192', '\u2248', '\u0106', '\u00AB', + // 0xC8 + '\u010C', '\u2026', '\u00A0', '\u00C0', '\u00C3', '\u00D5', '\u0152', '\u0153', + // 0xD0 + '\u0110', '\u2014', '\u201C', '\u201D', '\u2018', '\u2019', '\u00F7', '\u25CA', + // 0xD8 + '\uF8FF', '\u00A9', '\u2044', '\u20AC', '\u2039', '\u203A', '\u00C6', '\u00BB', + // 0xE0 + '\u2013', '\u00B7', '\u201A', '\u201E', '\u2030', '\u00C2', '\u0107', '\u00C1', + // 0xE8 + '\u010D', '\u00C8', '\u00CD', '\u00CE', '\u00CF', '\u00CC', '\u00D3', '\u00D4', + // 0xF0 + '\u0111', '\u00D2', '\u00DA', '\u00D8', '\u00D9', '\u0131', '\u02C6', '\u02DC', + // 0xF8 + '\u00AF', '\u03C0', '\u00CB', '\u02DA', '\u00B8', '\u00CA', '\u00E6', '\u02C7' + }; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. + /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. /// - public override bool IsBrowserSave { - get { return browserSave; } - } + public override bool IsBrowserDisplay => browserDisplay; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. + /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. /// - public override bool IsMailNewsDisplay { - get { return mailNewsDisplay; } - } + public override bool IsBrowserSave => browserSave; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. /// - public override bool IsMailNewsSave { - get { return mailNewsSave; } - } + public override bool IsMailNewsDisplay => mailNewsDisplay; /// - /// Gets a value indicating whether the current encoding is read-only. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// + public override bool IsMailNewsSave => mailNewsSave; + + /// + /// Gets a value indicating whether the current encoding is read-only. /// /// The is single byte. - public override bool IsReadOnly { - get { return readOnly; } - } + public override bool IsReadOnly => readOnly; /// - /// Gets a value indicating whether the current encoding uses single-byte code points. + /// Gets a value indicating whether the current encoding uses single-byte code points. /// - public override bool IsSingleByte { - get { return singleByte; } - } + public override bool IsSingleByte => singleByte; /// - /// Gets the code page identifier of the current Encoding. + /// Gets the code page identifier of the current Encoding. /// - public override int CodePage { - get { return _codepage; } - } + public override int CodePage => _codepage; /// - /// Gets a name for the current encoding that can be used with mail agent body tags + /// Gets a name for the current encoding that can be used with mail agent body tags /// - public override string BodyName { - get { return _bodyname; } - } + public override string BodyName => _bodyname; /// - /// Gets a name for the current encoding that can be used with mail agent header tags + /// Gets a name for the current encoding that can be used with mail agent header tags /// - public override string HeaderName { - get { return _headername; } - } + public override string HeaderName => _headername; /// - /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. + /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. /// - public override string WebName { - get { return _webname; } - } + public override string WebName => _webname; /// - /// Gets the human-readable description of the current encoding. + /// Gets the human-readable description of the current encoding. /// - public override string EncodingName { - get { return _encodingname; } - } + public override string EncodingName => _encodingname; /// - /// Gets the Windows operating system code page that most closely corresponds to the current encoding. + /// Gets the Windows operating system code page that most closely corresponds to the current encoding. /// - public override int WindowsCodePage { - get { return _windowsCodepage; } - } + public override int WindowsCodePage => _windowsCodepage; /// - /// Calculates the number of bytes produced by encoding the characters in the specified . + /// Calculates the number of bytes produced by encoding the characters in the specified . /// /// The number of bytes produced by encoding the specified characters. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. public override int GetByteCount(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return s.Length; } /// - /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. + /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. /// /// The number of bytes produced by encoding the specified characters. /// The character array containing the set of characters to encode. @@ -154,36 +200,32 @@ namespace Claunia.Encoding /// The number of characters to encode. public override int GetByteCount(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0 || index >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0 || index >= chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0 || index + count > chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(count < 0 || index + count > chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); return count; } /// - /// Calculates the number of bytes produced by encoding all the characters in the specified character array. + /// Calculates the number of bytes produced by encoding all the characters in the specified character array. /// /// The number of bytes produced by encoding all the characters in the specified character array. /// The character array containing the characters to encode. public override int GetByteCount(char[] chars) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); return chars.Length; } /// - /// Encodes a set of characters from the specified into the specified byte array. + /// Encodes a set of characters from the specified into the specified byte array. /// /// The actual number of bytes written into bytes. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. /// The index of the first character to encode. /// The number of characters to encode. /// The byte array to contain the resulting sequence of bytes. @@ -194,20 +236,19 @@ namespace Claunia.Encoding } /// - /// Encodes all the characters in the specified string into a sequence of bytes. + /// Encodes all the characters in the specified string into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The string containing the characters to encode. public override byte[] GetBytes(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return GetBytes(s.ToCharArray(), 0, s.Length); } /// - /// Encodes a set of characters from the specified character array into the specified byte array. + /// Encodes a set of characters from the specified character array into the specified byte array. /// /// The actual number of bytes written into bytes. /// The character array containing the set of characters to encode. @@ -217,43 +258,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting sequence of bytes. public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount + charIndex > chars.Length) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount + charIndex > chars.Length) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteIndex + charCount > bytes.Length) - throw new ArgumentException(nameof(bytes)); + if(byteIndex + charCount > bytes.Length) throw new ArgumentException(nameof(bytes)); byte[] temp = GetBytes(chars, charIndex, charCount); - for(int i = 0; i < temp.Length; i++) - bytes[i + byteIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) bytes[i + byteIndex] = temp[i]; return charCount; } /// - /// Encodes a set of characters from the specified character array into a sequence of bytes. + /// Encodes a set of characters from the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the set of characters to encode. @@ -261,28 +292,23 @@ namespace Claunia.Encoding /// The number of characters to encode. public override byte[] GetBytes(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > chars.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > chars.Length) throw new ArgumentOutOfRangeException(nameof(count)); byte[] bytes = new byte[count]; - for(int i = 0; i < count; i++) - bytes[i] = GetByte(chars[index + i]); + for(int i = 0; i < count; i++) bytes[i] = GetByte(chars[index + i]); return bytes; } /// - /// Encodes all the characters in the specified character array into a sequence of bytes. + /// Encodes all the characters in the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the characters to encode. @@ -292,7 +318,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. + /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -302,7 +328,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. + /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -310,23 +336,19 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override int GetCharCount(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); return count; } /// - /// Decodes a sequence of bytes from the specified byte array into the specified character array. + /// Decodes a sequence of bytes from the specified byte array into the specified character array. /// /// The actual number of characters written into chars. /// The byte array containing the sequence of bytes to decode. @@ -336,43 +358,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting set of characters. public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount + byteIndex > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount + byteIndex > bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charIndex + byteCount > chars.Length) - throw new ArgumentException(nameof(chars)); + if(charIndex + byteCount > chars.Length) throw new ArgumentException(nameof(chars)); char[] temp = GetChars(bytes, byteIndex, byteCount); - for(int i = 0; i < temp.Length; i++) - chars[i + charIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) chars[i + charIndex] = temp[i]; return byteCount; } /// - /// Decodes all the bytes in the specified byte array into a set of characters. + /// Decodes all the bytes in the specified byte array into a set of characters. /// /// A character array containing the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -382,7 +394,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a set of characters. + /// Decodes a sequence of bytes from the specified byte array into a set of characters. /// /// The chars. /// The byte array containing the sequence of bytes to decode. @@ -390,54 +402,47 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override char[] GetChars(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); char[] chars = new char[count]; - for(int i = 0; i < count; i++) - chars[i] = GetChar(bytes[index + i]); + for(int i = 0; i < count; i++) chars[i] = GetChar(bytes[index + i]); return chars; } /// - /// Calculates the maximum number of bytes produced by encoding the specified number of characters. + /// Calculates the maximum number of bytes produced by encoding the specified number of characters. /// /// The maximum number of bytes produced by encoding the specified number of characters. /// The number of characters to encode. public override int GetMaxByteCount(int charCount) { - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); return charCount; } /// - /// Calculates the maximum number of characters produced by decoding the specified number of bytes. + /// Calculates the maximum number of characters produced by decoding the specified number of bytes. /// /// The maximum number of characters produced by decoding the specified number of bytes. /// The number of bytes to decode. public override int GetMaxCharCount(int byteCount) { - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); return byteCount; } /// - /// Returns a sequence of bytes that specifies the encoding used. + /// Returns a sequence of bytes that specifies the encoding used. /// /// A byte array of length zero, as a preamble is not required. public override byte[] GetPreamble() @@ -446,7 +451,7 @@ namespace Claunia.Encoding } /// - /// Decodes all the bytes in the specified byte array into a string. + /// Decodes all the bytes in the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -456,7 +461,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a string. + /// Decodes a sequence of bytes from the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -468,77 +473,7 @@ namespace Claunia.Encoding } /// - /// The Macintosh Croatian to Unicode character map. - /// - static readonly char[] MacCroatianTable = { - // 0x00 - '\u0000','\u0001','\u0002','\u0003','\u0004','\u0005','\u0006','\u0007', - // 0x08 - '\u0008','\u0009','\u000A','\u000B','\u000C','\u000D','\u000E','\u000F', - // 0x10 - '\u0010','\u0011','\u0012','\u0013','\u0014','\u0015','\u0016','\u0017', - // 0x18 - '\u0018','\u0019','\u001A','\u001B','\u001C','\u001D','\u001E','\u001F', - // 0x20 - '\u0020','\u0021','\u0022','\u0023','\u0024','\u0025','\u0026','\u0027', - // 0x28 - '\u0028','\u0029','\u002A','\u002B','\u002C','\u002D','\u002E','\u002F', - // 0x30 - '\u0030','\u0031','\u0032','\u0033','\u0034','\u0035','\u0036','\u0037', - // 0x38 - '\u0038','\u0039','\u003A','\u003B','\u003C','\u003D','\u003E','\u003F', - // 0x40 - '\u0040','\u0041','\u0042','\u0043','\u0044','\u0045','\u0046','\u0047', - // 0x48 - '\u0048','\u0049','\u004A','\u004B','\u004C','\u004D','\u004E','\u004F', - // 0x50 - '\u0050','\u0051','\u0052','\u0053','\u0054','\u0055','\u0056','\u0057', - // 0x58 - '\u0058','\u0059','\u005A','\u005B','\u005C','\u005D','\u005E','\u005F', - // 0x60 - '\u0060','\u0061','\u0062','\u0063','\u0064','\u0065','\u0066','\u0067', - // 0x68 - '\u0068','\u0069','\u006A','\u006B','\u006C','\u006D','\u006E','\u006F', - // 0x70 - '\u0070','\u0071','\u0072','\u0073','\u0074','\u0075','\u0076','\u0077', - // 0x78 - '\u0078','\u0079','\u007A','\u007B','\u007C','\u007D','\u007E','\u007F', - // 0x80 - '\u00C4','\u00C5','\u00C7','\u00C9','\u00D1','\u00D6','\u00DC','\u00E1', - // 0x88 - '\u00E0','\u00E2','\u00E4','\u00E3','\u00E5','\u00E7','\u00E9','\u00E8', - // 0x90 - '\u00EA','\u00EB','\u00ED','\u00EC','\u00EE','\u00EF','\u00F1','\u00F3', - // 0x98 - '\u00F2','\u00F4','\u00F6','\u00F5','\u00FA','\u00F9','\u00FB','\u00FC', - // 0xA0 - '\u2020','\u00B0','\u00A2','\u00A3','\u00A7','\u2022','\u00B6','\u00DF', - // 0xA8 - '\u00AE','\u0160','\u2122','\u00B4','\u00A8','\u2260','\u017D','\u00D8', - // 0xB0 - '\u221E','\u00B1','\u2264','\u2265','\u2206','\u00B5','\u2202','\u2211', - // 0xB8 - '\u220F','\u0161','\u222B','\u00AA','\u00BA','\u03A9','\u017E','\u00F8', - // 0xC0 - '\u00BF','\u00A1','\u00AC','\u221A','\u0192','\u2248','\u0106','\u00AB', - // 0xC8 - '\u010C','\u2026','\u00A0','\u00C0','\u00C3','\u00D5','\u0152','\u0153', - // 0xD0 - '\u0110','\u2014','\u201C','\u201D','\u2018','\u2019','\u00F7','\u25CA', - // 0xD8 - '\uF8FF','\u00A9','\u2044','\u20AC','\u2039','\u203A','\u00C6','\u00BB', - // 0xE0 - '\u2013','\u00B7','\u201A','\u201E','\u2030','\u00C2','\u0107','\u00C1', - // 0xE8 - '\u010D','\u00C8','\u00CD','\u00CE','\u00CF','\u00CC','\u00D3','\u00D4', - // 0xF0 - '\u0111','\u00D2','\u00DA','\u00D8','\u00D9','\u0131','\u02C6','\u02DC', - // 0xF8 - '\u00AF','\u03C0','\u00CB','\u02DA','\u00B8','\u00CA','\u00E6','\u02C7' - }; - - /// - /// Converts a Mac Croatian character to an Unicode character + /// Converts a Mac Croatian character to an Unicode character /// /// Unicode character. /// Mac Croatian character. @@ -548,525 +483,270 @@ namespace Claunia.Encoding } /// - /// Converts a Unicode character to an Mac Croatian character + /// Converts a Unicode character to an Mac Croatian character /// /// Mac Croatian character. /// Unicode character. static byte GetByte(char character) { - switch(character) { - case '\u0000': - return 0x00; - case '\u0001': - return 0x01; - case '\u0002': - return 0x02; - case '\u0003': - return 0x03; - case '\u0004': - return 0x04; - case '\u0005': - return 0x05; - case '\u0006': - return 0x06; - case '\u0007': - return 0x07; - case '\u0008': - return 0x08; - case '\u0009': - return 0x09; - case '\u000A': - return 0x0A; - case '\u000B': - return 0x0B; - case '\u000C': - return 0x0C; - case '\u000D': - return 0x0D; - case '\u000E': - return 0x0E; - case '\u000F': - return 0x0F; - case '\u0010': - return 0x10; - case '\u0011': - return 0x11; - case '\u0012': - return 0x12; - case '\u0013': - return 0x13; - case '\u0014': - return 0x14; - case '\u0015': - return 0x15; - case '\u0016': - return 0x16; - case '\u0017': - return 0x17; - case '\u0018': - return 0x18; - case '\u0019': - return 0x19; - case '\u001A': - return 0x1A; - case '\u001B': - return 0x1B; - case '\u001C': - return 0x1C; - case '\u001D': - return 0x1D; - case '\u001E': - return 0x1E; - case '\u001F': - return 0x1F; - case '\u0020': - return 0x20; - case '\u0021': - return 0x21; - case '\u0022': - return 0x22; - case '\u0023': - return 0x23; - case '\u0024': - return 0x24; - case '\u0025': - return 0x25; - case '\u0026': - return 0x26; - case '\u0027': - return 0x27; - case '\u0028': - return 0x28; - case '\u0029': - return 0x29; - case '\u002A': - return 0x2A; - case '\u002B': - return 0x2B; - case '\u002C': - return 0x2C; - case '\u002D': - return 0x2D; - case '\u002E': - return 0x2E; - case '\u002F': - return 0x2F; - case '\u0030': - return 0x30; - case '\u0031': - return 0x31; - case '\u0032': - return 0x32; - case '\u0033': - return 0x33; - case '\u0034': - return 0x34; - case '\u0035': - return 0x35; - case '\u0036': - return 0x36; - case '\u0037': - return 0x37; - case '\u0038': - return 0x38; - case '\u0039': - return 0x39; - case '\u003A': - return 0x3A; - case '\u003B': - return 0x3B; - case '\u003C': - return 0x3C; - case '\u003D': - return 0x3D; - case '\u003E': - return 0x3E; - case '\u003F': - return 0x3F; - case '\u0040': - return 0x40; - case '\u0041': - return 0x41; - case '\u0042': - return 0x42; - case '\u0043': - return 0x43; - case '\u0044': - return 0x44; - case '\u0045': - return 0x45; - case '\u0046': - return 0x46; - case '\u0047': - return 0x47; - case '\u0048': - return 0x48; - case '\u0049': - return 0x49; - case '\u004A': - return 0x4A; - case '\u004B': - return 0x4B; - case '\u004C': - return 0x4C; - case '\u004D': - return 0x4D; - case '\u004E': - return 0x4E; - case '\u004F': - return 0x4F; - case '\u0050': - return 0x50; - case '\u0051': - return 0x51; - case '\u0052': - return 0x52; - case '\u0053': - return 0x53; - case '\u0054': - return 0x54; - case '\u0055': - return 0x55; - case '\u0056': - return 0x56; - case '\u0057': - return 0x57; - case '\u0058': - return 0x58; - case '\u0059': - return 0x59; - case '\u005A': - return 0x5A; - case '\u005B': - return 0x5B; - case '\u005C': - return 0x5C; - case '\u005D': - return 0x5D; - case '\u005E': - return 0x5E; - case '\u005F': - return 0x5F; - case '\u0060': - return 0x60; - case '\u0061': - return 0x61; - case '\u0062': - return 0x62; - case '\u0063': - return 0x63; - case '\u0064': - return 0x64; - case '\u0065': - return 0x65; - case '\u0066': - return 0x66; - case '\u0067': - return 0x67; - case '\u0068': - return 0x68; - case '\u0069': - return 0x69; - case '\u006A': - return 0x6A; - case '\u006B': - return 0x6B; - case '\u006C': - return 0x6C; - case '\u006D': - return 0x6D; - case '\u006E': - return 0x6E; - case '\u006F': - return 0x6F; - case '\u0070': - return 0x70; - case '\u0071': - return 0x71; - case '\u0072': - return 0x72; - case '\u0073': - return 0x73; - case '\u0074': - return 0x74; - case '\u0075': - return 0x75; - case '\u0076': - return 0x76; - case '\u0077': - return 0x77; - case '\u0078': - return 0x78; - case '\u0079': - return 0x79; - case '\u007A': - return 0x7A; - case '\u007B': - return 0x7B; - case '\u007C': - return 0x7C; - case '\u007D': - return 0x7D; - case '\u007E': - return 0x7E; - case '\u007F': - return 0x7F; - case '\u00C4': - return 0x80; - case '\u00C5': - return 0x81; - case '\u00C7': - return 0x82; - case '\u00C9': - return 0x83; - case '\u00D1': - return 0x84; - case '\u00D6': - return 0x85; - case '\u00DC': - return 0x86; - case '\u00E1': - return 0x87; - case '\u00E0': - return 0x88; - case '\u00E2': - return 0x89; - case '\u00E4': - return 0x8A; - case '\u00E3': - return 0x8B; - case '\u00E5': - return 0x8C; - case '\u00E7': - return 0x8D; - case '\u00E9': - return 0x8E; - case '\u00E8': - return 0x8F; - case '\u00EA': - return 0x90; - case '\u00EB': - return 0x91; - case '\u00ED': - return 0x92; - case '\u00EC': - return 0x93; - case '\u00EE': - return 0x94; - case '\u00EF': - return 0x95; - case '\u00F1': - return 0x96; - case '\u00F3': - return 0x97; - case '\u00F2': - return 0x98; - case '\u00F4': - return 0x99; - case '\u00F6': - return 0x9A; - case '\u00F5': - return 0x9B; - case '\u00FA': - return 0x9C; - case '\u00F9': - return 0x9D; - case '\u00FB': - return 0x9E; - case '\u00FC': - return 0x9F; - case '\u2020': - return 0xA0; - case '\u00B0': - return 0xA1; - case '\u00A2': - return 0xA2; - case '\u00A3': - return 0xA3; - case '\u00A7': - return 0xA4; - case '\u2022': - return 0xA5; - case '\u00B6': - return 0xA6; - case '\u00DF': - return 0xA7; - case '\u00AE': - return 0xA8; - case '\u0160': - return 0xA9; - case '\u2122': - return 0xAA; - case '\u00B4': - return 0xAB; - case '\u00A8': - return 0xAC; - case '\u2260': - return 0xAD; - case '\u017D': - return 0xAE; - case '\u00D8': - return 0xAF; - case '\u221E': - return 0xB0; - case '\u00B1': - return 0xB1; - case '\u2264': - return 0xB2; - case '\u2265': - return 0xB3; - case '\u2206': - return 0xB4; - case '\u00B5': - return 0xB5; - case '\u2202': - return 0xB6; - case '\u2211': - return 0xB7; - case '\u220F': - return 0xB8; - case '\u0161': - return 0xB9; - case '\u222B': - return 0xBA; - case '\u00AA': - return 0xBB; - case '\u00BA': - return 0xBC; - case '\u03A9': - return 0xBD; - case '\u017E': - return 0xBE; - case '\u00F8': - return 0xBF; - case '\u00BF': - return 0xC0; - case '\u00A1': - return 0xC1; - case '\u00AC': - return 0xC2; - case '\u221A': - return 0xC3; - case '\u0192': - return 0xC4; - case '\u2248': - return 0xC5; - case '\u0106': - return 0xC6; - case '\u00AB': - return 0xC7; - case '\u010C': - return 0xC8; - case '\u2026': - return 0xC9; - case '\u00A0': - return 0xCA; - case '\u00C0': - return 0xCB; - case '\u00C3': - return 0xCC; - case '\u00D5': - return 0xCD; - case '\u0152': - return 0xCE; - case '\u0153': - return 0xCF; - case '\u0110': - return 0xD0; - case '\u2014': - return 0xD1; - case '\u201C': - return 0xD2; - case '\u201D': - return 0xD3; - case '\u2018': - return 0xD4; - case '\u2019': - return 0xD5; - case '\u00F7': - return 0xD6; - case '\u25CA': - return 0xD7; - case '\uF8FF': - return 0xD8; - case '\u00A9': - return 0xD9; - case '\u2044': - return 0xDA; - case '\u20AC': - return 0xDB; - case '\u2039': - return 0xDC; - case '\u203A': - return 0xDD; - case '\u00C6': - return 0xDE; - case '\u00BB': - return 0xDF; - case '\u2013': - return 0xE0; - case '\u00B7': - return 0xE1; - case '\u201A': - return 0xE2; - case '\u201E': - return 0xE3; - case '\u2030': - return 0xE4; - case '\u00C2': - return 0xE5; - case '\u0107': - return 0xE6; - case '\u00C1': - return 0xE7; - case '\u010D': - return 0xE8; - case '\u00C8': - return 0xE9; - case '\u00CD': - return 0xEA; - case '\u00CE': - return 0xEB; - case '\u00CF': - return 0xEC; - case '\u00CC': - return 0xED; - case '\u00D3': - return 0xEE; - case '\u00D4': - return 0xEF; - case '\u0111': - return 0xF0; - case '\u00D2': - return 0xF1; - case '\u00DA': - return 0xF2; - case '\u00DB': - return 0xF3; - case '\u00D9': - return 0xF4; - case '\u0131': - return 0xF5; - case '\u02C6': - return 0xF6; - case '\u02DC': - return 0xF7; - case '\u00AF': - return 0xF8; - case '\u03C0': - return 0xF9; - case '\u00CB': - return 0xFA; - case '\u02DA': - return 0xFB; - case '\u00B8': - return 0xFC; - case '\u00CA': - return 0xFD; - case '\u00E6': - return 0xFE; - case '\u02C7': - return 0xFF; + switch(character) + { + case '\u0000': return 0x00; + case '\u0001': return 0x01; + case '\u0002': return 0x02; + case '\u0003': return 0x03; + case '\u0004': return 0x04; + case '\u0005': return 0x05; + case '\u0006': return 0x06; + case '\u0007': return 0x07; + case '\u0008': return 0x08; + case '\u0009': return 0x09; + case '\u000A': return 0x0A; + case '\u000B': return 0x0B; + case '\u000C': return 0x0C; + case '\u000D': return 0x0D; + case '\u000E': return 0x0E; + case '\u000F': return 0x0F; + case '\u0010': return 0x10; + case '\u0011': return 0x11; + case '\u0012': return 0x12; + case '\u0013': return 0x13; + case '\u0014': return 0x14; + case '\u0015': return 0x15; + case '\u0016': return 0x16; + case '\u0017': return 0x17; + case '\u0018': return 0x18; + case '\u0019': return 0x19; + case '\u001A': return 0x1A; + case '\u001B': return 0x1B; + case '\u001C': return 0x1C; + case '\u001D': return 0x1D; + case '\u001E': return 0x1E; + case '\u001F': return 0x1F; + case '\u0020': return 0x20; + case '\u0021': return 0x21; + case '\u0022': return 0x22; + case '\u0023': return 0x23; + case '\u0024': return 0x24; + case '\u0025': return 0x25; + case '\u0026': return 0x26; + case '\u0027': return 0x27; + case '\u0028': return 0x28; + case '\u0029': return 0x29; + case '\u002A': return 0x2A; + case '\u002B': return 0x2B; + case '\u002C': return 0x2C; + case '\u002D': return 0x2D; + case '\u002E': return 0x2E; + case '\u002F': return 0x2F; + case '\u0030': return 0x30; + case '\u0031': return 0x31; + case '\u0032': return 0x32; + case '\u0033': return 0x33; + case '\u0034': return 0x34; + case '\u0035': return 0x35; + case '\u0036': return 0x36; + case '\u0037': return 0x37; + case '\u0038': return 0x38; + case '\u0039': return 0x39; + case '\u003A': return 0x3A; + case '\u003B': return 0x3B; + case '\u003C': return 0x3C; + case '\u003D': return 0x3D; + case '\u003E': return 0x3E; + case '\u003F': return 0x3F; + case '\u0040': return 0x40; + case '\u0041': return 0x41; + case '\u0042': return 0x42; + case '\u0043': return 0x43; + case '\u0044': return 0x44; + case '\u0045': return 0x45; + case '\u0046': return 0x46; + case '\u0047': return 0x47; + case '\u0048': return 0x48; + case '\u0049': return 0x49; + case '\u004A': return 0x4A; + case '\u004B': return 0x4B; + case '\u004C': return 0x4C; + case '\u004D': return 0x4D; + case '\u004E': return 0x4E; + case '\u004F': return 0x4F; + case '\u0050': return 0x50; + case '\u0051': return 0x51; + case '\u0052': return 0x52; + case '\u0053': return 0x53; + case '\u0054': return 0x54; + case '\u0055': return 0x55; + case '\u0056': return 0x56; + case '\u0057': return 0x57; + case '\u0058': return 0x58; + case '\u0059': return 0x59; + case '\u005A': return 0x5A; + case '\u005B': return 0x5B; + case '\u005C': return 0x5C; + case '\u005D': return 0x5D; + case '\u005E': return 0x5E; + case '\u005F': return 0x5F; + case '\u0060': return 0x60; + case '\u0061': return 0x61; + case '\u0062': return 0x62; + case '\u0063': return 0x63; + case '\u0064': return 0x64; + case '\u0065': return 0x65; + case '\u0066': return 0x66; + case '\u0067': return 0x67; + case '\u0068': return 0x68; + case '\u0069': return 0x69; + case '\u006A': return 0x6A; + case '\u006B': return 0x6B; + case '\u006C': return 0x6C; + case '\u006D': return 0x6D; + case '\u006E': return 0x6E; + case '\u006F': return 0x6F; + case '\u0070': return 0x70; + case '\u0071': return 0x71; + case '\u0072': return 0x72; + case '\u0073': return 0x73; + case '\u0074': return 0x74; + case '\u0075': return 0x75; + case '\u0076': return 0x76; + case '\u0077': return 0x77; + case '\u0078': return 0x78; + case '\u0079': return 0x79; + case '\u007A': return 0x7A; + case '\u007B': return 0x7B; + case '\u007C': return 0x7C; + case '\u007D': return 0x7D; + case '\u007E': return 0x7E; + case '\u007F': return 0x7F; + case '\u00C4': return 0x80; + case '\u00C5': return 0x81; + case '\u00C7': return 0x82; + case '\u00C9': return 0x83; + case '\u00D1': return 0x84; + case '\u00D6': return 0x85; + case '\u00DC': return 0x86; + case '\u00E1': return 0x87; + case '\u00E0': return 0x88; + case '\u00E2': return 0x89; + case '\u00E4': return 0x8A; + case '\u00E3': return 0x8B; + case '\u00E5': return 0x8C; + case '\u00E7': return 0x8D; + case '\u00E9': return 0x8E; + case '\u00E8': return 0x8F; + case '\u00EA': return 0x90; + case '\u00EB': return 0x91; + case '\u00ED': return 0x92; + case '\u00EC': return 0x93; + case '\u00EE': return 0x94; + case '\u00EF': return 0x95; + case '\u00F1': return 0x96; + case '\u00F3': return 0x97; + case '\u00F2': return 0x98; + case '\u00F4': return 0x99; + case '\u00F6': return 0x9A; + case '\u00F5': return 0x9B; + case '\u00FA': return 0x9C; + case '\u00F9': return 0x9D; + case '\u00FB': return 0x9E; + case '\u00FC': return 0x9F; + case '\u2020': return 0xA0; + case '\u00B0': return 0xA1; + case '\u00A2': return 0xA2; + case '\u00A3': return 0xA3; + case '\u00A7': return 0xA4; + case '\u2022': return 0xA5; + case '\u00B6': return 0xA6; + case '\u00DF': return 0xA7; + case '\u00AE': return 0xA8; + case '\u0160': return 0xA9; + case '\u2122': return 0xAA; + case '\u00B4': return 0xAB; + case '\u00A8': return 0xAC; + case '\u2260': return 0xAD; + case '\u017D': return 0xAE; + case '\u00D8': return 0xAF; + case '\u221E': return 0xB0; + case '\u00B1': return 0xB1; + case '\u2264': return 0xB2; + case '\u2265': return 0xB3; + case '\u2206': return 0xB4; + case '\u00B5': return 0xB5; + case '\u2202': return 0xB6; + case '\u2211': return 0xB7; + case '\u220F': return 0xB8; + case '\u0161': return 0xB9; + case '\u222B': return 0xBA; + case '\u00AA': return 0xBB; + case '\u00BA': return 0xBC; + case '\u03A9': return 0xBD; + case '\u017E': return 0xBE; + case '\u00F8': return 0xBF; + case '\u00BF': return 0xC0; + case '\u00A1': return 0xC1; + case '\u00AC': return 0xC2; + case '\u221A': return 0xC3; + case '\u0192': return 0xC4; + case '\u2248': return 0xC5; + case '\u0106': return 0xC6; + case '\u00AB': return 0xC7; + case '\u010C': return 0xC8; + case '\u2026': return 0xC9; + case '\u00A0': return 0xCA; + case '\u00C0': return 0xCB; + case '\u00C3': return 0xCC; + case '\u00D5': return 0xCD; + case '\u0152': return 0xCE; + case '\u0153': return 0xCF; + case '\u0110': return 0xD0; + case '\u2014': return 0xD1; + case '\u201C': return 0xD2; + case '\u201D': return 0xD3; + case '\u2018': return 0xD4; + case '\u2019': return 0xD5; + case '\u00F7': return 0xD6; + case '\u25CA': return 0xD7; + case '\uF8FF': return 0xD8; + case '\u00A9': return 0xD9; + case '\u2044': return 0xDA; + case '\u20AC': return 0xDB; + case '\u2039': return 0xDC; + case '\u203A': return 0xDD; + case '\u00C6': return 0xDE; + case '\u00BB': return 0xDF; + case '\u2013': return 0xE0; + case '\u00B7': return 0xE1; + case '\u201A': return 0xE2; + case '\u201E': return 0xE3; + case '\u2030': return 0xE4; + case '\u00C2': return 0xE5; + case '\u0107': return 0xE6; + case '\u00C1': return 0xE7; + case '\u010D': return 0xE8; + case '\u00C8': return 0xE9; + case '\u00CD': return 0xEA; + case '\u00CE': return 0xEB; + case '\u00CF': return 0xEC; + case '\u00CC': return 0xED; + case '\u00D3': return 0xEE; + case '\u00D4': return 0xEF; + case '\u0111': return 0xF0; + case '\u00D2': return 0xF1; + case '\u00DA': return 0xF2; + case '\u00DB': return 0xF3; + case '\u00D9': return 0xF4; + case '\u0131': return 0xF5; + case '\u02C6': return 0xF6; + case '\u02DC': return 0xF7; + case '\u00AF': return 0xF8; + case '\u03C0': return 0xF9; + case '\u00CB': return 0xFA; + case '\u02DA': return 0xFB; + case '\u00B8': return 0xFC; + case '\u00CA': return 0xFD; + case '\u00E6': return 0xFE; + case '\u02C7': return 0xFF; default: // Fallback to '?' return 0x3F; diff --git a/Claunia.Encoding/MacCyrillic.cs b/Claunia.Encoding/MacCyrillic.cs index 53a087a..ab0c2f3 100644 --- a/Claunia.Encoding/MacCyrillic.cs +++ b/Claunia.Encoding/MacCyrillic.cs @@ -29,7 +29,7 @@ using System; namespace Claunia.Encoding { /// - /// Represents an Mac Cyrillic character encoding of Unicode characters. + /// Represents an Mac Cyrillic character encoding of Unicode characters. /// public class MacCyrillic : Encoding { @@ -48,105 +48,151 @@ namespace Claunia.Encoding const bool singleByte = true; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. + /// The Macintosh Cyrillic to Unicode character map. /// - public override bool IsBrowserDisplay { - get { return browserDisplay; } - } + static readonly char[] MacCyrillicTable = + { + // 0x00 + '\u0000', '\u0001', '\u0002', '\u0003', '\u0004', '\u0005', '\u0006', '\u0007', + // 0x08 + '\u0008', '\u0009', '\u000A', '\u000B', '\u000C', '\u000D', '\u000E', '\u000F', + // 0x10 + '\u0010', '\u0011', '\u0012', '\u0013', '\u0014', '\u0015', '\u0016', '\u0017', + // 0x18 + '\u0018', '\u0019', '\u001A', '\u001B', '\u001C', '\u001D', '\u001E', '\u001F', + // 0x20 + '\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027', + // 0x28 + '\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F', + // 0x30 + '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', + // 0x38 + '\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F', + // 0x40 + '\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047', + // 0x48 + '\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F', + // 0x50 + '\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057', + // 0x58 + '\u0058', '\u0059', '\u005A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F', + // 0x60 + '\u0060', '\u0061', '\u0062', '\u0063', '\u0064', '\u0065', '\u0066', '\u0067', + // 0x68 + '\u0068', '\u0069', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F', + // 0x70 + '\u0070', '\u0071', '\u0072', '\u0073', '\u0074', '\u0075', '\u0076', '\u0077', + // 0x78 + '\u0078', '\u0079', '\u007A', '\u007B', '\u007C', '\u007D', '\u007E', '\u007F', + // 0x80 + '\u0410', '\u0411', '\u0412', '\u0413', '\u0414', '\u0415', '\u0416', '\u0417', + // 0x88 + '\u0418', '\u0419', '\u041A', '\u041B', '\u041C', '\u041D', '\u041E', '\u041F', + // 0x90 + '\u0420', '\u0421', '\u0422', '\u0423', '\u0424', '\u0425', '\u0426', '\u0427', + // 0x98 + '\u0428', '\u0429', '\u042A', '\u042B', '\u042C', '\u042D', '\u042E', '\u042F', + // 0xA0 + '\u2020', '\u00B0', '\u00A2', '\u00A3', '\u00A7', '\u2022', '\u00B6', '\u0406', + // 0xA8 + '\u00AE', '\u00A9', '\u2122', '\u0402', '\u0452', '\u2260', '\u0403', '\u0453', + // 0xB0 + '\u221E', '\u00B1', '\u2264', '\u2265', '\u0456', '\u00B5', '\u2202', '\u0408', + // 0xB8 + '\u0404', '\u0454', '\u0407', '\u0457', '\u0409', '\u0459', '\u040A', '\u045A', + // 0xC0 + '\u0458', '\u0405', '\u00AC', '\u221A', '\u0192', '\u2248', '\u2206', '\u00AB', + // 0xC8 + '\u00BB', '\u2026', '\u00A0', '\u040B', '\u045B', '\u040C', '\u045C', '\u0455', + // 0xD0 + '\u2013', '\u2014', '\u201C', '\u201D', '\u2018', '\u2019', '\u00F7', '\u201E', + // 0xD8 + '\u040E', '\u045E', '\u040F', '\u045F', '\u2116', '\u0401', '\u0451', '\u044F', + // 0xE0 + '\u0430', '\u0431', '\u0432', '\u0433', '\u0434', '\u0435', '\u0436', '\u0437', + // 0xE8 + '\u0438', '\u0439', '\u043A', '\u043B', '\u043C', '\u043D', '\u043E', '\u043F', + // 0xF0 + '\u0440', '\u0441', '\u0442', '\u0443', '\u0444', '\u0445', '\u0446', '\u0447', + // 0xF8 + '\u0448', '\u0449', '\u044A', '\u044B', '\u044C', '\u044D', '\u044E', '\u20AC' + }; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. + /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. /// - public override bool IsBrowserSave { - get { return browserSave; } - } + public override bool IsBrowserDisplay => browserDisplay; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. + /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. /// - public override bool IsMailNewsDisplay { - get { return mailNewsDisplay; } - } + public override bool IsBrowserSave => browserSave; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. /// - public override bool IsMailNewsSave { - get { return mailNewsSave; } - } + public override bool IsMailNewsDisplay => mailNewsDisplay; /// - /// Gets a value indicating whether the current encoding is read-only. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// + public override bool IsMailNewsSave => mailNewsSave; + + /// + /// Gets a value indicating whether the current encoding is read-only. /// /// The is single byte. - public override bool IsReadOnly { - get { return readOnly; } - } + public override bool IsReadOnly => readOnly; /// - /// Gets a value indicating whether the current encoding uses single-byte code points. + /// Gets a value indicating whether the current encoding uses single-byte code points. /// - public override bool IsSingleByte { - get { return singleByte; } - } + public override bool IsSingleByte => singleByte; /// - /// Gets the code page identifier of the current Encoding. + /// Gets the code page identifier of the current Encoding. /// - public override int CodePage { - get { return _codepage; } - } + public override int CodePage => _codepage; /// - /// Gets a name for the current encoding that can be used with mail agent body tags + /// Gets a name for the current encoding that can be used with mail agent body tags /// - public override string BodyName { - get { return _bodyname; } - } + public override string BodyName => _bodyname; /// - /// Gets a name for the current encoding that can be used with mail agent header tags + /// Gets a name for the current encoding that can be used with mail agent header tags /// - public override string HeaderName { - get { return _headername; } - } + public override string HeaderName => _headername; /// - /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. + /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. /// - public override string WebName { - get { return _webname; } - } + public override string WebName => _webname; /// - /// Gets the human-readable description of the current encoding. + /// Gets the human-readable description of the current encoding. /// - public override string EncodingName { - get { return _encodingname; } - } + public override string EncodingName => _encodingname; /// - /// Gets the Windows operating system code page that most closely corresponds to the current encoding. + /// Gets the Windows operating system code page that most closely corresponds to the current encoding. /// - public override int WindowsCodePage { - get { return _windowsCodepage; } - } + public override int WindowsCodePage => _windowsCodepage; /// - /// Calculates the number of bytes produced by encoding the characters in the specified . + /// Calculates the number of bytes produced by encoding the characters in the specified . /// /// The number of bytes produced by encoding the specified characters. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. public override int GetByteCount(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return s.Length; } /// - /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. + /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. /// /// The number of bytes produced by encoding the specified characters. /// The character array containing the set of characters to encode. @@ -154,36 +200,32 @@ namespace Claunia.Encoding /// The number of characters to encode. public override int GetByteCount(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0 || index >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0 || index >= chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0 || index + count > chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(count < 0 || index + count > chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); return count; } /// - /// Calculates the number of bytes produced by encoding all the characters in the specified character array. + /// Calculates the number of bytes produced by encoding all the characters in the specified character array. /// /// The number of bytes produced by encoding all the characters in the specified character array. /// The character array containing the characters to encode. public override int GetByteCount(char[] chars) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); return chars.Length; } /// - /// Encodes a set of characters from the specified into the specified byte array. + /// Encodes a set of characters from the specified into the specified byte array. /// /// The actual number of bytes written into bytes. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. /// The index of the first character to encode. /// The number of characters to encode. /// The byte array to contain the resulting sequence of bytes. @@ -194,20 +236,19 @@ namespace Claunia.Encoding } /// - /// Encodes all the characters in the specified string into a sequence of bytes. + /// Encodes all the characters in the specified string into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The string containing the characters to encode. public override byte[] GetBytes(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return GetBytes(s.ToCharArray(), 0, s.Length); } /// - /// Encodes a set of characters from the specified character array into the specified byte array. + /// Encodes a set of characters from the specified character array into the specified byte array. /// /// The actual number of bytes written into bytes. /// The character array containing the set of characters to encode. @@ -217,43 +258,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting sequence of bytes. public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount + charIndex > chars.Length) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount + charIndex > chars.Length) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteIndex + charCount > bytes.Length) - throw new ArgumentException(nameof(bytes)); + if(byteIndex + charCount > bytes.Length) throw new ArgumentException(nameof(bytes)); byte[] temp = GetBytes(chars, charIndex, charCount); - for(int i = 0; i < temp.Length; i++) - bytes[i + byteIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) bytes[i + byteIndex] = temp[i]; return charCount; } /// - /// Encodes a set of characters from the specified character array into a sequence of bytes. + /// Encodes a set of characters from the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the set of characters to encode. @@ -261,28 +292,23 @@ namespace Claunia.Encoding /// The number of characters to encode. public override byte[] GetBytes(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > chars.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > chars.Length) throw new ArgumentOutOfRangeException(nameof(count)); byte[] bytes = new byte[count]; - for(int i = 0; i < count; i++) - bytes[i] = GetByte(chars[index + i]); + for(int i = 0; i < count; i++) bytes[i] = GetByte(chars[index + i]); return bytes; } /// - /// Encodes all the characters in the specified character array into a sequence of bytes. + /// Encodes all the characters in the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the characters to encode. @@ -292,7 +318,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. + /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -302,7 +328,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. + /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -310,23 +336,19 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override int GetCharCount(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); return count; } /// - /// Decodes a sequence of bytes from the specified byte array into the specified character array. + /// Decodes a sequence of bytes from the specified byte array into the specified character array. /// /// The actual number of characters written into chars. /// The byte array containing the sequence of bytes to decode. @@ -336,43 +358,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting set of characters. public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount + byteIndex > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount + byteIndex > bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charIndex + byteCount > chars.Length) - throw new ArgumentException(nameof(chars)); + if(charIndex + byteCount > chars.Length) throw new ArgumentException(nameof(chars)); char[] temp = GetChars(bytes, byteIndex, byteCount); - for(int i = 0; i < temp.Length; i++) - chars[i + charIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) chars[i + charIndex] = temp[i]; return byteCount; } /// - /// Decodes all the bytes in the specified byte array into a set of characters. + /// Decodes all the bytes in the specified byte array into a set of characters. /// /// A character array containing the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -382,7 +394,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a set of characters. + /// Decodes a sequence of bytes from the specified byte array into a set of characters. /// /// The chars. /// The byte array containing the sequence of bytes to decode. @@ -390,54 +402,47 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override char[] GetChars(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); char[] chars = new char[count]; - for(int i = 0; i < count; i++) - chars[i] = GetChar(bytes[index + i]); + for(int i = 0; i < count; i++) chars[i] = GetChar(bytes[index + i]); return chars; } /// - /// Calculates the maximum number of bytes produced by encoding the specified number of characters. + /// Calculates the maximum number of bytes produced by encoding the specified number of characters. /// /// The maximum number of bytes produced by encoding the specified number of characters. /// The number of characters to encode. public override int GetMaxByteCount(int charCount) { - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); return charCount; } /// - /// Calculates the maximum number of characters produced by decoding the specified number of bytes. + /// Calculates the maximum number of characters produced by decoding the specified number of bytes. /// /// The maximum number of characters produced by decoding the specified number of bytes. /// The number of bytes to decode. public override int GetMaxCharCount(int byteCount) { - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); return byteCount; } /// - /// Returns a sequence of bytes that specifies the encoding used. + /// Returns a sequence of bytes that specifies the encoding used. /// /// A byte array of length zero, as a preamble is not required. public override byte[] GetPreamble() @@ -446,7 +451,7 @@ namespace Claunia.Encoding } /// - /// Decodes all the bytes in the specified byte array into a string. + /// Decodes all the bytes in the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -456,7 +461,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a string. + /// Decodes a sequence of bytes from the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -468,77 +473,7 @@ namespace Claunia.Encoding } /// - /// The Macintosh Cyrillic to Unicode character map. - /// - static readonly char[] MacCyrillicTable = { - // 0x00 - '\u0000','\u0001','\u0002','\u0003','\u0004','\u0005','\u0006','\u0007', - // 0x08 - '\u0008','\u0009','\u000A','\u000B','\u000C','\u000D','\u000E','\u000F', - // 0x10 - '\u0010','\u0011','\u0012','\u0013','\u0014','\u0015','\u0016','\u0017', - // 0x18 - '\u0018','\u0019','\u001A','\u001B','\u001C','\u001D','\u001E','\u001F', - // 0x20 - '\u0020','\u0021','\u0022','\u0023','\u0024','\u0025','\u0026','\u0027', - // 0x28 - '\u0028','\u0029','\u002A','\u002B','\u002C','\u002D','\u002E','\u002F', - // 0x30 - '\u0030','\u0031','\u0032','\u0033','\u0034','\u0035','\u0036','\u0037', - // 0x38 - '\u0038','\u0039','\u003A','\u003B','\u003C','\u003D','\u003E','\u003F', - // 0x40 - '\u0040','\u0041','\u0042','\u0043','\u0044','\u0045','\u0046','\u0047', - // 0x48 - '\u0048','\u0049','\u004A','\u004B','\u004C','\u004D','\u004E','\u004F', - // 0x50 - '\u0050','\u0051','\u0052','\u0053','\u0054','\u0055','\u0056','\u0057', - // 0x58 - '\u0058','\u0059','\u005A','\u005B','\u005C','\u005D','\u005E','\u005F', - // 0x60 - '\u0060','\u0061','\u0062','\u0063','\u0064','\u0065','\u0066','\u0067', - // 0x68 - '\u0068','\u0069','\u006A','\u006B','\u006C','\u006D','\u006E','\u006F', - // 0x70 - '\u0070','\u0071','\u0072','\u0073','\u0074','\u0075','\u0076','\u0077', - // 0x78 - '\u0078','\u0079','\u007A','\u007B','\u007C','\u007D','\u007E','\u007F', - // 0x80 - '\u0410','\u0411','\u0412','\u0413','\u0414','\u0415','\u0416','\u0417', - // 0x88 - '\u0418','\u0419','\u041A','\u041B','\u041C','\u041D','\u041E','\u041F', - // 0x90 - '\u0420','\u0421','\u0422','\u0423','\u0424','\u0425','\u0426','\u0427', - // 0x98 - '\u0428','\u0429','\u042A','\u042B','\u042C','\u042D','\u042E','\u042F', - // 0xA0 - '\u2020','\u00B0','\u00A2','\u00A3','\u00A7','\u2022','\u00B6','\u0406', - // 0xA8 - '\u00AE','\u00A9','\u2122','\u0402','\u0452','\u2260','\u0403','\u0453', - // 0xB0 - '\u221E','\u00B1','\u2264','\u2265','\u0456','\u00B5','\u2202','\u0408', - // 0xB8 - '\u0404','\u0454','\u0407','\u0457','\u0409','\u0459','\u040A','\u045A', - // 0xC0 - '\u0458','\u0405','\u00AC','\u221A','\u0192','\u2248','\u2206','\u00AB', - // 0xC8 - '\u00BB','\u2026','\u00A0','\u040B','\u045B','\u040C','\u045C','\u0455', - // 0xD0 - '\u2013','\u2014','\u201C','\u201D','\u2018','\u2019','\u00F7','\u201E', - // 0xD8 - '\u040E','\u045E','\u040F','\u045F','\u2116','\u0401','\u0451','\u044F', - // 0xE0 - '\u0430','\u0431','\u0432','\u0433','\u0434','\u0435','\u0436','\u0437', - // 0xE8 - '\u0438','\u0439','\u043A','\u043B','\u043C','\u043D','\u043E','\u043F', - // 0xF0 - '\u0440','\u0441','\u0442','\u0443','\u0444','\u0445','\u0446','\u0447', - // 0xF8 - '\u0448','\u0449','\u044A','\u044B','\u044C','\u044D','\u044E','\u20AC' - }; - - /// - /// Converts a Mac Cyrillic character to an Unicode character + /// Converts a Mac Cyrillic character to an Unicode character /// /// Unicode character. /// Mac Cyrillic character. @@ -548,525 +483,270 @@ namespace Claunia.Encoding } /// - /// Converts a Unicode character to an Mac Cyrillic character + /// Converts a Unicode character to an Mac Cyrillic character /// /// Mac Cyrillic character. /// Unicode character. static byte GetByte(char character) { - switch(character) { - case '\u0000': - return 0x00; - case '\u0001': - return 0x01; - case '\u0002': - return 0x02; - case '\u0003': - return 0x03; - case '\u0004': - return 0x04; - case '\u0005': - return 0x05; - case '\u0006': - return 0x06; - case '\u0007': - return 0x07; - case '\u0008': - return 0x08; - case '\u0009': - return 0x09; - case '\u000A': - return 0x0A; - case '\u000B': - return 0x0B; - case '\u000C': - return 0x0C; - case '\u000D': - return 0x0D; - case '\u000E': - return 0x0E; - case '\u000F': - return 0x0F; - case '\u0010': - return 0x10; - case '\u0011': - return 0x11; - case '\u0012': - return 0x12; - case '\u0013': - return 0x13; - case '\u0014': - return 0x14; - case '\u0015': - return 0x15; - case '\u0016': - return 0x16; - case '\u0017': - return 0x17; - case '\u0018': - return 0x18; - case '\u0019': - return 0x19; - case '\u001A': - return 0x1A; - case '\u001B': - return 0x1B; - case '\u001C': - return 0x1C; - case '\u001D': - return 0x1D; - case '\u001E': - return 0x1E; - case '\u001F': - return 0x1F; - case '\u0020': - return 0x20; - case '\u0021': - return 0x21; - case '\u0022': - return 0x22; - case '\u0023': - return 0x23; - case '\u0024': - return 0x24; - case '\u0025': - return 0x25; - case '\u0026': - return 0x26; - case '\u0027': - return 0x27; - case '\u0028': - return 0x28; - case '\u0029': - return 0x29; - case '\u002A': - return 0x2A; - case '\u002B': - return 0x2B; - case '\u002C': - return 0x2C; - case '\u002D': - return 0x2D; - case '\u002E': - return 0x2E; - case '\u002F': - return 0x2F; - case '\u0030': - return 0x30; - case '\u0031': - return 0x31; - case '\u0032': - return 0x32; - case '\u0033': - return 0x33; - case '\u0034': - return 0x34; - case '\u0035': - return 0x35; - case '\u0036': - return 0x36; - case '\u0037': - return 0x37; - case '\u0038': - return 0x38; - case '\u0039': - return 0x39; - case '\u003A': - return 0x3A; - case '\u003B': - return 0x3B; - case '\u003C': - return 0x3C; - case '\u003D': - return 0x3D; - case '\u003E': - return 0x3E; - case '\u003F': - return 0x3F; - case '\u0040': - return 0x40; - case '\u0041': - return 0x41; - case '\u0042': - return 0x42; - case '\u0043': - return 0x43; - case '\u0044': - return 0x44; - case '\u0045': - return 0x45; - case '\u0046': - return 0x46; - case '\u0047': - return 0x47; - case '\u0048': - return 0x48; - case '\u0049': - return 0x49; - case '\u004A': - return 0x4A; - case '\u004B': - return 0x4B; - case '\u004C': - return 0x4C; - case '\u004D': - return 0x4D; - case '\u004E': - return 0x4E; - case '\u004F': - return 0x4F; - case '\u0050': - return 0x50; - case '\u0051': - return 0x51; - case '\u0052': - return 0x52; - case '\u0053': - return 0x53; - case '\u0054': - return 0x54; - case '\u0055': - return 0x55; - case '\u0056': - return 0x56; - case '\u0057': - return 0x57; - case '\u0058': - return 0x58; - case '\u0059': - return 0x59; - case '\u005A': - return 0x5A; - case '\u005B': - return 0x5B; - case '\u005C': - return 0x5C; - case '\u005D': - return 0x5D; - case '\u005E': - return 0x5E; - case '\u005F': - return 0x5F; - case '\u0060': - return 0x60; - case '\u0061': - return 0x61; - case '\u0062': - return 0x62; - case '\u0063': - return 0x63; - case '\u0064': - return 0x64; - case '\u0065': - return 0x65; - case '\u0066': - return 0x66; - case '\u0067': - return 0x67; - case '\u0068': - return 0x68; - case '\u0069': - return 0x69; - case '\u006A': - return 0x6A; - case '\u006B': - return 0x6B; - case '\u006C': - return 0x6C; - case '\u006D': - return 0x6D; - case '\u006E': - return 0x6E; - case '\u006F': - return 0x6F; - case '\u0070': - return 0x70; - case '\u0071': - return 0x71; - case '\u0072': - return 0x72; - case '\u0073': - return 0x73; - case '\u0074': - return 0x74; - case '\u0075': - return 0x75; - case '\u0076': - return 0x76; - case '\u0077': - return 0x77; - case '\u0078': - return 0x78; - case '\u0079': - return 0x79; - case '\u007A': - return 0x7A; - case '\u007B': - return 0x7B; - case '\u007C': - return 0x7C; - case '\u007D': - return 0x7D; - case '\u007E': - return 0x7E; - case '\u007F': - return 0x7F; - case '\u0410': - return 0x80; - case '\u0411': - return 0x81; - case '\u0412': - return 0x82; - case '\u0413': - return 0x83; - case '\u0414': - return 0x84; - case '\u0415': - return 0x85; - case '\u0416': - return 0x86; - case '\u0417': - return 0x87; - case '\u0418': - return 0x88; - case '\u0419': - return 0x89; - case '\u041A': - return 0x8A; - case '\u041B': - return 0x8B; - case '\u041C': - return 0x8C; - case '\u041D': - return 0x8D; - case '\u041E': - return 0x8E; - case '\u041F': - return 0x8F; - case '\u0420': - return 0x90; - case '\u0421': - return 0x91; - case '\u0422': - return 0x92; - case '\u0423': - return 0x93; - case '\u0424': - return 0x94; - case '\u0425': - return 0x95; - case '\u0426': - return 0x96; - case '\u0427': - return 0x97; - case '\u0428': - return 0x98; - case '\u0429': - return 0x99; - case '\u042A': - return 0x9A; - case '\u042B': - return 0x9B; - case '\u042C': - return 0x9C; - case '\u042D': - return 0x9D; - case '\u042E': - return 0x9E; - case '\u042F': - return 0x9F; - case '\u2020': - return 0xA0; - case '\u00B0': - return 0xA1; - case '\u0490': - return 0xA2; - case '\u00A3': - return 0xA3; - case '\u00A7': - return 0xA4; - case '\u2022': - return 0xA5; - case '\u00B6': - return 0xA6; - case '\u0406': - return 0xA7; - case '\u00AE': - return 0xA8; - case '\u00A9': - return 0xA9; - case '\u2122': - return 0xAA; - case '\u0402': - return 0xAB; - case '\u0452': - return 0xAC; - case '\u2260': - return 0xAD; - case '\u0403': - return 0xAE; - case '\u0453': - return 0xAF; - case '\u221E': - return 0xB0; - case '\u00B1': - return 0xB1; - case '\u2264': - return 0xB2; - case '\u2265': - return 0xB3; - case '\u0456': - return 0xB4; - case '\u00B5': - return 0xB5; - case '\u0491': - return 0xB6; - case '\u0408': - return 0xB7; - case '\u0404': - return 0xB8; - case '\u0454': - return 0xB9; - case '\u0407': - return 0xBA; - case '\u0457': - return 0xBB; - case '\u0409': - return 0xBC; - case '\u0459': - return 0xBD; - case '\u040A': - return 0xBE; - case '\u045A': - return 0xBF; - case '\u0458': - return 0xC0; - case '\u0405': - return 0xC1; - case '\u00AC': - return 0xC2; - case '\u221A': - return 0xC3; - case '\u0192': - return 0xC4; - case '\u2248': - return 0xC5; - case '\u2206': - return 0xC6; - case '\u00AB': - return 0xC7; - case '\u00BB': - return 0xC8; - case '\u2026': - return 0xC9; - case '\u00A0': - return 0xCA; - case '\u040B': - return 0xCB; - case '\u045B': - return 0xCC; - case '\u040C': - return 0xCD; - case '\u045C': - return 0xCE; - case '\u0455': - return 0xCF; - case '\u2013': - return 0xD0; - case '\u2014': - return 0xD1; - case '\u201C': - return 0xD2; - case '\u201D': - return 0xD3; - case '\u2018': - return 0xD4; - case '\u2019': - return 0xD5; - case '\u00F7': - return 0xD6; - case '\u201E': - return 0xD7; - case '\u040E': - return 0xD8; - case '\u045E': - return 0xD9; - case '\u040F': - return 0xDA; - case '\u045F': - return 0xDB; - case '\u2116': - return 0xDC; - case '\u0401': - return 0xDD; - case '\u0451': - return 0xDE; - case '\u044F': - return 0xDF; - case '\u0430': - return 0xE0; - case '\u0431': - return 0xE1; - case '\u0432': - return 0xE2; - case '\u0433': - return 0xE3; - case '\u0434': - return 0xE4; - case '\u0435': - return 0xE5; - case '\u0436': - return 0xE6; - case '\u0437': - return 0xE7; - case '\u0438': - return 0xE8; - case '\u0439': - return 0xE9; - case '\u043A': - return 0xEA; - case '\u043B': - return 0xEB; - case '\u043C': - return 0xEC; - case '\u043D': - return 0xED; - case '\u043E': - return 0xEE; - case '\u043F': - return 0xEF; - case '\u0440': - return 0xF0; - case '\u0441': - return 0xF1; - case '\u0442': - return 0xF2; - case '\u0443': - return 0xF3; - case '\u0444': - return 0xF4; - case '\u0445': - return 0xF5; - case '\u0446': - return 0xF6; - case '\u0447': - return 0xF7; - case '\u0448': - return 0xF8; - case '\u0449': - return 0xF9; - case '\u044A': - return 0xFA; - case '\u044B': - return 0xFB; - case '\u044C': - return 0xFC; - case '\u044D': - return 0xFD; - case '\u044E': - return 0xFE; - case '\u20AC': - return 0xFF; + switch(character) + { + case '\u0000': return 0x00; + case '\u0001': return 0x01; + case '\u0002': return 0x02; + case '\u0003': return 0x03; + case '\u0004': return 0x04; + case '\u0005': return 0x05; + case '\u0006': return 0x06; + case '\u0007': return 0x07; + case '\u0008': return 0x08; + case '\u0009': return 0x09; + case '\u000A': return 0x0A; + case '\u000B': return 0x0B; + case '\u000C': return 0x0C; + case '\u000D': return 0x0D; + case '\u000E': return 0x0E; + case '\u000F': return 0x0F; + case '\u0010': return 0x10; + case '\u0011': return 0x11; + case '\u0012': return 0x12; + case '\u0013': return 0x13; + case '\u0014': return 0x14; + case '\u0015': return 0x15; + case '\u0016': return 0x16; + case '\u0017': return 0x17; + case '\u0018': return 0x18; + case '\u0019': return 0x19; + case '\u001A': return 0x1A; + case '\u001B': return 0x1B; + case '\u001C': return 0x1C; + case '\u001D': return 0x1D; + case '\u001E': return 0x1E; + case '\u001F': return 0x1F; + case '\u0020': return 0x20; + case '\u0021': return 0x21; + case '\u0022': return 0x22; + case '\u0023': return 0x23; + case '\u0024': return 0x24; + case '\u0025': return 0x25; + case '\u0026': return 0x26; + case '\u0027': return 0x27; + case '\u0028': return 0x28; + case '\u0029': return 0x29; + case '\u002A': return 0x2A; + case '\u002B': return 0x2B; + case '\u002C': return 0x2C; + case '\u002D': return 0x2D; + case '\u002E': return 0x2E; + case '\u002F': return 0x2F; + case '\u0030': return 0x30; + case '\u0031': return 0x31; + case '\u0032': return 0x32; + case '\u0033': return 0x33; + case '\u0034': return 0x34; + case '\u0035': return 0x35; + case '\u0036': return 0x36; + case '\u0037': return 0x37; + case '\u0038': return 0x38; + case '\u0039': return 0x39; + case '\u003A': return 0x3A; + case '\u003B': return 0x3B; + case '\u003C': return 0x3C; + case '\u003D': return 0x3D; + case '\u003E': return 0x3E; + case '\u003F': return 0x3F; + case '\u0040': return 0x40; + case '\u0041': return 0x41; + case '\u0042': return 0x42; + case '\u0043': return 0x43; + case '\u0044': return 0x44; + case '\u0045': return 0x45; + case '\u0046': return 0x46; + case '\u0047': return 0x47; + case '\u0048': return 0x48; + case '\u0049': return 0x49; + case '\u004A': return 0x4A; + case '\u004B': return 0x4B; + case '\u004C': return 0x4C; + case '\u004D': return 0x4D; + case '\u004E': return 0x4E; + case '\u004F': return 0x4F; + case '\u0050': return 0x50; + case '\u0051': return 0x51; + case '\u0052': return 0x52; + case '\u0053': return 0x53; + case '\u0054': return 0x54; + case '\u0055': return 0x55; + case '\u0056': return 0x56; + case '\u0057': return 0x57; + case '\u0058': return 0x58; + case '\u0059': return 0x59; + case '\u005A': return 0x5A; + case '\u005B': return 0x5B; + case '\u005C': return 0x5C; + case '\u005D': return 0x5D; + case '\u005E': return 0x5E; + case '\u005F': return 0x5F; + case '\u0060': return 0x60; + case '\u0061': return 0x61; + case '\u0062': return 0x62; + case '\u0063': return 0x63; + case '\u0064': return 0x64; + case '\u0065': return 0x65; + case '\u0066': return 0x66; + case '\u0067': return 0x67; + case '\u0068': return 0x68; + case '\u0069': return 0x69; + case '\u006A': return 0x6A; + case '\u006B': return 0x6B; + case '\u006C': return 0x6C; + case '\u006D': return 0x6D; + case '\u006E': return 0x6E; + case '\u006F': return 0x6F; + case '\u0070': return 0x70; + case '\u0071': return 0x71; + case '\u0072': return 0x72; + case '\u0073': return 0x73; + case '\u0074': return 0x74; + case '\u0075': return 0x75; + case '\u0076': return 0x76; + case '\u0077': return 0x77; + case '\u0078': return 0x78; + case '\u0079': return 0x79; + case '\u007A': return 0x7A; + case '\u007B': return 0x7B; + case '\u007C': return 0x7C; + case '\u007D': return 0x7D; + case '\u007E': return 0x7E; + case '\u007F': return 0x7F; + case '\u0410': return 0x80; + case '\u0411': return 0x81; + case '\u0412': return 0x82; + case '\u0413': return 0x83; + case '\u0414': return 0x84; + case '\u0415': return 0x85; + case '\u0416': return 0x86; + case '\u0417': return 0x87; + case '\u0418': return 0x88; + case '\u0419': return 0x89; + case '\u041A': return 0x8A; + case '\u041B': return 0x8B; + case '\u041C': return 0x8C; + case '\u041D': return 0x8D; + case '\u041E': return 0x8E; + case '\u041F': return 0x8F; + case '\u0420': return 0x90; + case '\u0421': return 0x91; + case '\u0422': return 0x92; + case '\u0423': return 0x93; + case '\u0424': return 0x94; + case '\u0425': return 0x95; + case '\u0426': return 0x96; + case '\u0427': return 0x97; + case '\u0428': return 0x98; + case '\u0429': return 0x99; + case '\u042A': return 0x9A; + case '\u042B': return 0x9B; + case '\u042C': return 0x9C; + case '\u042D': return 0x9D; + case '\u042E': return 0x9E; + case '\u042F': return 0x9F; + case '\u2020': return 0xA0; + case '\u00B0': return 0xA1; + case '\u0490': return 0xA2; + case '\u00A3': return 0xA3; + case '\u00A7': return 0xA4; + case '\u2022': return 0xA5; + case '\u00B6': return 0xA6; + case '\u0406': return 0xA7; + case '\u00AE': return 0xA8; + case '\u00A9': return 0xA9; + case '\u2122': return 0xAA; + case '\u0402': return 0xAB; + case '\u0452': return 0xAC; + case '\u2260': return 0xAD; + case '\u0403': return 0xAE; + case '\u0453': return 0xAF; + case '\u221E': return 0xB0; + case '\u00B1': return 0xB1; + case '\u2264': return 0xB2; + case '\u2265': return 0xB3; + case '\u0456': return 0xB4; + case '\u00B5': return 0xB5; + case '\u0491': return 0xB6; + case '\u0408': return 0xB7; + case '\u0404': return 0xB8; + case '\u0454': return 0xB9; + case '\u0407': return 0xBA; + case '\u0457': return 0xBB; + case '\u0409': return 0xBC; + case '\u0459': return 0xBD; + case '\u040A': return 0xBE; + case '\u045A': return 0xBF; + case '\u0458': return 0xC0; + case '\u0405': return 0xC1; + case '\u00AC': return 0xC2; + case '\u221A': return 0xC3; + case '\u0192': return 0xC4; + case '\u2248': return 0xC5; + case '\u2206': return 0xC6; + case '\u00AB': return 0xC7; + case '\u00BB': return 0xC8; + case '\u2026': return 0xC9; + case '\u00A0': return 0xCA; + case '\u040B': return 0xCB; + case '\u045B': return 0xCC; + case '\u040C': return 0xCD; + case '\u045C': return 0xCE; + case '\u0455': return 0xCF; + case '\u2013': return 0xD0; + case '\u2014': return 0xD1; + case '\u201C': return 0xD2; + case '\u201D': return 0xD3; + case '\u2018': return 0xD4; + case '\u2019': return 0xD5; + case '\u00F7': return 0xD6; + case '\u201E': return 0xD7; + case '\u040E': return 0xD8; + case '\u045E': return 0xD9; + case '\u040F': return 0xDA; + case '\u045F': return 0xDB; + case '\u2116': return 0xDC; + case '\u0401': return 0xDD; + case '\u0451': return 0xDE; + case '\u044F': return 0xDF; + case '\u0430': return 0xE0; + case '\u0431': return 0xE1; + case '\u0432': return 0xE2; + case '\u0433': return 0xE3; + case '\u0434': return 0xE4; + case '\u0435': return 0xE5; + case '\u0436': return 0xE6; + case '\u0437': return 0xE7; + case '\u0438': return 0xE8; + case '\u0439': return 0xE9; + case '\u043A': return 0xEA; + case '\u043B': return 0xEB; + case '\u043C': return 0xEC; + case '\u043D': return 0xED; + case '\u043E': return 0xEE; + case '\u043F': return 0xEF; + case '\u0440': return 0xF0; + case '\u0441': return 0xF1; + case '\u0442': return 0xF2; + case '\u0443': return 0xF3; + case '\u0444': return 0xF4; + case '\u0445': return 0xF5; + case '\u0446': return 0xF6; + case '\u0447': return 0xF7; + case '\u0448': return 0xF8; + case '\u0449': return 0xF9; + case '\u044A': return 0xFA; + case '\u044B': return 0xFB; + case '\u044C': return 0xFC; + case '\u044D': return 0xFD; + case '\u044E': return 0xFE; + case '\u20AC': return 0xFF; default: // Fallback to '?' return 0x3F; diff --git a/Claunia.Encoding/MacFarsi.cs b/Claunia.Encoding/MacFarsi.cs index 499168a..bc1080e 100644 --- a/Claunia.Encoding/MacFarsi.cs +++ b/Claunia.Encoding/MacFarsi.cs @@ -29,7 +29,7 @@ using System; namespace Claunia.Encoding { /// - /// Represents an Mac Farsi character encoding of Unicode characters. + /// Represents an Mac Farsi character encoding of Unicode characters. /// public class MacFarsi : Encoding { @@ -48,105 +48,151 @@ namespace Claunia.Encoding const bool singleByte = true; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. + /// The Macintosh Farsi to Unicode character map. /// - public override bool IsBrowserDisplay { - get { return browserDisplay; } - } + static readonly char[] MacFarsiTable = + { + // 0x00 + '\u0000', '\u0001', '\u0002', '\u0003', '\u0004', '\u0005', '\u0006', '\u0007', + // 0x08 + '\u0008', '\u0009', '\u000A', '\u000B', '\u000C', '\u000D', '\u000E', '\u000F', + // 0x10 + '\u0010', '\u0011', '\u0012', '\u0013', '\u0014', '\u0015', '\u0016', '\u0017', + // 0x18 + '\u0018', '\u0019', '\u001A', '\u001B', '\u001C', '\u001D', '\u001E', '\u001F', + // 0x20 + '\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027', + // 0x28 + '\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F', + // 0x30 + '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', + // 0x38 + '\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F', + // 0x40 + '\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047', + // 0x48 + '\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F', + // 0x50 + '\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057', + // 0x58 + '\u0058', '\u0059', '\u005A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F', + // 0x60 + '\u0060', '\u0061', '\u0062', '\u0063', '\u0064', '\u0065', '\u0066', '\u0067', + // 0x68 + '\u0068', '\u0069', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F', + // 0x70 + '\u0070', '\u0071', '\u0072', '\u0073', '\u0074', '\u0075', '\u0076', '\u0077', + // 0x78 + '\u0078', '\u0079', '\u007A', '\u007B', '\u007C', '\u007D', '\u007E', '\u007F', + // 0x80 + '\u00C4', '\u00A0', '\u00C7', '\u00C9', '\u00D1', '\u00D6', '\u00DC', '\u00E1', + // 0x88 + '\u00E0', '\u00E2', '\u00E4', '\u06BA', '\u00AB', '\u00E7', '\u00E9', '\u00E8', + // 0x90 + '\u00EA', '\u00EB', '\u00ED', '\u2026', '\u00EE', '\u00EF', '\u00F1', '\u00F3', + // 0x98 + '\u00BB', '\u00F4', '\u00F6', '\u00F7', '\u00FA', '\u00F9', '\u00FB', '\u00FC', + // 0xA0 + '\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u066A', '\u0026', '\u0027', + // 0xA8 + '\u0028', '\u0029', '\u002A', '\u002B', '\u060C', '\u002D', '\u002E', '\u002F', + // 0xB0 + '\u06F0', '\u06F1', '\u06F2', '\u06F3', '\u06F4', '\u06F5', '\u06F6', '\u06F7', + // 0xB8 + '\u06F8', '\u06F9', '\u003A', '\u061B', '\u003C', '\u003D', '\u003E', '\u061F', + // 0xC0 + '\u274A', '\u0621', '\u0622', '\u0623', '\u0624', '\u0625', '\u0626', '\u0627', + // 0xC8 + '\u0628', '\u0629', '\u062A', '\u062B', '\u062C', '\u062D', '\u062E', '\u062F', + // 0xD0 + '\u0630', '\u0631', '\u0632', '\u0633', '\u0634', '\u0635', '\u0636', '\u0637', + // 0xD8 + '\u0638', '\u0639', '\u063A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F', + // 0xE0 + '\u0640', '\u0641', '\u0642', '\u0643', '\u0644', '\u0645', '\u0646', '\u0647', + // 0xE8 + '\u0648', '\u0649', '\u064A', '\u064B', '\u064C', '\u064D', '\u064E', '\u064F', + // 0xF0 + '\u0650', '\u0651', '\u0652', '\u067E', '\u0679', '\u0686', '\u06D5', '\u06A4', + // 0xF8 + '\u06AF', '\u0688', '\u0691', '\u007B', '\u007C', '\u007D', '\u0698', '\u06D2' + }; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. + /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. /// - public override bool IsBrowserSave { - get { return browserSave; } - } + public override bool IsBrowserDisplay => browserDisplay; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. + /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. /// - public override bool IsMailNewsDisplay { - get { return mailNewsDisplay; } - } + public override bool IsBrowserSave => browserSave; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. /// - public override bool IsMailNewsSave { - get { return mailNewsSave; } - } + public override bool IsMailNewsDisplay => mailNewsDisplay; /// - /// Gets a value indicating whether the current encoding is read-only. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// + public override bool IsMailNewsSave => mailNewsSave; + + /// + /// Gets a value indicating whether the current encoding is read-only. /// /// The is single byte. - public override bool IsReadOnly { - get { return readOnly; } - } + public override bool IsReadOnly => readOnly; /// - /// Gets a value indicating whether the current encoding uses single-byte code points. + /// Gets a value indicating whether the current encoding uses single-byte code points. /// - public override bool IsSingleByte { - get { return singleByte; } - } + public override bool IsSingleByte => singleByte; /// - /// Gets the code page identifier of the current Encoding. + /// Gets the code page identifier of the current Encoding. /// - public override int CodePage { - get { return _codepage; } - } + public override int CodePage => _codepage; /// - /// Gets a name for the current encoding that can be used with mail agent body tags + /// Gets a name for the current encoding that can be used with mail agent body tags /// - public override string BodyName { - get { return _bodyname; } - } + public override string BodyName => _bodyname; /// - /// Gets a name for the current encoding that can be used with mail agent header tags + /// Gets a name for the current encoding that can be used with mail agent header tags /// - public override string HeaderName { - get { return _headername; } - } + public override string HeaderName => _headername; /// - /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. + /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. /// - public override string WebName { - get { return _webname; } - } + public override string WebName => _webname; /// - /// Gets the human-readable description of the current encoding. + /// Gets the human-readable description of the current encoding. /// - public override string EncodingName { - get { return _encodingname; } - } + public override string EncodingName => _encodingname; /// - /// Gets the Windows operating system code page that most closely corresponds to the current encoding. + /// Gets the Windows operating system code page that most closely corresponds to the current encoding. /// - public override int WindowsCodePage { - get { return _windowsCodepage; } - } + public override int WindowsCodePage => _windowsCodepage; /// - /// Calculates the number of bytes produced by encoding the characters in the specified . + /// Calculates the number of bytes produced by encoding the characters in the specified . /// /// The number of bytes produced by encoding the specified characters. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. public override int GetByteCount(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return s.Length; } /// - /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. + /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. /// /// The number of bytes produced by encoding the specified characters. /// The character array containing the set of characters to encode. @@ -154,36 +200,32 @@ namespace Claunia.Encoding /// The number of characters to encode. public override int GetByteCount(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0 || index >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0 || index >= chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0 || index + count > chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(count < 0 || index + count > chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); return count; } /// - /// Calculates the number of bytes produced by encoding all the characters in the specified character array. + /// Calculates the number of bytes produced by encoding all the characters in the specified character array. /// /// The number of bytes produced by encoding all the characters in the specified character array. /// The character array containing the characters to encode. public override int GetByteCount(char[] chars) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); return chars.Length; } /// - /// Encodes a set of characters from the specified into the specified byte array. + /// Encodes a set of characters from the specified into the specified byte array. /// /// The actual number of bytes written into bytes. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. /// The index of the first character to encode. /// The number of characters to encode. /// The byte array to contain the resulting sequence of bytes. @@ -194,20 +236,19 @@ namespace Claunia.Encoding } /// - /// Encodes all the characters in the specified string into a sequence of bytes. + /// Encodes all the characters in the specified string into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The string containing the characters to encode. public override byte[] GetBytes(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return GetBytes(s.ToCharArray(), 0, s.Length); } /// - /// Encodes a set of characters from the specified character array into the specified byte array. + /// Encodes a set of characters from the specified character array into the specified byte array. /// /// The actual number of bytes written into bytes. /// The character array containing the set of characters to encode. @@ -217,43 +258,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting sequence of bytes. public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount + charIndex > chars.Length) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount + charIndex > chars.Length) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteIndex + charCount > bytes.Length) - throw new ArgumentException(nameof(bytes)); + if(byteIndex + charCount > bytes.Length) throw new ArgumentException(nameof(bytes)); byte[] temp = GetBytes(chars, charIndex, charCount); - for(int i = 0; i < temp.Length; i++) - bytes[i + byteIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) bytes[i + byteIndex] = temp[i]; return charCount; } /// - /// Encodes a set of characters from the specified character array into a sequence of bytes. + /// Encodes a set of characters from the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the set of characters to encode. @@ -261,28 +292,23 @@ namespace Claunia.Encoding /// The number of characters to encode. public override byte[] GetBytes(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > chars.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > chars.Length) throw new ArgumentOutOfRangeException(nameof(count)); byte[] bytes = new byte[count]; - for(int i = 0; i < count; i++) - bytes[i] = GetByte(chars[index + i]); + for(int i = 0; i < count; i++) bytes[i] = GetByte(chars[index + i]); return bytes; } /// - /// Encodes all the characters in the specified character array into a sequence of bytes. + /// Encodes all the characters in the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the characters to encode. @@ -292,7 +318,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. + /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -302,7 +328,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. + /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -310,23 +336,19 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override int GetCharCount(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); return count; } /// - /// Decodes a sequence of bytes from the specified byte array into the specified character array. + /// Decodes a sequence of bytes from the specified byte array into the specified character array. /// /// The actual number of characters written into chars. /// The byte array containing the sequence of bytes to decode. @@ -336,43 +358,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting set of characters. public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount + byteIndex > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount + byteIndex > bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charIndex + byteCount > chars.Length) - throw new ArgumentException(nameof(chars)); + if(charIndex + byteCount > chars.Length) throw new ArgumentException(nameof(chars)); char[] temp = GetChars(bytes, byteIndex, byteCount); - for(int i = 0; i < temp.Length; i++) - chars[i + charIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) chars[i + charIndex] = temp[i]; return byteCount; } /// - /// Decodes all the bytes in the specified byte array into a set of characters. + /// Decodes all the bytes in the specified byte array into a set of characters. /// /// A character array containing the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -382,7 +394,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a set of characters. + /// Decodes a sequence of bytes from the specified byte array into a set of characters. /// /// The chars. /// The byte array containing the sequence of bytes to decode. @@ -390,54 +402,47 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override char[] GetChars(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); char[] chars = new char[count]; - for(int i = 0; i < count; i++) - chars[i] = GetChar(bytes[index + i]); + for(int i = 0; i < count; i++) chars[i] = GetChar(bytes[index + i]); return chars; } /// - /// Calculates the maximum number of bytes produced by encoding the specified number of characters. + /// Calculates the maximum number of bytes produced by encoding the specified number of characters. /// /// The maximum number of bytes produced by encoding the specified number of characters. /// The number of characters to encode. public override int GetMaxByteCount(int charCount) { - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); return charCount; } /// - /// Calculates the maximum number of characters produced by decoding the specified number of bytes. + /// Calculates the maximum number of characters produced by decoding the specified number of bytes. /// /// The maximum number of characters produced by decoding the specified number of bytes. /// The number of bytes to decode. public override int GetMaxCharCount(int byteCount) { - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); return byteCount; } /// - /// Returns a sequence of bytes that specifies the encoding used. + /// Returns a sequence of bytes that specifies the encoding used. /// /// A byte array of length zero, as a preamble is not required. public override byte[] GetPreamble() @@ -446,7 +451,7 @@ namespace Claunia.Encoding } /// - /// Decodes all the bytes in the specified byte array into a string. + /// Decodes all the bytes in the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -456,7 +461,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a string. + /// Decodes a sequence of bytes from the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -468,77 +473,7 @@ namespace Claunia.Encoding } /// - /// The Macintosh Farsi to Unicode character map. - /// - static readonly char[] MacFarsiTable = { - // 0x00 - '\u0000','\u0001','\u0002','\u0003','\u0004','\u0005','\u0006','\u0007', - // 0x08 - '\u0008','\u0009','\u000A','\u000B','\u000C','\u000D','\u000E','\u000F', - // 0x10 - '\u0010','\u0011','\u0012','\u0013','\u0014','\u0015','\u0016','\u0017', - // 0x18 - '\u0018','\u0019','\u001A','\u001B','\u001C','\u001D','\u001E','\u001F', - // 0x20 - '\u0020','\u0021','\u0022','\u0023','\u0024','\u0025','\u0026','\u0027', - // 0x28 - '\u0028','\u0029','\u002A','\u002B','\u002C','\u002D','\u002E','\u002F', - // 0x30 - '\u0030','\u0031','\u0032','\u0033','\u0034','\u0035','\u0036','\u0037', - // 0x38 - '\u0038','\u0039','\u003A','\u003B','\u003C','\u003D','\u003E','\u003F', - // 0x40 - '\u0040','\u0041','\u0042','\u0043','\u0044','\u0045','\u0046','\u0047', - // 0x48 - '\u0048','\u0049','\u004A','\u004B','\u004C','\u004D','\u004E','\u004F', - // 0x50 - '\u0050','\u0051','\u0052','\u0053','\u0054','\u0055','\u0056','\u0057', - // 0x58 - '\u0058','\u0059','\u005A','\u005B','\u005C','\u005D','\u005E','\u005F', - // 0x60 - '\u0060','\u0061','\u0062','\u0063','\u0064','\u0065','\u0066','\u0067', - // 0x68 - '\u0068','\u0069','\u006A','\u006B','\u006C','\u006D','\u006E','\u006F', - // 0x70 - '\u0070','\u0071','\u0072','\u0073','\u0074','\u0075','\u0076','\u0077', - // 0x78 - '\u0078','\u0079','\u007A','\u007B','\u007C','\u007D','\u007E','\u007F', - // 0x80 - '\u00C4','\u00A0','\u00C7','\u00C9','\u00D1','\u00D6','\u00DC','\u00E1', - // 0x88 - '\u00E0','\u00E2','\u00E4','\u06BA','\u00AB','\u00E7','\u00E9','\u00E8', - // 0x90 - '\u00EA','\u00EB','\u00ED','\u2026','\u00EE','\u00EF','\u00F1','\u00F3', - // 0x98 - '\u00BB','\u00F4','\u00F6','\u00F7','\u00FA','\u00F9','\u00FB','\u00FC', - // 0xA0 - '\u0020','\u0021','\u0022','\u0023','\u0024','\u066A','\u0026','\u0027', - // 0xA8 - '\u0028','\u0029','\u002A','\u002B','\u060C','\u002D','\u002E','\u002F', - // 0xB0 - '\u06F0','\u06F1','\u06F2','\u06F3','\u06F4','\u06F5','\u06F6','\u06F7', - // 0xB8 - '\u06F8','\u06F9','\u003A','\u061B','\u003C','\u003D','\u003E','\u061F', - // 0xC0 - '\u274A','\u0621','\u0622','\u0623','\u0624','\u0625','\u0626','\u0627', - // 0xC8 - '\u0628','\u0629','\u062A','\u062B','\u062C','\u062D','\u062E','\u062F', - // 0xD0 - '\u0630','\u0631','\u0632','\u0633','\u0634','\u0635','\u0636','\u0637', - // 0xD8 - '\u0638','\u0639','\u063A','\u005B','\u005C','\u005D','\u005E','\u005F', - // 0xE0 - '\u0640','\u0641','\u0642','\u0643','\u0644','\u0645','\u0646','\u0647', - // 0xE8 - '\u0648','\u0649','\u064A','\u064B','\u064C','\u064D','\u064E','\u064F', - // 0xF0 - '\u0650','\u0651','\u0652','\u067E','\u0679','\u0686','\u06D5','\u06A4', - // 0xF8 - '\u06AF','\u0688','\u0691','\u007B','\u007C','\u007D','\u0698','\u06D2' - }; - - /// - /// Converts a Mac Farsi character to an Unicode character + /// Converts a Mac Farsi character to an Unicode character /// /// Unicode character. /// Mac Farsi character. @@ -548,473 +483,244 @@ namespace Claunia.Encoding } /// - /// Converts a Unicode character to an Mac Farsi character + /// Converts a Unicode character to an Mac Farsi character /// /// Mac Farsi character. /// Unicode character. static byte GetByte(char character) { - switch(character) { - case '\u0000': - return 0x00; - case '\u0001': - return 0x01; - case '\u0002': - return 0x02; - case '\u0003': - return 0x03; - case '\u0004': - return 0x04; - case '\u0005': - return 0x05; - case '\u0006': - return 0x06; - case '\u0007': - return 0x07; - case '\u0008': - return 0x08; - case '\u0009': - return 0x09; - case '\u000A': - return 0x0A; - case '\u000B': - return 0x0B; - case '\u000C': - return 0x0C; - case '\u000D': - return 0x0D; - case '\u000E': - return 0x0E; - case '\u000F': - return 0x0F; - case '\u0010': - return 0x10; - case '\u0011': - return 0x11; - case '\u0012': - return 0x12; - case '\u0013': - return 0x13; - case '\u0014': - return 0x14; - case '\u0015': - return 0x15; - case '\u0016': - return 0x16; - case '\u0017': - return 0x17; - case '\u0018': - return 0x18; - case '\u0019': - return 0x19; - case '\u001A': - return 0x1A; - case '\u001B': - return 0x1B; - case '\u001C': - return 0x1C; - case '\u001D': - return 0x1D; - case '\u001E': - return 0x1E; - case '\u001F': - return 0x1F; - case '\u0020': - return 0x20; - case '\u0021': - return 0x21; - case '\u0022': - return 0x22; - case '\u0023': - return 0x23; - case '\u0024': - return 0x24; - case '\u0025': - return 0x25; - case '\u0026': - return 0x26; - case '\u0027': - return 0x27; - case '\u0028': - return 0x28; - case '\u0029': - return 0x29; - case '\u002A': - return 0x2A; - case '\u002B': - return 0x2B; - case '\u002C': - return 0x2C; - case '\u002D': - return 0x2D; - case '\u002E': - return 0x2E; - case '\u002F': - return 0x2F; - case '\u0030': - return 0x30; - case '\u0031': - return 0x31; - case '\u0032': - return 0x32; - case '\u0033': - return 0x33; - case '\u0034': - return 0x34; - case '\u0035': - return 0x35; - case '\u0036': - return 0x36; - case '\u0037': - return 0x37; - case '\u0038': - return 0x38; - case '\u0039': - return 0x39; - case '\u003A': - return 0x3A; - case '\u003B': - return 0x3B; - case '\u003C': - return 0x3C; - case '\u003D': - return 0x3D; - case '\u003E': - return 0x3E; - case '\u003F': - return 0x3F; - case '\u0040': - return 0x40; - case '\u0041': - return 0x41; - case '\u0042': - return 0x42; - case '\u0043': - return 0x43; - case '\u0044': - return 0x44; - case '\u0045': - return 0x45; - case '\u0046': - return 0x46; - case '\u0047': - return 0x47; - case '\u0048': - return 0x48; - case '\u0049': - return 0x49; - case '\u004A': - return 0x4A; - case '\u004B': - return 0x4B; - case '\u004C': - return 0x4C; - case '\u004D': - return 0x4D; - case '\u004E': - return 0x4E; - case '\u004F': - return 0x4F; - case '\u0050': - return 0x50; - case '\u0051': - return 0x51; - case '\u0052': - return 0x52; - case '\u0053': - return 0x53; - case '\u0054': - return 0x54; - case '\u0055': - return 0x55; - case '\u0056': - return 0x56; - case '\u0057': - return 0x57; - case '\u0058': - return 0x58; - case '\u0059': - return 0x59; - case '\u005A': - return 0x5A; - case '\u005B': - return 0x5B; - case '\u005C': - return 0x5C; - case '\u005D': - return 0x5D; - case '\u005E': - return 0x5E; - case '\u005F': - return 0x5F; - case '\u0060': - return 0x60; - case '\u0061': - return 0x61; - case '\u0062': - return 0x62; - case '\u0063': - return 0x63; - case '\u0064': - return 0x64; - case '\u0065': - return 0x65; - case '\u0066': - return 0x66; - case '\u0067': - return 0x67; - case '\u0068': - return 0x68; - case '\u0069': - return 0x69; - case '\u006A': - return 0x6A; - case '\u006B': - return 0x6B; - case '\u006C': - return 0x6C; - case '\u006D': - return 0x6D; - case '\u006E': - return 0x6E; - case '\u006F': - return 0x6F; - case '\u0070': - return 0x70; - case '\u0071': - return 0x71; - case '\u0072': - return 0x72; - case '\u0073': - return 0x73; - case '\u0074': - return 0x74; - case '\u0075': - return 0x75; - case '\u0076': - return 0x76; - case '\u0077': - return 0x77; - case '\u0078': - return 0x78; - case '\u0079': - return 0x79; - case '\u007A': - return 0x7A; - case '\u007B': - return 0x7B; - case '\u007C': - return 0x7C; - case '\u007D': - return 0x7D; - case '\u007E': - return 0x7E; - case '\u007F': - return 0x7F; - case '\u00C4': - return 0x80; - case '\u00A0': - return 0x81; - case '\u00C7': - return 0x82; - case '\u00C9': - return 0x83; - case '\u00D1': - return 0x84; - case '\u00D6': - return 0x85; - case '\u00DC': - return 0x86; - case '\u00E1': - return 0x87; - case '\u00E0': - return 0x88; - case '\u00E2': - return 0x89; - case '\u00E4': - return 0x8A; - case '\u06BA': - return 0x8B; - case '\u00AB': - return 0x8C; - case '\u00E7': - return 0x8D; - case '\u00E9': - return 0x8E; - case '\u00E8': - return 0x8F; - case '\u00EA': - return 0x90; - case '\u00EB': - return 0x91; - case '\u00ED': - return 0x92; - case '\u2026': - return 0x93; - case '\u00EE': - return 0x94; - case '\u00EF': - return 0x95; - case '\u00F1': - return 0x96; - case '\u00F3': - return 0x97; - case '\u00BB': - return 0x98; - case '\u00F4': - return 0x99; - case '\u00F6': - return 0x9A; - case '\u00F7': - return 0x9B; - case '\u00FA': - return 0x9C; - case '\u00F9': - return 0x9D; - case '\u00FB': - return 0x9E; - case '\u00FC': - return 0x9F; - case '\u066A': - return 0xA5; - case '\u060C': - return 0xAC; - case '\u06F0': - return 0xB0; - case '\u06F1': - return 0xB1; - case '\u06F2': - return 0xB2; - case '\u06F3': - return 0xB3; - case '\u06F4': - return 0xB4; - case '\u06F5': - return 0xB5; - case '\u06F6': - return 0xB6; - case '\u06F7': - return 0xB7; - case '\u06F8': - return 0xB8; - case '\u06F9': - return 0xB9; - case '\u061B': - return 0xBB; - case '\u061F': - return 0xBF; - case '\u274A': - return 0xC0; - case '\u0621': - return 0xC1; - case '\u0622': - return 0xC2; - case '\u0623': - return 0xC3; - case '\u0624': - return 0xC4; - case '\u0625': - return 0xC5; - case '\u0626': - return 0xC6; - case '\u0627': - return 0xC7; - case '\u0628': - return 0xC8; - case '\u0629': - return 0xC9; - case '\u062A': - return 0xCA; - case '\u062B': - return 0xCB; - case '\u062C': - return 0xCC; - case '\u062D': - return 0xCD; - case '\u062E': - return 0xCE; - case '\u062F': - return 0xCF; - case '\u0630': - return 0xD0; - case '\u0631': - return 0xD1; - case '\u0632': - return 0xD2; - case '\u0633': - return 0xD3; - case '\u0634': - return 0xD4; - case '\u0635': - return 0xD5; - case '\u0636': - return 0xD6; - case '\u0637': - return 0xD7; - case '\u0638': - return 0xD8; - case '\u0639': - return 0xD9; - case '\u063A': - return 0xDA; - case '\u0640': - return 0xE0; - case '\u0641': - return 0xE1; - case '\u0642': - return 0xE2; - case '\u0643': - return 0xE3; - case '\u0644': - return 0xE4; - case '\u0645': - return 0xE5; - case '\u0646': - return 0xE6; - case '\u0647': - return 0xE7; - case '\u0648': - return 0xE8; - case '\u0649': - return 0xE9; - case '\u064A': - return 0xEA; - case '\u064B': - return 0xEB; - case '\u064C': - return 0xEC; - case '\u064D': - return 0xED; - case '\u064E': - return 0xEE; - case '\u064F': - return 0xEF; - case '\u0650': - return 0xF0; - case '\u0651': - return 0xF1; - case '\u0652': - return 0xF2; - case '\u067E': - return 0xF3; - case '\u0679': - return 0xF4; - case '\u0686': - return 0xF5; - case '\u06D5': - return 0xF6; - case '\u06A4': - return 0xF7; - case '\u06AF': - return 0xF8; - case '\u0688': - return 0xF9; - case '\u0691': - return 0xFA; - case '\u0698': - return 0xFE; - case '\u06D2': - return 0xFF; + switch(character) + { + case '\u0000': return 0x00; + case '\u0001': return 0x01; + case '\u0002': return 0x02; + case '\u0003': return 0x03; + case '\u0004': return 0x04; + case '\u0005': return 0x05; + case '\u0006': return 0x06; + case '\u0007': return 0x07; + case '\u0008': return 0x08; + case '\u0009': return 0x09; + case '\u000A': return 0x0A; + case '\u000B': return 0x0B; + case '\u000C': return 0x0C; + case '\u000D': return 0x0D; + case '\u000E': return 0x0E; + case '\u000F': return 0x0F; + case '\u0010': return 0x10; + case '\u0011': return 0x11; + case '\u0012': return 0x12; + case '\u0013': return 0x13; + case '\u0014': return 0x14; + case '\u0015': return 0x15; + case '\u0016': return 0x16; + case '\u0017': return 0x17; + case '\u0018': return 0x18; + case '\u0019': return 0x19; + case '\u001A': return 0x1A; + case '\u001B': return 0x1B; + case '\u001C': return 0x1C; + case '\u001D': return 0x1D; + case '\u001E': return 0x1E; + case '\u001F': return 0x1F; + case '\u0020': return 0x20; + case '\u0021': return 0x21; + case '\u0022': return 0x22; + case '\u0023': return 0x23; + case '\u0024': return 0x24; + case '\u0025': return 0x25; + case '\u0026': return 0x26; + case '\u0027': return 0x27; + case '\u0028': return 0x28; + case '\u0029': return 0x29; + case '\u002A': return 0x2A; + case '\u002B': return 0x2B; + case '\u002C': return 0x2C; + case '\u002D': return 0x2D; + case '\u002E': return 0x2E; + case '\u002F': return 0x2F; + case '\u0030': return 0x30; + case '\u0031': return 0x31; + case '\u0032': return 0x32; + case '\u0033': return 0x33; + case '\u0034': return 0x34; + case '\u0035': return 0x35; + case '\u0036': return 0x36; + case '\u0037': return 0x37; + case '\u0038': return 0x38; + case '\u0039': return 0x39; + case '\u003A': return 0x3A; + case '\u003B': return 0x3B; + case '\u003C': return 0x3C; + case '\u003D': return 0x3D; + case '\u003E': return 0x3E; + case '\u003F': return 0x3F; + case '\u0040': return 0x40; + case '\u0041': return 0x41; + case '\u0042': return 0x42; + case '\u0043': return 0x43; + case '\u0044': return 0x44; + case '\u0045': return 0x45; + case '\u0046': return 0x46; + case '\u0047': return 0x47; + case '\u0048': return 0x48; + case '\u0049': return 0x49; + case '\u004A': return 0x4A; + case '\u004B': return 0x4B; + case '\u004C': return 0x4C; + case '\u004D': return 0x4D; + case '\u004E': return 0x4E; + case '\u004F': return 0x4F; + case '\u0050': return 0x50; + case '\u0051': return 0x51; + case '\u0052': return 0x52; + case '\u0053': return 0x53; + case '\u0054': return 0x54; + case '\u0055': return 0x55; + case '\u0056': return 0x56; + case '\u0057': return 0x57; + case '\u0058': return 0x58; + case '\u0059': return 0x59; + case '\u005A': return 0x5A; + case '\u005B': return 0x5B; + case '\u005C': return 0x5C; + case '\u005D': return 0x5D; + case '\u005E': return 0x5E; + case '\u005F': return 0x5F; + case '\u0060': return 0x60; + case '\u0061': return 0x61; + case '\u0062': return 0x62; + case '\u0063': return 0x63; + case '\u0064': return 0x64; + case '\u0065': return 0x65; + case '\u0066': return 0x66; + case '\u0067': return 0x67; + case '\u0068': return 0x68; + case '\u0069': return 0x69; + case '\u006A': return 0x6A; + case '\u006B': return 0x6B; + case '\u006C': return 0x6C; + case '\u006D': return 0x6D; + case '\u006E': return 0x6E; + case '\u006F': return 0x6F; + case '\u0070': return 0x70; + case '\u0071': return 0x71; + case '\u0072': return 0x72; + case '\u0073': return 0x73; + case '\u0074': return 0x74; + case '\u0075': return 0x75; + case '\u0076': return 0x76; + case '\u0077': return 0x77; + case '\u0078': return 0x78; + case '\u0079': return 0x79; + case '\u007A': return 0x7A; + case '\u007B': return 0x7B; + case '\u007C': return 0x7C; + case '\u007D': return 0x7D; + case '\u007E': return 0x7E; + case '\u007F': return 0x7F; + case '\u00C4': return 0x80; + case '\u00A0': return 0x81; + case '\u00C7': return 0x82; + case '\u00C9': return 0x83; + case '\u00D1': return 0x84; + case '\u00D6': return 0x85; + case '\u00DC': return 0x86; + case '\u00E1': return 0x87; + case '\u00E0': return 0x88; + case '\u00E2': return 0x89; + case '\u00E4': return 0x8A; + case '\u06BA': return 0x8B; + case '\u00AB': return 0x8C; + case '\u00E7': return 0x8D; + case '\u00E9': return 0x8E; + case '\u00E8': return 0x8F; + case '\u00EA': return 0x90; + case '\u00EB': return 0x91; + case '\u00ED': return 0x92; + case '\u2026': return 0x93; + case '\u00EE': return 0x94; + case '\u00EF': return 0x95; + case '\u00F1': return 0x96; + case '\u00F3': return 0x97; + case '\u00BB': return 0x98; + case '\u00F4': return 0x99; + case '\u00F6': return 0x9A; + case '\u00F7': return 0x9B; + case '\u00FA': return 0x9C; + case '\u00F9': return 0x9D; + case '\u00FB': return 0x9E; + case '\u00FC': return 0x9F; + case '\u066A': return 0xA5; + case '\u060C': return 0xAC; + case '\u06F0': return 0xB0; + case '\u06F1': return 0xB1; + case '\u06F2': return 0xB2; + case '\u06F3': return 0xB3; + case '\u06F4': return 0xB4; + case '\u06F5': return 0xB5; + case '\u06F6': return 0xB6; + case '\u06F7': return 0xB7; + case '\u06F8': return 0xB8; + case '\u06F9': return 0xB9; + case '\u061B': return 0xBB; + case '\u061F': return 0xBF; + case '\u274A': return 0xC0; + case '\u0621': return 0xC1; + case '\u0622': return 0xC2; + case '\u0623': return 0xC3; + case '\u0624': return 0xC4; + case '\u0625': return 0xC5; + case '\u0626': return 0xC6; + case '\u0627': return 0xC7; + case '\u0628': return 0xC8; + case '\u0629': return 0xC9; + case '\u062A': return 0xCA; + case '\u062B': return 0xCB; + case '\u062C': return 0xCC; + case '\u062D': return 0xCD; + case '\u062E': return 0xCE; + case '\u062F': return 0xCF; + case '\u0630': return 0xD0; + case '\u0631': return 0xD1; + case '\u0632': return 0xD2; + case '\u0633': return 0xD3; + case '\u0634': return 0xD4; + case '\u0635': return 0xD5; + case '\u0636': return 0xD6; + case '\u0637': return 0xD7; + case '\u0638': return 0xD8; + case '\u0639': return 0xD9; + case '\u063A': return 0xDA; + case '\u0640': return 0xE0; + case '\u0641': return 0xE1; + case '\u0642': return 0xE2; + case '\u0643': return 0xE3; + case '\u0644': return 0xE4; + case '\u0645': return 0xE5; + case '\u0646': return 0xE6; + case '\u0647': return 0xE7; + case '\u0648': return 0xE8; + case '\u0649': return 0xE9; + case '\u064A': return 0xEA; + case '\u064B': return 0xEB; + case '\u064C': return 0xEC; + case '\u064D': return 0xED; + case '\u064E': return 0xEE; + case '\u064F': return 0xEF; + case '\u0650': return 0xF0; + case '\u0651': return 0xF1; + case '\u0652': return 0xF2; + case '\u067E': return 0xF3; + case '\u0679': return 0xF4; + case '\u0686': return 0xF5; + case '\u06D5': return 0xF6; + case '\u06A4': return 0xF7; + case '\u06AF': return 0xF8; + case '\u0688': return 0xF9; + case '\u0691': return 0xFA; + case '\u0698': return 0xFE; + case '\u06D2': return 0xFF; default: // Fallback to '?' return 0x3F; diff --git a/Claunia.Encoding/MacGreek.cs b/Claunia.Encoding/MacGreek.cs index a1f3f48..c9a1cd8 100644 --- a/Claunia.Encoding/MacGreek.cs +++ b/Claunia.Encoding/MacGreek.cs @@ -29,7 +29,7 @@ using System; namespace Claunia.Encoding { /// - /// Represents an Mac Greek character encoding of Unicode characters. + /// Represents an Mac Greek character encoding of Unicode characters. /// public class MacGreek : Encoding { @@ -48,105 +48,151 @@ namespace Claunia.Encoding const bool singleByte = true; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. + /// The Macintosh Greek to Unicode character map. /// - public override bool IsBrowserDisplay { - get { return browserDisplay; } - } + static readonly char[] MacGreekTable = + { + // 0x00 + '\u0000', '\u0001', '\u0002', '\u0003', '\u0004', '\u0005', '\u0006', '\u0007', + // 0x08 + '\u0008', '\u0009', '\u000A', '\u000B', '\u000C', '\u000D', '\u000E', '\u000F', + // 0x10 + '\u0010', '\u0011', '\u0012', '\u0013', '\u0014', '\u0015', '\u0016', '\u0017', + // 0x18 + '\u0018', '\u0019', '\u001A', '\u001B', '\u001C', '\u001D', '\u001E', '\u001F', + // 0x20 + '\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027', + // 0x28 + '\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F', + // 0x30 + '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', + // 0x38 + '\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F', + // 0x40 + '\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047', + // 0x48 + '\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F', + // 0x50 + '\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057', + // 0x58 + '\u0058', '\u0059', '\u005A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F', + // 0x60 + '\u0060', '\u0061', '\u0062', '\u0063', '\u0064', '\u0065', '\u0066', '\u0067', + // 0x68 + '\u0068', '\u0069', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F', + // 0x70 + '\u0070', '\u0071', '\u0072', '\u0073', '\u0074', '\u0075', '\u0076', '\u0077', + // 0x78 + '\u0078', '\u0079', '\u007A', '\u007B', '\u007C', '\u007D', '\u007E', '\u007F', + // 0x80 + '\u00C4', '\u00B9', '\u00B2', '\u00C9', '\u00B3', '\u00D6', '\u00DC', '\u0385', + // 0x88 + '\u00E0', '\u00E2', '\u00E4', '\u0384', '\u00A8', '\u00E7', '\u00E9', '\u00E8', + // 0x90 + '\u00EA', '\u00EB', '\u00A3', '\u2122', '\u00EE', '\u00EF', '\u2022', '\u00BD', + // 0x98 + '\u2030', '\u00F4', '\u00F6', '\u00A6', '\u20AC', '\u00F9', '\u00FB', '\u00FC', + // 0xA0 + '\u2020', '\u0393', '\u0394', '\u0398', '\u039B', '\u039E', '\u03A0', '\u00DF', + // 0xA8 + '\u00AE', '\u00A9', '\u03A3', '\u03AA', '\u00A7', '\u2260', '\u00B0', '\u00B7', + // 0xB0 + '\u0391', '\u00B1', '\u2264', '\u2265', '\u00A5', '\u0392', '\u0395', '\u0396', + // 0xB8 + '\u0397', '\u0399', '\u039A', '\u039C', '\u03A6', '\u03AB', '\u03A8', '\u03A9', + // 0xC0 + '\u03AC', '\u039D', '\u00AC', '\u039F', '\u03A1', '\u2248', '\u03A4', '\u00AB', + // 0xC8 + '\u00BB', '\u2026', '\u00A0', '\u03A5', '\u03A7', '\u0386', '\u0388', '\u0153', + // 0xD0 + '\u2013', '\u2015', '\u201C', '\u201D', '\u2018', '\u2019', '\u00F7', '\u0389', + // 0xD8 + '\u038A', '\u038C', '\u038E', '\u03AD', '\u03AE', '\u03AF', '\u03CC', '\u038F', + // 0xE0 + '\u03CD', '\u03B1', '\u03B2', '\u03C8', '\u03B4', '\u03B5', '\u03C6', '\u03B3', + // 0xE8 + '\u03B7', '\u03B9', '\u03BE', '\u03BA', '\u03BB', '\u03BC', '\u03BD', '\u03BF', + // 0xF0 + '\u03C0', '\u03CE', '\u03C1', '\u03C3', '\u03C4', '\u03B8', '\u03C9', '\u03C2', + // 0xF8 + '\u03C7', '\u03C5', '\u03B6', '\u03CA', '\u03CB', '\u0390', '\u03B0', '\u00AD' + }; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. + /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. /// - public override bool IsBrowserSave { - get { return browserSave; } - } + public override bool IsBrowserDisplay => browserDisplay; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. + /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. /// - public override bool IsMailNewsDisplay { - get { return mailNewsDisplay; } - } + public override bool IsBrowserSave => browserSave; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. /// - public override bool IsMailNewsSave { - get { return mailNewsSave; } - } + public override bool IsMailNewsDisplay => mailNewsDisplay; /// - /// Gets a value indicating whether the current encoding is read-only. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// + public override bool IsMailNewsSave => mailNewsSave; + + /// + /// Gets a value indicating whether the current encoding is read-only. /// /// The is single byte. - public override bool IsReadOnly { - get { return readOnly; } - } + public override bool IsReadOnly => readOnly; /// - /// Gets a value indicating whether the current encoding uses single-byte code points. + /// Gets a value indicating whether the current encoding uses single-byte code points. /// - public override bool IsSingleByte { - get { return singleByte; } - } + public override bool IsSingleByte => singleByte; /// - /// Gets the code page identifier of the current Encoding. + /// Gets the code page identifier of the current Encoding. /// - public override int CodePage { - get { return _codepage; } - } + public override int CodePage => _codepage; /// - /// Gets a name for the current encoding that can be used with mail agent body tags + /// Gets a name for the current encoding that can be used with mail agent body tags /// - public override string BodyName { - get { return _bodyname; } - } + public override string BodyName => _bodyname; /// - /// Gets a name for the current encoding that can be used with mail agent header tags + /// Gets a name for the current encoding that can be used with mail agent header tags /// - public override string HeaderName { - get { return _headername; } - } + public override string HeaderName => _headername; /// - /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. + /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. /// - public override string WebName { - get { return _webname; } - } + public override string WebName => _webname; /// - /// Gets the human-readable description of the current encoding. + /// Gets the human-readable description of the current encoding. /// - public override string EncodingName { - get { return _encodingname; } - } + public override string EncodingName => _encodingname; /// - /// Gets the Windows operating system code page that most closely corresponds to the current encoding. + /// Gets the Windows operating system code page that most closely corresponds to the current encoding. /// - public override int WindowsCodePage { - get { return _windowsCodepage; } - } + public override int WindowsCodePage => _windowsCodepage; /// - /// Calculates the number of bytes produced by encoding the characters in the specified . + /// Calculates the number of bytes produced by encoding the characters in the specified . /// /// The number of bytes produced by encoding the specified characters. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. public override int GetByteCount(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return s.Length; } /// - /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. + /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. /// /// The number of bytes produced by encoding the specified characters. /// The character array containing the set of characters to encode. @@ -154,36 +200,32 @@ namespace Claunia.Encoding /// The number of characters to encode. public override int GetByteCount(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0 || index >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0 || index >= chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0 || index + count > chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(count < 0 || index + count > chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); return count; } /// - /// Calculates the number of bytes produced by encoding all the characters in the specified character array. + /// Calculates the number of bytes produced by encoding all the characters in the specified character array. /// /// The number of bytes produced by encoding all the characters in the specified character array. /// The character array containing the characters to encode. public override int GetByteCount(char[] chars) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); return chars.Length; } /// - /// Encodes a set of characters from the specified into the specified byte array. + /// Encodes a set of characters from the specified into the specified byte array. /// /// The actual number of bytes written into bytes. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. /// The index of the first character to encode. /// The number of characters to encode. /// The byte array to contain the resulting sequence of bytes. @@ -194,20 +236,19 @@ namespace Claunia.Encoding } /// - /// Encodes all the characters in the specified string into a sequence of bytes. + /// Encodes all the characters in the specified string into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The string containing the characters to encode. public override byte[] GetBytes(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return GetBytes(s.ToCharArray(), 0, s.Length); } /// - /// Encodes a set of characters from the specified character array into the specified byte array. + /// Encodes a set of characters from the specified character array into the specified byte array. /// /// The actual number of bytes written into bytes. /// The character array containing the set of characters to encode. @@ -217,43 +258,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting sequence of bytes. public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount + charIndex > chars.Length) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount + charIndex > chars.Length) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteIndex + charCount > bytes.Length) - throw new ArgumentException(nameof(bytes)); + if(byteIndex + charCount > bytes.Length) throw new ArgumentException(nameof(bytes)); byte[] temp = GetBytes(chars, charIndex, charCount); - for(int i = 0; i < temp.Length; i++) - bytes[i + byteIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) bytes[i + byteIndex] = temp[i]; return charCount; } /// - /// Encodes a set of characters from the specified character array into a sequence of bytes. + /// Encodes a set of characters from the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the set of characters to encode. @@ -261,28 +292,23 @@ namespace Claunia.Encoding /// The number of characters to encode. public override byte[] GetBytes(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > chars.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > chars.Length) throw new ArgumentOutOfRangeException(nameof(count)); byte[] bytes = new byte[count]; - for(int i = 0; i < count; i++) - bytes[i] = GetByte(chars[index + i]); + for(int i = 0; i < count; i++) bytes[i] = GetByte(chars[index + i]); return bytes; } /// - /// Encodes all the characters in the specified character array into a sequence of bytes. + /// Encodes all the characters in the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the characters to encode. @@ -292,7 +318,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. + /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -302,7 +328,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. + /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -310,23 +336,19 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override int GetCharCount(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); return count; } /// - /// Decodes a sequence of bytes from the specified byte array into the specified character array. + /// Decodes a sequence of bytes from the specified byte array into the specified character array. /// /// The actual number of characters written into chars. /// The byte array containing the sequence of bytes to decode. @@ -336,43 +358,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting set of characters. public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount + byteIndex > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount + byteIndex > bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charIndex + byteCount > chars.Length) - throw new ArgumentException(nameof(chars)); + if(charIndex + byteCount > chars.Length) throw new ArgumentException(nameof(chars)); char[] temp = GetChars(bytes, byteIndex, byteCount); - for(int i = 0; i < temp.Length; i++) - chars[i + charIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) chars[i + charIndex] = temp[i]; return byteCount; } /// - /// Decodes all the bytes in the specified byte array into a set of characters. + /// Decodes all the bytes in the specified byte array into a set of characters. /// /// A character array containing the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -382,7 +394,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a set of characters. + /// Decodes a sequence of bytes from the specified byte array into a set of characters. /// /// The chars. /// The byte array containing the sequence of bytes to decode. @@ -390,54 +402,47 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override char[] GetChars(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); char[] chars = new char[count]; - for(int i = 0; i < count; i++) - chars[i] = GetChar(bytes[index + i]); + for(int i = 0; i < count; i++) chars[i] = GetChar(bytes[index + i]); return chars; } /// - /// Calculates the maximum number of bytes produced by encoding the specified number of characters. + /// Calculates the maximum number of bytes produced by encoding the specified number of characters. /// /// The maximum number of bytes produced by encoding the specified number of characters. /// The number of characters to encode. public override int GetMaxByteCount(int charCount) { - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); return charCount; } /// - /// Calculates the maximum number of characters produced by decoding the specified number of bytes. + /// Calculates the maximum number of characters produced by decoding the specified number of bytes. /// /// The maximum number of characters produced by decoding the specified number of bytes. /// The number of bytes to decode. public override int GetMaxCharCount(int byteCount) { - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); return byteCount; } /// - /// Returns a sequence of bytes that specifies the encoding used. + /// Returns a sequence of bytes that specifies the encoding used. /// /// A byte array of length zero, as a preamble is not required. public override byte[] GetPreamble() @@ -446,7 +451,7 @@ namespace Claunia.Encoding } /// - /// Decodes all the bytes in the specified byte array into a string. + /// Decodes all the bytes in the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -456,7 +461,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a string. + /// Decodes a sequence of bytes from the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -468,77 +473,7 @@ namespace Claunia.Encoding } /// - /// The Macintosh Greek to Unicode character map. - /// - static readonly char[] MacGreekTable = { - // 0x00 - '\u0000','\u0001','\u0002','\u0003','\u0004','\u0005','\u0006','\u0007', - // 0x08 - '\u0008','\u0009','\u000A','\u000B','\u000C','\u000D','\u000E','\u000F', - // 0x10 - '\u0010','\u0011','\u0012','\u0013','\u0014','\u0015','\u0016','\u0017', - // 0x18 - '\u0018','\u0019','\u001A','\u001B','\u001C','\u001D','\u001E','\u001F', - // 0x20 - '\u0020','\u0021','\u0022','\u0023','\u0024','\u0025','\u0026','\u0027', - // 0x28 - '\u0028','\u0029','\u002A','\u002B','\u002C','\u002D','\u002E','\u002F', - // 0x30 - '\u0030','\u0031','\u0032','\u0033','\u0034','\u0035','\u0036','\u0037', - // 0x38 - '\u0038','\u0039','\u003A','\u003B','\u003C','\u003D','\u003E','\u003F', - // 0x40 - '\u0040','\u0041','\u0042','\u0043','\u0044','\u0045','\u0046','\u0047', - // 0x48 - '\u0048','\u0049','\u004A','\u004B','\u004C','\u004D','\u004E','\u004F', - // 0x50 - '\u0050','\u0051','\u0052','\u0053','\u0054','\u0055','\u0056','\u0057', - // 0x58 - '\u0058','\u0059','\u005A','\u005B','\u005C','\u005D','\u005E','\u005F', - // 0x60 - '\u0060','\u0061','\u0062','\u0063','\u0064','\u0065','\u0066','\u0067', - // 0x68 - '\u0068','\u0069','\u006A','\u006B','\u006C','\u006D','\u006E','\u006F', - // 0x70 - '\u0070','\u0071','\u0072','\u0073','\u0074','\u0075','\u0076','\u0077', - // 0x78 - '\u0078','\u0079','\u007A','\u007B','\u007C','\u007D','\u007E','\u007F', - // 0x80 - '\u00C4','\u00B9','\u00B2','\u00C9','\u00B3','\u00D6','\u00DC','\u0385', - // 0x88 - '\u00E0','\u00E2','\u00E4','\u0384','\u00A8','\u00E7','\u00E9','\u00E8', - // 0x90 - '\u00EA','\u00EB','\u00A3','\u2122','\u00EE','\u00EF','\u2022','\u00BD', - // 0x98 - '\u2030','\u00F4','\u00F6','\u00A6','\u20AC','\u00F9','\u00FB','\u00FC', - // 0xA0 - '\u2020','\u0393','\u0394','\u0398','\u039B','\u039E','\u03A0','\u00DF', - // 0xA8 - '\u00AE','\u00A9','\u03A3','\u03AA','\u00A7','\u2260','\u00B0','\u00B7', - // 0xB0 - '\u0391','\u00B1','\u2264','\u2265','\u00A5','\u0392','\u0395','\u0396', - // 0xB8 - '\u0397','\u0399','\u039A','\u039C','\u03A6','\u03AB','\u03A8','\u03A9', - // 0xC0 - '\u03AC','\u039D','\u00AC','\u039F','\u03A1','\u2248','\u03A4','\u00AB', - // 0xC8 - '\u00BB','\u2026','\u00A0','\u03A5','\u03A7','\u0386','\u0388','\u0153', - // 0xD0 - '\u2013','\u2015','\u201C','\u201D','\u2018','\u2019','\u00F7','\u0389', - // 0xD8 - '\u038A','\u038C','\u038E','\u03AD','\u03AE','\u03AF','\u03CC','\u038F', - // 0xE0 - '\u03CD','\u03B1','\u03B2','\u03C8','\u03B4','\u03B5','\u03C6','\u03B3', - // 0xE8 - '\u03B7','\u03B9','\u03BE','\u03BA','\u03BB','\u03BC','\u03BD','\u03BF', - // 0xF0 - '\u03C0','\u03CE','\u03C1','\u03C3','\u03C4','\u03B8','\u03C9','\u03C2', - // 0xF8 - '\u03C7','\u03C5','\u03B6','\u03CA','\u03CB','\u0390','\u03B0','\u00AD' - }; - - /// - /// Converts a Mac Greek character to an Unicode character + /// Converts a Mac Greek character to an Unicode character /// /// Unicode character. /// Mac Greek character. @@ -548,525 +483,270 @@ namespace Claunia.Encoding } /// - /// Converts a Unicode character to an Mac Greek character + /// Converts a Unicode character to an Mac Greek character /// /// Mac Greek character. /// Unicode character. static byte GetByte(char character) { - switch(character) { - case '\u0000': - return 0x00; - case '\u0001': - return 0x01; - case '\u0002': - return 0x02; - case '\u0003': - return 0x03; - case '\u0004': - return 0x04; - case '\u0005': - return 0x05; - case '\u0006': - return 0x06; - case '\u0007': - return 0x07; - case '\u0008': - return 0x08; - case '\u0009': - return 0x09; - case '\u000A': - return 0x0A; - case '\u000B': - return 0x0B; - case '\u000C': - return 0x0C; - case '\u000D': - return 0x0D; - case '\u000E': - return 0x0E; - case '\u000F': - return 0x0F; - case '\u0010': - return 0x10; - case '\u0011': - return 0x11; - case '\u0012': - return 0x12; - case '\u0013': - return 0x13; - case '\u0014': - return 0x14; - case '\u0015': - return 0x15; - case '\u0016': - return 0x16; - case '\u0017': - return 0x17; - case '\u0018': - return 0x18; - case '\u0019': - return 0x19; - case '\u001A': - return 0x1A; - case '\u001B': - return 0x1B; - case '\u001C': - return 0x1C; - case '\u001D': - return 0x1D; - case '\u001E': - return 0x1E; - case '\u001F': - return 0x1F; - case '\u0020': - return 0x20; - case '\u0021': - return 0x21; - case '\u0022': - return 0x22; - case '\u0023': - return 0x23; - case '\u0024': - return 0x24; - case '\u0025': - return 0x25; - case '\u0026': - return 0x26; - case '\u0027': - return 0x27; - case '\u0028': - return 0x28; - case '\u0029': - return 0x29; - case '\u002A': - return 0x2A; - case '\u002B': - return 0x2B; - case '\u002C': - return 0x2C; - case '\u002D': - return 0x2D; - case '\u002E': - return 0x2E; - case '\u002F': - return 0x2F; - case '\u0030': - return 0x30; - case '\u0031': - return 0x31; - case '\u0032': - return 0x32; - case '\u0033': - return 0x33; - case '\u0034': - return 0x34; - case '\u0035': - return 0x35; - case '\u0036': - return 0x36; - case '\u0037': - return 0x37; - case '\u0038': - return 0x38; - case '\u0039': - return 0x39; - case '\u003A': - return 0x3A; - case '\u003B': - return 0x3B; - case '\u003C': - return 0x3C; - case '\u003D': - return 0x3D; - case '\u003E': - return 0x3E; - case '\u003F': - return 0x3F; - case '\u0040': - return 0x40; - case '\u0041': - return 0x41; - case '\u0042': - return 0x42; - case '\u0043': - return 0x43; - case '\u0044': - return 0x44; - case '\u0045': - return 0x45; - case '\u0046': - return 0x46; - case '\u0047': - return 0x47; - case '\u0048': - return 0x48; - case '\u0049': - return 0x49; - case '\u004A': - return 0x4A; - case '\u004B': - return 0x4B; - case '\u004C': - return 0x4C; - case '\u004D': - return 0x4D; - case '\u004E': - return 0x4E; - case '\u004F': - return 0x4F; - case '\u0050': - return 0x50; - case '\u0051': - return 0x51; - case '\u0052': - return 0x52; - case '\u0053': - return 0x53; - case '\u0054': - return 0x54; - case '\u0055': - return 0x55; - case '\u0056': - return 0x56; - case '\u0057': - return 0x57; - case '\u0058': - return 0x58; - case '\u0059': - return 0x59; - case '\u005A': - return 0x5A; - case '\u005B': - return 0x5B; - case '\u005C': - return 0x5C; - case '\u005D': - return 0x5D; - case '\u005E': - return 0x5E; - case '\u005F': - return 0x5F; - case '\u0060': - return 0x60; - case '\u0061': - return 0x61; - case '\u0062': - return 0x62; - case '\u0063': - return 0x63; - case '\u0064': - return 0x64; - case '\u0065': - return 0x65; - case '\u0066': - return 0x66; - case '\u0067': - return 0x67; - case '\u0068': - return 0x68; - case '\u0069': - return 0x69; - case '\u006A': - return 0x6A; - case '\u006B': - return 0x6B; - case '\u006C': - return 0x6C; - case '\u006D': - return 0x6D; - case '\u006E': - return 0x6E; - case '\u006F': - return 0x6F; - case '\u0070': - return 0x70; - case '\u0071': - return 0x71; - case '\u0072': - return 0x72; - case '\u0073': - return 0x73; - case '\u0074': - return 0x74; - case '\u0075': - return 0x75; - case '\u0076': - return 0x76; - case '\u0077': - return 0x77; - case '\u0078': - return 0x78; - case '\u0079': - return 0x79; - case '\u007A': - return 0x7A; - case '\u007B': - return 0x7B; - case '\u007C': - return 0x7C; - case '\u007D': - return 0x7D; - case '\u007E': - return 0x7E; - case '\u007F': - return 0x7F; - case '\u00C4': - return 0x80; - case '\u00B9': - return 0x81; - case '\u00B2': - return 0x82; - case '\u00C9': - return 0x83; - case '\u00B3': - return 0x84; - case '\u00D6': - return 0x85; - case '\u00DC': - return 0x86; - case '\u0385': - return 0x87; - case '\u00E0': - return 0x88; - case '\u00E2': - return 0x89; - case '\u00E4': - return 0x8A; - case '\u0384': - return 0x8B; - case '\u00A8': - return 0x8C; - case '\u00E7': - return 0x8D; - case '\u00E9': - return 0x8E; - case '\u00E8': - return 0x8F; - case '\u00EA': - return 0x90; - case '\u00EB': - return 0x91; - case '\u00A3': - return 0x92; - case '\u2122': - return 0x93; - case '\u00EE': - return 0x94; - case '\u00EF': - return 0x95; - case '\u2022': - return 0x96; - case '\u00BD': - return 0x97; - case '\u2030': - return 0x98; - case '\u00F4': - return 0x99; - case '\u00F6': - return 0x9A; - case '\u00A6': - return 0x9B; - case '\u20AC': - return 0x9C; - case '\u00F9': - return 0x9D; - case '\u00FB': - return 0x9E; - case '\u00FC': - return 0x9F; - case '\u2020': - return 0xA0; - case '\u0393': - return 0xA1; - case '\u0394': - return 0xA2; - case '\u0398': - return 0xA3; - case '\u039B': - return 0xA4; - case '\u039E': - return 0xA5; - case '\u03A0': - return 0xA6; - case '\u00DF': - return 0xA7; - case '\u00AE': - return 0xA8; - case '\u00A9': - return 0xA9; - case '\u03A3': - return 0xAA; - case '\u03AA': - return 0xAB; - case '\u00A7': - return 0xAC; - case '\u2260': - return 0xAD; - case '\u00B0': - return 0xAE; - case '\u00B7': - return 0xAF; - case '\u0391': - return 0xB0; - case '\u00B1': - return 0xB1; - case '\u2264': - return 0xB2; - case '\u2265': - return 0xB3; - case '\u00A5': - return 0xB4; - case '\u0392': - return 0xB5; - case '\u0395': - return 0xB6; - case '\u0396': - return 0xB7; - case '\u0397': - return 0xB8; - case '\u0399': - return 0xB9; - case '\u039A': - return 0xBA; - case '\u039C': - return 0xBB; - case '\u03A6': - return 0xBC; - case '\u03AB': - return 0xBD; - case '\u03A8': - return 0xBE; - case '\u03A9': - return 0xBF; - case '\u03AC': - return 0xC0; - case '\u039D': - return 0xC1; - case '\u00AC': - return 0xC2; - case '\u039F': - return 0xC3; - case '\u03A1': - return 0xC4; - case '\u2248': - return 0xC5; - case '\u03A4': - return 0xC6; - case '\u00AB': - return 0xC7; - case '\u00BB': - return 0xC8; - case '\u2026': - return 0xC9; - case '\u00A0': - return 0xCA; - case '\u03A5': - return 0xCB; - case '\u03A7': - return 0xCC; - case '\u0386': - return 0xCD; - case '\u0388': - return 0xCE; - case '\u0153': - return 0xCF; - case '\u2013': - return 0xD0; - case '\u2015': - return 0xD1; - case '\u201C': - return 0xD2; - case '\u201D': - return 0xD3; - case '\u2018': - return 0xD4; - case '\u2019': - return 0xD5; - case '\u00F7': - return 0xD6; - case '\u0389': - return 0xD7; - case '\u038A': - return 0xD8; - case '\u038C': - return 0xD9; - case '\u038E': - return 0xDA; - case '\u03AD': - return 0xDB; - case '\u03AE': - return 0xDC; - case '\u03AF': - return 0xDD; - case '\u03CC': - return 0xDE; - case '\u038F': - return 0xDF; - case '\u03CD': - return 0xE0; - case '\u03B1': - return 0xE1; - case '\u03B2': - return 0xE2; - case '\u03C8': - return 0xE3; - case '\u03B4': - return 0xE4; - case '\u03B5': - return 0xE5; - case '\u03C6': - return 0xE6; - case '\u03B3': - return 0xE7; - case '\u03B7': - return 0xE8; - case '\u03B9': - return 0xE9; - case '\u03BE': - return 0xEA; - case '\u03BA': - return 0xEB; - case '\u03BB': - return 0xEC; - case '\u03BC': - return 0xED; - case '\u03BD': - return 0xEE; - case '\u03BF': - return 0xEF; - case '\u03C0': - return 0xF0; - case '\u03CE': - return 0xF1; - case '\u03C1': - return 0xF2; - case '\u03C3': - return 0xF3; - case '\u03C4': - return 0xF4; - case '\u03B8': - return 0xF5; - case '\u03C9': - return 0xF6; - case '\u03C2': - return 0xF7; - case '\u03C7': - return 0xF8; - case '\u03C5': - return 0xF9; - case '\u03B6': - return 0xFA; - case '\u03CA': - return 0xFB; - case '\u03CB': - return 0xFC; - case '\u0390': - return 0xFD; - case '\u03B0': - return 0xFE; - case '\u00AD': - return 0xFF; + switch(character) + { + case '\u0000': return 0x00; + case '\u0001': return 0x01; + case '\u0002': return 0x02; + case '\u0003': return 0x03; + case '\u0004': return 0x04; + case '\u0005': return 0x05; + case '\u0006': return 0x06; + case '\u0007': return 0x07; + case '\u0008': return 0x08; + case '\u0009': return 0x09; + case '\u000A': return 0x0A; + case '\u000B': return 0x0B; + case '\u000C': return 0x0C; + case '\u000D': return 0x0D; + case '\u000E': return 0x0E; + case '\u000F': return 0x0F; + case '\u0010': return 0x10; + case '\u0011': return 0x11; + case '\u0012': return 0x12; + case '\u0013': return 0x13; + case '\u0014': return 0x14; + case '\u0015': return 0x15; + case '\u0016': return 0x16; + case '\u0017': return 0x17; + case '\u0018': return 0x18; + case '\u0019': return 0x19; + case '\u001A': return 0x1A; + case '\u001B': return 0x1B; + case '\u001C': return 0x1C; + case '\u001D': return 0x1D; + case '\u001E': return 0x1E; + case '\u001F': return 0x1F; + case '\u0020': return 0x20; + case '\u0021': return 0x21; + case '\u0022': return 0x22; + case '\u0023': return 0x23; + case '\u0024': return 0x24; + case '\u0025': return 0x25; + case '\u0026': return 0x26; + case '\u0027': return 0x27; + case '\u0028': return 0x28; + case '\u0029': return 0x29; + case '\u002A': return 0x2A; + case '\u002B': return 0x2B; + case '\u002C': return 0x2C; + case '\u002D': return 0x2D; + case '\u002E': return 0x2E; + case '\u002F': return 0x2F; + case '\u0030': return 0x30; + case '\u0031': return 0x31; + case '\u0032': return 0x32; + case '\u0033': return 0x33; + case '\u0034': return 0x34; + case '\u0035': return 0x35; + case '\u0036': return 0x36; + case '\u0037': return 0x37; + case '\u0038': return 0x38; + case '\u0039': return 0x39; + case '\u003A': return 0x3A; + case '\u003B': return 0x3B; + case '\u003C': return 0x3C; + case '\u003D': return 0x3D; + case '\u003E': return 0x3E; + case '\u003F': return 0x3F; + case '\u0040': return 0x40; + case '\u0041': return 0x41; + case '\u0042': return 0x42; + case '\u0043': return 0x43; + case '\u0044': return 0x44; + case '\u0045': return 0x45; + case '\u0046': return 0x46; + case '\u0047': return 0x47; + case '\u0048': return 0x48; + case '\u0049': return 0x49; + case '\u004A': return 0x4A; + case '\u004B': return 0x4B; + case '\u004C': return 0x4C; + case '\u004D': return 0x4D; + case '\u004E': return 0x4E; + case '\u004F': return 0x4F; + case '\u0050': return 0x50; + case '\u0051': return 0x51; + case '\u0052': return 0x52; + case '\u0053': return 0x53; + case '\u0054': return 0x54; + case '\u0055': return 0x55; + case '\u0056': return 0x56; + case '\u0057': return 0x57; + case '\u0058': return 0x58; + case '\u0059': return 0x59; + case '\u005A': return 0x5A; + case '\u005B': return 0x5B; + case '\u005C': return 0x5C; + case '\u005D': return 0x5D; + case '\u005E': return 0x5E; + case '\u005F': return 0x5F; + case '\u0060': return 0x60; + case '\u0061': return 0x61; + case '\u0062': return 0x62; + case '\u0063': return 0x63; + case '\u0064': return 0x64; + case '\u0065': return 0x65; + case '\u0066': return 0x66; + case '\u0067': return 0x67; + case '\u0068': return 0x68; + case '\u0069': return 0x69; + case '\u006A': return 0x6A; + case '\u006B': return 0x6B; + case '\u006C': return 0x6C; + case '\u006D': return 0x6D; + case '\u006E': return 0x6E; + case '\u006F': return 0x6F; + case '\u0070': return 0x70; + case '\u0071': return 0x71; + case '\u0072': return 0x72; + case '\u0073': return 0x73; + case '\u0074': return 0x74; + case '\u0075': return 0x75; + case '\u0076': return 0x76; + case '\u0077': return 0x77; + case '\u0078': return 0x78; + case '\u0079': return 0x79; + case '\u007A': return 0x7A; + case '\u007B': return 0x7B; + case '\u007C': return 0x7C; + case '\u007D': return 0x7D; + case '\u007E': return 0x7E; + case '\u007F': return 0x7F; + case '\u00C4': return 0x80; + case '\u00B9': return 0x81; + case '\u00B2': return 0x82; + case '\u00C9': return 0x83; + case '\u00B3': return 0x84; + case '\u00D6': return 0x85; + case '\u00DC': return 0x86; + case '\u0385': return 0x87; + case '\u00E0': return 0x88; + case '\u00E2': return 0x89; + case '\u00E4': return 0x8A; + case '\u0384': return 0x8B; + case '\u00A8': return 0x8C; + case '\u00E7': return 0x8D; + case '\u00E9': return 0x8E; + case '\u00E8': return 0x8F; + case '\u00EA': return 0x90; + case '\u00EB': return 0x91; + case '\u00A3': return 0x92; + case '\u2122': return 0x93; + case '\u00EE': return 0x94; + case '\u00EF': return 0x95; + case '\u2022': return 0x96; + case '\u00BD': return 0x97; + case '\u2030': return 0x98; + case '\u00F4': return 0x99; + case '\u00F6': return 0x9A; + case '\u00A6': return 0x9B; + case '\u20AC': return 0x9C; + case '\u00F9': return 0x9D; + case '\u00FB': return 0x9E; + case '\u00FC': return 0x9F; + case '\u2020': return 0xA0; + case '\u0393': return 0xA1; + case '\u0394': return 0xA2; + case '\u0398': return 0xA3; + case '\u039B': return 0xA4; + case '\u039E': return 0xA5; + case '\u03A0': return 0xA6; + case '\u00DF': return 0xA7; + case '\u00AE': return 0xA8; + case '\u00A9': return 0xA9; + case '\u03A3': return 0xAA; + case '\u03AA': return 0xAB; + case '\u00A7': return 0xAC; + case '\u2260': return 0xAD; + case '\u00B0': return 0xAE; + case '\u00B7': return 0xAF; + case '\u0391': return 0xB0; + case '\u00B1': return 0xB1; + case '\u2264': return 0xB2; + case '\u2265': return 0xB3; + case '\u00A5': return 0xB4; + case '\u0392': return 0xB5; + case '\u0395': return 0xB6; + case '\u0396': return 0xB7; + case '\u0397': return 0xB8; + case '\u0399': return 0xB9; + case '\u039A': return 0xBA; + case '\u039C': return 0xBB; + case '\u03A6': return 0xBC; + case '\u03AB': return 0xBD; + case '\u03A8': return 0xBE; + case '\u03A9': return 0xBF; + case '\u03AC': return 0xC0; + case '\u039D': return 0xC1; + case '\u00AC': return 0xC2; + case '\u039F': return 0xC3; + case '\u03A1': return 0xC4; + case '\u2248': return 0xC5; + case '\u03A4': return 0xC6; + case '\u00AB': return 0xC7; + case '\u00BB': return 0xC8; + case '\u2026': return 0xC9; + case '\u00A0': return 0xCA; + case '\u03A5': return 0xCB; + case '\u03A7': return 0xCC; + case '\u0386': return 0xCD; + case '\u0388': return 0xCE; + case '\u0153': return 0xCF; + case '\u2013': return 0xD0; + case '\u2015': return 0xD1; + case '\u201C': return 0xD2; + case '\u201D': return 0xD3; + case '\u2018': return 0xD4; + case '\u2019': return 0xD5; + case '\u00F7': return 0xD6; + case '\u0389': return 0xD7; + case '\u038A': return 0xD8; + case '\u038C': return 0xD9; + case '\u038E': return 0xDA; + case '\u03AD': return 0xDB; + case '\u03AE': return 0xDC; + case '\u03AF': return 0xDD; + case '\u03CC': return 0xDE; + case '\u038F': return 0xDF; + case '\u03CD': return 0xE0; + case '\u03B1': return 0xE1; + case '\u03B2': return 0xE2; + case '\u03C8': return 0xE3; + case '\u03B4': return 0xE4; + case '\u03B5': return 0xE5; + case '\u03C6': return 0xE6; + case '\u03B3': return 0xE7; + case '\u03B7': return 0xE8; + case '\u03B9': return 0xE9; + case '\u03BE': return 0xEA; + case '\u03BA': return 0xEB; + case '\u03BB': return 0xEC; + case '\u03BC': return 0xED; + case '\u03BD': return 0xEE; + case '\u03BF': return 0xEF; + case '\u03C0': return 0xF0; + case '\u03CE': return 0xF1; + case '\u03C1': return 0xF2; + case '\u03C3': return 0xF3; + case '\u03C4': return 0xF4; + case '\u03B8': return 0xF5; + case '\u03C9': return 0xF6; + case '\u03C2': return 0xF7; + case '\u03C7': return 0xF8; + case '\u03C5': return 0xF9; + case '\u03B6': return 0xFA; + case '\u03CA': return 0xFB; + case '\u03CB': return 0xFC; + case '\u0390': return 0xFD; + case '\u03B0': return 0xFE; + case '\u00AD': return 0xFF; default: // Fallback to '?' return 0x3F; diff --git a/Claunia.Encoding/MacHebrew.cs b/Claunia.Encoding/MacHebrew.cs index fdfd156..1c61da1 100644 --- a/Claunia.Encoding/MacHebrew.cs +++ b/Claunia.Encoding/MacHebrew.cs @@ -29,7 +29,7 @@ using System; namespace Claunia.Encoding { /// - /// Represents an Mac Hebrew character encoding of Unicode characters. + /// Represents an Mac Hebrew character encoding of Unicode characters. /// public class MacHebrew : Encoding { @@ -48,105 +48,154 @@ namespace Claunia.Encoding const bool singleByte = true; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. + /// The Macintosh Hebrew to Unicode character map. /// - public override bool IsBrowserDisplay { - get { return browserDisplay; } - } + // TODO: 0x81 => 0x05F2+0x05B7 + // TODO: 0xC0 => 0xF86A+0x05DC+0x05B9 + // TODO: 0xDE => 0x05B8+0xF87F + static readonly char[] MacHebrewTable = + { + // 0x00 + '\u0000', '\u0001', '\u0002', '\u0003', '\u0004', '\u0005', '\u0006', '\u0007', + // 0x08 + '\u0008', '\u0009', '\u000A', '\u000B', '\u000C', '\u000D', '\u000E', '\u000F', + // 0x10 + '\u0010', '\u0011', '\u0012', '\u0013', '\u0014', '\u0015', '\u0016', '\u0017', + // 0x18 + '\u0018', '\u0019', '\u001A', '\u001B', '\u001C', '\u001D', '\u001E', '\u001F', + // 0x20 + '\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027', + // 0x28 + '\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F', + // 0x30 + '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', + // 0x38 + '\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F', + // 0x40 + '\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047', + // 0x48 + '\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F', + // 0x50 + '\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057', + // 0x58 + '\u0058', '\u0059', '\u005A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F', + // 0x60 + '\u0060', '\u0061', '\u0062', '\u0063', '\u0064', '\u0065', '\u0066', '\u0067', + // 0x68 + '\u0068', '\u0069', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F', + // 0x70 + '\u0070', '\u0071', '\u0072', '\u0073', '\u0074', '\u0075', '\u0076', '\u0077', + // 0x78 + '\u0078', '\u0079', '\u007A', '\u007B', '\u007C', '\u007D', '\u007E', '\u007F', + // 0x80 + '\u00C4', '\u0081', '\u00C7', '\u00C9', '\u00D1', '\u00D6', '\u00DC', '\u00E1', + // 0x88 + '\u00E0', '\u00E2', '\u00E4', '\u00E3', '\u00E5', '\u00E7', '\u00E9', '\u00E8', + // 0x90 + '\u00EA', '\u00EB', '\u00ED', '\u00EC', '\u00EE', '\u00EF', '\u00F1', '\u00F3', + // 0x98 + '\u00F2', '\u00F4', '\u00F6', '\u00F5', '\u00FA', '\u00F9', '\u00FB', '\u00FC', + // 0xA0 + '\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u20AA', '\u0027', + // 0xA8 + '\u0029', '\u0028', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F', + // 0xB0 + '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', + // 0xB8 + '\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F', + // 0xC0 + '\uF86A', '\u201E', '\uF89B', '\uF89C', '\uF89D', '\uF89E', '\u05BC', '\uFB4B', + // 0xC8 + '\uFB35', '\u2026', '\u00A0', '\u05B8', '\u05B7', '\u05B5', '\u05B6', '\u05B4', + // 0xD0 + '\u2013', '\u2014', '\u201C', '\u201D', '\u2018', '\u2019', '\uFB2A', '\uFB2B', + // 0xD8 + '\u05BF', '\u05B0', '\u05B2', '\u05B1', '\u05BB', '\u05B9', '\u05B8', '\u05B3', + // 0xE0 + '\u05D0', '\u05D1', '\u05D2', '\u05D3', '\u05D4', '\u05D5', '\u05D6', '\u05D7', + // 0xE8 + '\u05D8', '\u05D9', '\u05DA', '\u05DB', '\u05DC', '\u05DD', '\u05DE', '\u05DF', + // 0xF0 + '\u05E0', '\u05E1', '\u05E2', '\u05E3', '\u05E4', '\u05E5', '\u05E6', '\u05E7', + // 0xF8 + '\u05E8', '\u05E9', '\u05EA', '\u007D', '\u005D', '\u007B', '\u005B', '\u007C' + }; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. + /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. /// - public override bool IsBrowserSave { - get { return browserSave; } - } + public override bool IsBrowserDisplay => browserDisplay; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. + /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. /// - public override bool IsMailNewsDisplay { - get { return mailNewsDisplay; } - } + public override bool IsBrowserSave => browserSave; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. /// - public override bool IsMailNewsSave { - get { return mailNewsSave; } - } + public override bool IsMailNewsDisplay => mailNewsDisplay; /// - /// Gets a value indicating whether the current encoding is read-only. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// + public override bool IsMailNewsSave => mailNewsSave; + + /// + /// Gets a value indicating whether the current encoding is read-only. /// /// The is single byte. - public override bool IsReadOnly { - get { return readOnly; } - } + public override bool IsReadOnly => readOnly; /// - /// Gets a value indicating whether the current encoding uses single-byte code points. + /// Gets a value indicating whether the current encoding uses single-byte code points. /// - public override bool IsSingleByte { - get { return singleByte; } - } + public override bool IsSingleByte => singleByte; /// - /// Gets the code page identifier of the current Encoding. + /// Gets the code page identifier of the current Encoding. /// - public override int CodePage { - get { return _codepage; } - } + public override int CodePage => _codepage; /// - /// Gets a name for the current encoding that can be used with mail agent body tags + /// Gets a name for the current encoding that can be used with mail agent body tags /// - public override string BodyName { - get { return _bodyname; } - } + public override string BodyName => _bodyname; /// - /// Gets a name for the current encoding that can be used with mail agent header tags + /// Gets a name for the current encoding that can be used with mail agent header tags /// - public override string HeaderName { - get { return _headername; } - } + public override string HeaderName => _headername; /// - /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. + /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. /// - public override string WebName { - get { return _webname; } - } + public override string WebName => _webname; /// - /// Gets the human-readable description of the current encoding. + /// Gets the human-readable description of the current encoding. /// - public override string EncodingName { - get { return _encodingname; } - } + public override string EncodingName => _encodingname; /// - /// Gets the Windows operating system code page that most closely corresponds to the current encoding. + /// Gets the Windows operating system code page that most closely corresponds to the current encoding. /// - public override int WindowsCodePage { - get { return _windowsCodepage; } - } + public override int WindowsCodePage => _windowsCodepage; /// - /// Calculates the number of bytes produced by encoding the characters in the specified . + /// Calculates the number of bytes produced by encoding the characters in the specified . /// /// The number of bytes produced by encoding the specified characters. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. public override int GetByteCount(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return s.Length; } /// - /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. + /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. /// /// The number of bytes produced by encoding the specified characters. /// The character array containing the set of characters to encode. @@ -154,36 +203,32 @@ namespace Claunia.Encoding /// The number of characters to encode. public override int GetByteCount(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0 || index >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0 || index >= chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0 || index + count > chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(count < 0 || index + count > chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); return count; } /// - /// Calculates the number of bytes produced by encoding all the characters in the specified character array. + /// Calculates the number of bytes produced by encoding all the characters in the specified character array. /// /// The number of bytes produced by encoding all the characters in the specified character array. /// The character array containing the characters to encode. public override int GetByteCount(char[] chars) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); return chars.Length; } /// - /// Encodes a set of characters from the specified into the specified byte array. + /// Encodes a set of characters from the specified into the specified byte array. /// /// The actual number of bytes written into bytes. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. /// The index of the first character to encode. /// The number of characters to encode. /// The byte array to contain the resulting sequence of bytes. @@ -194,20 +239,19 @@ namespace Claunia.Encoding } /// - /// Encodes all the characters in the specified string into a sequence of bytes. + /// Encodes all the characters in the specified string into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The string containing the characters to encode. public override byte[] GetBytes(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return GetBytes(s.ToCharArray(), 0, s.Length); } /// - /// Encodes a set of characters from the specified character array into the specified byte array. + /// Encodes a set of characters from the specified character array into the specified byte array. /// /// The actual number of bytes written into bytes. /// The character array containing the set of characters to encode. @@ -217,43 +261,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting sequence of bytes. public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount + charIndex > chars.Length) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount + charIndex > chars.Length) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteIndex + charCount > bytes.Length) - throw new ArgumentException(nameof(bytes)); + if(byteIndex + charCount > bytes.Length) throw new ArgumentException(nameof(bytes)); byte[] temp = GetBytes(chars, charIndex, charCount); - for(int i = 0; i < temp.Length; i++) - bytes[i + byteIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) bytes[i + byteIndex] = temp[i]; return charCount; } /// - /// Encodes a set of characters from the specified character array into a sequence of bytes. + /// Encodes a set of characters from the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the set of characters to encode. @@ -261,28 +295,23 @@ namespace Claunia.Encoding /// The number of characters to encode. public override byte[] GetBytes(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > chars.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > chars.Length) throw new ArgumentOutOfRangeException(nameof(count)); byte[] bytes = new byte[count]; - for(int i = 0; i < count; i++) - bytes[i] = GetByte(chars[index + i]); + for(int i = 0; i < count; i++) bytes[i] = GetByte(chars[index + i]); return bytes; } /// - /// Encodes all the characters in the specified character array into a sequence of bytes. + /// Encodes all the characters in the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the characters to encode. @@ -292,7 +321,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. + /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -302,7 +331,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. + /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -310,23 +339,19 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override int GetCharCount(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); return count; } /// - /// Decodes a sequence of bytes from the specified byte array into the specified character array. + /// Decodes a sequence of bytes from the specified byte array into the specified character array. /// /// The actual number of characters written into chars. /// The byte array containing the sequence of bytes to decode. @@ -336,43 +361,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting set of characters. public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount + byteIndex > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount + byteIndex > bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charIndex + byteCount > chars.Length) - throw new ArgumentException(nameof(chars)); + if(charIndex + byteCount > chars.Length) throw new ArgumentException(nameof(chars)); char[] temp = GetChars(bytes, byteIndex, byteCount); - for(int i = 0; i < temp.Length; i++) - chars[i + charIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) chars[i + charIndex] = temp[i]; return byteCount; } /// - /// Decodes all the bytes in the specified byte array into a set of characters. + /// Decodes all the bytes in the specified byte array into a set of characters. /// /// A character array containing the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -382,7 +397,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a set of characters. + /// Decodes a sequence of bytes from the specified byte array into a set of characters. /// /// The chars. /// The byte array containing the sequence of bytes to decode. @@ -390,54 +405,47 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override char[] GetChars(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); char[] chars = new char[count]; - for(int i = 0; i < count; i++) - chars[i] = GetChar(bytes[index + i]); + for(int i = 0; i < count; i++) chars[i] = GetChar(bytes[index + i]); return chars; } /// - /// Calculates the maximum number of bytes produced by encoding the specified number of characters. + /// Calculates the maximum number of bytes produced by encoding the specified number of characters. /// /// The maximum number of bytes produced by encoding the specified number of characters. /// The number of characters to encode. public override int GetMaxByteCount(int charCount) { - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); return charCount; } /// - /// Calculates the maximum number of characters produced by decoding the specified number of bytes. + /// Calculates the maximum number of characters produced by decoding the specified number of bytes. /// /// The maximum number of characters produced by decoding the specified number of bytes. /// The number of bytes to decode. public override int GetMaxCharCount(int byteCount) { - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); return byteCount; } /// - /// Returns a sequence of bytes that specifies the encoding used. + /// Returns a sequence of bytes that specifies the encoding used. /// /// A byte array of length zero, as a preamble is not required. public override byte[] GetPreamble() @@ -446,7 +454,7 @@ namespace Claunia.Encoding } /// - /// Decodes all the bytes in the specified byte array into a string. + /// Decodes all the bytes in the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -456,7 +464,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a string. + /// Decodes a sequence of bytes from the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -468,80 +476,7 @@ namespace Claunia.Encoding } /// - /// The Macintosh Hebrew to Unicode character map. - /// - // TODO: 0x81 => 0x05F2+0x05B7 - // TODO: 0xC0 => 0xF86A+0x05DC+0x05B9 - // TODO: 0xDE => 0x05B8+0xF87F - static readonly char[] MacHebrewTable = { - // 0x00 - '\u0000','\u0001','\u0002','\u0003','\u0004','\u0005','\u0006','\u0007', - // 0x08 - '\u0008','\u0009','\u000A','\u000B','\u000C','\u000D','\u000E','\u000F', - // 0x10 - '\u0010','\u0011','\u0012','\u0013','\u0014','\u0015','\u0016','\u0017', - // 0x18 - '\u0018','\u0019','\u001A','\u001B','\u001C','\u001D','\u001E','\u001F', - // 0x20 - '\u0020','\u0021','\u0022','\u0023','\u0024','\u0025','\u0026','\u0027', - // 0x28 - '\u0028','\u0029','\u002A','\u002B','\u002C','\u002D','\u002E','\u002F', - // 0x30 - '\u0030','\u0031','\u0032','\u0033','\u0034','\u0035','\u0036','\u0037', - // 0x38 - '\u0038','\u0039','\u003A','\u003B','\u003C','\u003D','\u003E','\u003F', - // 0x40 - '\u0040','\u0041','\u0042','\u0043','\u0044','\u0045','\u0046','\u0047', - // 0x48 - '\u0048','\u0049','\u004A','\u004B','\u004C','\u004D','\u004E','\u004F', - // 0x50 - '\u0050','\u0051','\u0052','\u0053','\u0054','\u0055','\u0056','\u0057', - // 0x58 - '\u0058','\u0059','\u005A','\u005B','\u005C','\u005D','\u005E','\u005F', - // 0x60 - '\u0060','\u0061','\u0062','\u0063','\u0064','\u0065','\u0066','\u0067', - // 0x68 - '\u0068','\u0069','\u006A','\u006B','\u006C','\u006D','\u006E','\u006F', - // 0x70 - '\u0070','\u0071','\u0072','\u0073','\u0074','\u0075','\u0076','\u0077', - // 0x78 - '\u0078','\u0079','\u007A','\u007B','\u007C','\u007D','\u007E','\u007F', - // 0x80 - '\u00C4','\u0081','\u00C7','\u00C9','\u00D1','\u00D6','\u00DC','\u00E1', - // 0x88 - '\u00E0','\u00E2','\u00E4','\u00E3','\u00E5','\u00E7','\u00E9','\u00E8', - // 0x90 - '\u00EA','\u00EB','\u00ED','\u00EC','\u00EE','\u00EF','\u00F1','\u00F3', - // 0x98 - '\u00F2','\u00F4','\u00F6','\u00F5','\u00FA','\u00F9','\u00FB','\u00FC', - // 0xA0 - '\u0020','\u0021','\u0022','\u0023','\u0024','\u0025','\u20AA','\u0027', - // 0xA8 - '\u0029','\u0028','\u002A','\u002B','\u002C','\u002D','\u002E','\u002F', - // 0xB0 - '\u0030','\u0031','\u0032','\u0033','\u0034','\u0035','\u0036','\u0037', - // 0xB8 - '\u0038','\u0039','\u003A','\u003B','\u003C','\u003D','\u003E','\u003F', - // 0xC0 - '\uF86A','\u201E','\uF89B','\uF89C','\uF89D','\uF89E','\u05BC','\uFB4B', - // 0xC8 - '\uFB35','\u2026','\u00A0','\u05B8','\u05B7','\u05B5','\u05B6','\u05B4', - // 0xD0 - '\u2013','\u2014','\u201C','\u201D','\u2018','\u2019','\uFB2A','\uFB2B', - // 0xD8 - '\u05BF','\u05B0','\u05B2','\u05B1','\u05BB','\u05B9','\u05B8','\u05B3', - // 0xE0 - '\u05D0','\u05D1','\u05D2','\u05D3','\u05D4','\u05D5','\u05D6','\u05D7', - // 0xE8 - '\u05D8','\u05D9','\u05DA','\u05DB','\u05DC','\u05DD','\u05DE','\u05DF', - // 0xF0 - '\u05E0','\u05E1','\u05E2','\u05E3','\u05E4','\u05E5','\u05E6','\u05E7', - // 0xF8 - '\u05E8','\u05E9','\u05EA','\u007D','\u005D','\u007B','\u005B','\u007C' - }; - - /// - /// Converts a Mac Hebrew character to an Unicode character + /// Converts a Mac Hebrew character to an Unicode character /// /// Unicode character. /// Mac Hebrew character. @@ -551,447 +486,231 @@ namespace Claunia.Encoding } /// - /// Converts a Unicode character to an Mac Hebrew character + /// Converts a Unicode character to an Mac Hebrew character /// /// Mac Hebrew character. /// Unicode character. static byte GetByte(char character) { - switch(character) { - case '\u0000': - return 0x00; - case '\u0001': - return 0x01; - case '\u0002': - return 0x02; - case '\u0003': - return 0x03; - case '\u0004': - return 0x04; - case '\u0005': - return 0x05; - case '\u0006': - return 0x06; - case '\u0007': - return 0x07; - case '\u0008': - return 0x08; - case '\u0009': - return 0x09; - case '\u000A': - return 0x0A; - case '\u000B': - return 0x0B; - case '\u000C': - return 0x0C; - case '\u000D': - return 0x0D; - case '\u000E': - return 0x0E; - case '\u000F': - return 0x0F; - case '\u0010': - return 0x10; - case '\u0011': - return 0x11; - case '\u0012': - return 0x12; - case '\u0013': - return 0x13; - case '\u0014': - return 0x14; - case '\u0015': - return 0x15; - case '\u0016': - return 0x16; - case '\u0017': - return 0x17; - case '\u0018': - return 0x18; - case '\u0019': - return 0x19; - case '\u001A': - return 0x1A; - case '\u001B': - return 0x1B; - case '\u001C': - return 0x1C; - case '\u001D': - return 0x1D; - case '\u001E': - return 0x1E; - case '\u001F': - return 0x1F; - case '\u0020': - return 0x20; - case '\u0021': - return 0x21; - case '\u0022': - return 0x22; - case '\u0023': - return 0x23; - case '\u0024': - return 0x24; - case '\u0025': - return 0x25; - case '\u0026': - return 0x26; - case '\u0027': - return 0x27; - case '\u0028': - return 0x28; - case '\u0029': - return 0x29; - case '\u002A': - return 0x2A; - case '\u002B': - return 0x2B; - case '\u002C': - return 0x2C; - case '\u002D': - return 0x2D; - case '\u002E': - return 0x2E; - case '\u002F': - return 0x2F; - case '\u0030': - return 0x30; - case '\u0031': - return 0x31; - case '\u0032': - return 0x32; - case '\u0033': - return 0x33; - case '\u0034': - return 0x34; - case '\u0035': - return 0x35; - case '\u0036': - return 0x36; - case '\u0037': - return 0x37; - case '\u0038': - return 0x38; - case '\u0039': - return 0x39; - case '\u003A': - return 0x3A; - case '\u003B': - return 0x3B; - case '\u003C': - return 0x3C; - case '\u003D': - return 0x3D; - case '\u003E': - return 0x3E; - case '\u003F': - return 0x3F; - case '\u0040': - return 0x40; - case '\u0041': - return 0x41; - case '\u0042': - return 0x42; - case '\u0043': - return 0x43; - case '\u0044': - return 0x44; - case '\u0045': - return 0x45; - case '\u0046': - return 0x46; - case '\u0047': - return 0x47; - case '\u0048': - return 0x48; - case '\u0049': - return 0x49; - case '\u004A': - return 0x4A; - case '\u004B': - return 0x4B; - case '\u004C': - return 0x4C; - case '\u004D': - return 0x4D; - case '\u004E': - return 0x4E; - case '\u004F': - return 0x4F; - case '\u0050': - return 0x50; - case '\u0051': - return 0x51; - case '\u0052': - return 0x52; - case '\u0053': - return 0x53; - case '\u0054': - return 0x54; - case '\u0055': - return 0x55; - case '\u0056': - return 0x56; - case '\u0057': - return 0x57; - case '\u0058': - return 0x58; - case '\u0059': - return 0x59; - case '\u005A': - return 0x5A; - case '\u005B': - return 0x5B; - case '\u005C': - return 0x5C; - case '\u005D': - return 0x5D; - case '\u005E': - return 0x5E; - case '\u005F': - return 0x5F; - case '\u0060': - return 0x60; - case '\u0061': - return 0x61; - case '\u0062': - return 0x62; - case '\u0063': - return 0x63; - case '\u0064': - return 0x64; - case '\u0065': - return 0x65; - case '\u0066': - return 0x66; - case '\u0067': - return 0x67; - case '\u0068': - return 0x68; - case '\u0069': - return 0x69; - case '\u006A': - return 0x6A; - case '\u006B': - return 0x6B; - case '\u006C': - return 0x6C; - case '\u006D': - return 0x6D; - case '\u006E': - return 0x6E; - case '\u006F': - return 0x6F; - case '\u0070': - return 0x70; - case '\u0071': - return 0x71; - case '\u0072': - return 0x72; - case '\u0073': - return 0x73; - case '\u0074': - return 0x74; - case '\u0075': - return 0x75; - case '\u0076': - return 0x76; - case '\u0077': - return 0x77; - case '\u0078': - return 0x78; - case '\u0079': - return 0x79; - case '\u007A': - return 0x7A; - case '\u007B': - return 0x7B; - case '\u007C': - return 0x7C; - case '\u007D': - return 0x7D; - case '\u007E': - return 0x7E; - case '\u007F': - return 0x7F; - case '\u00C4': - return 0x80; - case '\u00C7': - return 0x82; - case '\u00C9': - return 0x83; - case '\u00D1': - return 0x84; - case '\u00D6': - return 0x85; - case '\u00DC': - return 0x86; - case '\u00E1': - return 0x87; - case '\u00E0': - return 0x88; - case '\u00E2': - return 0x89; - case '\u00E4': - return 0x8A; - case '\u00E3': - return 0x8B; - case '\u00E5': - return 0x8C; - case '\u00E7': - return 0x8D; - case '\u00E9': - return 0x8E; - case '\u00E8': - return 0x8F; - case '\u00EA': - return 0x90; - case '\u00EB': - return 0x91; - case '\u00ED': - return 0x92; - case '\u00EC': - return 0x93; - case '\u00EE': - return 0x94; - case '\u00EF': - return 0x95; - case '\u00F1': - return 0x96; - case '\u00F3': - return 0x97; - case '\u00F2': - return 0x98; - case '\u00F4': - return 0x99; - case '\u00F6': - return 0x9A; - case '\u00F5': - return 0x9B; - case '\u00FA': - return 0x9C; - case '\u00F9': - return 0x9D; - case '\u00FB': - return 0x9E; - case '\u00FC': - return 0x9F; - case '\u20AA': - return 0xA6; - case '\u201E': - return 0xC1; - case '\uF89B': - return 0xC2; - case '\uF89C': - return 0xC3; - case '\uF89D': - return 0xC4; - case '\uF89E': - return 0xC5; - case '\u05BC': - return 0xC6; - case '\uFB4B': - return 0xC7; - case '\uFB35': - return 0xC8; - case '\u2026': - return 0xC9; - case '\u00A0': - return 0xCA; - case '\u05B8': - return 0xCB; - case '\u05B7': - return 0xCC; - case '\u05B5': - return 0xCD; - case '\u05B6': - return 0xCE; - case '\u05B4': - return 0xCF; - case '\u2013': - return 0xD0; - case '\u2014': - return 0xD1; - case '\u201C': - return 0xD2; - case '\u201D': - return 0xD3; - case '\u2018': - return 0xD4; - case '\u2019': - return 0xD5; - case '\uFB2A': - return 0xD6; - case '\uFB2B': - return 0xD7; - case '\u05BF': - return 0xD8; - case '\u05B0': - return 0xD9; - case '\u05B2': - return 0xDA; - case '\u05B1': - return 0xDB; - case '\u05BB': - return 0xDC; - case '\u05B9': - return 0xDD; - case '\u05B3': - return 0xDF; - case '\u05D0': - return 0xE0; - case '\u05D1': - return 0xE1; - case '\u05D2': - return 0xE2; - case '\u05D3': - return 0xE3; - case '\u05D4': - return 0xE4; - case '\u05D5': - return 0xE5; - case '\u05D6': - return 0xE6; - case '\u05D7': - return 0xE7; - case '\u05D8': - return 0xE8; - case '\u05D9': - return 0xE9; - case '\u05DA': - return 0xEA; - case '\u05DB': - return 0xEB; - case '\u05DC': - return 0xEC; - case '\u05DD': - return 0xED; - case '\u05DE': - return 0xEE; - case '\u05DF': - return 0xEF; - case '\u05E0': - return 0xF0; - case '\u05E1': - return 0xF1; - case '\u05E2': - return 0xF2; - case '\u05E3': - return 0xF3; - case '\u05E4': - return 0xF4; - case '\u05E5': - return 0xF5; - case '\u05E6': - return 0xF6; - case '\u05E7': - return 0xF7; - case '\u05E8': - return 0xF8; - case '\u05E9': - return 0xF9; - case '\u05EA': - return 0xFA; + switch(character) + { + case '\u0000': return 0x00; + case '\u0001': return 0x01; + case '\u0002': return 0x02; + case '\u0003': return 0x03; + case '\u0004': return 0x04; + case '\u0005': return 0x05; + case '\u0006': return 0x06; + case '\u0007': return 0x07; + case '\u0008': return 0x08; + case '\u0009': return 0x09; + case '\u000A': return 0x0A; + case '\u000B': return 0x0B; + case '\u000C': return 0x0C; + case '\u000D': return 0x0D; + case '\u000E': return 0x0E; + case '\u000F': return 0x0F; + case '\u0010': return 0x10; + case '\u0011': return 0x11; + case '\u0012': return 0x12; + case '\u0013': return 0x13; + case '\u0014': return 0x14; + case '\u0015': return 0x15; + case '\u0016': return 0x16; + case '\u0017': return 0x17; + case '\u0018': return 0x18; + case '\u0019': return 0x19; + case '\u001A': return 0x1A; + case '\u001B': return 0x1B; + case '\u001C': return 0x1C; + case '\u001D': return 0x1D; + case '\u001E': return 0x1E; + case '\u001F': return 0x1F; + case '\u0020': return 0x20; + case '\u0021': return 0x21; + case '\u0022': return 0x22; + case '\u0023': return 0x23; + case '\u0024': return 0x24; + case '\u0025': return 0x25; + case '\u0026': return 0x26; + case '\u0027': return 0x27; + case '\u0028': return 0x28; + case '\u0029': return 0x29; + case '\u002A': return 0x2A; + case '\u002B': return 0x2B; + case '\u002C': return 0x2C; + case '\u002D': return 0x2D; + case '\u002E': return 0x2E; + case '\u002F': return 0x2F; + case '\u0030': return 0x30; + case '\u0031': return 0x31; + case '\u0032': return 0x32; + case '\u0033': return 0x33; + case '\u0034': return 0x34; + case '\u0035': return 0x35; + case '\u0036': return 0x36; + case '\u0037': return 0x37; + case '\u0038': return 0x38; + case '\u0039': return 0x39; + case '\u003A': return 0x3A; + case '\u003B': return 0x3B; + case '\u003C': return 0x3C; + case '\u003D': return 0x3D; + case '\u003E': return 0x3E; + case '\u003F': return 0x3F; + case '\u0040': return 0x40; + case '\u0041': return 0x41; + case '\u0042': return 0x42; + case '\u0043': return 0x43; + case '\u0044': return 0x44; + case '\u0045': return 0x45; + case '\u0046': return 0x46; + case '\u0047': return 0x47; + case '\u0048': return 0x48; + case '\u0049': return 0x49; + case '\u004A': return 0x4A; + case '\u004B': return 0x4B; + case '\u004C': return 0x4C; + case '\u004D': return 0x4D; + case '\u004E': return 0x4E; + case '\u004F': return 0x4F; + case '\u0050': return 0x50; + case '\u0051': return 0x51; + case '\u0052': return 0x52; + case '\u0053': return 0x53; + case '\u0054': return 0x54; + case '\u0055': return 0x55; + case '\u0056': return 0x56; + case '\u0057': return 0x57; + case '\u0058': return 0x58; + case '\u0059': return 0x59; + case '\u005A': return 0x5A; + case '\u005B': return 0x5B; + case '\u005C': return 0x5C; + case '\u005D': return 0x5D; + case '\u005E': return 0x5E; + case '\u005F': return 0x5F; + case '\u0060': return 0x60; + case '\u0061': return 0x61; + case '\u0062': return 0x62; + case '\u0063': return 0x63; + case '\u0064': return 0x64; + case '\u0065': return 0x65; + case '\u0066': return 0x66; + case '\u0067': return 0x67; + case '\u0068': return 0x68; + case '\u0069': return 0x69; + case '\u006A': return 0x6A; + case '\u006B': return 0x6B; + case '\u006C': return 0x6C; + case '\u006D': return 0x6D; + case '\u006E': return 0x6E; + case '\u006F': return 0x6F; + case '\u0070': return 0x70; + case '\u0071': return 0x71; + case '\u0072': return 0x72; + case '\u0073': return 0x73; + case '\u0074': return 0x74; + case '\u0075': return 0x75; + case '\u0076': return 0x76; + case '\u0077': return 0x77; + case '\u0078': return 0x78; + case '\u0079': return 0x79; + case '\u007A': return 0x7A; + case '\u007B': return 0x7B; + case '\u007C': return 0x7C; + case '\u007D': return 0x7D; + case '\u007E': return 0x7E; + case '\u007F': return 0x7F; + case '\u00C4': return 0x80; + case '\u00C7': return 0x82; + case '\u00C9': return 0x83; + case '\u00D1': return 0x84; + case '\u00D6': return 0x85; + case '\u00DC': return 0x86; + case '\u00E1': return 0x87; + case '\u00E0': return 0x88; + case '\u00E2': return 0x89; + case '\u00E4': return 0x8A; + case '\u00E3': return 0x8B; + case '\u00E5': return 0x8C; + case '\u00E7': return 0x8D; + case '\u00E9': return 0x8E; + case '\u00E8': return 0x8F; + case '\u00EA': return 0x90; + case '\u00EB': return 0x91; + case '\u00ED': return 0x92; + case '\u00EC': return 0x93; + case '\u00EE': return 0x94; + case '\u00EF': return 0x95; + case '\u00F1': return 0x96; + case '\u00F3': return 0x97; + case '\u00F2': return 0x98; + case '\u00F4': return 0x99; + case '\u00F6': return 0x9A; + case '\u00F5': return 0x9B; + case '\u00FA': return 0x9C; + case '\u00F9': return 0x9D; + case '\u00FB': return 0x9E; + case '\u00FC': return 0x9F; + case '\u20AA': return 0xA6; + case '\u201E': return 0xC1; + case '\uF89B': return 0xC2; + case '\uF89C': return 0xC3; + case '\uF89D': return 0xC4; + case '\uF89E': return 0xC5; + case '\u05BC': return 0xC6; + case '\uFB4B': return 0xC7; + case '\uFB35': return 0xC8; + case '\u2026': return 0xC9; + case '\u00A0': return 0xCA; + case '\u05B8': return 0xCB; + case '\u05B7': return 0xCC; + case '\u05B5': return 0xCD; + case '\u05B6': return 0xCE; + case '\u05B4': return 0xCF; + case '\u2013': return 0xD0; + case '\u2014': return 0xD1; + case '\u201C': return 0xD2; + case '\u201D': return 0xD3; + case '\u2018': return 0xD4; + case '\u2019': return 0xD5; + case '\uFB2A': return 0xD6; + case '\uFB2B': return 0xD7; + case '\u05BF': return 0xD8; + case '\u05B0': return 0xD9; + case '\u05B2': return 0xDA; + case '\u05B1': return 0xDB; + case '\u05BB': return 0xDC; + case '\u05B9': return 0xDD; + case '\u05B3': return 0xDF; + case '\u05D0': return 0xE0; + case '\u05D1': return 0xE1; + case '\u05D2': return 0xE2; + case '\u05D3': return 0xE3; + case '\u05D4': return 0xE4; + case '\u05D5': return 0xE5; + case '\u05D6': return 0xE6; + case '\u05D7': return 0xE7; + case '\u05D8': return 0xE8; + case '\u05D9': return 0xE9; + case '\u05DA': return 0xEA; + case '\u05DB': return 0xEB; + case '\u05DC': return 0xEC; + case '\u05DD': return 0xED; + case '\u05DE': return 0xEE; + case '\u05DF': return 0xEF; + case '\u05E0': return 0xF0; + case '\u05E1': return 0xF1; + case '\u05E2': return 0xF2; + case '\u05E3': return 0xF3; + case '\u05E4': return 0xF4; + case '\u05E5': return 0xF5; + case '\u05E6': return 0xF6; + case '\u05E7': return 0xF7; + case '\u05E8': return 0xF8; + case '\u05E9': return 0xF9; + case '\u05EA': return 0xFA; default: // Fallback to '?' return 0x3F; diff --git a/Claunia.Encoding/MacRoman.cs b/Claunia.Encoding/MacRoman.cs index 893bf34..bf4082e 100644 --- a/Claunia.Encoding/MacRoman.cs +++ b/Claunia.Encoding/MacRoman.cs @@ -29,7 +29,7 @@ using System; namespace Claunia.Encoding { /// - /// Represents an Apple Mac character encoding of Unicode characters. + /// Represents an Apple Mac character encoding of Unicode characters. /// public class MacRoman : Encoding { @@ -48,105 +48,152 @@ namespace Claunia.Encoding const bool singleByte = true; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. + /// The Mac to Unicode character map. + /// MacRoman is a superset of LisaRoman. /// - public override bool IsBrowserDisplay { - get { return browserDisplay; } - } + static readonly char[] MacRomanTable = + { + // 0x00 + '\u0000', '\u0001', '\u0002', '\u0003', '\u0004', '\u0005', '\u0006', '\u0007', + // 0x08 + '\u0008', '\u0009', '\u000A', '\u000B', '\u000C', '\u000D', '\u000E', '\u000F', + // 0x10 + '\u0010', '\u0011', '\u0012', '\u0013', '\u0014', '\u0015', '\u0016', '\u0017', + // 0x18 + '\u0018', '\u0019', '\u001A', '\u001B', '\u001C', '\u001D', '\u001E', '\u001F', + // 0x20 + '\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027', + // 0x28 + '\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F', + // 0x30 + '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', + // 0x38 + '\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F', + // 0x40 + '\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047', + // 0x48 + '\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F', + // 0x50 + '\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057', + // 0x58 + '\u0058', '\u0059', '\u005A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F', + // 0x60 + '\u0060', '\u0061', '\u0062', '\u0063', '\u0064', '\u0065', '\u0066', '\u0067', + // 0x68 + '\u0068', '\u0069', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F', + // 0x70 + '\u0070', '\u0071', '\u0072', '\u0073', '\u0074', '\u0075', '\u0076', '\u0077', + // 0x78 + '\u0078', '\u0079', '\u007A', '\u007B', '\u007C', '\u007D', '\u007E', '\u007F', + // 0x80 + '\u00C4', '\u00C5', '\u00C7', '\u00C9', '\u00D1', '\u00D6', '\u00DC', '\u00E1', + // 0x88 + '\u00E0', '\u00E2', '\u00E4', '\u00E3', '\u00E5', '\u00E7', '\u00E9', '\u00E8', + // 0x90 + '\u00EA', '\u00EB', '\u00ED', '\u00EC', '\u00EE', '\u00EF', '\u00F1', '\u00F3', + // 0x98 + '\u00F2', '\u00F4', '\u00F6', '\u00F5', '\u00FA', '\u00F9', '\u00FB', '\u00FC', + // 0xA0 + '\u2020', '\u00B0', '\u00A2', '\u00A3', '\u00A7', '\u2022', '\u00B6', '\u00DF', + // 0xA8 + '\u00AE', '\u00A9', '\u2122', '\u00B4', '\u00A8', '\u2260', '\u00C6', '\u00D8', + // 0xB0 + '\u221E', '\u00B1', '\u2264', '\u2265', '\u00A5', '\u00B5', '\u2202', '\u2211', + // 0xB8 + '\u220F', '\u03C0', '\u222B', '\u00AA', '\u00BA', '\u03A9', '\u00E6', '\u00F8', + // 0xC0 + '\u00BF', '\u00A1', '\u00AC', '\u221A', '\u0192', '\u2248', '\u2206', '\u00AB', + // 0xC8 + '\u00BB', '\u2026', '\u00A0', '\u00C0', '\u00C3', '\u00D5', '\u0152', '\u0153', + // 0xD0 + '\u2013', '\u2014', '\u201C', '\u201D', '\u2018', '\u2019', '\u00F7', '\u25CA', + // 0xD8 + '\u00FF', '\u0178', '\u2044', '\u20AC', '\u2039', '\u203A', '\uFB01', '\uFB02', + // 0xE0 + '\u2021', '\u00B7', '\u201A', '\u201E', '\u2030', '\u00C2', '\u00CA', '\u00C1', + // 0xE8 + '\u00CB', '\u00C8', '\u00CD', '\u00CE', '\u00CF', '\u00CC', '\u00D3', '\u00D4', + // 0xF0 + '\uF8FF', '\u00D2', '\u00DA', '\u00DB', '\u00D9', '\u0131', '\u02C6', '\u02DC', + // 0xF8 + '\u00AF', '\u02D8', '\u02D9', '\u02DA', '\u00B8', '\u02DD', '\u02DB', '\u02C7' + }; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. + /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. /// - public override bool IsBrowserSave { - get { return browserSave; } - } + public override bool IsBrowserDisplay => browserDisplay; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. + /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. /// - public override bool IsMailNewsDisplay { - get { return mailNewsDisplay; } - } + public override bool IsBrowserSave => browserSave; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. /// - public override bool IsMailNewsSave { - get { return mailNewsSave; } - } + public override bool IsMailNewsDisplay => mailNewsDisplay; /// - /// Gets a value indicating whether the current encoding is read-only. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// + public override bool IsMailNewsSave => mailNewsSave; + + /// + /// Gets a value indicating whether the current encoding is read-only. /// /// The is single byte. - public override bool IsReadOnly { - get { return readOnly; } - } + public override bool IsReadOnly => readOnly; /// - /// Gets a value indicating whether the current encoding uses single-byte code points. + /// Gets a value indicating whether the current encoding uses single-byte code points. /// - public override bool IsSingleByte { - get { return singleByte; } - } + public override bool IsSingleByte => singleByte; /// - /// Gets the code page identifier of the current Encoding. + /// Gets the code page identifier of the current Encoding. /// - public override int CodePage { - get { return _codepage; } - } + public override int CodePage => _codepage; /// - /// Gets a name for the current encoding that can be used with mail agent body tags + /// Gets a name for the current encoding that can be used with mail agent body tags /// - public override string BodyName { - get { return _bodyname; } - } + public override string BodyName => _bodyname; /// - /// Gets a name for the current encoding that can be used with mail agent header tags + /// Gets a name for the current encoding that can be used with mail agent header tags /// - public override string HeaderName { - get { return _headername; } - } + public override string HeaderName => _headername; /// - /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. + /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. /// - public override string WebName { - get { return _webname; } - } + public override string WebName => _webname; /// - /// Gets the human-readable description of the current encoding. + /// Gets the human-readable description of the current encoding. /// - public override string EncodingName { - get { return _encodingname; } - } + public override string EncodingName => _encodingname; /// - /// Gets the Windows operating system code page that most closely corresponds to the current encoding. + /// Gets the Windows operating system code page that most closely corresponds to the current encoding. /// - public override int WindowsCodePage { - get { return _windowsCodepage; } - } + public override int WindowsCodePage => _windowsCodepage; /// - /// Calculates the number of bytes produced by encoding the characters in the specified . + /// Calculates the number of bytes produced by encoding the characters in the specified . /// /// The number of bytes produced by encoding the specified characters. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. public override int GetByteCount(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return s.Length; } /// - /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. + /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. /// /// The number of bytes produced by encoding the specified characters. /// The character array containing the set of characters to encode. @@ -154,36 +201,32 @@ namespace Claunia.Encoding /// The number of characters to encode. public override int GetByteCount(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0 || index >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0 || index >= chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0 || index + count > chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(count < 0 || index + count > chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); return count; } /// - /// Calculates the number of bytes produced by encoding all the characters in the specified character array. + /// Calculates the number of bytes produced by encoding all the characters in the specified character array. /// /// The number of bytes produced by encoding all the characters in the specified character array. /// The character array containing the characters to encode. public override int GetByteCount(char[] chars) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); return chars.Length; } /// - /// Encodes a set of characters from the specified into the specified byte array. + /// Encodes a set of characters from the specified into the specified byte array. /// /// The actual number of bytes written into bytes. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. /// The index of the first character to encode. /// The number of characters to encode. /// The byte array to contain the resulting sequence of bytes. @@ -194,20 +237,19 @@ namespace Claunia.Encoding } /// - /// Encodes all the characters in the specified string into a sequence of bytes. + /// Encodes all the characters in the specified string into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The string containing the characters to encode. public override byte[] GetBytes(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return GetBytes(s.ToCharArray(), 0, s.Length); } /// - /// Encodes a set of characters from the specified character array into the specified byte array. + /// Encodes a set of characters from the specified character array into the specified byte array. /// /// The actual number of bytes written into bytes. /// The character array containing the set of characters to encode. @@ -217,43 +259,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting sequence of bytes. public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount + charIndex > chars.Length) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount + charIndex > chars.Length) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteIndex + charCount > bytes.Length) - throw new ArgumentException(nameof(bytes)); + if(byteIndex + charCount > bytes.Length) throw new ArgumentException(nameof(bytes)); byte[] temp = GetBytes(chars, charIndex, charCount); - for(int i = 0; i < temp.Length; i++) - bytes[i + byteIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) bytes[i + byteIndex] = temp[i]; return charCount; } /// - /// Encodes a set of characters from the specified character array into a sequence of bytes. + /// Encodes a set of characters from the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the set of characters to encode. @@ -261,28 +293,23 @@ namespace Claunia.Encoding /// The number of characters to encode. public override byte[] GetBytes(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > chars.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > chars.Length) throw new ArgumentOutOfRangeException(nameof(count)); byte[] bytes = new byte[count]; - for(int i = 0; i < count; i++) - bytes[i] = GetByte(chars[index + i]); + for(int i = 0; i < count; i++) bytes[i] = GetByte(chars[index + i]); return bytes; } /// - /// Encodes all the characters in the specified character array into a sequence of bytes. + /// Encodes all the characters in the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the characters to encode. @@ -292,7 +319,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. + /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -302,7 +329,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. + /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -310,23 +337,19 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override int GetCharCount(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); return count; } /// - /// Decodes a sequence of bytes from the specified byte array into the specified character array. + /// Decodes a sequence of bytes from the specified byte array into the specified character array. /// /// The actual number of characters written into chars. /// The byte array containing the sequence of bytes to decode. @@ -336,43 +359,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting set of characters. public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount + byteIndex > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount + byteIndex > bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charIndex + byteCount > chars.Length) - throw new ArgumentException(nameof(chars)); + if(charIndex + byteCount > chars.Length) throw new ArgumentException(nameof(chars)); char[] temp = GetChars(bytes, byteIndex, byteCount); - for(int i = 0; i < temp.Length; i++) - chars[i + charIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) chars[i + charIndex] = temp[i]; return byteCount; } /// - /// Decodes all the bytes in the specified byte array into a set of characters. + /// Decodes all the bytes in the specified byte array into a set of characters. /// /// A character array containing the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -382,7 +395,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a set of characters. + /// Decodes a sequence of bytes from the specified byte array into a set of characters. /// /// The chars. /// The byte array containing the sequence of bytes to decode. @@ -390,54 +403,47 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override char[] GetChars(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); char[] chars = new char[count]; - for(int i = 0; i < count; i++) - chars[i] = GetChar(bytes[index + i]); + for(int i = 0; i < count; i++) chars[i] = GetChar(bytes[index + i]); return chars; } /// - /// Calculates the maximum number of bytes produced by encoding the specified number of characters. + /// Calculates the maximum number of bytes produced by encoding the specified number of characters. /// /// The maximum number of bytes produced by encoding the specified number of characters. /// The number of characters to encode. public override int GetMaxByteCount(int charCount) { - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); return charCount; } /// - /// Calculates the maximum number of characters produced by decoding the specified number of bytes. + /// Calculates the maximum number of characters produced by decoding the specified number of bytes. /// /// The maximum number of characters produced by decoding the specified number of bytes. /// The number of bytes to decode. public override int GetMaxCharCount(int byteCount) { - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); return byteCount; } /// - /// Returns a sequence of bytes that specifies the encoding used. + /// Returns a sequence of bytes that specifies the encoding used. /// /// A byte array of length zero, as a preamble is not required. public override byte[] GetPreamble() @@ -446,7 +452,7 @@ namespace Claunia.Encoding } /// - /// Decodes all the bytes in the specified byte array into a string. + /// Decodes all the bytes in the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -456,7 +462,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a string. + /// Decodes a sequence of bytes from the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -468,78 +474,7 @@ namespace Claunia.Encoding } /// - /// The Mac to Unicode character map. - /// MacRoman is a superset of LisaRoman. - /// - static readonly char[] MacRomanTable = { - // 0x00 - '\u0000','\u0001','\u0002','\u0003','\u0004','\u0005','\u0006','\u0007', - // 0x08 - '\u0008','\u0009','\u000A','\u000B','\u000C','\u000D','\u000E','\u000F', - // 0x10 - '\u0010','\u0011','\u0012','\u0013','\u0014','\u0015','\u0016','\u0017', - // 0x18 - '\u0018','\u0019','\u001A','\u001B','\u001C','\u001D','\u001E','\u001F', - // 0x20 - '\u0020','\u0021','\u0022','\u0023','\u0024','\u0025','\u0026','\u0027', - // 0x28 - '\u0028','\u0029','\u002A','\u002B','\u002C','\u002D','\u002E','\u002F', - // 0x30 - '\u0030','\u0031','\u0032','\u0033','\u0034','\u0035','\u0036','\u0037', - // 0x38 - '\u0038','\u0039','\u003A','\u003B','\u003C','\u003D','\u003E','\u003F', - // 0x40 - '\u0040','\u0041','\u0042','\u0043','\u0044','\u0045','\u0046','\u0047', - // 0x48 - '\u0048','\u0049','\u004A','\u004B','\u004C','\u004D','\u004E','\u004F', - // 0x50 - '\u0050','\u0051','\u0052','\u0053','\u0054','\u0055','\u0056','\u0057', - // 0x58 - '\u0058','\u0059','\u005A','\u005B','\u005C','\u005D','\u005E','\u005F', - // 0x60 - '\u0060','\u0061','\u0062','\u0063','\u0064','\u0065','\u0066','\u0067', - // 0x68 - '\u0068','\u0069','\u006A','\u006B','\u006C','\u006D','\u006E','\u006F', - // 0x70 - '\u0070','\u0071','\u0072','\u0073','\u0074','\u0075','\u0076','\u0077', - // 0x78 - '\u0078','\u0079','\u007A','\u007B','\u007C','\u007D','\u007E','\u007F', - // 0x80 - '\u00C4','\u00C5','\u00C7','\u00C9','\u00D1','\u00D6','\u00DC','\u00E1', - // 0x88 - '\u00E0','\u00E2','\u00E4','\u00E3','\u00E5','\u00E7','\u00E9','\u00E8', - // 0x90 - '\u00EA','\u00EB','\u00ED','\u00EC','\u00EE','\u00EF','\u00F1','\u00F3', - // 0x98 - '\u00F2','\u00F4','\u00F6','\u00F5','\u00FA','\u00F9','\u00FB','\u00FC', - // 0xA0 - '\u2020','\u00B0','\u00A2','\u00A3','\u00A7','\u2022','\u00B6','\u00DF', - // 0xA8 - '\u00AE','\u00A9','\u2122','\u00B4','\u00A8','\u2260','\u00C6','\u00D8', - // 0xB0 - '\u221E','\u00B1','\u2264','\u2265','\u00A5','\u00B5','\u2202','\u2211', - // 0xB8 - '\u220F','\u03C0','\u222B','\u00AA','\u00BA','\u03A9','\u00E6','\u00F8', - // 0xC0 - '\u00BF','\u00A1','\u00AC','\u221A','\u0192','\u2248','\u2206','\u00AB', - // 0xC8 - '\u00BB','\u2026','\u00A0','\u00C0','\u00C3','\u00D5','\u0152','\u0153', - // 0xD0 - '\u2013','\u2014','\u201C','\u201D','\u2018','\u2019','\u00F7','\u25CA', - // 0xD8 - '\u00FF','\u0178','\u2044','\u20AC','\u2039','\u203A','\uFB01','\uFB02', - // 0xE0 - '\u2021','\u00B7','\u201A','\u201E','\u2030','\u00C2','\u00CA','\u00C1', - // 0xE8 - '\u00CB','\u00C8','\u00CD','\u00CE','\u00CF','\u00CC','\u00D3','\u00D4', - // 0xF0 - '\uF8FF','\u00D2','\u00DA','\u00DB','\u00D9','\u0131','\u02C6','\u02DC', - // 0xF8 - '\u00AF','\u02D8','\u02D9','\u02DA','\u00B8','\u02DD','\u02DB','\u02C7' - }; - - /// - /// Converts a MacRoman character to an Unicode character + /// Converts a MacRoman character to an Unicode character /// /// Unicode character. /// MacRoman character. @@ -549,529 +484,274 @@ namespace Claunia.Encoding } /// - /// Converts a Unicode character to an MacRoman character + /// Converts a Unicode character to an MacRoman character /// /// MacRoman character. /// Unicode character. static byte GetByte(char character) { - switch(character) { - case '\u0000': - return 0x00; - case '\u0001': - return 0x01; - case '\u0002': - return 0x02; - case '\u0003': - return 0x03; - case '\u0004': - return 0x04; - case '\u0005': - return 0x05; - case '\u0006': - return 0x06; - case '\u0007': - return 0x07; - case '\u0008': - return 0x08; - case '\u0009': - return 0x09; - case '\u000A': - return 0x0A; - case '\u000B': - return 0x0B; - case '\u000C': - return 0x0C; - case '\u000D': - return 0x0D; - case '\u000E': - return 0x0E; - case '\u000F': - return 0x0F; - case '\u0010': - return 0x10; - case '\u0011': - return 0x11; - case '\u0012': - return 0x12; - case '\u0013': - return 0x13; - case '\u0014': - return 0x14; - case '\u0015': - return 0x15; - case '\u0016': - return 0x16; - case '\u0017': - return 0x17; - case '\u0018': - return 0x18; - case '\u0019': - return 0x19; - case '\u001A': - return 0x1A; - case '\u001B': - return 0x1B; - case '\u001C': - return 0x1C; - case '\u001D': - return 0x1D; - case '\u001E': - return 0x1E; - case '\u001F': - return 0x1F; - case '\u0020': - return 0x20; - case '\u0021': - return 0x21; - case '\u0022': - return 0x22; - case '\u0023': - return 0x23; - case '\u0024': - return 0x24; - case '\u0025': - return 0x25; - case '\u0026': - return 0x26; - case '\u0027': - return 0x27; - case '\u0028': - return 0x28; - case '\u0029': - return 0x29; - case '\u002A': - return 0x2A; - case '\u002B': - return 0x2B; - case '\u002C': - return 0x2C; - case '\u002D': - return 0x2D; - case '\u002E': - return 0x2E; - case '\u002F': - return 0x2F; - case '\u0030': - return 0x30; - case '\u0031': - return 0x31; - case '\u0032': - return 0x32; - case '\u0033': - return 0x33; - case '\u0034': - return 0x34; - case '\u0035': - return 0x35; - case '\u0036': - return 0x36; - case '\u0037': - return 0x37; - case '\u0038': - return 0x38; - case '\u0039': - return 0x39; - case '\u003A': - return 0x3A; - case '\u003B': - return 0x3B; - case '\u003C': - return 0x3C; - case '\u003D': - return 0x3D; - case '\u003E': - return 0x3E; - case '\u003F': - return 0x3F; - case '\u0040': - return 0x40; - case '\u0041': - return 0x41; - case '\u0042': - return 0x42; - case '\u0043': - return 0x43; - case '\u0044': - return 0x44; - case '\u0045': - return 0x45; - case '\u0046': - return 0x46; - case '\u0047': - return 0x47; - case '\u0048': - return 0x48; - case '\u0049': - return 0x49; - case '\u004A': - return 0x4A; - case '\u004B': - return 0x4B; - case '\u004C': - return 0x4C; - case '\u004D': - return 0x4D; - case '\u004E': - return 0x4E; - case '\u004F': - return 0x4F; - case '\u0050': - return 0x50; - case '\u0051': - return 0x51; - case '\u0052': - return 0x52; - case '\u0053': - return 0x53; - case '\u0054': - return 0x54; - case '\u0055': - return 0x55; - case '\u0056': - return 0x56; - case '\u0057': - return 0x57; - case '\u0058': - return 0x58; - case '\u0059': - return 0x59; - case '\u005A': - return 0x5A; - case '\u005B': - return 0x5B; - case '\u005C': - return 0x5C; - case '\u005D': - return 0x5D; - case '\u005E': - return 0x5E; - case '\u005F': - return 0x5F; - case '\u0060': - return 0x60; - case '\u0061': - return 0x61; - case '\u0062': - return 0x62; - case '\u0063': - return 0x63; - case '\u0064': - return 0x64; - case '\u0065': - return 0x65; - case '\u0066': - return 0x66; - case '\u0067': - return 0x67; - case '\u0068': - return 0x68; - case '\u0069': - return 0x69; - case '\u006A': - return 0x6A; - case '\u006B': - return 0x6B; - case '\u006C': - return 0x6C; - case '\u006D': - return 0x6D; - case '\u006E': - return 0x6E; - case '\u006F': - return 0x6F; - case '\u0070': - return 0x70; - case '\u0071': - return 0x71; - case '\u0072': - return 0x72; - case '\u0073': - return 0x73; - case '\u0074': - return 0x74; - case '\u0075': - return 0x75; - case '\u0076': - return 0x76; - case '\u0077': - return 0x77; - case '\u0078': - return 0x78; - case '\u0079': - return 0x79; - case '\u007A': - return 0x7A; - case '\u007B': - return 0x7B; - case '\u007C': - return 0x7C; - case '\u007D': - return 0x7D; - case '\u007E': - return 0x7E; - case '\u007F': - return 0x7F; - case '\u00C4': - return 0x80; - case '\u00C5': - return 0x81; - case '\u00C7': - return 0x82; - case '\u00C9': - return 0x83; - case '\u00D1': - return 0x84; - case '\u00D6': - return 0x85; - case '\u00DC': - return 0x86; - case '\u00E1': - return 0x87; - case '\u00E0': - return 0x88; - case '\u00E2': - return 0x89; - case '\u00E4': - return 0x8A; - case '\u00E3': - return 0x8B; - case '\u00E5': - return 0x8C; - case '\u00E7': - return 0x8D; - case '\u00E9': - return 0x8E; - case '\u00E8': - return 0x8F; - case '\u00EA': - return 0x90; - case '\u00EB': - return 0x91; - case '\u00ED': - return 0x92; - case '\u00EC': - return 0x93; - case '\u00EE': - return 0x94; - case '\u00EF': - return 0x95; - case '\u00F1': - return 0x96; - case '\u00F3': - return 0x97; - case '\u00F2': - return 0x98; - case '\u00F4': - return 0x99; - case '\u00F6': - return 0x9A; - case '\u00F5': - return 0x9B; - case '\u00FA': - return 0x9C; - case '\u00F9': - return 0x9D; - case '\u00FB': - return 0x9E; - case '\u00FC': - return 0x9F; - case '\u2020': - return 0xA0; - case '\u00B0': - return 0xA1; - case '\u00A2': - return 0xA2; - case '\u00A3': - return 0xA3; - case '\u00A7': - return 0xA4; - case '\u2022': - return 0xA5; - case '\u00B6': - return 0xA6; - case '\u00DF': - return 0xA7; - case '\u00AE': - return 0xA8; - case '\u00A9': - return 0xA9; - case '\u2122': - return 0xAA; - case '\u00B4': - return 0xAB; - case '\u00A8': - return 0xAC; - case '\u2260': - return 0xAD; - case '\u00C6': - return 0xAE; - case '\u00D8': - return 0xAF; - case '\u221E': - return 0xB0; - case '\u00B1': - return 0xB1; - case '\u2264': - return 0xB2; - case '\u2265': - return 0xB3; - case '\u00A5': - return 0xB4; - case '\u00B5': - return 0xB5; - case '\u2202': - return 0xB6; - case '\u2211': - return 0xB7; - case '\u220F': - return 0xB8; - case '\u03C0': - return 0xB9; - case '\u222B': - return 0xBA; - case '\u00AA': - return 0xBB; - case '\u00BA': - return 0xBC; - case '\u03A9': - return 0xBD; - case '\u00E6': - return 0xBE; - case '\u00F8': - return 0xBF; - case '\u00BF': - return 0xC0; - case '\u00A1': - return 0xC1; - case '\u00AC': - return 0xC2; - case '\u221A': - return 0xC3; - case '\u0192': - return 0xC4; - case '\u2248': - return 0xC5; - case '\u2206': - return 0xC6; - case '\u00AB': - return 0xC7; - case '\u00BB': - return 0xC8; - case '\u2026': - return 0xC9; - case '\u00A0': - return 0xCA; - case '\u00C0': - return 0xCB; - case '\u00C3': - return 0xCC; - case '\u00D5': - return 0xCD; - case '\u0152': - return 0xCE; - case '\u0153': - return 0xCF; - case '\u2013': - return 0xD0; - case '\u2014': - return 0xD1; - case '\u201C': - return 0xD2; - case '\u201D': - return 0xD3; - case '\u2018': - return 0xD4; - case '\u2019': - return 0xD5; - case '\u00F7': - return 0xD6; - case '\u25CA': - return 0xD7; - case '\u00FF': - return 0xD8; - case '\u0178': - return 0xD9; - case '\u2044': - return 0xDA; - case '\u20AC': - return 0xDB; - case '\u2039': - return 0xDC; - case '\u203A': - return 0xDD; - case '\uFB01': - return 0xDE; - case '\uFB02': - return 0xDF; - case '\u2021': - return 0xE0; - case '\u00B7': - return 0xE1; - case '\u201A': - return 0xE2; - case '\u201E': - return 0xE3; - case '\u2030': - return 0xE4; - case '\u00C2': - return 0xE5; - case '\u00CA': - return 0xE6; - case '\u00C1': - return 0xE7; - case '\u00CB': - return 0xE8; - case '\u00C8': - return 0xE9; - case '\u00CD': - return 0xEA; - case '\u00CE': - return 0xEB; - case '\u00CF': - return 0xEC; - case '\u00CC': - return 0xED; - case '\u00D3': - return 0xEE; - case '\u00D4': - return 0xEF; - case '\uF8FF': - return 0xF0; - case '\u00D2': - return 0xF1; - case '\u00DA': - return 0xF2; - case '\u00DB': - return 0xF3; - case '\u00D9': - return 0xF4; - case '\u0131': - return 0xF5; - case '\u02C6': - return 0xF6; - case '\u02DC': - return 0xF7; - case '\u00AF': - return 0xF8; - case '\u02D8': - return 0xF9; - case '\u02D9': - return 0xFA; - case '\u02DA': - return 0xFB; - case '\u00B8': - return 0xFC; - case '\u02DD': - return 0xFD; - case '\u02DB': - return 0xFE; - case '\u02C7': - return 0xFF; + switch(character) + { + case '\u0000': return 0x00; + case '\u0001': return 0x01; + case '\u0002': return 0x02; + case '\u0003': return 0x03; + case '\u0004': return 0x04; + case '\u0005': return 0x05; + case '\u0006': return 0x06; + case '\u0007': return 0x07; + case '\u0008': return 0x08; + case '\u0009': return 0x09; + case '\u000A': return 0x0A; + case '\u000B': return 0x0B; + case '\u000C': return 0x0C; + case '\u000D': return 0x0D; + case '\u000E': return 0x0E; + case '\u000F': return 0x0F; + case '\u0010': return 0x10; + case '\u0011': return 0x11; + case '\u0012': return 0x12; + case '\u0013': return 0x13; + case '\u0014': return 0x14; + case '\u0015': return 0x15; + case '\u0016': return 0x16; + case '\u0017': return 0x17; + case '\u0018': return 0x18; + case '\u0019': return 0x19; + case '\u001A': return 0x1A; + case '\u001B': return 0x1B; + case '\u001C': return 0x1C; + case '\u001D': return 0x1D; + case '\u001E': return 0x1E; + case '\u001F': return 0x1F; + case '\u0020': return 0x20; + case '\u0021': return 0x21; + case '\u0022': return 0x22; + case '\u0023': return 0x23; + case '\u0024': return 0x24; + case '\u0025': return 0x25; + case '\u0026': return 0x26; + case '\u0027': return 0x27; + case '\u0028': return 0x28; + case '\u0029': return 0x29; + case '\u002A': return 0x2A; + case '\u002B': return 0x2B; + case '\u002C': return 0x2C; + case '\u002D': return 0x2D; + case '\u002E': return 0x2E; + case '\u002F': return 0x2F; + case '\u0030': return 0x30; + case '\u0031': return 0x31; + case '\u0032': return 0x32; + case '\u0033': return 0x33; + case '\u0034': return 0x34; + case '\u0035': return 0x35; + case '\u0036': return 0x36; + case '\u0037': return 0x37; + case '\u0038': return 0x38; + case '\u0039': return 0x39; + case '\u003A': return 0x3A; + case '\u003B': return 0x3B; + case '\u003C': return 0x3C; + case '\u003D': return 0x3D; + case '\u003E': return 0x3E; + case '\u003F': return 0x3F; + case '\u0040': return 0x40; + case '\u0041': return 0x41; + case '\u0042': return 0x42; + case '\u0043': return 0x43; + case '\u0044': return 0x44; + case '\u0045': return 0x45; + case '\u0046': return 0x46; + case '\u0047': return 0x47; + case '\u0048': return 0x48; + case '\u0049': return 0x49; + case '\u004A': return 0x4A; + case '\u004B': return 0x4B; + case '\u004C': return 0x4C; + case '\u004D': return 0x4D; + case '\u004E': return 0x4E; + case '\u004F': return 0x4F; + case '\u0050': return 0x50; + case '\u0051': return 0x51; + case '\u0052': return 0x52; + case '\u0053': return 0x53; + case '\u0054': return 0x54; + case '\u0055': return 0x55; + case '\u0056': return 0x56; + case '\u0057': return 0x57; + case '\u0058': return 0x58; + case '\u0059': return 0x59; + case '\u005A': return 0x5A; + case '\u005B': return 0x5B; + case '\u005C': return 0x5C; + case '\u005D': return 0x5D; + case '\u005E': return 0x5E; + case '\u005F': return 0x5F; + case '\u0060': return 0x60; + case '\u0061': return 0x61; + case '\u0062': return 0x62; + case '\u0063': return 0x63; + case '\u0064': return 0x64; + case '\u0065': return 0x65; + case '\u0066': return 0x66; + case '\u0067': return 0x67; + case '\u0068': return 0x68; + case '\u0069': return 0x69; + case '\u006A': return 0x6A; + case '\u006B': return 0x6B; + case '\u006C': return 0x6C; + case '\u006D': return 0x6D; + case '\u006E': return 0x6E; + case '\u006F': return 0x6F; + case '\u0070': return 0x70; + case '\u0071': return 0x71; + case '\u0072': return 0x72; + case '\u0073': return 0x73; + case '\u0074': return 0x74; + case '\u0075': return 0x75; + case '\u0076': return 0x76; + case '\u0077': return 0x77; + case '\u0078': return 0x78; + case '\u0079': return 0x79; + case '\u007A': return 0x7A; + case '\u007B': return 0x7B; + case '\u007C': return 0x7C; + case '\u007D': return 0x7D; + case '\u007E': return 0x7E; + case '\u007F': return 0x7F; + case '\u00C4': return 0x80; + case '\u00C5': return 0x81; + case '\u00C7': return 0x82; + case '\u00C9': return 0x83; + case '\u00D1': return 0x84; + case '\u00D6': return 0x85; + case '\u00DC': return 0x86; + case '\u00E1': return 0x87; + case '\u00E0': return 0x88; + case '\u00E2': return 0x89; + case '\u00E4': return 0x8A; + case '\u00E3': return 0x8B; + case '\u00E5': return 0x8C; + case '\u00E7': return 0x8D; + case '\u00E9': return 0x8E; + case '\u00E8': return 0x8F; + case '\u00EA': return 0x90; + case '\u00EB': return 0x91; + case '\u00ED': return 0x92; + case '\u00EC': return 0x93; + case '\u00EE': return 0x94; + case '\u00EF': return 0x95; + case '\u00F1': return 0x96; + case '\u00F3': return 0x97; + case '\u00F2': return 0x98; + case '\u00F4': return 0x99; + case '\u00F6': return 0x9A; + case '\u00F5': return 0x9B; + case '\u00FA': return 0x9C; + case '\u00F9': return 0x9D; + case '\u00FB': return 0x9E; + case '\u00FC': return 0x9F; + case '\u2020': return 0xA0; + case '\u00B0': return 0xA1; + case '\u00A2': return 0xA2; + case '\u00A3': return 0xA3; + case '\u00A7': return 0xA4; + case '\u2022': return 0xA5; + case '\u00B6': return 0xA6; + case '\u00DF': return 0xA7; + case '\u00AE': return 0xA8; + case '\u00A9': return 0xA9; + case '\u2122': return 0xAA; + case '\u00B4': return 0xAB; + case '\u00A8': return 0xAC; + case '\u2260': return 0xAD; + case '\u00C6': return 0xAE; + case '\u00D8': return 0xAF; + case '\u221E': return 0xB0; + case '\u00B1': return 0xB1; + case '\u2264': return 0xB2; + case '\u2265': return 0xB3; + case '\u00A5': return 0xB4; + case '\u00B5': return 0xB5; + case '\u2202': return 0xB6; + case '\u2211': return 0xB7; + case '\u220F': return 0xB8; + case '\u03C0': return 0xB9; + case '\u222B': return 0xBA; + case '\u00AA': return 0xBB; + case '\u00BA': return 0xBC; + case '\u03A9': return 0xBD; + case '\u00E6': return 0xBE; + case '\u00F8': return 0xBF; + case '\u00BF': return 0xC0; + case '\u00A1': return 0xC1; + case '\u00AC': return 0xC2; + case '\u221A': return 0xC3; + case '\u0192': return 0xC4; + case '\u2248': return 0xC5; + case '\u2206': return 0xC6; + case '\u00AB': return 0xC7; + case '\u00BB': return 0xC8; + case '\u2026': return 0xC9; + case '\u00A0': return 0xCA; + case '\u00C0': return 0xCB; + case '\u00C3': return 0xCC; + case '\u00D5': return 0xCD; + case '\u0152': return 0xCE; + case '\u0153': return 0xCF; + case '\u2013': return 0xD0; + case '\u2014': return 0xD1; + case '\u201C': return 0xD2; + case '\u201D': return 0xD3; + case '\u2018': return 0xD4; + case '\u2019': return 0xD5; + case '\u00F7': return 0xD6; + case '\u25CA': return 0xD7; + case '\u00FF': return 0xD8; + case '\u0178': return 0xD9; + case '\u2044': return 0xDA; + case '\u20AC': return 0xDB; + case '\u2039': return 0xDC; + case '\u203A': return 0xDD; + case '\uFB01': return 0xDE; + case '\uFB02': return 0xDF; + case '\u2021': return 0xE0; + case '\u00B7': return 0xE1; + case '\u201A': return 0xE2; + case '\u201E': return 0xE3; + case '\u2030': return 0xE4; + case '\u00C2': return 0xE5; + case '\u00CA': return 0xE6; + case '\u00C1': return 0xE7; + case '\u00CB': return 0xE8; + case '\u00C8': return 0xE9; + case '\u00CD': return 0xEA; + case '\u00CE': return 0xEB; + case '\u00CF': return 0xEC; + case '\u00CC': return 0xED; + case '\u00D3': return 0xEE; + case '\u00D4': return 0xEF; + case '\uF8FF': return 0xF0; + case '\u00D2': return 0xF1; + case '\u00DA': return 0xF2; + case '\u00DB': return 0xF3; + case '\u00D9': return 0xF4; + case '\u0131': return 0xF5; + case '\u02C6': return 0xF6; + case '\u02DC': return 0xF7; + case '\u00AF': return 0xF8; + case '\u02D8': return 0xF9; + case '\u02D9': return 0xFA; + case '\u02DA': return 0xFB; + case '\u00B8': return 0xFC; + case '\u02DD': return 0xFD; + case '\u02DB': return 0xFE; + case '\u02C7': return 0xFF; default: // Fallback to '?' return 0x3F; } } } -} +} \ No newline at end of file diff --git a/Claunia.Encoding/MacRomanian.cs b/Claunia.Encoding/MacRomanian.cs index 5e52ad2..46d6e1c 100644 --- a/Claunia.Encoding/MacRomanian.cs +++ b/Claunia.Encoding/MacRomanian.cs @@ -29,7 +29,7 @@ using System; namespace Claunia.Encoding { /// - /// Represents an Apple Mac character encoding of Unicode characters. + /// Represents an Apple Mac character encoding of Unicode characters. /// public class MacRomanian : Encoding { @@ -48,105 +48,152 @@ namespace Claunia.Encoding const bool singleByte = true; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. + /// The Mac to Unicode character map. + /// MacRomanian is a superset of MacRomanian. /// - public override bool IsBrowserDisplay { - get { return browserDisplay; } - } + static readonly char[] MacRomanianTable = + { + // 0x00 + '\u0000', '\u0001', '\u0002', '\u0003', '\u0004', '\u0005', '\u0006', '\u0007', + // 0x08 + '\u0008', '\u0009', '\u000A', '\u000B', '\u000C', '\u000D', '\u000E', '\u000F', + // 0x10 + '\u0010', '\u0011', '\u0012', '\u0013', '\u0014', '\u0015', '\u0016', '\u0017', + // 0x18 + '\u0018', '\u0019', '\u001A', '\u001B', '\u001C', '\u001D', '\u001E', '\u001F', + // 0x20 + '\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027', + // 0x28 + '\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F', + // 0x30 + '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', + // 0x38 + '\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F', + // 0x40 + '\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047', + // 0x48 + '\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F', + // 0x50 + '\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057', + // 0x58 + '\u0058', '\u0059', '\u005A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F', + // 0x60 + '\u0060', '\u0061', '\u0062', '\u0063', '\u0064', '\u0065', '\u0066', '\u0067', + // 0x68 + '\u0068', '\u0069', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F', + // 0x70 + '\u0070', '\u0071', '\u0072', '\u0073', '\u0074', '\u0075', '\u0076', '\u0077', + // 0x78 + '\u0078', '\u0079', '\u007A', '\u007B', '\u007C', '\u007D', '\u007E', '\u007F', + // 0x80 + '\u00C4', '\u00C5', '\u00C7', '\u00C9', '\u00D1', '\u00D6', '\u00DC', '\u00E1', + // 0x88 + '\u00E0', '\u00E2', '\u00E4', '\u00E3', '\u00E5', '\u00E7', '\u00E9', '\u00E8', + // 0x90 + '\u00EA', '\u00EB', '\u00ED', '\u00EC', '\u00EE', '\u00EF', '\u00F1', '\u00F3', + // 0x98 + '\u00F2', '\u00F4', '\u00F6', '\u00F5', '\u00FA', '\u00F9', '\u00FB', '\u00FC', + // 0xA0 + '\u2020', '\u00B0', '\u00A2', '\u00A3', '\u00A7', '\u2022', '\u00B6', '\u00DF', + // 0xA8 + '\u00AE', '\u00A9', '\u2122', '\u00B4', '\u00A8', '\u2260', '\u0102', '\u0218', + // 0xB0 + '\u221E', '\u00B1', '\u2264', '\u2265', '\u00A5', '\u00B5', '\u2202', '\u2211', + // 0xB8 + '\u220F', '\u03C0', '\u222B', '\u00AA', '\u00BA', '\u03A9', '\u0103', '\u0219', + // 0xC0 + '\u00BF', '\u00A1', '\u00AC', '\u221A', '\u0192', '\u2248', '\u2206', '\u00AB', + // 0xC8 + '\u00BB', '\u2026', '\u00A0', '\u00C0', '\u00C3', '\u00D5', '\u0152', '\u0153', + // 0xD0 + '\u2013', '\u2014', '\u201C', '\u201D', '\u2018', '\u2019', '\u00F7', '\u25CA', + // 0xD8 + '\u00FF', '\u0178', '\u2044', '\u20AC', '\u2039', '\u203A', '\u021A', '\u021B', + // 0xE0 + '\u2021', '\u00B7', '\u201A', '\u201E', '\u2030', '\u00C2', '\u00CA', '\u00C1', + // 0xE8 + '\u00CB', '\u00C8', '\u00CD', '\u00CE', '\u00CF', '\u00CC', '\u00D3', '\u00D4', + // 0xF0 + '\uF8FF', '\u00D2', '\u00DA', '\u00DB', '\u00D9', '\u0131', '\u02C6', '\u02DC', + // 0xF8 + '\u00AF', '\u02D8', '\u02D9', '\u02DA', '\u00B8', '\u02DD', '\u02DB', '\u02C7' + }; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. + /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. /// - public override bool IsBrowserSave { - get { return browserSave; } - } + public override bool IsBrowserDisplay => browserDisplay; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. + /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. /// - public override bool IsMailNewsDisplay { - get { return mailNewsDisplay; } - } + public override bool IsBrowserSave => browserSave; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. /// - public override bool IsMailNewsSave { - get { return mailNewsSave; } - } + public override bool IsMailNewsDisplay => mailNewsDisplay; /// - /// Gets a value indicating whether the current encoding is read-only. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// + public override bool IsMailNewsSave => mailNewsSave; + + /// + /// Gets a value indicating whether the current encoding is read-only. /// /// The is single byte. - public override bool IsReadOnly { - get { return readOnly; } - } + public override bool IsReadOnly => readOnly; /// - /// Gets a value indicating whether the current encoding uses single-byte code points. + /// Gets a value indicating whether the current encoding uses single-byte code points. /// - public override bool IsSingleByte { - get { return singleByte; } - } + public override bool IsSingleByte => singleByte; /// - /// Gets the code page identifier of the current Encoding. + /// Gets the code page identifier of the current Encoding. /// - public override int CodePage { - get { return _codepage; } - } + public override int CodePage => _codepage; /// - /// Gets a name for the current encoding that can be used with mail agent body tags + /// Gets a name for the current encoding that can be used with mail agent body tags /// - public override string BodyName { - get { return _bodyname; } - } + public override string BodyName => _bodyname; /// - /// Gets a name for the current encoding that can be used with mail agent header tags + /// Gets a name for the current encoding that can be used with mail agent header tags /// - public override string HeaderName { - get { return _headername; } - } + public override string HeaderName => _headername; /// - /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. + /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. /// - public override string WebName { - get { return _webname; } - } + public override string WebName => _webname; /// - /// Gets the human-readable description of the current encoding. + /// Gets the human-readable description of the current encoding. /// - public override string EncodingName { - get { return _encodingname; } - } + public override string EncodingName => _encodingname; /// - /// Gets the Windows operating system code page that most closely corresponds to the current encoding. + /// Gets the Windows operating system code page that most closely corresponds to the current encoding. /// - public override int WindowsCodePage { - get { return _windowsCodepage; } - } + public override int WindowsCodePage => _windowsCodepage; /// - /// Calculates the number of bytes produced by encoding the characters in the specified . + /// Calculates the number of bytes produced by encoding the characters in the specified . /// /// The number of bytes produced by encoding the specified characters. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. public override int GetByteCount(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return s.Length; } /// - /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. + /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. /// /// The number of bytes produced by encoding the specified characters. /// The character array containing the set of characters to encode. @@ -154,36 +201,32 @@ namespace Claunia.Encoding /// The number of characters to encode. public override int GetByteCount(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0 || index >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0 || index >= chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0 || index + count > chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(count < 0 || index + count > chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); return count; } /// - /// Calculates the number of bytes produced by encoding all the characters in the specified character array. + /// Calculates the number of bytes produced by encoding all the characters in the specified character array. /// /// The number of bytes produced by encoding all the characters in the specified character array. /// The character array containing the characters to encode. public override int GetByteCount(char[] chars) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); return chars.Length; } /// - /// Encodes a set of characters from the specified into the specified byte array. + /// Encodes a set of characters from the specified into the specified byte array. /// /// The actual number of bytes written into bytes. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. /// The index of the first character to encode. /// The number of characters to encode. /// The byte array to contain the resulting sequence of bytes. @@ -194,20 +237,19 @@ namespace Claunia.Encoding } /// - /// Encodes all the characters in the specified string into a sequence of bytes. + /// Encodes all the characters in the specified string into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The string containing the characters to encode. public override byte[] GetBytes(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return GetBytes(s.ToCharArray(), 0, s.Length); } /// - /// Encodes a set of characters from the specified character array into the specified byte array. + /// Encodes a set of characters from the specified character array into the specified byte array. /// /// The actual number of bytes written into bytes. /// The character array containing the set of characters to encode. @@ -217,43 +259,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting sequence of bytes. public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount + charIndex > chars.Length) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount + charIndex > chars.Length) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteIndex + charCount > bytes.Length) - throw new ArgumentException(nameof(bytes)); + if(byteIndex + charCount > bytes.Length) throw new ArgumentException(nameof(bytes)); byte[] temp = GetBytes(chars, charIndex, charCount); - for(int i = 0; i < temp.Length; i++) - bytes[i + byteIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) bytes[i + byteIndex] = temp[i]; return charCount; } /// - /// Encodes a set of characters from the specified character array into a sequence of bytes. + /// Encodes a set of characters from the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the set of characters to encode. @@ -261,28 +293,23 @@ namespace Claunia.Encoding /// The number of characters to encode. public override byte[] GetBytes(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > chars.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > chars.Length) throw new ArgumentOutOfRangeException(nameof(count)); byte[] bytes = new byte[count]; - for(int i = 0; i < count; i++) - bytes[i] = GetByte(chars[index + i]); + for(int i = 0; i < count; i++) bytes[i] = GetByte(chars[index + i]); return bytes; } /// - /// Encodes all the characters in the specified character array into a sequence of bytes. + /// Encodes all the characters in the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the characters to encode. @@ -292,7 +319,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. + /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -302,7 +329,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. + /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -310,23 +337,19 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override int GetCharCount(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); return count; } /// - /// Decodes a sequence of bytes from the specified byte array into the specified character array. + /// Decodes a sequence of bytes from the specified byte array into the specified character array. /// /// The actual number of characters written into chars. /// The byte array containing the sequence of bytes to decode. @@ -336,43 +359,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting set of characters. public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount + byteIndex > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount + byteIndex > bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charIndex + byteCount > chars.Length) - throw new ArgumentException(nameof(chars)); + if(charIndex + byteCount > chars.Length) throw new ArgumentException(nameof(chars)); char[] temp = GetChars(bytes, byteIndex, byteCount); - for(int i = 0; i < temp.Length; i++) - chars[i + charIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) chars[i + charIndex] = temp[i]; return byteCount; } /// - /// Decodes all the bytes in the specified byte array into a set of characters. + /// Decodes all the bytes in the specified byte array into a set of characters. /// /// A character array containing the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -382,7 +395,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a set of characters. + /// Decodes a sequence of bytes from the specified byte array into a set of characters. /// /// The chars. /// The byte array containing the sequence of bytes to decode. @@ -390,54 +403,47 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override char[] GetChars(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); char[] chars = new char[count]; - for(int i = 0; i < count; i++) - chars[i] = GetChar(bytes[index + i]); + for(int i = 0; i < count; i++) chars[i] = GetChar(bytes[index + i]); return chars; } /// - /// Calculates the maximum number of bytes produced by encoding the specified number of characters. + /// Calculates the maximum number of bytes produced by encoding the specified number of characters. /// /// The maximum number of bytes produced by encoding the specified number of characters. /// The number of characters to encode. public override int GetMaxByteCount(int charCount) { - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); return charCount; } /// - /// Calculates the maximum number of characters produced by decoding the specified number of bytes. + /// Calculates the maximum number of characters produced by decoding the specified number of bytes. /// /// The maximum number of characters produced by decoding the specified number of bytes. /// The number of bytes to decode. public override int GetMaxCharCount(int byteCount) { - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); return byteCount; } /// - /// Returns a sequence of bytes that specifies the encoding used. + /// Returns a sequence of bytes that specifies the encoding used. /// /// A byte array of length zero, as a preamble is not required. public override byte[] GetPreamble() @@ -446,7 +452,7 @@ namespace Claunia.Encoding } /// - /// Decodes all the bytes in the specified byte array into a string. + /// Decodes all the bytes in the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -456,7 +462,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a string. + /// Decodes a sequence of bytes from the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -468,78 +474,7 @@ namespace Claunia.Encoding } /// - /// The Mac to Unicode character map. - /// MacRomanian is a superset of MacRomanian. - /// - static readonly char[] MacRomanianTable = { - // 0x00 - '\u0000','\u0001','\u0002','\u0003','\u0004','\u0005','\u0006','\u0007', - // 0x08 - '\u0008','\u0009','\u000A','\u000B','\u000C','\u000D','\u000E','\u000F', - // 0x10 - '\u0010','\u0011','\u0012','\u0013','\u0014','\u0015','\u0016','\u0017', - // 0x18 - '\u0018','\u0019','\u001A','\u001B','\u001C','\u001D','\u001E','\u001F', - // 0x20 - '\u0020','\u0021','\u0022','\u0023','\u0024','\u0025','\u0026','\u0027', - // 0x28 - '\u0028','\u0029','\u002A','\u002B','\u002C','\u002D','\u002E','\u002F', - // 0x30 - '\u0030','\u0031','\u0032','\u0033','\u0034','\u0035','\u0036','\u0037', - // 0x38 - '\u0038','\u0039','\u003A','\u003B','\u003C','\u003D','\u003E','\u003F', - // 0x40 - '\u0040','\u0041','\u0042','\u0043','\u0044','\u0045','\u0046','\u0047', - // 0x48 - '\u0048','\u0049','\u004A','\u004B','\u004C','\u004D','\u004E','\u004F', - // 0x50 - '\u0050','\u0051','\u0052','\u0053','\u0054','\u0055','\u0056','\u0057', - // 0x58 - '\u0058','\u0059','\u005A','\u005B','\u005C','\u005D','\u005E','\u005F', - // 0x60 - '\u0060','\u0061','\u0062','\u0063','\u0064','\u0065','\u0066','\u0067', - // 0x68 - '\u0068','\u0069','\u006A','\u006B','\u006C','\u006D','\u006E','\u006F', - // 0x70 - '\u0070','\u0071','\u0072','\u0073','\u0074','\u0075','\u0076','\u0077', - // 0x78 - '\u0078','\u0079','\u007A','\u007B','\u007C','\u007D','\u007E','\u007F', - // 0x80 - '\u00C4','\u00C5','\u00C7','\u00C9','\u00D1','\u00D6','\u00DC','\u00E1', - // 0x88 - '\u00E0','\u00E2','\u00E4','\u00E3','\u00E5','\u00E7','\u00E9','\u00E8', - // 0x90 - '\u00EA','\u00EB','\u00ED','\u00EC','\u00EE','\u00EF','\u00F1','\u00F3', - // 0x98 - '\u00F2','\u00F4','\u00F6','\u00F5','\u00FA','\u00F9','\u00FB','\u00FC', - // 0xA0 - '\u2020','\u00B0','\u00A2','\u00A3','\u00A7','\u2022','\u00B6','\u00DF', - // 0xA8 - '\u00AE','\u00A9','\u2122','\u00B4','\u00A8','\u2260','\u0102','\u0218', - // 0xB0 - '\u221E','\u00B1','\u2264','\u2265','\u00A5','\u00B5','\u2202','\u2211', - // 0xB8 - '\u220F','\u03C0','\u222B','\u00AA','\u00BA','\u03A9','\u0103','\u0219', - // 0xC0 - '\u00BF','\u00A1','\u00AC','\u221A','\u0192','\u2248','\u2206','\u00AB', - // 0xC8 - '\u00BB','\u2026','\u00A0','\u00C0','\u00C3','\u00D5','\u0152','\u0153', - // 0xD0 - '\u2013','\u2014','\u201C','\u201D','\u2018','\u2019','\u00F7','\u25CA', - // 0xD8 - '\u00FF','\u0178','\u2044','\u20AC','\u2039','\u203A','\u021A','\u021B', - // 0xE0 - '\u2021','\u00B7','\u201A','\u201E','\u2030','\u00C2','\u00CA','\u00C1', - // 0xE8 - '\u00CB','\u00C8','\u00CD','\u00CE','\u00CF','\u00CC','\u00D3','\u00D4', - // 0xF0 - '\uF8FF','\u00D2','\u00DA','\u00DB','\u00D9','\u0131','\u02C6','\u02DC', - // 0xF8 - '\u00AF','\u02D8','\u02D9','\u02DA','\u00B8','\u02DD','\u02DB','\u02C7' - }; - - /// - /// Converts a MacRomanian character to an Unicode character + /// Converts a MacRomanian character to an Unicode character /// /// Unicode character. /// MacRomanian character. @@ -549,529 +484,274 @@ namespace Claunia.Encoding } /// - /// Converts a Unicode character to an MacRomanian character + /// Converts a Unicode character to an MacRomanian character /// /// MacRomanian character. /// Unicode character. static byte GetByte(char character) { - switch(character) { - case '\u0000': - return 0x00; - case '\u0001': - return 0x01; - case '\u0002': - return 0x02; - case '\u0003': - return 0x03; - case '\u0004': - return 0x04; - case '\u0005': - return 0x05; - case '\u0006': - return 0x06; - case '\u0007': - return 0x07; - case '\u0008': - return 0x08; - case '\u0009': - return 0x09; - case '\u000A': - return 0x0A; - case '\u000B': - return 0x0B; - case '\u000C': - return 0x0C; - case '\u000D': - return 0x0D; - case '\u000E': - return 0x0E; - case '\u000F': - return 0x0F; - case '\u0010': - return 0x10; - case '\u0011': - return 0x11; - case '\u0012': - return 0x12; - case '\u0013': - return 0x13; - case '\u0014': - return 0x14; - case '\u0015': - return 0x15; - case '\u0016': - return 0x16; - case '\u0017': - return 0x17; - case '\u0018': - return 0x18; - case '\u0019': - return 0x19; - case '\u001A': - return 0x1A; - case '\u001B': - return 0x1B; - case '\u001C': - return 0x1C; - case '\u001D': - return 0x1D; - case '\u001E': - return 0x1E; - case '\u001F': - return 0x1F; - case '\u0020': - return 0x20; - case '\u0021': - return 0x21; - case '\u0022': - return 0x22; - case '\u0023': - return 0x23; - case '\u0024': - return 0x24; - case '\u0025': - return 0x25; - case '\u0026': - return 0x26; - case '\u0027': - return 0x27; - case '\u0028': - return 0x28; - case '\u0029': - return 0x29; - case '\u002A': - return 0x2A; - case '\u002B': - return 0x2B; - case '\u002C': - return 0x2C; - case '\u002D': - return 0x2D; - case '\u002E': - return 0x2E; - case '\u002F': - return 0x2F; - case '\u0030': - return 0x30; - case '\u0031': - return 0x31; - case '\u0032': - return 0x32; - case '\u0033': - return 0x33; - case '\u0034': - return 0x34; - case '\u0035': - return 0x35; - case '\u0036': - return 0x36; - case '\u0037': - return 0x37; - case '\u0038': - return 0x38; - case '\u0039': - return 0x39; - case '\u003A': - return 0x3A; - case '\u003B': - return 0x3B; - case '\u003C': - return 0x3C; - case '\u003D': - return 0x3D; - case '\u003E': - return 0x3E; - case '\u003F': - return 0x3F; - case '\u0040': - return 0x40; - case '\u0041': - return 0x41; - case '\u0042': - return 0x42; - case '\u0043': - return 0x43; - case '\u0044': - return 0x44; - case '\u0045': - return 0x45; - case '\u0046': - return 0x46; - case '\u0047': - return 0x47; - case '\u0048': - return 0x48; - case '\u0049': - return 0x49; - case '\u004A': - return 0x4A; - case '\u004B': - return 0x4B; - case '\u004C': - return 0x4C; - case '\u004D': - return 0x4D; - case '\u004E': - return 0x4E; - case '\u004F': - return 0x4F; - case '\u0050': - return 0x50; - case '\u0051': - return 0x51; - case '\u0052': - return 0x52; - case '\u0053': - return 0x53; - case '\u0054': - return 0x54; - case '\u0055': - return 0x55; - case '\u0056': - return 0x56; - case '\u0057': - return 0x57; - case '\u0058': - return 0x58; - case '\u0059': - return 0x59; - case '\u005A': - return 0x5A; - case '\u005B': - return 0x5B; - case '\u005C': - return 0x5C; - case '\u005D': - return 0x5D; - case '\u005E': - return 0x5E; - case '\u005F': - return 0x5F; - case '\u0060': - return 0x60; - case '\u0061': - return 0x61; - case '\u0062': - return 0x62; - case '\u0063': - return 0x63; - case '\u0064': - return 0x64; - case '\u0065': - return 0x65; - case '\u0066': - return 0x66; - case '\u0067': - return 0x67; - case '\u0068': - return 0x68; - case '\u0069': - return 0x69; - case '\u006A': - return 0x6A; - case '\u006B': - return 0x6B; - case '\u006C': - return 0x6C; - case '\u006D': - return 0x6D; - case '\u006E': - return 0x6E; - case '\u006F': - return 0x6F; - case '\u0070': - return 0x70; - case '\u0071': - return 0x71; - case '\u0072': - return 0x72; - case '\u0073': - return 0x73; - case '\u0074': - return 0x74; - case '\u0075': - return 0x75; - case '\u0076': - return 0x76; - case '\u0077': - return 0x77; - case '\u0078': - return 0x78; - case '\u0079': - return 0x79; - case '\u007A': - return 0x7A; - case '\u007B': - return 0x7B; - case '\u007C': - return 0x7C; - case '\u007D': - return 0x7D; - case '\u007E': - return 0x7E; - case '\u007F': - return 0x7F; - case '\u00C4': - return 0x80; - case '\u00C5': - return 0x81; - case '\u00C7': - return 0x82; - case '\u00C9': - return 0x83; - case '\u00D1': - return 0x84; - case '\u00D6': - return 0x85; - case '\u00DC': - return 0x86; - case '\u00E1': - return 0x87; - case '\u00E0': - return 0x88; - case '\u00E2': - return 0x89; - case '\u00E4': - return 0x8A; - case '\u00E3': - return 0x8B; - case '\u00E5': - return 0x8C; - case '\u00E7': - return 0x8D; - case '\u00E9': - return 0x8E; - case '\u00E8': - return 0x8F; - case '\u00EA': - return 0x90; - case '\u00EB': - return 0x91; - case '\u00ED': - return 0x92; - case '\u00EC': - return 0x93; - case '\u00EE': - return 0x94; - case '\u00EF': - return 0x95; - case '\u00F1': - return 0x96; - case '\u00F3': - return 0x97; - case '\u00F2': - return 0x98; - case '\u00F4': - return 0x99; - case '\u00F6': - return 0x9A; - case '\u00F5': - return 0x9B; - case '\u00FA': - return 0x9C; - case '\u00F9': - return 0x9D; - case '\u00FB': - return 0x9E; - case '\u00FC': - return 0x9F; - case '\u2020': - return 0xA0; - case '\u00B0': - return 0xA1; - case '\u00A2': - return 0xA2; - case '\u00A3': - return 0xA3; - case '\u00A7': - return 0xA4; - case '\u2022': - return 0xA5; - case '\u00B6': - return 0xA6; - case '\u00DF': - return 0xA7; - case '\u00AE': - return 0xA8; - case '\u00A9': - return 0xA9; - case '\u2122': - return 0xAA; - case '\u00B4': - return 0xAB; - case '\u00A8': - return 0xAC; - case '\u2260': - return 0xAD; - case '\u0102': - return 0xAE; - case '\u0218': - return 0xAF; - case '\u221E': - return 0xB0; - case '\u00B1': - return 0xB1; - case '\u2264': - return 0xB2; - case '\u2265': - return 0xB3; - case '\u00A5': - return 0xB4; - case '\u00B5': - return 0xB5; - case '\u2202': - return 0xB6; - case '\u2211': - return 0xB7; - case '\u220F': - return 0xB8; - case '\u03C0': - return 0xB9; - case '\u222B': - return 0xBA; - case '\u00AA': - return 0xBB; - case '\u00BA': - return 0xBC; - case '\u03A9': - return 0xBD; - case '\u0103': - return 0xBE; - case '\u0219': - return 0xBF; - case '\u00BF': - return 0xC0; - case '\u00A1': - return 0xC1; - case '\u00AC': - return 0xC2; - case '\u221A': - return 0xC3; - case '\u0192': - return 0xC4; - case '\u2248': - return 0xC5; - case '\u2206': - return 0xC6; - case '\u00AB': - return 0xC7; - case '\u00BB': - return 0xC8; - case '\u2026': - return 0xC9; - case '\u00A0': - return 0xCA; - case '\u00C0': - return 0xCB; - case '\u00C3': - return 0xCC; - case '\u00D5': - return 0xCD; - case '\u0152': - return 0xCE; - case '\u0153': - return 0xCF; - case '\u2013': - return 0xD0; - case '\u2014': - return 0xD1; - case '\u201C': - return 0xD2; - case '\u201D': - return 0xD3; - case '\u2018': - return 0xD4; - case '\u2019': - return 0xD5; - case '\u00F7': - return 0xD6; - case '\u25CA': - return 0xD7; - case '\u00FF': - return 0xD8; - case '\u0178': - return 0xD9; - case '\u2044': - return 0xDA; - case '\u20AC': - return 0xDB; - case '\u2039': - return 0xDC; - case '\u203A': - return 0xDD; - case '\u021A': - return 0xDE; - case '\u021B': - return 0xDF; - case '\u2021': - return 0xE0; - case '\u00B7': - return 0xE1; - case '\u201A': - return 0xE2; - case '\u201E': - return 0xE3; - case '\u2030': - return 0xE4; - case '\u00C2': - return 0xE5; - case '\u00CA': - return 0xE6; - case '\u00C1': - return 0xE7; - case '\u00CB': - return 0xE8; - case '\u00C8': - return 0xE9; - case '\u00CD': - return 0xEA; - case '\u00CE': - return 0xEB; - case '\u00CF': - return 0xEC; - case '\u00CC': - return 0xED; - case '\u00D3': - return 0xEE; - case '\u00D4': - return 0xEF; - case '\uF8FF': - return 0xF0; - case '\u00D2': - return 0xF1; - case '\u00DA': - return 0xF2; - case '\u00DB': - return 0xF3; - case '\u00D9': - return 0xF4; - case '\u0131': - return 0xF5; - case '\u02C6': - return 0xF6; - case '\u02DC': - return 0xF7; - case '\u00AF': - return 0xF8; - case '\u02D8': - return 0xF9; - case '\u02D9': - return 0xFA; - case '\u02DA': - return 0xFB; - case '\u00B8': - return 0xFC; - case '\u02DD': - return 0xFD; - case '\u02DB': - return 0xFE; - case '\u02C7': - return 0xFF; + switch(character) + { + case '\u0000': return 0x00; + case '\u0001': return 0x01; + case '\u0002': return 0x02; + case '\u0003': return 0x03; + case '\u0004': return 0x04; + case '\u0005': return 0x05; + case '\u0006': return 0x06; + case '\u0007': return 0x07; + case '\u0008': return 0x08; + case '\u0009': return 0x09; + case '\u000A': return 0x0A; + case '\u000B': return 0x0B; + case '\u000C': return 0x0C; + case '\u000D': return 0x0D; + case '\u000E': return 0x0E; + case '\u000F': return 0x0F; + case '\u0010': return 0x10; + case '\u0011': return 0x11; + case '\u0012': return 0x12; + case '\u0013': return 0x13; + case '\u0014': return 0x14; + case '\u0015': return 0x15; + case '\u0016': return 0x16; + case '\u0017': return 0x17; + case '\u0018': return 0x18; + case '\u0019': return 0x19; + case '\u001A': return 0x1A; + case '\u001B': return 0x1B; + case '\u001C': return 0x1C; + case '\u001D': return 0x1D; + case '\u001E': return 0x1E; + case '\u001F': return 0x1F; + case '\u0020': return 0x20; + case '\u0021': return 0x21; + case '\u0022': return 0x22; + case '\u0023': return 0x23; + case '\u0024': return 0x24; + case '\u0025': return 0x25; + case '\u0026': return 0x26; + case '\u0027': return 0x27; + case '\u0028': return 0x28; + case '\u0029': return 0x29; + case '\u002A': return 0x2A; + case '\u002B': return 0x2B; + case '\u002C': return 0x2C; + case '\u002D': return 0x2D; + case '\u002E': return 0x2E; + case '\u002F': return 0x2F; + case '\u0030': return 0x30; + case '\u0031': return 0x31; + case '\u0032': return 0x32; + case '\u0033': return 0x33; + case '\u0034': return 0x34; + case '\u0035': return 0x35; + case '\u0036': return 0x36; + case '\u0037': return 0x37; + case '\u0038': return 0x38; + case '\u0039': return 0x39; + case '\u003A': return 0x3A; + case '\u003B': return 0x3B; + case '\u003C': return 0x3C; + case '\u003D': return 0x3D; + case '\u003E': return 0x3E; + case '\u003F': return 0x3F; + case '\u0040': return 0x40; + case '\u0041': return 0x41; + case '\u0042': return 0x42; + case '\u0043': return 0x43; + case '\u0044': return 0x44; + case '\u0045': return 0x45; + case '\u0046': return 0x46; + case '\u0047': return 0x47; + case '\u0048': return 0x48; + case '\u0049': return 0x49; + case '\u004A': return 0x4A; + case '\u004B': return 0x4B; + case '\u004C': return 0x4C; + case '\u004D': return 0x4D; + case '\u004E': return 0x4E; + case '\u004F': return 0x4F; + case '\u0050': return 0x50; + case '\u0051': return 0x51; + case '\u0052': return 0x52; + case '\u0053': return 0x53; + case '\u0054': return 0x54; + case '\u0055': return 0x55; + case '\u0056': return 0x56; + case '\u0057': return 0x57; + case '\u0058': return 0x58; + case '\u0059': return 0x59; + case '\u005A': return 0x5A; + case '\u005B': return 0x5B; + case '\u005C': return 0x5C; + case '\u005D': return 0x5D; + case '\u005E': return 0x5E; + case '\u005F': return 0x5F; + case '\u0060': return 0x60; + case '\u0061': return 0x61; + case '\u0062': return 0x62; + case '\u0063': return 0x63; + case '\u0064': return 0x64; + case '\u0065': return 0x65; + case '\u0066': return 0x66; + case '\u0067': return 0x67; + case '\u0068': return 0x68; + case '\u0069': return 0x69; + case '\u006A': return 0x6A; + case '\u006B': return 0x6B; + case '\u006C': return 0x6C; + case '\u006D': return 0x6D; + case '\u006E': return 0x6E; + case '\u006F': return 0x6F; + case '\u0070': return 0x70; + case '\u0071': return 0x71; + case '\u0072': return 0x72; + case '\u0073': return 0x73; + case '\u0074': return 0x74; + case '\u0075': return 0x75; + case '\u0076': return 0x76; + case '\u0077': return 0x77; + case '\u0078': return 0x78; + case '\u0079': return 0x79; + case '\u007A': return 0x7A; + case '\u007B': return 0x7B; + case '\u007C': return 0x7C; + case '\u007D': return 0x7D; + case '\u007E': return 0x7E; + case '\u007F': return 0x7F; + case '\u00C4': return 0x80; + case '\u00C5': return 0x81; + case '\u00C7': return 0x82; + case '\u00C9': return 0x83; + case '\u00D1': return 0x84; + case '\u00D6': return 0x85; + case '\u00DC': return 0x86; + case '\u00E1': return 0x87; + case '\u00E0': return 0x88; + case '\u00E2': return 0x89; + case '\u00E4': return 0x8A; + case '\u00E3': return 0x8B; + case '\u00E5': return 0x8C; + case '\u00E7': return 0x8D; + case '\u00E9': return 0x8E; + case '\u00E8': return 0x8F; + case '\u00EA': return 0x90; + case '\u00EB': return 0x91; + case '\u00ED': return 0x92; + case '\u00EC': return 0x93; + case '\u00EE': return 0x94; + case '\u00EF': return 0x95; + case '\u00F1': return 0x96; + case '\u00F3': return 0x97; + case '\u00F2': return 0x98; + case '\u00F4': return 0x99; + case '\u00F6': return 0x9A; + case '\u00F5': return 0x9B; + case '\u00FA': return 0x9C; + case '\u00F9': return 0x9D; + case '\u00FB': return 0x9E; + case '\u00FC': return 0x9F; + case '\u2020': return 0xA0; + case '\u00B0': return 0xA1; + case '\u00A2': return 0xA2; + case '\u00A3': return 0xA3; + case '\u00A7': return 0xA4; + case '\u2022': return 0xA5; + case '\u00B6': return 0xA6; + case '\u00DF': return 0xA7; + case '\u00AE': return 0xA8; + case '\u00A9': return 0xA9; + case '\u2122': return 0xAA; + case '\u00B4': return 0xAB; + case '\u00A8': return 0xAC; + case '\u2260': return 0xAD; + case '\u0102': return 0xAE; + case '\u0218': return 0xAF; + case '\u221E': return 0xB0; + case '\u00B1': return 0xB1; + case '\u2264': return 0xB2; + case '\u2265': return 0xB3; + case '\u00A5': return 0xB4; + case '\u00B5': return 0xB5; + case '\u2202': return 0xB6; + case '\u2211': return 0xB7; + case '\u220F': return 0xB8; + case '\u03C0': return 0xB9; + case '\u222B': return 0xBA; + case '\u00AA': return 0xBB; + case '\u00BA': return 0xBC; + case '\u03A9': return 0xBD; + case '\u0103': return 0xBE; + case '\u0219': return 0xBF; + case '\u00BF': return 0xC0; + case '\u00A1': return 0xC1; + case '\u00AC': return 0xC2; + case '\u221A': return 0xC3; + case '\u0192': return 0xC4; + case '\u2248': return 0xC5; + case '\u2206': return 0xC6; + case '\u00AB': return 0xC7; + case '\u00BB': return 0xC8; + case '\u2026': return 0xC9; + case '\u00A0': return 0xCA; + case '\u00C0': return 0xCB; + case '\u00C3': return 0xCC; + case '\u00D5': return 0xCD; + case '\u0152': return 0xCE; + case '\u0153': return 0xCF; + case '\u2013': return 0xD0; + case '\u2014': return 0xD1; + case '\u201C': return 0xD2; + case '\u201D': return 0xD3; + case '\u2018': return 0xD4; + case '\u2019': return 0xD5; + case '\u00F7': return 0xD6; + case '\u25CA': return 0xD7; + case '\u00FF': return 0xD8; + case '\u0178': return 0xD9; + case '\u2044': return 0xDA; + case '\u20AC': return 0xDB; + case '\u2039': return 0xDC; + case '\u203A': return 0xDD; + case '\u021A': return 0xDE; + case '\u021B': return 0xDF; + case '\u2021': return 0xE0; + case '\u00B7': return 0xE1; + case '\u201A': return 0xE2; + case '\u201E': return 0xE3; + case '\u2030': return 0xE4; + case '\u00C2': return 0xE5; + case '\u00CA': return 0xE6; + case '\u00C1': return 0xE7; + case '\u00CB': return 0xE8; + case '\u00C8': return 0xE9; + case '\u00CD': return 0xEA; + case '\u00CE': return 0xEB; + case '\u00CF': return 0xEC; + case '\u00CC': return 0xED; + case '\u00D3': return 0xEE; + case '\u00D4': return 0xEF; + case '\uF8FF': return 0xF0; + case '\u00D2': return 0xF1; + case '\u00DA': return 0xF2; + case '\u00DB': return 0xF3; + case '\u00D9': return 0xF4; + case '\u0131': return 0xF5; + case '\u02C6': return 0xF6; + case '\u02DC': return 0xF7; + case '\u00AF': return 0xF8; + case '\u02D8': return 0xF9; + case '\u02D9': return 0xFA; + case '\u02DA': return 0xFB; + case '\u00B8': return 0xFC; + case '\u02DD': return 0xFD; + case '\u02DB': return 0xFE; + case '\u02C7': return 0xFF; default: // Fallback to '?' return 0x3F; } } } -} +} \ No newline at end of file diff --git a/Claunia.Encoding/MacTurkish.cs b/Claunia.Encoding/MacTurkish.cs index add84f2..4aeca57 100644 --- a/Claunia.Encoding/MacTurkish.cs +++ b/Claunia.Encoding/MacTurkish.cs @@ -29,7 +29,7 @@ using System; namespace Claunia.Encoding { /// - /// Represents an Mac Turkish character encoding of Unicode characters. + /// Represents an Mac Turkish character encoding of Unicode characters. /// public class MacTurkish : Encoding { @@ -48,105 +48,151 @@ namespace Claunia.Encoding const bool singleByte = true; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. + /// The Macintosh Turkish to Unicode character map. /// - public override bool IsBrowserDisplay { - get { return browserDisplay; } - } + static readonly char[] MacTurkishTable = + { + // 0x00 + '\u0000', '\u0001', '\u0002', '\u0003', '\u0004', '\u0005', '\u0006', '\u0007', + // 0x08 + '\u0008', '\u0009', '\u000A', '\u000B', '\u000C', '\u000D', '\u000E', '\u000F', + // 0x10 + '\u0010', '\u0011', '\u0012', '\u0013', '\u0014', '\u0015', '\u0016', '\u0017', + // 0x18 + '\u0018', '\u0019', '\u001A', '\u001B', '\u001C', '\u001D', '\u001E', '\u001F', + // 0x20 + '\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027', + // 0x28 + '\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F', + // 0x30 + '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', + // 0x38 + '\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F', + // 0x40 + '\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047', + // 0x48 + '\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F', + // 0x50 + '\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057', + // 0x58 + '\u0058', '\u0059', '\u005A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F', + // 0x60 + '\u0060', '\u0061', '\u0062', '\u0063', '\u0064', '\u0065', '\u0066', '\u0067', + // 0x68 + '\u0068', '\u0069', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F', + // 0x70 + '\u0070', '\u0071', '\u0072', '\u0073', '\u0074', '\u0075', '\u0076', '\u0077', + // 0x78 + '\u0078', '\u0079', '\u007A', '\u007B', '\u007C', '\u007D', '\u007E', '\u007F', + // 0x80 + '\u00C4', '\u00C5', '\u00C7', '\u00C9', '\u00D1', '\u00D6', '\u00DC', '\u00E1', + // 0x88 + '\u00E0', '\u00E2', '\u00E4', '\u00E3', '\u00E5', '\u00E7', '\u00E9', '\u00E8', + // 0x90 + '\u00EA', '\u00EB', '\u00ED', '\u00EC', '\u00EE', '\u00EF', '\u00F1', '\u00F3', + // 0x98 + '\u00F2', '\u00F4', '\u00F6', '\u00F5', '\u00FA', '\u00F9', '\u00FB', '\u00FC', + // 0xA0 + '\u2020', '\u00B0', '\u00A2', '\u00A3', '\u00A7', '\u2022', '\u00B6', '\u00DF', + // 0xA8 + '\u00AE', '\u00A9', '\u2122', '\u00B4', '\u00A8', '\u2260', '\u00C6', '\u00D8', + // 0xB0 + '\u221E', '\u00B1', '\u2264', '\u2265', '\u00A5', '\u00B5', '\u2202', '\u2211', + // 0xB8 + '\u220F', '\u03C0', '\u222B', '\u00AA', '\u00BA', '\u03A9', '\u00E6', '\u00F8', + // 0xC0 + '\u00BF', '\u00A1', '\u00AC', '\u221A', '\u0192', '\u2248', '\u2206', '\u00AB', + // 0xC8 + '\u00BB', '\u2026', '\u00A0', '\u00C0', '\u00C3', '\u00D5', '\u0152', '\u0153', + // 0xD0 + '\u2013', '\u2014', '\u201C', '\u201D', '\u2018', '\u2019', '\u00F7', '\u25CA', + // 0xD8 + '\u00FF', '\u0178', '\u011E', '\u011F', '\u0130', '\u0131', '\u015E', '\u015F', + // 0xE0 + '\u2021', '\u00B7', '\u201A', '\u201E', '\u2030', '\u00C2', '\u00CA', '\u00C1', + // 0xE8 + '\u00CB', '\u00C8', '\u00CD', '\u00CE', '\u00CF', '\u00CC', '\u00D3', '\u00D4', + // 0xF0 + '\uF8FF', '\u00D2', '\u00DA', '\u00D8', '\u00D9', '\uF8A0', '\u02C6', '\u02DC', + // 0xF8 + '\u00AF', '\u02D8', '\u02D9', '\u02DA', '\u00B8', '\u02DD', '\u02DB', '\u02C7' + }; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. + /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. /// - public override bool IsBrowserSave { - get { return browserSave; } - } + public override bool IsBrowserDisplay => browserDisplay; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. + /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. /// - public override bool IsMailNewsDisplay { - get { return mailNewsDisplay; } - } + public override bool IsBrowserSave => browserSave; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. /// - public override bool IsMailNewsSave { - get { return mailNewsSave; } - } + public override bool IsMailNewsDisplay => mailNewsDisplay; /// - /// Gets a value indicating whether the current encoding is read-only. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// + public override bool IsMailNewsSave => mailNewsSave; + + /// + /// Gets a value indicating whether the current encoding is read-only. /// /// The is single byte. - public override bool IsReadOnly { - get { return readOnly; } - } + public override bool IsReadOnly => readOnly; /// - /// Gets a value indicating whether the current encoding uses single-byte code points. + /// Gets a value indicating whether the current encoding uses single-byte code points. /// - public override bool IsSingleByte { - get { return singleByte; } - } + public override bool IsSingleByte => singleByte; /// - /// Gets the code page identifier of the current Encoding. + /// Gets the code page identifier of the current Encoding. /// - public override int CodePage { - get { return _codepage; } - } + public override int CodePage => _codepage; /// - /// Gets a name for the current encoding that can be used with mail agent body tags + /// Gets a name for the current encoding that can be used with mail agent body tags /// - public override string BodyName { - get { return _bodyname; } - } + public override string BodyName => _bodyname; /// - /// Gets a name for the current encoding that can be used with mail agent header tags + /// Gets a name for the current encoding that can be used with mail agent header tags /// - public override string HeaderName { - get { return _headername; } - } + public override string HeaderName => _headername; /// - /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. + /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. /// - public override string WebName { - get { return _webname; } - } + public override string WebName => _webname; /// - /// Gets the human-readable description of the current encoding. + /// Gets the human-readable description of the current encoding. /// - public override string EncodingName { - get { return _encodingname; } - } + public override string EncodingName => _encodingname; /// - /// Gets the Windows operating system code page that most closely corresponds to the current encoding. + /// Gets the Windows operating system code page that most closely corresponds to the current encoding. /// - public override int WindowsCodePage { - get { return _windowsCodepage; } - } + public override int WindowsCodePage => _windowsCodepage; /// - /// Calculates the number of bytes produced by encoding the characters in the specified . + /// Calculates the number of bytes produced by encoding the characters in the specified . /// /// The number of bytes produced by encoding the specified characters. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. public override int GetByteCount(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return s.Length; } /// - /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. + /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. /// /// The number of bytes produced by encoding the specified characters. /// The character array containing the set of characters to encode. @@ -154,36 +200,32 @@ namespace Claunia.Encoding /// The number of characters to encode. public override int GetByteCount(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0 || index >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0 || index >= chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0 || index + count > chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(count < 0 || index + count > chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); return count; } /// - /// Calculates the number of bytes produced by encoding all the characters in the specified character array. + /// Calculates the number of bytes produced by encoding all the characters in the specified character array. /// /// The number of bytes produced by encoding all the characters in the specified character array. /// The character array containing the characters to encode. public override int GetByteCount(char[] chars) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); return chars.Length; } /// - /// Encodes a set of characters from the specified into the specified byte array. + /// Encodes a set of characters from the specified into the specified byte array. /// /// The actual number of bytes written into bytes. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. /// The index of the first character to encode. /// The number of characters to encode. /// The byte array to contain the resulting sequence of bytes. @@ -194,20 +236,19 @@ namespace Claunia.Encoding } /// - /// Encodes all the characters in the specified string into a sequence of bytes. + /// Encodes all the characters in the specified string into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The string containing the characters to encode. public override byte[] GetBytes(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return GetBytes(s.ToCharArray(), 0, s.Length); } /// - /// Encodes a set of characters from the specified character array into the specified byte array. + /// Encodes a set of characters from the specified character array into the specified byte array. /// /// The actual number of bytes written into bytes. /// The character array containing the set of characters to encode. @@ -217,43 +258,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting sequence of bytes. public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount + charIndex > chars.Length) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount + charIndex > chars.Length) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteIndex + charCount > bytes.Length) - throw new ArgumentException(nameof(bytes)); + if(byteIndex + charCount > bytes.Length) throw new ArgumentException(nameof(bytes)); byte[] temp = GetBytes(chars, charIndex, charCount); - for(int i = 0; i < temp.Length; i++) - bytes[i + byteIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) bytes[i + byteIndex] = temp[i]; return charCount; } /// - /// Encodes a set of characters from the specified character array into a sequence of bytes. + /// Encodes a set of characters from the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the set of characters to encode. @@ -261,28 +292,23 @@ namespace Claunia.Encoding /// The number of characters to encode. public override byte[] GetBytes(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > chars.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > chars.Length) throw new ArgumentOutOfRangeException(nameof(count)); byte[] bytes = new byte[count]; - for(int i = 0; i < count; i++) - bytes[i] = GetByte(chars[index + i]); + for(int i = 0; i < count; i++) bytes[i] = GetByte(chars[index + i]); return bytes; } /// - /// Encodes all the characters in the specified character array into a sequence of bytes. + /// Encodes all the characters in the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the characters to encode. @@ -292,7 +318,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. + /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -302,7 +328,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. + /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -310,23 +336,19 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override int GetCharCount(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); return count; } /// - /// Decodes a sequence of bytes from the specified byte array into the specified character array. + /// Decodes a sequence of bytes from the specified byte array into the specified character array. /// /// The actual number of characters written into chars. /// The byte array containing the sequence of bytes to decode. @@ -336,43 +358,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting set of characters. public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount + byteIndex > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount + byteIndex > bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charIndex + byteCount > chars.Length) - throw new ArgumentException(nameof(chars)); + if(charIndex + byteCount > chars.Length) throw new ArgumentException(nameof(chars)); char[] temp = GetChars(bytes, byteIndex, byteCount); - for(int i = 0; i < temp.Length; i++) - chars[i + charIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) chars[i + charIndex] = temp[i]; return byteCount; } /// - /// Decodes all the bytes in the specified byte array into a set of characters. + /// Decodes all the bytes in the specified byte array into a set of characters. /// /// A character array containing the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -382,7 +394,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a set of characters. + /// Decodes a sequence of bytes from the specified byte array into a set of characters. /// /// The chars. /// The byte array containing the sequence of bytes to decode. @@ -390,54 +402,47 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override char[] GetChars(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); char[] chars = new char[count]; - for(int i = 0; i < count; i++) - chars[i] = GetChar(bytes[index + i]); + for(int i = 0; i < count; i++) chars[i] = GetChar(bytes[index + i]); return chars; } /// - /// Calculates the maximum number of bytes produced by encoding the specified number of characters. + /// Calculates the maximum number of bytes produced by encoding the specified number of characters. /// /// The maximum number of bytes produced by encoding the specified number of characters. /// The number of characters to encode. public override int GetMaxByteCount(int charCount) { - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); return charCount; } /// - /// Calculates the maximum number of characters produced by decoding the specified number of bytes. + /// Calculates the maximum number of characters produced by decoding the specified number of bytes. /// /// The maximum number of characters produced by decoding the specified number of bytes. /// The number of bytes to decode. public override int GetMaxCharCount(int byteCount) { - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); return byteCount; } /// - /// Returns a sequence of bytes that specifies the encoding used. + /// Returns a sequence of bytes that specifies the encoding used. /// /// A byte array of length zero, as a preamble is not required. public override byte[] GetPreamble() @@ -446,7 +451,7 @@ namespace Claunia.Encoding } /// - /// Decodes all the bytes in the specified byte array into a string. + /// Decodes all the bytes in the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -456,7 +461,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a string. + /// Decodes a sequence of bytes from the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -468,77 +473,7 @@ namespace Claunia.Encoding } /// - /// The Macintosh Turkish to Unicode character map. - /// - static readonly char[] MacTurkishTable = { - // 0x00 - '\u0000','\u0001','\u0002','\u0003','\u0004','\u0005','\u0006','\u0007', - // 0x08 - '\u0008','\u0009','\u000A','\u000B','\u000C','\u000D','\u000E','\u000F', - // 0x10 - '\u0010','\u0011','\u0012','\u0013','\u0014','\u0015','\u0016','\u0017', - // 0x18 - '\u0018','\u0019','\u001A','\u001B','\u001C','\u001D','\u001E','\u001F', - // 0x20 - '\u0020','\u0021','\u0022','\u0023','\u0024','\u0025','\u0026','\u0027', - // 0x28 - '\u0028','\u0029','\u002A','\u002B','\u002C','\u002D','\u002E','\u002F', - // 0x30 - '\u0030','\u0031','\u0032','\u0033','\u0034','\u0035','\u0036','\u0037', - // 0x38 - '\u0038','\u0039','\u003A','\u003B','\u003C','\u003D','\u003E','\u003F', - // 0x40 - '\u0040','\u0041','\u0042','\u0043','\u0044','\u0045','\u0046','\u0047', - // 0x48 - '\u0048','\u0049','\u004A','\u004B','\u004C','\u004D','\u004E','\u004F', - // 0x50 - '\u0050','\u0051','\u0052','\u0053','\u0054','\u0055','\u0056','\u0057', - // 0x58 - '\u0058','\u0059','\u005A','\u005B','\u005C','\u005D','\u005E','\u005F', - // 0x60 - '\u0060','\u0061','\u0062','\u0063','\u0064','\u0065','\u0066','\u0067', - // 0x68 - '\u0068','\u0069','\u006A','\u006B','\u006C','\u006D','\u006E','\u006F', - // 0x70 - '\u0070','\u0071','\u0072','\u0073','\u0074','\u0075','\u0076','\u0077', - // 0x78 - '\u0078','\u0079','\u007A','\u007B','\u007C','\u007D','\u007E','\u007F', - // 0x80 - '\u00C4','\u00C5','\u00C7','\u00C9','\u00D1','\u00D6','\u00DC','\u00E1', - // 0x88 - '\u00E0','\u00E2','\u00E4','\u00E3','\u00E5','\u00E7','\u00E9','\u00E8', - // 0x90 - '\u00EA','\u00EB','\u00ED','\u00EC','\u00EE','\u00EF','\u00F1','\u00F3', - // 0x98 - '\u00F2','\u00F4','\u00F6','\u00F5','\u00FA','\u00F9','\u00FB','\u00FC', - // 0xA0 - '\u2020','\u00B0','\u00A2','\u00A3','\u00A7','\u2022','\u00B6','\u00DF', - // 0xA8 - '\u00AE','\u00A9','\u2122','\u00B4','\u00A8','\u2260','\u00C6','\u00D8', - // 0xB0 - '\u221E','\u00B1','\u2264','\u2265','\u00A5','\u00B5','\u2202','\u2211', - // 0xB8 - '\u220F','\u03C0','\u222B','\u00AA','\u00BA','\u03A9','\u00E6','\u00F8', - // 0xC0 - '\u00BF','\u00A1','\u00AC','\u221A','\u0192','\u2248','\u2206','\u00AB', - // 0xC8 - '\u00BB','\u2026','\u00A0','\u00C0','\u00C3','\u00D5','\u0152','\u0153', - // 0xD0 - '\u2013','\u2014','\u201C','\u201D','\u2018','\u2019','\u00F7','\u25CA', - // 0xD8 - '\u00FF','\u0178','\u011E','\u011F','\u0130','\u0131','\u015E','\u015F', - // 0xE0 - '\u2021','\u00B7','\u201A','\u201E','\u2030','\u00C2','\u00CA','\u00C1', - // 0xE8 - '\u00CB','\u00C8','\u00CD','\u00CE','\u00CF','\u00CC','\u00D3','\u00D4', - // 0xF0 - '\uF8FF','\u00D2','\u00DA','\u00D8','\u00D9','\uF8A0','\u02C6','\u02DC', - // 0xF8 - '\u00AF','\u02D8','\u02D9','\u02DA','\u00B8','\u02DD','\u02DB','\u02C7' - }; - - /// - /// Converts a Mac Turkish character to an Unicode character + /// Converts a Mac Turkish character to an Unicode character /// /// Unicode character. /// Mac Turkish character. @@ -548,525 +483,270 @@ namespace Claunia.Encoding } /// - /// Converts a Unicode character to an Mac Turkish character + /// Converts a Unicode character to an Mac Turkish character /// /// Mac Turkish character. /// Unicode character. static byte GetByte(char character) { - switch(character) { - case '\u0000': - return 0x00; - case '\u0001': - return 0x01; - case '\u0002': - return 0x02; - case '\u0003': - return 0x03; - case '\u0004': - return 0x04; - case '\u0005': - return 0x05; - case '\u0006': - return 0x06; - case '\u0007': - return 0x07; - case '\u0008': - return 0x08; - case '\u0009': - return 0x09; - case '\u000A': - return 0x0A; - case '\u000B': - return 0x0B; - case '\u000C': - return 0x0C; - case '\u000D': - return 0x0D; - case '\u000E': - return 0x0E; - case '\u000F': - return 0x0F; - case '\u0010': - return 0x10; - case '\u0011': - return 0x11; - case '\u0012': - return 0x12; - case '\u0013': - return 0x13; - case '\u0014': - return 0x14; - case '\u0015': - return 0x15; - case '\u0016': - return 0x16; - case '\u0017': - return 0x17; - case '\u0018': - return 0x18; - case '\u0019': - return 0x19; - case '\u001A': - return 0x1A; - case '\u001B': - return 0x1B; - case '\u001C': - return 0x1C; - case '\u001D': - return 0x1D; - case '\u001E': - return 0x1E; - case '\u001F': - return 0x1F; - case '\u0020': - return 0x20; - case '\u0021': - return 0x21; - case '\u0022': - return 0x22; - case '\u0023': - return 0x23; - case '\u0024': - return 0x24; - case '\u0025': - return 0x25; - case '\u0026': - return 0x26; - case '\u0027': - return 0x27; - case '\u0028': - return 0x28; - case '\u0029': - return 0x29; - case '\u002A': - return 0x2A; - case '\u002B': - return 0x2B; - case '\u002C': - return 0x2C; - case '\u002D': - return 0x2D; - case '\u002E': - return 0x2E; - case '\u002F': - return 0x2F; - case '\u0030': - return 0x30; - case '\u0031': - return 0x31; - case '\u0032': - return 0x32; - case '\u0033': - return 0x33; - case '\u0034': - return 0x34; - case '\u0035': - return 0x35; - case '\u0036': - return 0x36; - case '\u0037': - return 0x37; - case '\u0038': - return 0x38; - case '\u0039': - return 0x39; - case '\u003A': - return 0x3A; - case '\u003B': - return 0x3B; - case '\u003C': - return 0x3C; - case '\u003D': - return 0x3D; - case '\u003E': - return 0x3E; - case '\u003F': - return 0x3F; - case '\u0040': - return 0x40; - case '\u0041': - return 0x41; - case '\u0042': - return 0x42; - case '\u0043': - return 0x43; - case '\u0044': - return 0x44; - case '\u0045': - return 0x45; - case '\u0046': - return 0x46; - case '\u0047': - return 0x47; - case '\u0048': - return 0x48; - case '\u0049': - return 0x49; - case '\u004A': - return 0x4A; - case '\u004B': - return 0x4B; - case '\u004C': - return 0x4C; - case '\u004D': - return 0x4D; - case '\u004E': - return 0x4E; - case '\u004F': - return 0x4F; - case '\u0050': - return 0x50; - case '\u0051': - return 0x51; - case '\u0052': - return 0x52; - case '\u0053': - return 0x53; - case '\u0054': - return 0x54; - case '\u0055': - return 0x55; - case '\u0056': - return 0x56; - case '\u0057': - return 0x57; - case '\u0058': - return 0x58; - case '\u0059': - return 0x59; - case '\u005A': - return 0x5A; - case '\u005B': - return 0x5B; - case '\u005C': - return 0x5C; - case '\u005D': - return 0x5D; - case '\u005E': - return 0x5E; - case '\u005F': - return 0x5F; - case '\u0060': - return 0x60; - case '\u0061': - return 0x61; - case '\u0062': - return 0x62; - case '\u0063': - return 0x63; - case '\u0064': - return 0x64; - case '\u0065': - return 0x65; - case '\u0066': - return 0x66; - case '\u0067': - return 0x67; - case '\u0068': - return 0x68; - case '\u0069': - return 0x69; - case '\u006A': - return 0x6A; - case '\u006B': - return 0x6B; - case '\u006C': - return 0x6C; - case '\u006D': - return 0x6D; - case '\u006E': - return 0x6E; - case '\u006F': - return 0x6F; - case '\u0070': - return 0x70; - case '\u0071': - return 0x71; - case '\u0072': - return 0x72; - case '\u0073': - return 0x73; - case '\u0074': - return 0x74; - case '\u0075': - return 0x75; - case '\u0076': - return 0x76; - case '\u0077': - return 0x77; - case '\u0078': - return 0x78; - case '\u0079': - return 0x79; - case '\u007A': - return 0x7A; - case '\u007B': - return 0x7B; - case '\u007C': - return 0x7C; - case '\u007D': - return 0x7D; - case '\u007E': - return 0x7E; - case '\u007F': - return 0x7F; - case '\u00C4': - return 0x80; - case '\u00C5': - return 0x81; - case '\u00C7': - return 0x82; - case '\u00C9': - return 0x83; - case '\u00D1': - return 0x84; - case '\u00D6': - return 0x85; - case '\u00DC': - return 0x86; - case '\u00E1': - return 0x87; - case '\u00E0': - return 0x88; - case '\u00E2': - return 0x89; - case '\u00E4': - return 0x8A; - case '\u00E3': - return 0x8B; - case '\u00E5': - return 0x8C; - case '\u00E7': - return 0x8D; - case '\u00E9': - return 0x8E; - case '\u00E8': - return 0x8F; - case '\u00EA': - return 0x90; - case '\u00EB': - return 0x91; - case '\u00ED': - return 0x92; - case '\u00EC': - return 0x93; - case '\u00EE': - return 0x94; - case '\u00EF': - return 0x95; - case '\u00F1': - return 0x96; - case '\u00F3': - return 0x97; - case '\u00F2': - return 0x98; - case '\u00F4': - return 0x99; - case '\u00F6': - return 0x9A; - case '\u00F5': - return 0x9B; - case '\u00FA': - return 0x9C; - case '\u00F9': - return 0x9D; - case '\u00FB': - return 0x9E; - case '\u00FC': - return 0x9F; - case '\u2020': - return 0xA0; - case '\u00B0': - return 0xA1; - case '\u00A2': - return 0xA2; - case '\u00A3': - return 0xA3; - case '\u00A7': - return 0xA4; - case '\u2022': - return 0xA5; - case '\u00B6': - return 0xA6; - case '\u00DF': - return 0xA7; - case '\u00AE': - return 0xA8; - case '\u00A9': - return 0xA9; - case '\u2122': - return 0xAA; - case '\u00B4': - return 0xAB; - case '\u00A8': - return 0xAC; - case '\u2260': - return 0xAD; - case '\u00C6': - return 0xAE; - case '\u00D8': - return 0xAF; - case '\u221E': - return 0xB0; - case '\u00B1': - return 0xB1; - case '\u2264': - return 0xB2; - case '\u2265': - return 0xB3; - case '\u00A5': - return 0xB4; - case '\u00B5': - return 0xB5; - case '\u2202': - return 0xB6; - case '\u2211': - return 0xB7; - case '\u220F': - return 0xB8; - case '\u03C0': - return 0xB9; - case '\u222B': - return 0xBA; - case '\u00AA': - return 0xBB; - case '\u00BA': - return 0xBC; - case '\u03A9': - return 0xBD; - case '\u00E6': - return 0xBE; - case '\u00F8': - return 0xBF; - case '\u00BF': - return 0xC0; - case '\u00A1': - return 0xC1; - case '\u00AC': - return 0xC2; - case '\u221A': - return 0xC3; - case '\u0192': - return 0xC4; - case '\u2248': - return 0xC5; - case '\u2206': - return 0xC6; - case '\u00AB': - return 0xC7; - case '\u00BB': - return 0xC8; - case '\u2026': - return 0xC9; - case '\u00A0': - return 0xCA; - case '\u00C0': - return 0xCB; - case '\u00C3': - return 0xCC; - case '\u00D5': - return 0xCD; - case '\u0152': - return 0xCE; - case '\u0153': - return 0xCF; - case '\u2013': - return 0xD0; - case '\u2014': - return 0xD1; - case '\u201C': - return 0xD2; - case '\u201D': - return 0xD3; - case '\u2018': - return 0xD4; - case '\u2019': - return 0xD5; - case '\u00F7': - return 0xD6; - case '\u05CA': - return 0xD7; - case '\u00FF': - return 0xD8; - case '\u0178': - return 0xD9; - case '\u011E': - return 0xDA; - case '\u011F': - return 0xDB; - case '\u0130': - return 0xDC; - case '\u0131': - return 0xDD; - case '\u015E': - return 0xDE; - case '\u015F': - return 0xDF; - case '\u2021': - return 0xE0; - case '\u00B7': - return 0xE1; - case '\u201A': - return 0xE2; - case '\u201E': - return 0xE3; - case '\u2030': - return 0xE4; - case '\u00C2': - return 0xE5; - case '\u00CA': - return 0xE6; - case '\u00C1': - return 0xE7; - case '\u00CB': - return 0xE8; - case '\u00C8': - return 0xE9; - case '\u00CD': - return 0xEA; - case '\u00CE': - return 0xEB; - case '\u00CF': - return 0xEC; - case '\u00CC': - return 0xED; - case '\u00D3': - return 0xEE; - case '\u00D4': - return 0xEF; - case '\uF8FF': - return 0xF0; - case '\u00D2': - return 0xF1; - case '\u00DA': - return 0xF2; - case '\u00DB': - return 0xF3; - case '\u00D9': - return 0xF4; - case '\uF8A0': - return 0xF5; - case '\u02C6': - return 0xF6; - case '\u02DC': - return 0xF7; - case '\u00AF': - return 0xF8; - case '\u02D8': - return 0xF9; - case '\u02D9': - return 0xFA; - case '\u02DA': - return 0xFB; - case '\u00B8': - return 0xFC; - case '\u02DD': - return 0xFD; - case '\u02DB': - return 0xFE; - case '\u02C7': - return 0xFF; + switch(character) + { + case '\u0000': return 0x00; + case '\u0001': return 0x01; + case '\u0002': return 0x02; + case '\u0003': return 0x03; + case '\u0004': return 0x04; + case '\u0005': return 0x05; + case '\u0006': return 0x06; + case '\u0007': return 0x07; + case '\u0008': return 0x08; + case '\u0009': return 0x09; + case '\u000A': return 0x0A; + case '\u000B': return 0x0B; + case '\u000C': return 0x0C; + case '\u000D': return 0x0D; + case '\u000E': return 0x0E; + case '\u000F': return 0x0F; + case '\u0010': return 0x10; + case '\u0011': return 0x11; + case '\u0012': return 0x12; + case '\u0013': return 0x13; + case '\u0014': return 0x14; + case '\u0015': return 0x15; + case '\u0016': return 0x16; + case '\u0017': return 0x17; + case '\u0018': return 0x18; + case '\u0019': return 0x19; + case '\u001A': return 0x1A; + case '\u001B': return 0x1B; + case '\u001C': return 0x1C; + case '\u001D': return 0x1D; + case '\u001E': return 0x1E; + case '\u001F': return 0x1F; + case '\u0020': return 0x20; + case '\u0021': return 0x21; + case '\u0022': return 0x22; + case '\u0023': return 0x23; + case '\u0024': return 0x24; + case '\u0025': return 0x25; + case '\u0026': return 0x26; + case '\u0027': return 0x27; + case '\u0028': return 0x28; + case '\u0029': return 0x29; + case '\u002A': return 0x2A; + case '\u002B': return 0x2B; + case '\u002C': return 0x2C; + case '\u002D': return 0x2D; + case '\u002E': return 0x2E; + case '\u002F': return 0x2F; + case '\u0030': return 0x30; + case '\u0031': return 0x31; + case '\u0032': return 0x32; + case '\u0033': return 0x33; + case '\u0034': return 0x34; + case '\u0035': return 0x35; + case '\u0036': return 0x36; + case '\u0037': return 0x37; + case '\u0038': return 0x38; + case '\u0039': return 0x39; + case '\u003A': return 0x3A; + case '\u003B': return 0x3B; + case '\u003C': return 0x3C; + case '\u003D': return 0x3D; + case '\u003E': return 0x3E; + case '\u003F': return 0x3F; + case '\u0040': return 0x40; + case '\u0041': return 0x41; + case '\u0042': return 0x42; + case '\u0043': return 0x43; + case '\u0044': return 0x44; + case '\u0045': return 0x45; + case '\u0046': return 0x46; + case '\u0047': return 0x47; + case '\u0048': return 0x48; + case '\u0049': return 0x49; + case '\u004A': return 0x4A; + case '\u004B': return 0x4B; + case '\u004C': return 0x4C; + case '\u004D': return 0x4D; + case '\u004E': return 0x4E; + case '\u004F': return 0x4F; + case '\u0050': return 0x50; + case '\u0051': return 0x51; + case '\u0052': return 0x52; + case '\u0053': return 0x53; + case '\u0054': return 0x54; + case '\u0055': return 0x55; + case '\u0056': return 0x56; + case '\u0057': return 0x57; + case '\u0058': return 0x58; + case '\u0059': return 0x59; + case '\u005A': return 0x5A; + case '\u005B': return 0x5B; + case '\u005C': return 0x5C; + case '\u005D': return 0x5D; + case '\u005E': return 0x5E; + case '\u005F': return 0x5F; + case '\u0060': return 0x60; + case '\u0061': return 0x61; + case '\u0062': return 0x62; + case '\u0063': return 0x63; + case '\u0064': return 0x64; + case '\u0065': return 0x65; + case '\u0066': return 0x66; + case '\u0067': return 0x67; + case '\u0068': return 0x68; + case '\u0069': return 0x69; + case '\u006A': return 0x6A; + case '\u006B': return 0x6B; + case '\u006C': return 0x6C; + case '\u006D': return 0x6D; + case '\u006E': return 0x6E; + case '\u006F': return 0x6F; + case '\u0070': return 0x70; + case '\u0071': return 0x71; + case '\u0072': return 0x72; + case '\u0073': return 0x73; + case '\u0074': return 0x74; + case '\u0075': return 0x75; + case '\u0076': return 0x76; + case '\u0077': return 0x77; + case '\u0078': return 0x78; + case '\u0079': return 0x79; + case '\u007A': return 0x7A; + case '\u007B': return 0x7B; + case '\u007C': return 0x7C; + case '\u007D': return 0x7D; + case '\u007E': return 0x7E; + case '\u007F': return 0x7F; + case '\u00C4': return 0x80; + case '\u00C5': return 0x81; + case '\u00C7': return 0x82; + case '\u00C9': return 0x83; + case '\u00D1': return 0x84; + case '\u00D6': return 0x85; + case '\u00DC': return 0x86; + case '\u00E1': return 0x87; + case '\u00E0': return 0x88; + case '\u00E2': return 0x89; + case '\u00E4': return 0x8A; + case '\u00E3': return 0x8B; + case '\u00E5': return 0x8C; + case '\u00E7': return 0x8D; + case '\u00E9': return 0x8E; + case '\u00E8': return 0x8F; + case '\u00EA': return 0x90; + case '\u00EB': return 0x91; + case '\u00ED': return 0x92; + case '\u00EC': return 0x93; + case '\u00EE': return 0x94; + case '\u00EF': return 0x95; + case '\u00F1': return 0x96; + case '\u00F3': return 0x97; + case '\u00F2': return 0x98; + case '\u00F4': return 0x99; + case '\u00F6': return 0x9A; + case '\u00F5': return 0x9B; + case '\u00FA': return 0x9C; + case '\u00F9': return 0x9D; + case '\u00FB': return 0x9E; + case '\u00FC': return 0x9F; + case '\u2020': return 0xA0; + case '\u00B0': return 0xA1; + case '\u00A2': return 0xA2; + case '\u00A3': return 0xA3; + case '\u00A7': return 0xA4; + case '\u2022': return 0xA5; + case '\u00B6': return 0xA6; + case '\u00DF': return 0xA7; + case '\u00AE': return 0xA8; + case '\u00A9': return 0xA9; + case '\u2122': return 0xAA; + case '\u00B4': return 0xAB; + case '\u00A8': return 0xAC; + case '\u2260': return 0xAD; + case '\u00C6': return 0xAE; + case '\u00D8': return 0xAF; + case '\u221E': return 0xB0; + case '\u00B1': return 0xB1; + case '\u2264': return 0xB2; + case '\u2265': return 0xB3; + case '\u00A5': return 0xB4; + case '\u00B5': return 0xB5; + case '\u2202': return 0xB6; + case '\u2211': return 0xB7; + case '\u220F': return 0xB8; + case '\u03C0': return 0xB9; + case '\u222B': return 0xBA; + case '\u00AA': return 0xBB; + case '\u00BA': return 0xBC; + case '\u03A9': return 0xBD; + case '\u00E6': return 0xBE; + case '\u00F8': return 0xBF; + case '\u00BF': return 0xC0; + case '\u00A1': return 0xC1; + case '\u00AC': return 0xC2; + case '\u221A': return 0xC3; + case '\u0192': return 0xC4; + case '\u2248': return 0xC5; + case '\u2206': return 0xC6; + case '\u00AB': return 0xC7; + case '\u00BB': return 0xC8; + case '\u2026': return 0xC9; + case '\u00A0': return 0xCA; + case '\u00C0': return 0xCB; + case '\u00C3': return 0xCC; + case '\u00D5': return 0xCD; + case '\u0152': return 0xCE; + case '\u0153': return 0xCF; + case '\u2013': return 0xD0; + case '\u2014': return 0xD1; + case '\u201C': return 0xD2; + case '\u201D': return 0xD3; + case '\u2018': return 0xD4; + case '\u2019': return 0xD5; + case '\u00F7': return 0xD6; + case '\u05CA': return 0xD7; + case '\u00FF': return 0xD8; + case '\u0178': return 0xD9; + case '\u011E': return 0xDA; + case '\u011F': return 0xDB; + case '\u0130': return 0xDC; + case '\u0131': return 0xDD; + case '\u015E': return 0xDE; + case '\u015F': return 0xDF; + case '\u2021': return 0xE0; + case '\u00B7': return 0xE1; + case '\u201A': return 0xE2; + case '\u201E': return 0xE3; + case '\u2030': return 0xE4; + case '\u00C2': return 0xE5; + case '\u00CA': return 0xE6; + case '\u00C1': return 0xE7; + case '\u00CB': return 0xE8; + case '\u00C8': return 0xE9; + case '\u00CD': return 0xEA; + case '\u00CE': return 0xEB; + case '\u00CF': return 0xEC; + case '\u00CC': return 0xED; + case '\u00D3': return 0xEE; + case '\u00D4': return 0xEF; + case '\uF8FF': return 0xF0; + case '\u00D2': return 0xF1; + case '\u00DA': return 0xF2; + case '\u00DB': return 0xF3; + case '\u00D9': return 0xF4; + case '\uF8A0': return 0xF5; + case '\u02C6': return 0xF6; + case '\u02DC': return 0xF7; + case '\u00AF': return 0xF8; + case '\u02D8': return 0xF9; + case '\u02D9': return 0xFA; + case '\u02DA': return 0xFB; + case '\u00B8': return 0xFC; + case '\u02DD': return 0xFD; + case '\u02DB': return 0xFE; + case '\u02C7': return 0xFF; default: // Fallback to '?' return 0x3F; diff --git a/Claunia.Encoding/MacUkrainian.cs b/Claunia.Encoding/MacUkrainian.cs index a529c04..173b11a 100644 --- a/Claunia.Encoding/MacUkrainian.cs +++ b/Claunia.Encoding/MacUkrainian.cs @@ -29,7 +29,7 @@ using System; namespace Claunia.Encoding { /// - /// Represents an Mac Ukrainian character encoding of Unicode characters. + /// Represents an Mac Ukrainian character encoding of Unicode characters. /// public class MacUkrainian : Encoding { @@ -48,105 +48,151 @@ namespace Claunia.Encoding const bool singleByte = true; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. + /// The Macintosh Ukrainian to Unicode character map. /// - public override bool IsBrowserDisplay { - get { return browserDisplay; } - } + static readonly char[] MacUkrainianTable = + { + // 0x00 + '\u0000', '\u0001', '\u0002', '\u0003', '\u0004', '\u0005', '\u0006', '\u0007', + // 0x08 + '\u0008', '\u0009', '\u000A', '\u000B', '\u000C', '\u000D', '\u000E', '\u000F', + // 0x10 + '\u0010', '\u0011', '\u0012', '\u0013', '\u0014', '\u0015', '\u0016', '\u0017', + // 0x18 + '\u0018', '\u0019', '\u001A', '\u001B', '\u001C', '\u001D', '\u001E', '\u001F', + // 0x20 + '\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027', + // 0x28 + '\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F', + // 0x30 + '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', + // 0x38 + '\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F', + // 0x40 + '\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047', + // 0x48 + '\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F', + // 0x50 + '\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057', + // 0x58 + '\u0058', '\u0059', '\u005A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F', + // 0x60 + '\u0060', '\u0061', '\u0062', '\u0063', '\u0064', '\u0065', '\u0066', '\u0067', + // 0x68 + '\u0068', '\u0069', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F', + // 0x70 + '\u0070', '\u0071', '\u0072', '\u0073', '\u0074', '\u0075', '\u0076', '\u0077', + // 0x78 + '\u0078', '\u0079', '\u007A', '\u007B', '\u007C', '\u007D', '\u007E', '\u007F', + // 0x80 + '\u0410', '\u0411', '\u0412', '\u0413', '\u0414', '\u0415', '\u0416', '\u0417', + // 0x88 + '\u0418', '\u0419', '\u041A', '\u041B', '\u041C', '\u041D', '\u041E', '\u041F', + // 0x90 + '\u0420', '\u0421', '\u0422', '\u0423', '\u0424', '\u0425', '\u0426', '\u0427', + // 0x98 + '\u0428', '\u0429', '\u042A', '\u042B', '\u042C', '\u042D', '\u042E', '\u042F', + // 0xA0 + '\u2020', '\u00B0', '\u0490', '\u00A3', '\u00A7', '\u2022', '\u00B6', '\u0406', + // 0xA8 + '\u00AE', '\u00A9', '\u2122', '\u0402', '\u0452', '\u2260', '\u0403', '\u0453', + // 0xB0 + '\u221E', '\u00B1', '\u2264', '\u2265', '\u0456', '\u00B5', '\u0491', '\u0408', + // 0xB8 + '\u0404', '\u0454', '\u0407', '\u0457', '\u0409', '\u0459', '\u040A', '\u045A', + // 0xC0 + '\u0458', '\u0405', '\u00AC', '\u221A', '\u0192', '\u2248', '\u2206', '\u00AB', + // 0xC8 + '\u00BB', '\u2026', '\u00A0', '\u040B', '\u045B', '\u040C', '\u045C', '\u0455', + // 0xD0 + '\u2013', '\u2014', '\u201C', '\u201D', '\u2018', '\u2019', '\u00F7', '\u201E', + // 0xD8 + '\u040E', '\u045E', '\u040F', '\u045F', '\u2116', '\u0401', '\u0451', '\u044F', + // 0xE0 + '\u0430', '\u0431', '\u0432', '\u0433', '\u0434', '\u0435', '\u0436', '\u0437', + // 0xE8 + '\u0438', '\u0439', '\u043A', '\u043B', '\u043C', '\u043D', '\u043E', '\u043F', + // 0xF0 + '\u0440', '\u0441', '\u0442', '\u0443', '\u0444', '\u0445', '\u0446', '\u0447', + // 0xF8 + '\u0448', '\u0449', '\u044A', '\u044B', '\u044C', '\u044D', '\u044E', '\u20AC' + }; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. + /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. /// - public override bool IsBrowserSave { - get { return browserSave; } - } + public override bool IsBrowserDisplay => browserDisplay; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. + /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. /// - public override bool IsMailNewsDisplay { - get { return mailNewsDisplay; } - } + public override bool IsBrowserSave => browserSave; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. /// - public override bool IsMailNewsSave { - get { return mailNewsSave; } - } + public override bool IsMailNewsDisplay => mailNewsDisplay; /// - /// Gets a value indicating whether the current encoding is read-only. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// + public override bool IsMailNewsSave => mailNewsSave; + + /// + /// Gets a value indicating whether the current encoding is read-only. /// /// The is single byte. - public override bool IsReadOnly { - get { return readOnly; } - } + public override bool IsReadOnly => readOnly; /// - /// Gets a value indicating whether the current encoding uses single-byte code points. + /// Gets a value indicating whether the current encoding uses single-byte code points. /// - public override bool IsSingleByte { - get { return singleByte; } - } + public override bool IsSingleByte => singleByte; /// - /// Gets the code page identifier of the current Encoding. + /// Gets the code page identifier of the current Encoding. /// - public override int CodePage { - get { return _codepage; } - } + public override int CodePage => _codepage; /// - /// Gets a name for the current encoding that can be used with mail agent body tags + /// Gets a name for the current encoding that can be used with mail agent body tags /// - public override string BodyName { - get { return _bodyname; } - } + public override string BodyName => _bodyname; /// - /// Gets a name for the current encoding that can be used with mail agent header tags + /// Gets a name for the current encoding that can be used with mail agent header tags /// - public override string HeaderName { - get { return _headername; } - } + public override string HeaderName => _headername; /// - /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. + /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. /// - public override string WebName { - get { return _webname; } - } + public override string WebName => _webname; /// - /// Gets the human-readable description of the current encoding. + /// Gets the human-readable description of the current encoding. /// - public override string EncodingName { - get { return _encodingname; } - } + public override string EncodingName => _encodingname; /// - /// Gets the Windows operating system code page that most closely corresponds to the current encoding. + /// Gets the Windows operating system code page that most closely corresponds to the current encoding. /// - public override int WindowsCodePage { - get { return _windowsCodepage; } - } + public override int WindowsCodePage => _windowsCodepage; /// - /// Calculates the number of bytes produced by encoding the characters in the specified . + /// Calculates the number of bytes produced by encoding the characters in the specified . /// /// The number of bytes produced by encoding the specified characters. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. public override int GetByteCount(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return s.Length; } /// - /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. + /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. /// /// The number of bytes produced by encoding the specified characters. /// The character array containing the set of characters to encode. @@ -154,36 +200,32 @@ namespace Claunia.Encoding /// The number of characters to encode. public override int GetByteCount(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0 || index >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0 || index >= chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0 || index + count > chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(count < 0 || index + count > chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); return count; } /// - /// Calculates the number of bytes produced by encoding all the characters in the specified character array. + /// Calculates the number of bytes produced by encoding all the characters in the specified character array. /// /// The number of bytes produced by encoding all the characters in the specified character array. /// The character array containing the characters to encode. public override int GetByteCount(char[] chars) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); return chars.Length; } /// - /// Encodes a set of characters from the specified into the specified byte array. + /// Encodes a set of characters from the specified into the specified byte array. /// /// The actual number of bytes written into bytes. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. /// The index of the first character to encode. /// The number of characters to encode. /// The byte array to contain the resulting sequence of bytes. @@ -194,20 +236,19 @@ namespace Claunia.Encoding } /// - /// Encodes all the characters in the specified string into a sequence of bytes. + /// Encodes all the characters in the specified string into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The string containing the characters to encode. public override byte[] GetBytes(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return GetBytes(s.ToCharArray(), 0, s.Length); } /// - /// Encodes a set of characters from the specified character array into the specified byte array. + /// Encodes a set of characters from the specified character array into the specified byte array. /// /// The actual number of bytes written into bytes. /// The character array containing the set of characters to encode. @@ -217,43 +258,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting sequence of bytes. public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount + charIndex > chars.Length) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount + charIndex > chars.Length) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteIndex + charCount > bytes.Length) - throw new ArgumentException(nameof(bytes)); + if(byteIndex + charCount > bytes.Length) throw new ArgumentException(nameof(bytes)); byte[] temp = GetBytes(chars, charIndex, charCount); - for(int i = 0; i < temp.Length; i++) - bytes[i + byteIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) bytes[i + byteIndex] = temp[i]; return charCount; } /// - /// Encodes a set of characters from the specified character array into a sequence of bytes. + /// Encodes a set of characters from the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the set of characters to encode. @@ -261,28 +292,23 @@ namespace Claunia.Encoding /// The number of characters to encode. public override byte[] GetBytes(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > chars.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > chars.Length) throw new ArgumentOutOfRangeException(nameof(count)); byte[] bytes = new byte[count]; - for(int i = 0; i < count; i++) - bytes[i] = GetByte(chars[index + i]); + for(int i = 0; i < count; i++) bytes[i] = GetByte(chars[index + i]); return bytes; } /// - /// Encodes all the characters in the specified character array into a sequence of bytes. + /// Encodes all the characters in the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the characters to encode. @@ -292,7 +318,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. + /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -302,7 +328,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. + /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -310,23 +336,19 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override int GetCharCount(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); return count; } /// - /// Decodes a sequence of bytes from the specified byte array into the specified character array. + /// Decodes a sequence of bytes from the specified byte array into the specified character array. /// /// The actual number of characters written into chars. /// The byte array containing the sequence of bytes to decode. @@ -336,43 +358,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting set of characters. public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount + byteIndex > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount + byteIndex > bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charIndex + byteCount > chars.Length) - throw new ArgumentException(nameof(chars)); + if(charIndex + byteCount > chars.Length) throw new ArgumentException(nameof(chars)); char[] temp = GetChars(bytes, byteIndex, byteCount); - for(int i = 0; i < temp.Length; i++) - chars[i + charIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) chars[i + charIndex] = temp[i]; return byteCount; } /// - /// Decodes all the bytes in the specified byte array into a set of characters. + /// Decodes all the bytes in the specified byte array into a set of characters. /// /// A character array containing the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -382,7 +394,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a set of characters. + /// Decodes a sequence of bytes from the specified byte array into a set of characters. /// /// The chars. /// The byte array containing the sequence of bytes to decode. @@ -390,54 +402,47 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override char[] GetChars(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); char[] chars = new char[count]; - for(int i = 0; i < count; i++) - chars[i] = GetChar(bytes[index + i]); + for(int i = 0; i < count; i++) chars[i] = GetChar(bytes[index + i]); return chars; } /// - /// Calculates the maximum number of bytes produced by encoding the specified number of characters. + /// Calculates the maximum number of bytes produced by encoding the specified number of characters. /// /// The maximum number of bytes produced by encoding the specified number of characters. /// The number of characters to encode. public override int GetMaxByteCount(int charCount) { - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); return charCount; } /// - /// Calculates the maximum number of characters produced by decoding the specified number of bytes. + /// Calculates the maximum number of characters produced by decoding the specified number of bytes. /// /// The maximum number of characters produced by decoding the specified number of bytes. /// The number of bytes to decode. public override int GetMaxCharCount(int byteCount) { - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); return byteCount; } /// - /// Returns a sequence of bytes that specifies the encoding used. + /// Returns a sequence of bytes that specifies the encoding used. /// /// A byte array of length zero, as a preamble is not required. public override byte[] GetPreamble() @@ -446,7 +451,7 @@ namespace Claunia.Encoding } /// - /// Decodes all the bytes in the specified byte array into a string. + /// Decodes all the bytes in the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -456,7 +461,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a string. + /// Decodes a sequence of bytes from the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -468,77 +473,7 @@ namespace Claunia.Encoding } /// - /// The Macintosh Ukrainian to Unicode character map. - /// - static readonly char[] MacUkrainianTable = { - // 0x00 - '\u0000','\u0001','\u0002','\u0003','\u0004','\u0005','\u0006','\u0007', - // 0x08 - '\u0008','\u0009','\u000A','\u000B','\u000C','\u000D','\u000E','\u000F', - // 0x10 - '\u0010','\u0011','\u0012','\u0013','\u0014','\u0015','\u0016','\u0017', - // 0x18 - '\u0018','\u0019','\u001A','\u001B','\u001C','\u001D','\u001E','\u001F', - // 0x20 - '\u0020','\u0021','\u0022','\u0023','\u0024','\u0025','\u0026','\u0027', - // 0x28 - '\u0028','\u0029','\u002A','\u002B','\u002C','\u002D','\u002E','\u002F', - // 0x30 - '\u0030','\u0031','\u0032','\u0033','\u0034','\u0035','\u0036','\u0037', - // 0x38 - '\u0038','\u0039','\u003A','\u003B','\u003C','\u003D','\u003E','\u003F', - // 0x40 - '\u0040','\u0041','\u0042','\u0043','\u0044','\u0045','\u0046','\u0047', - // 0x48 - '\u0048','\u0049','\u004A','\u004B','\u004C','\u004D','\u004E','\u004F', - // 0x50 - '\u0050','\u0051','\u0052','\u0053','\u0054','\u0055','\u0056','\u0057', - // 0x58 - '\u0058','\u0059','\u005A','\u005B','\u005C','\u005D','\u005E','\u005F', - // 0x60 - '\u0060','\u0061','\u0062','\u0063','\u0064','\u0065','\u0066','\u0067', - // 0x68 - '\u0068','\u0069','\u006A','\u006B','\u006C','\u006D','\u006E','\u006F', - // 0x70 - '\u0070','\u0071','\u0072','\u0073','\u0074','\u0075','\u0076','\u0077', - // 0x78 - '\u0078','\u0079','\u007A','\u007B','\u007C','\u007D','\u007E','\u007F', - // 0x80 - '\u0410','\u0411','\u0412','\u0413','\u0414','\u0415','\u0416','\u0417', - // 0x88 - '\u0418','\u0419','\u041A','\u041B','\u041C','\u041D','\u041E','\u041F', - // 0x90 - '\u0420','\u0421','\u0422','\u0423','\u0424','\u0425','\u0426','\u0427', - // 0x98 - '\u0428','\u0429','\u042A','\u042B','\u042C','\u042D','\u042E','\u042F', - // 0xA0 - '\u2020','\u00B0','\u0490','\u00A3','\u00A7','\u2022','\u00B6','\u0406', - // 0xA8 - '\u00AE','\u00A9','\u2122','\u0402','\u0452','\u2260','\u0403','\u0453', - // 0xB0 - '\u221E','\u00B1','\u2264','\u2265','\u0456','\u00B5','\u0491','\u0408', - // 0xB8 - '\u0404','\u0454','\u0407','\u0457','\u0409','\u0459','\u040A','\u045A', - // 0xC0 - '\u0458','\u0405','\u00AC','\u221A','\u0192','\u2248','\u2206','\u00AB', - // 0xC8 - '\u00BB','\u2026','\u00A0','\u040B','\u045B','\u040C','\u045C','\u0455', - // 0xD0 - '\u2013','\u2014','\u201C','\u201D','\u2018','\u2019','\u00F7','\u201E', - // 0xD8 - '\u040E','\u045E','\u040F','\u045F','\u2116','\u0401','\u0451','\u044F', - // 0xE0 - '\u0430','\u0431','\u0432','\u0433','\u0434','\u0435','\u0436','\u0437', - // 0xE8 - '\u0438','\u0439','\u043A','\u043B','\u043C','\u043D','\u043E','\u043F', - // 0xF0 - '\u0440','\u0441','\u0442','\u0443','\u0444','\u0445','\u0446','\u0447', - // 0xF8 - '\u0448','\u0449','\u044A','\u044B','\u044C','\u044D','\u044E','\u20AC' - }; - - /// - /// Converts a Mac Ukrainian character to an Unicode character + /// Converts a Mac Ukrainian character to an Unicode character /// /// Unicode character. /// Mac Ukrainian character. @@ -548,525 +483,270 @@ namespace Claunia.Encoding } /// - /// Converts a Unicode character to an Mac Ukrainian character + /// Converts a Unicode character to an Mac Ukrainian character /// /// Mac Ukrainian character. /// Unicode character. static byte GetByte(char character) { - switch(character) { - case '\u0000': - return 0x00; - case '\u0001': - return 0x01; - case '\u0002': - return 0x02; - case '\u0003': - return 0x03; - case '\u0004': - return 0x04; - case '\u0005': - return 0x05; - case '\u0006': - return 0x06; - case '\u0007': - return 0x07; - case '\u0008': - return 0x08; - case '\u0009': - return 0x09; - case '\u000A': - return 0x0A; - case '\u000B': - return 0x0B; - case '\u000C': - return 0x0C; - case '\u000D': - return 0x0D; - case '\u000E': - return 0x0E; - case '\u000F': - return 0x0F; - case '\u0010': - return 0x10; - case '\u0011': - return 0x11; - case '\u0012': - return 0x12; - case '\u0013': - return 0x13; - case '\u0014': - return 0x14; - case '\u0015': - return 0x15; - case '\u0016': - return 0x16; - case '\u0017': - return 0x17; - case '\u0018': - return 0x18; - case '\u0019': - return 0x19; - case '\u001A': - return 0x1A; - case '\u001B': - return 0x1B; - case '\u001C': - return 0x1C; - case '\u001D': - return 0x1D; - case '\u001E': - return 0x1E; - case '\u001F': - return 0x1F; - case '\u0020': - return 0x20; - case '\u0021': - return 0x21; - case '\u0022': - return 0x22; - case '\u0023': - return 0x23; - case '\u0024': - return 0x24; - case '\u0025': - return 0x25; - case '\u0026': - return 0x26; - case '\u0027': - return 0x27; - case '\u0028': - return 0x28; - case '\u0029': - return 0x29; - case '\u002A': - return 0x2A; - case '\u002B': - return 0x2B; - case '\u002C': - return 0x2C; - case '\u002D': - return 0x2D; - case '\u002E': - return 0x2E; - case '\u002F': - return 0x2F; - case '\u0030': - return 0x30; - case '\u0031': - return 0x31; - case '\u0032': - return 0x32; - case '\u0033': - return 0x33; - case '\u0034': - return 0x34; - case '\u0035': - return 0x35; - case '\u0036': - return 0x36; - case '\u0037': - return 0x37; - case '\u0038': - return 0x38; - case '\u0039': - return 0x39; - case '\u003A': - return 0x3A; - case '\u003B': - return 0x3B; - case '\u003C': - return 0x3C; - case '\u003D': - return 0x3D; - case '\u003E': - return 0x3E; - case '\u003F': - return 0x3F; - case '\u0040': - return 0x40; - case '\u0041': - return 0x41; - case '\u0042': - return 0x42; - case '\u0043': - return 0x43; - case '\u0044': - return 0x44; - case '\u0045': - return 0x45; - case '\u0046': - return 0x46; - case '\u0047': - return 0x47; - case '\u0048': - return 0x48; - case '\u0049': - return 0x49; - case '\u004A': - return 0x4A; - case '\u004B': - return 0x4B; - case '\u004C': - return 0x4C; - case '\u004D': - return 0x4D; - case '\u004E': - return 0x4E; - case '\u004F': - return 0x4F; - case '\u0050': - return 0x50; - case '\u0051': - return 0x51; - case '\u0052': - return 0x52; - case '\u0053': - return 0x53; - case '\u0054': - return 0x54; - case '\u0055': - return 0x55; - case '\u0056': - return 0x56; - case '\u0057': - return 0x57; - case '\u0058': - return 0x58; - case '\u0059': - return 0x59; - case '\u005A': - return 0x5A; - case '\u005B': - return 0x5B; - case '\u005C': - return 0x5C; - case '\u005D': - return 0x5D; - case '\u005E': - return 0x5E; - case '\u005F': - return 0x5F; - case '\u0060': - return 0x60; - case '\u0061': - return 0x61; - case '\u0062': - return 0x62; - case '\u0063': - return 0x63; - case '\u0064': - return 0x64; - case '\u0065': - return 0x65; - case '\u0066': - return 0x66; - case '\u0067': - return 0x67; - case '\u0068': - return 0x68; - case '\u0069': - return 0x69; - case '\u006A': - return 0x6A; - case '\u006B': - return 0x6B; - case '\u006C': - return 0x6C; - case '\u006D': - return 0x6D; - case '\u006E': - return 0x6E; - case '\u006F': - return 0x6F; - case '\u0070': - return 0x70; - case '\u0071': - return 0x71; - case '\u0072': - return 0x72; - case '\u0073': - return 0x73; - case '\u0074': - return 0x74; - case '\u0075': - return 0x75; - case '\u0076': - return 0x76; - case '\u0077': - return 0x77; - case '\u0078': - return 0x78; - case '\u0079': - return 0x79; - case '\u007A': - return 0x7A; - case '\u007B': - return 0x7B; - case '\u007C': - return 0x7C; - case '\u007D': - return 0x7D; - case '\u007E': - return 0x7E; - case '\u007F': - return 0x7F; - case '\u0410': - return 0x80; - case '\u0411': - return 0x81; - case '\u0412': - return 0x82; - case '\u0413': - return 0x83; - case '\u0414': - return 0x84; - case '\u0415': - return 0x85; - case '\u0416': - return 0x86; - case '\u0417': - return 0x87; - case '\u0418': - return 0x88; - case '\u0419': - return 0x89; - case '\u041A': - return 0x8A; - case '\u041B': - return 0x8B; - case '\u041C': - return 0x8C; - case '\u041D': - return 0x8D; - case '\u041E': - return 0x8E; - case '\u041F': - return 0x8F; - case '\u0420': - return 0x90; - case '\u0421': - return 0x91; - case '\u0422': - return 0x92; - case '\u0423': - return 0x93; - case '\u0424': - return 0x94; - case '\u0425': - return 0x95; - case '\u0426': - return 0x96; - case '\u0427': - return 0x97; - case '\u0428': - return 0x98; - case '\u0429': - return 0x99; - case '\u042A': - return 0x9A; - case '\u042B': - return 0x9B; - case '\u042C': - return 0x9C; - case '\u042D': - return 0x9D; - case '\u042E': - return 0x9E; - case '\u042F': - return 0x9F; - case '\u2020': - return 0xA0; - case '\u00B0': - return 0xA1; - case '\u0490': - return 0xA2; - case '\u00A3': - return 0xA3; - case '\u00A7': - return 0xA4; - case '\u2022': - return 0xA5; - case '\u00B6': - return 0xA6; - case '\u0406': - return 0xA7; - case '\u00AE': - return 0xA8; - case '\u00A9': - return 0xA9; - case '\u2122': - return 0xAA; - case '\u0402': - return 0xAB; - case '\u0452': - return 0xAC; - case '\u2260': - return 0xAD; - case '\u0403': - return 0xAE; - case '\u0453': - return 0xAF; - case '\u221E': - return 0xB0; - case '\u00B1': - return 0xB1; - case '\u2264': - return 0xB2; - case '\u2265': - return 0xB3; - case '\u0456': - return 0xB4; - case '\u00B5': - return 0xB5; - case '\u0491': - return 0xB6; - case '\u0408': - return 0xB7; - case '\u0404': - return 0xB8; - case '\u0454': - return 0xB9; - case '\u0407': - return 0xBA; - case '\u0457': - return 0xBB; - case '\u0409': - return 0xBC; - case '\u0459': - return 0xBD; - case '\u040A': - return 0xBE; - case '\u045A': - return 0xBF; - case '\u0458': - return 0xC0; - case '\u0405': - return 0xC1; - case '\u00AC': - return 0xC2; - case '\u221A': - return 0xC3; - case '\u0192': - return 0xC4; - case '\u2248': - return 0xC5; - case '\u2206': - return 0xC6; - case '\u00AB': - return 0xC7; - case '\u00BB': - return 0xC8; - case '\u2026': - return 0xC9; - case '\u00A0': - return 0xCA; - case '\u040B': - return 0xCB; - case '\u045B': - return 0xCC; - case '\u040C': - return 0xCD; - case '\u045C': - return 0xCE; - case '\u0455': - return 0xCF; - case '\u2013': - return 0xD0; - case '\u2014': - return 0xD1; - case '\u201C': - return 0xD2; - case '\u201D': - return 0xD3; - case '\u2018': - return 0xD4; - case '\u2019': - return 0xD5; - case '\u00F7': - return 0xD6; - case '\u201E': - return 0xD7; - case '\u040E': - return 0xD8; - case '\u045E': - return 0xD9; - case '\u040F': - return 0xDA; - case '\u045F': - return 0xDB; - case '\u2116': - return 0xDC; - case '\u0401': - return 0xDD; - case '\u0451': - return 0xDE; - case '\u044F': - return 0xDF; - case '\u0430': - return 0xE0; - case '\u0431': - return 0xE1; - case '\u0432': - return 0xE2; - case '\u0433': - return 0xE3; - case '\u0434': - return 0xE4; - case '\u0435': - return 0xE5; - case '\u0436': - return 0xE6; - case '\u0437': - return 0xE7; - case '\u0438': - return 0xE8; - case '\u0439': - return 0xE9; - case '\u043A': - return 0xEA; - case '\u043B': - return 0xEB; - case '\u043C': - return 0xEC; - case '\u043D': - return 0xED; - case '\u043E': - return 0xEE; - case '\u043F': - return 0xEF; - case '\u0440': - return 0xF0; - case '\u0441': - return 0xF1; - case '\u0442': - return 0xF2; - case '\u0443': - return 0xF3; - case '\u0444': - return 0xF4; - case '\u0445': - return 0xF5; - case '\u0446': - return 0xF6; - case '\u0447': - return 0xF7; - case '\u0448': - return 0xF8; - case '\u0449': - return 0xF9; - case '\u044A': - return 0xFA; - case '\u044B': - return 0xFB; - case '\u044C': - return 0xFC; - case '\u044D': - return 0xFD; - case '\u044E': - return 0xFE; - case '\u20AC': - return 0xFF; + switch(character) + { + case '\u0000': return 0x00; + case '\u0001': return 0x01; + case '\u0002': return 0x02; + case '\u0003': return 0x03; + case '\u0004': return 0x04; + case '\u0005': return 0x05; + case '\u0006': return 0x06; + case '\u0007': return 0x07; + case '\u0008': return 0x08; + case '\u0009': return 0x09; + case '\u000A': return 0x0A; + case '\u000B': return 0x0B; + case '\u000C': return 0x0C; + case '\u000D': return 0x0D; + case '\u000E': return 0x0E; + case '\u000F': return 0x0F; + case '\u0010': return 0x10; + case '\u0011': return 0x11; + case '\u0012': return 0x12; + case '\u0013': return 0x13; + case '\u0014': return 0x14; + case '\u0015': return 0x15; + case '\u0016': return 0x16; + case '\u0017': return 0x17; + case '\u0018': return 0x18; + case '\u0019': return 0x19; + case '\u001A': return 0x1A; + case '\u001B': return 0x1B; + case '\u001C': return 0x1C; + case '\u001D': return 0x1D; + case '\u001E': return 0x1E; + case '\u001F': return 0x1F; + case '\u0020': return 0x20; + case '\u0021': return 0x21; + case '\u0022': return 0x22; + case '\u0023': return 0x23; + case '\u0024': return 0x24; + case '\u0025': return 0x25; + case '\u0026': return 0x26; + case '\u0027': return 0x27; + case '\u0028': return 0x28; + case '\u0029': return 0x29; + case '\u002A': return 0x2A; + case '\u002B': return 0x2B; + case '\u002C': return 0x2C; + case '\u002D': return 0x2D; + case '\u002E': return 0x2E; + case '\u002F': return 0x2F; + case '\u0030': return 0x30; + case '\u0031': return 0x31; + case '\u0032': return 0x32; + case '\u0033': return 0x33; + case '\u0034': return 0x34; + case '\u0035': return 0x35; + case '\u0036': return 0x36; + case '\u0037': return 0x37; + case '\u0038': return 0x38; + case '\u0039': return 0x39; + case '\u003A': return 0x3A; + case '\u003B': return 0x3B; + case '\u003C': return 0x3C; + case '\u003D': return 0x3D; + case '\u003E': return 0x3E; + case '\u003F': return 0x3F; + case '\u0040': return 0x40; + case '\u0041': return 0x41; + case '\u0042': return 0x42; + case '\u0043': return 0x43; + case '\u0044': return 0x44; + case '\u0045': return 0x45; + case '\u0046': return 0x46; + case '\u0047': return 0x47; + case '\u0048': return 0x48; + case '\u0049': return 0x49; + case '\u004A': return 0x4A; + case '\u004B': return 0x4B; + case '\u004C': return 0x4C; + case '\u004D': return 0x4D; + case '\u004E': return 0x4E; + case '\u004F': return 0x4F; + case '\u0050': return 0x50; + case '\u0051': return 0x51; + case '\u0052': return 0x52; + case '\u0053': return 0x53; + case '\u0054': return 0x54; + case '\u0055': return 0x55; + case '\u0056': return 0x56; + case '\u0057': return 0x57; + case '\u0058': return 0x58; + case '\u0059': return 0x59; + case '\u005A': return 0x5A; + case '\u005B': return 0x5B; + case '\u005C': return 0x5C; + case '\u005D': return 0x5D; + case '\u005E': return 0x5E; + case '\u005F': return 0x5F; + case '\u0060': return 0x60; + case '\u0061': return 0x61; + case '\u0062': return 0x62; + case '\u0063': return 0x63; + case '\u0064': return 0x64; + case '\u0065': return 0x65; + case '\u0066': return 0x66; + case '\u0067': return 0x67; + case '\u0068': return 0x68; + case '\u0069': return 0x69; + case '\u006A': return 0x6A; + case '\u006B': return 0x6B; + case '\u006C': return 0x6C; + case '\u006D': return 0x6D; + case '\u006E': return 0x6E; + case '\u006F': return 0x6F; + case '\u0070': return 0x70; + case '\u0071': return 0x71; + case '\u0072': return 0x72; + case '\u0073': return 0x73; + case '\u0074': return 0x74; + case '\u0075': return 0x75; + case '\u0076': return 0x76; + case '\u0077': return 0x77; + case '\u0078': return 0x78; + case '\u0079': return 0x79; + case '\u007A': return 0x7A; + case '\u007B': return 0x7B; + case '\u007C': return 0x7C; + case '\u007D': return 0x7D; + case '\u007E': return 0x7E; + case '\u007F': return 0x7F; + case '\u0410': return 0x80; + case '\u0411': return 0x81; + case '\u0412': return 0x82; + case '\u0413': return 0x83; + case '\u0414': return 0x84; + case '\u0415': return 0x85; + case '\u0416': return 0x86; + case '\u0417': return 0x87; + case '\u0418': return 0x88; + case '\u0419': return 0x89; + case '\u041A': return 0x8A; + case '\u041B': return 0x8B; + case '\u041C': return 0x8C; + case '\u041D': return 0x8D; + case '\u041E': return 0x8E; + case '\u041F': return 0x8F; + case '\u0420': return 0x90; + case '\u0421': return 0x91; + case '\u0422': return 0x92; + case '\u0423': return 0x93; + case '\u0424': return 0x94; + case '\u0425': return 0x95; + case '\u0426': return 0x96; + case '\u0427': return 0x97; + case '\u0428': return 0x98; + case '\u0429': return 0x99; + case '\u042A': return 0x9A; + case '\u042B': return 0x9B; + case '\u042C': return 0x9C; + case '\u042D': return 0x9D; + case '\u042E': return 0x9E; + case '\u042F': return 0x9F; + case '\u2020': return 0xA0; + case '\u00B0': return 0xA1; + case '\u0490': return 0xA2; + case '\u00A3': return 0xA3; + case '\u00A7': return 0xA4; + case '\u2022': return 0xA5; + case '\u00B6': return 0xA6; + case '\u0406': return 0xA7; + case '\u00AE': return 0xA8; + case '\u00A9': return 0xA9; + case '\u2122': return 0xAA; + case '\u0402': return 0xAB; + case '\u0452': return 0xAC; + case '\u2260': return 0xAD; + case '\u0403': return 0xAE; + case '\u0453': return 0xAF; + case '\u221E': return 0xB0; + case '\u00B1': return 0xB1; + case '\u2264': return 0xB2; + case '\u2265': return 0xB3; + case '\u0456': return 0xB4; + case '\u00B5': return 0xB5; + case '\u0491': return 0xB6; + case '\u0408': return 0xB7; + case '\u0404': return 0xB8; + case '\u0454': return 0xB9; + case '\u0407': return 0xBA; + case '\u0457': return 0xBB; + case '\u0409': return 0xBC; + case '\u0459': return 0xBD; + case '\u040A': return 0xBE; + case '\u045A': return 0xBF; + case '\u0458': return 0xC0; + case '\u0405': return 0xC1; + case '\u00AC': return 0xC2; + case '\u221A': return 0xC3; + case '\u0192': return 0xC4; + case '\u2248': return 0xC5; + case '\u2206': return 0xC6; + case '\u00AB': return 0xC7; + case '\u00BB': return 0xC8; + case '\u2026': return 0xC9; + case '\u00A0': return 0xCA; + case '\u040B': return 0xCB; + case '\u045B': return 0xCC; + case '\u040C': return 0xCD; + case '\u045C': return 0xCE; + case '\u0455': return 0xCF; + case '\u2013': return 0xD0; + case '\u2014': return 0xD1; + case '\u201C': return 0xD2; + case '\u201D': return 0xD3; + case '\u2018': return 0xD4; + case '\u2019': return 0xD5; + case '\u00F7': return 0xD6; + case '\u201E': return 0xD7; + case '\u040E': return 0xD8; + case '\u045E': return 0xD9; + case '\u040F': return 0xDA; + case '\u045F': return 0xDB; + case '\u2116': return 0xDC; + case '\u0401': return 0xDD; + case '\u0451': return 0xDE; + case '\u044F': return 0xDF; + case '\u0430': return 0xE0; + case '\u0431': return 0xE1; + case '\u0432': return 0xE2; + case '\u0433': return 0xE3; + case '\u0434': return 0xE4; + case '\u0435': return 0xE5; + case '\u0436': return 0xE6; + case '\u0437': return 0xE7; + case '\u0438': return 0xE8; + case '\u0439': return 0xE9; + case '\u043A': return 0xEA; + case '\u043B': return 0xEB; + case '\u043C': return 0xEC; + case '\u043D': return 0xED; + case '\u043E': return 0xEE; + case '\u043F': return 0xEF; + case '\u0440': return 0xF0; + case '\u0441': return 0xF1; + case '\u0442': return 0xF2; + case '\u0443': return 0xF3; + case '\u0444': return 0xF4; + case '\u0445': return 0xF5; + case '\u0446': return 0xF6; + case '\u0447': return 0xF7; + case '\u0448': return 0xF8; + case '\u0449': return 0xF9; + case '\u044A': return 0xFA; + case '\u044B': return 0xFB; + case '\u044C': return 0xFC; + case '\u044D': return 0xFD; + case '\u044E': return 0xFE; + case '\u20AC': return 0xFF; default: // Fallback to '?' return 0x3F; diff --git a/Claunia.Encoding/PETSCII.cs b/Claunia.Encoding/PETSCII.cs index b1735c9..fa00113 100644 --- a/Claunia.Encoding/PETSCII.cs +++ b/Claunia.Encoding/PETSCII.cs @@ -29,7 +29,8 @@ using System; namespace Claunia.Encoding { /// - /// Represents an Commodore PET Standard Code for Information Interchange (aka CBM ASCII) character encoding of Unicode characters. + /// Represents an Commodore PET Standard Code for Information Interchange (aka CBM ASCII) character encoding of Unicode + /// characters. /// public class PETSCII : Encoding { @@ -48,116 +49,151 @@ namespace Claunia.Encoding const bool singleByte = true; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. + /// The PETSCII to Unicode character map, unshifted (default) variant. /// - public override bool IsBrowserDisplay + /// Reference used: http://style64.org/petscii/ and others. + static readonly char[] PETSCIITable = { - get { return browserDisplay; } - } + // 0x00 + '\u0000', '\u0000', '\u0000', '\u0003', '\u0000', '\u0000', '\u0000', '\u0000', + // 0x08 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u000A', '\u0000', '\u0000', + // 0x10 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0008', '\u0000', '\u0000', '\u0000', + // 0x18 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0x20 + '\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027', + // 0x28 + '\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F', + // 0x30 + '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', + // 0x38 + '\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F', + // 0x40 + '\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047', + // 0x48 + '\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F', + // 0x50 + '\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057', + // 0x58 + '\u0058', '\u0059', '\u005A', '\u005B', '\u00A3', '\u005D', '\u2191', '\u2190', + // 0x60 + '\u2500', '\u2660', '\u2502', '\u2500', '\u0000', '\u0000', '\u0000', '\u0000', + // 0x68 + '\u0000', '\u256E', '\u2570', '\u256F', '\u0000', '\u2572', '\u2571', '\u0000', + // 0x70 + '\u0000', '\u2022', '\u0000', '\u2665', '\u0000', '\u256D', '\u2573', '\u25CB', + // 0x78 + '\u2663', '\u0000', '\u2666', '\u253C', '\u0000', '\u2502', '\u03C0', '\u25E5', + // 0x80 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0x88 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u2028', '\u0000', '\u0000', + // 0x90 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0x98 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xA0 + '\u00A0', '\u258C', '\u2584', '\u2594', '\u2581', '\u258E', '\u2592', '\u0000', + // 0xA8 + '\u0000', '\u25E4', '\u258A', '\u251C', '\u2597', '\u2514', '\u2510', '\u2582', + // 0xB0 + '\u250C', '\u2534', '\u252C', '\u2524', '\u258E', '\u258D', '\u0000', '\u0000', + // 0xB8 + '\u0000', '\u2583', '\u0000', '\u2596', '\u259D', '\u2518', '\u2598', '\u259A', + // 0xC0 (repeats 0x60 - 0x67) + '\u2500', '\u2660', '\u2502', '\u2500', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xC8 (repeats 0x68 - 0x6F) + '\u0000', '\u256E', '\u2570', '\u256F', '\u0000', '\u2572', '\u2571', '\u0000', + // 0xD0 (repeats 0x70 - 0x77) + '\u0000', '\u2022', '\u0000', '\u2665', '\u0000', '\u256D', '\u2573', '\u25CB', + // 0xD8 (repeats 0x78 - 0x7F) + '\u2663', '\u0000', '\u2666', '\u253C', '\u0000', '\u2502', '\u03C0', '\u25E5', + // 0xE0 (repeats 0xA0 - 0xA7) + '\u00A0', '\u258C', '\u2584', '\u2594', '\u2581', '\u258E', '\u2592', '\u0000', + // 0xE8 (repeats 0xA8 - 0xAF) + '\u0000', '\u25E4', '\u258A', '\u251C', '\u2597', '\u2514', '\u2510', '\u2582', + // 0xF0 (repeats 0xB0 - 0xB7) + '\u250C', '\u2534', '\u252C', '\u2524', '\u258E', '\u258D', '\u0000', '\u0000', + // 0xF8 (repeats 0xB8 - 0xBF) + '\u0000', '\u2583', '\u0000', '\u2596', '\u259D', '\u2518', '\u2598', '\u259A' + }; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. + /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. /// - public override bool IsBrowserSave - { - get { return browserSave; } - } + public override bool IsBrowserDisplay => browserDisplay; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. + /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. /// - public override bool IsMailNewsDisplay - { - get { return mailNewsDisplay; } - } + public override bool IsBrowserSave => browserSave; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. /// - public override bool IsMailNewsSave - { - get { return mailNewsSave; } - } + public override bool IsMailNewsDisplay => mailNewsDisplay; /// - /// Gets a value indicating whether the current encoding is read-only. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. /// - public override bool IsReadOnly - { - get { return readOnly; } - } + public override bool IsMailNewsSave => mailNewsSave; /// - /// Gets a value indicating whether the current encoding uses single-byte code points. + /// Gets a value indicating whether the current encoding is read-only. /// - public override bool IsSingleByte - { - get { return singleByte; } - } + public override bool IsReadOnly => readOnly; /// - /// Gets the code page identifier of the current Encoding. + /// Gets a value indicating whether the current encoding uses single-byte code points. /// - public override int CodePage - { - get { return _codepage; } - } + public override bool IsSingleByte => singleByte; /// - /// Gets a name for the current encoding that can be used with mail agent body tags + /// Gets the code page identifier of the current Encoding. /// - public override string BodyName - { - get { return _bodyname; } - } + public override int CodePage => _codepage; /// - /// Gets a name for the current encoding that can be used with mail agent header tags + /// Gets a name for the current encoding that can be used with mail agent body tags /// - public override string HeaderName - { - get { return _headername; } - } + public override string BodyName => _bodyname; /// - /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. + /// Gets a name for the current encoding that can be used with mail agent header tags /// - public override string WebName - { - get { return _webname; } - } + public override string HeaderName => _headername; /// - /// Gets the human-readable description of the current encoding. + /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. /// - public override string EncodingName - { - get { return _encodingname; } - } + public override string WebName => _webname; /// - /// Gets the Windows operating system code page that most closely corresponds to the current encoding. + /// Gets the human-readable description of the current encoding. /// - public override int WindowsCodePage - { - get { return _windowsCodepage; } - } + public override string EncodingName => _encodingname; /// - /// Calculates the number of bytes produced by encoding the characters in the specified . + /// Gets the Windows operating system code page that most closely corresponds to the current encoding. + /// + public override int WindowsCodePage => _windowsCodepage; + + /// + /// Calculates the number of bytes produced by encoding the characters in the specified . /// /// The number of bytes produced by encoding the specified characters. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. public override int GetByteCount(string s) { - if (s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return s.Length; } /// - /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. + /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. /// /// The number of bytes produced by encoding the specified characters. /// The character array containing the set of characters to encode. @@ -165,36 +201,32 @@ namespace Claunia.Encoding /// The number of characters to encode. public override int GetByteCount(char[] chars, int index, int count) { - if (chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if (index < 0 || index >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0 || index >= chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); - if (count < 0 || index + count > chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(count < 0 || index + count > chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); return count; } /// - /// Calculates the number of bytes produced by encoding all the characters in the specified character array. + /// Calculates the number of bytes produced by encoding all the characters in the specified character array. /// /// The number of bytes produced by encoding all the characters in the specified character array. /// The character array containing the characters to encode. public override int GetByteCount(char[] chars) { - if (chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); return chars.Length; } /// - /// Encodes a set of characters from the specified into the specified byte array. + /// Encodes a set of characters from the specified into the specified byte array. /// /// The actual number of bytes written into bytes. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. /// The index of the first character to encode. /// The number of characters to encode. /// The byte array to contain the resulting sequence of bytes. @@ -205,20 +237,19 @@ namespace Claunia.Encoding } /// - /// Encodes all the characters in the specified string into a sequence of bytes. + /// Encodes all the characters in the specified string into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The string containing the characters to encode. public override byte[] GetBytes(string s) { - if (s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return GetBytes(s.ToCharArray(), 0, s.Length); } /// - /// Encodes a set of characters from the specified character array into the specified byte array. + /// Encodes a set of characters from the specified character array into the specified byte array. /// /// The actual number of bytes written into bytes. /// The character array containing the set of characters to encode. @@ -228,43 +259,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting sequence of bytes. public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) { - if (chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if (bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if (charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if (charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); - if (byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if (charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if (charCount + charIndex > chars.Length) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount + charIndex > chars.Length) throw new ArgumentOutOfRangeException(nameof(charCount)); - if (byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if (byteIndex + charCount > bytes.Length) - throw new ArgumentException(nameof(bytes)); + if(byteIndex + charCount > bytes.Length) throw new ArgumentException(nameof(bytes)); byte[] temp = GetBytes(chars, charIndex, charCount); - for (int i = 0; i < temp.Length; i++) - bytes[i + byteIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) bytes[i + byteIndex] = temp[i]; return charCount; } /// - /// Encodes a set of characters from the specified character array into a sequence of bytes. + /// Encodes a set of characters from the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the set of characters to encode. @@ -272,28 +293,23 @@ namespace Claunia.Encoding /// The number of characters to encode. public override byte[] GetBytes(char[] chars, int index, int count) { - if (chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if (index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if (count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if (count + index > chars.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > chars.Length) throw new ArgumentOutOfRangeException(nameof(count)); byte[] bytes = new byte[count]; - for (int i = 0; i < count; i++) - bytes[i] = GetByte(chars[index + i]); + for(int i = 0; i < count; i++) bytes[i] = GetByte(chars[index + i]); return bytes; } /// - /// Encodes all the characters in the specified character array into a sequence of bytes. + /// Encodes all the characters in the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the characters to encode. @@ -303,7 +319,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. + /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -313,7 +329,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. + /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -321,23 +337,19 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override int GetCharCount(byte[] bytes, int index, int count) { - if (bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if (index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if (count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if (count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); return count; } /// - /// Decodes a sequence of bytes from the specified byte array into the specified character array. + /// Decodes a sequence of bytes from the specified byte array into the specified character array. /// /// The actual number of characters written into chars. /// The byte array containing the sequence of bytes to decode. @@ -347,43 +359,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting set of characters. public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { - if (bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if (chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if (byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if (byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if (charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if (byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if (byteCount + byteIndex > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount + byteIndex > bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if (charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if (charIndex + byteCount > chars.Length) - throw new ArgumentException(nameof(chars)); + if(charIndex + byteCount > chars.Length) throw new ArgumentException(nameof(chars)); char[] temp = GetChars(bytes, byteIndex, byteCount); - for (int i = 0; i < temp.Length; i++) - chars[i + charIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) chars[i + charIndex] = temp[i]; return byteCount; } /// - /// Decodes all the bytes in the specified byte array into a set of characters. + /// Decodes all the bytes in the specified byte array into a set of characters. /// /// A character array containing the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -393,7 +395,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a set of characters. + /// Decodes a sequence of bytes from the specified byte array into a set of characters. /// /// The chars. /// The byte array containing the sequence of bytes to decode. @@ -401,54 +403,47 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override char[] GetChars(byte[] bytes, int index, int count) { - if (bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if (index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if (count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if (count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); char[] chars = new char[count]; - for (int i = 0; i < count; i++) - chars[i] = GetChar(bytes[index + i]); + for(int i = 0; i < count; i++) chars[i] = GetChar(bytes[index + i]); return chars; } /// - /// Calculates the maximum number of bytes produced by encoding the specified number of characters. + /// Calculates the maximum number of bytes produced by encoding the specified number of characters. /// /// The maximum number of bytes produced by encoding the specified number of characters. /// The number of characters to encode. public override int GetMaxByteCount(int charCount) { - if (charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); return charCount; } /// - /// Calculates the maximum number of characters produced by decoding the specified number of bytes. + /// Calculates the maximum number of characters produced by decoding the specified number of bytes. /// /// The maximum number of characters produced by decoding the specified number of bytes. /// The number of bytes to decode. public override int GetMaxCharCount(int byteCount) { - if (byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); return byteCount; } /// - /// Returns a sequence of bytes that specifies the encoding used. + /// Returns a sequence of bytes that specifies the encoding used. /// /// A byte array of length zero, as a preamble is not required. public override byte[] GetPreamble() @@ -457,7 +452,7 @@ namespace Claunia.Encoding } /// - /// Decodes all the bytes in the specified byte array into a string. + /// Decodes all the bytes in the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -467,7 +462,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a string. + /// Decodes a sequence of bytes from the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -479,78 +474,7 @@ namespace Claunia.Encoding } /// - /// The PETSCII to Unicode character map, unshifted (default) variant. - /// - /// Reference used: http://style64.org/petscii/ and others. - static readonly char[] PETSCIITable = { - // 0x00 - '\u0000','\u0000','\u0000','\u0003','\u0000','\u0000','\u0000','\u0000', - // 0x08 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u000A','\u0000','\u0000', - // 0x10 - '\u0000','\u0000','\u0000','\u0000','\u0008','\u0000','\u0000','\u0000', - // 0x18 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0x20 - '\u0020','\u0021','\u0022','\u0023','\u0024','\u0025','\u0026','\u0027', - // 0x28 - '\u0028','\u0029','\u002A','\u002B','\u002C','\u002D','\u002E','\u002F', - // 0x30 - '\u0030','\u0031','\u0032','\u0033','\u0034','\u0035','\u0036','\u0037', - // 0x38 - '\u0038','\u0039','\u003A','\u003B','\u003C','\u003D','\u003E','\u003F', - // 0x40 - '\u0040','\u0041','\u0042','\u0043','\u0044','\u0045','\u0046','\u0047', - // 0x48 - '\u0048','\u0049','\u004A','\u004B','\u004C','\u004D','\u004E','\u004F', - // 0x50 - '\u0050','\u0051','\u0052','\u0053','\u0054','\u0055','\u0056','\u0057', - // 0x58 - '\u0058','\u0059','\u005A','\u005B','\u00A3','\u005D','\u2191','\u2190', - // 0x60 - '\u2500','\u2660','\u2502','\u2500','\u0000','\u0000','\u0000','\u0000', - // 0x68 - '\u0000','\u256E','\u2570','\u256F','\u0000','\u2572','\u2571','\u0000', - // 0x70 - '\u0000','\u2022','\u0000','\u2665','\u0000','\u256D','\u2573','\u25CB', - // 0x78 - '\u2663','\u0000','\u2666','\u253C','\u0000','\u2502','\u03C0','\u25E5', - // 0x80 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0x88 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u2028','\u0000','\u0000', - // 0x90 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0x98 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xA0 - '\u00A0','\u258C','\u2584','\u2594','\u2581','\u258E','\u2592','\u0000', - // 0xA8 - '\u0000','\u25E4','\u258A','\u251C','\u2597','\u2514','\u2510','\u2582', - // 0xB0 - '\u250C','\u2534','\u252C','\u2524','\u258E','\u258D','\u0000','\u0000', - // 0xB8 - '\u0000','\u2583','\u0000','\u2596','\u259D','\u2518','\u2598','\u259A', - // 0xC0 (repeats 0x60 - 0x67) - '\u2500','\u2660','\u2502','\u2500','\u0000','\u0000','\u0000','\u0000', - // 0xC8 (repeats 0x68 - 0x6F) - '\u0000','\u256E','\u2570','\u256F','\u0000','\u2572','\u2571','\u0000', - // 0xD0 (repeats 0x70 - 0x77) - '\u0000','\u2022','\u0000','\u2665','\u0000','\u256D','\u2573','\u25CB', - // 0xD8 (repeats 0x78 - 0x7F) - '\u2663','\u0000','\u2666','\u253C','\u0000','\u2502','\u03C0','\u25E5', - // 0xE0 (repeats 0xA0 - 0xA7) - '\u00A0','\u258C','\u2584','\u2594','\u2581','\u258E','\u2592','\u0000', - // 0xE8 (repeats 0xA8 - 0xAF) - '\u0000','\u25E4','\u258A','\u251C','\u2597','\u2514','\u2510','\u2582', - // 0xF0 (repeats 0xB0 - 0xB7) - '\u250C','\u2534','\u252C','\u2524','\u258E','\u258D','\u0000','\u0000', - // 0xF8 (repeats 0xB8 - 0xBF) - '\u0000','\u2583','\u0000','\u2596','\u259D','\u2518','\u2598','\u259A', - }; - - /// - /// Converts a PETSCII character to an Unicode character + /// Converts a PETSCII character to an Unicode character /// /// Unicode character. /// PETSCII character. @@ -560,24 +484,17 @@ namespace Claunia.Encoding } /// - /// Converts a Unicode character to an PETSCII character + /// Converts a Unicode character to an PETSCII character /// /// PETSCII character. /// Unicode character. static byte GetByte(char character) { - if (character == 0x0000) - { - // TODO: would returning 0x00 be more correct? - return 0x3F; - } + if(character == 0x0000) return 0x3F; - for (int i = 0; i < 256; i++) - { + for(int i = 0; i < 256; i++) // TODO: convert this to a gigantic switch statement too? - if (PETSCIITable[i] == character) - return (byte)i; - } + if(PETSCIITable[i] == character) return (byte)i; // Fallback to '?' return 0x3F; diff --git a/Claunia.Encoding/Pangrams.cs b/Claunia.Encoding/Pangrams.cs index b75ebbd..e018311 100644 --- a/Claunia.Encoding/Pangrams.cs +++ b/Claunia.Encoding/Pangrams.cs @@ -23,26 +23,29 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -using System; + namespace Claunia.Encoding { /// - /// Class containing pangrams for several languages that can be used to test encoding. + /// Class containing pangrams for several languages that can be used to test encoding. /// public static class Pangrams { /// A pangram that contains all (or most) Arabic characters. - public const string Arabic = "صِف خَلقَ خَودِ كَمِثلِ الشَمسِ إِذ بَزَغَت — يَحظى الضَجيعُ بِها نَجلاءَ مِعطارِ"; + public const string Arabic = + "صِف خَلقَ خَودِ كَمِثلِ الشَمسِ إِذ بَزَغَت — يَحظى الضَجيعُ بِها نَجلاءَ مِعطارِ"; /// A pangram that contains all (or most) Azeri characters. public const string Azeri = "Zəfər, jaketini də papağını da götür, bu axşam hava çox soyuq olacaq."; /// A pangram that contains all (or most) Basque characters. public const string Basque = "Vaudeville itxurako filmean, yogi ñaño bat jipoitzen dute Quebec-en, whiski truk"; /// A pangram that contains all (or most) Breton characters. - public const string Breton = "Yec’hed mat Jakez ! Skarzhit ar gwerennoù-mañ, kavet e vo gwin betek fin ho puhez."; + public const string Breton = + "Yec’hed mat Jakez ! Skarzhit ar gwerennoù-mañ, kavet e vo gwin betek fin ho puhez."; /// A pangram that contains all (or most) Bulgarian characters. public const string Bulgarian = "Хълцащ змей плюе шофьор стигнал чуждия бивак."; /// A pangram that contains all (or most) Catalan characters. - public const string Catalan = "«Dóna amor que seràs feliç!». Això, il·lús company geniüt, ja és un lluït rètol blavís d’onze kWh."; + public const string Catalan = + "«Dóna amor que seràs feliç!». Això, il·lús company geniüt, ja és un lluït rètol blavís d’onze kWh."; /// A pangram that contains Traditional Chinese characters. public const string ChineseTraditional = "視野無限廣,窗外有藍天"; /// A pangram that contains Simplified Chinese characters. @@ -50,9 +53,11 @@ namespace Claunia.Encoding /// A pangram that contains all (or most) Croatian characters. public const string Croatian = "Gojazni đačić s biciklom drži hmelj i finu vatu u džepu nošnje."; /// A pangram that contains all (or most) Czech characters. - public const string Czech = "Nechť již hříšné saxofony ďáblů rozezvučí síň úděsnými tóny waltzu, tanga a quickstepu."; + public const string Czech = + "Nechť již hříšné saxofony ďáblů rozezvučí síň úděsnými tóny waltzu, tanga a quickstepu."; /// A pangram that contains all (or most) Danish characters. - public const string Danish = "Quizdeltagerne spiste jordbær med fløde, mens cirkusklovnen Walther spillede på xylofon."; + public const string Danish = + "Quizdeltagerne spiste jordbær med fløde, mens cirkusklovnen Walther spillede på xylofon."; /// A pangram that contains all (or most) Dutch characters. public const string Dutch = "Pa’s wijze lynx bezag vroom het fikse aquaduct."; /// A pangram that contains all (or most) English characters. @@ -62,17 +67,26 @@ namespace Claunia.Encoding /// A pangram that contains all (or most) Estonian characters. public const string Estonian = "Põdur Zagrebi tšellomängija-följetonist Ciqo külmetas kehvas garaažis."; /// A pangram that contains all (or most) Finnish characters. - public const string Finnish = "Fahrenheit ja Celsius yrjösivät Åsan backgammon-peliin, Volkswagenissa, daiquirin ja ZX81:n yhteisvaikutuksesta."; + public const string Finnish = + "Fahrenheit ja Celsius yrjösivät Åsan backgammon-peliin, Volkswagenissa, daiquirin ja ZX81:n yhteisvaikutuksesta." + ; /// A pangram that contains all (or most) French characters. - public const string French = "Le cœur déçu mais l'âme plutôt naïve, Louÿs rêva de crapaüter en canoë au delà des îles, près du mälströn où brûlent les novæ."; + public const string French = + "Le cœur déçu mais l'âme plutôt naïve, Louÿs rêva de crapaüter en canoë au delà des îles, près du mälströn où brûlent les novæ." + ; /// A pangram that contains all (or most) Galician characters. - public const string Galician = "Necesitamos unha tipografía chuliña de cor kiwi, que lle zorregue unha labazada visual á xente."; + public const string Galician = + "Necesitamos unha tipografía chuliña de cor kiwi, que lle zorregue unha labazada visual á xente."; /// A pangram that contains all (or most) German characters. public const string German = "Falsches Üben von Xylophonmusik quält jeden größeren Zwerg."; /// A pangram that contains all (or most) Greek characters. - public const string Greek = "Ταχίστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός Takhístè alôpèx vaphês psèménè gè, draskelízei ypér nòthroý kynós."; + public const string Greek = + "Ταχίστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός Takhístè alôpèx vaphês psèménè gè, draskelízei ypér nòthroý kynós." + ; /// A pangram that contains all (or most) Hebrew characters. - public const string Hebrew = "לכן חכו לי נאם יהוה ליום קומי לעד, כי משפטי לאסף גוים לקבצי ממלכות, לשפך עליהם זעמי כל חרון אפי, כי באש קנאתי תאכל כל הארץ"; + public const string Hebrew = + "לכן חכו לי נאם יהוה ליום קומי לעד, כי משפטי לאסף גוים לקבצי ממלכות, לשפך עליהם זעמי כל חרון אפי, כי באש קנאתי תאכל כל הארץ" + ; /// A pangram that contains all (or most) Hungarian characters. public const string Hungarian = "Jó foxim és don Quijote húszwattos lámpánál ülve egy pár bűvös cipőt készít."; /// A pangram that contains all (or most) Icelandic characters. @@ -81,7 +95,7 @@ namespace Claunia.Encoding public const string Irish = "Ċuaiġ bé ṁórṡáċ le dlúṫspád fíorḟinn trí hata mo ḋea-ṗorcáin ḃig"; /// A pangram that contains all (or most) Japanese kanas. public const string Japanese = "いろはにほへと ちりぬるを わかよたれそ つねならむ うゐのおくやま けふこえて あさきゆめみし ゑひもせす(ん)"; - /// using Kanjis + /// using Kanjis public const string JapaneseKanji = "色は匂へど 散りぬるを 我が世誰ぞ 常ならむ 有為の奥山 今日越えて 浅き夢見じ 酔ひもせず(ん)"; /// A pangram that contains all (or most) Korean characters. public const string Korean = "키스의 고유조건은 입술끼리 만나야 하고 특별한 기술은 필요치 않다"; @@ -96,21 +110,27 @@ namespace Claunia.Encoding /// A pangram that contains all (or most) Polish characters. public const string Polish = "Jeżu klątw, spłódź Finom część gry hańb!"; /// A pangram that contains all (or most) Portuguese characters. - public const string Portuguese = "À noite, vovô Kowalsky vê o ímã cair no pé do pingüim queixoso e vovó põe açúcar no chá de tâmaras do jabuti feliz."; + public const string Portuguese = + "À noite, vovô Kowalsky vê o ímã cair no pé do pingüim queixoso e vovó põe açúcar no chá de tâmaras do jabuti feliz." + ; /// A pangram that contains all (or most) Romanian characters. public const string Romanian = "Înjurând pițigăiat, zoofobul comandă vexat whisky și tequila."; /// A pangram that contains all (or most) Russian characters. - public const string Russian = "Широкая электрификация южных губерний даст мощный толчок подъёму сельского хозяйства."; + public const string Russian = + "Широкая электрификация южных губерний даст мощный толчок подъёму сельского хозяйства."; /// A pangram that contains all (or most) Scottish Gaelic characters. public const string Scottish = "Mus d’fhàg Cèit-Ùna ròp Ì le ob."; /// A pangram that contains all (or most) Serbian characters. public const string Serbian = "Gojazni đačić s biciklom drži hmelj i finu vatu u džepu nošnje."; /// A pangram that contains all (or most) Slovak characters. - public const string Slovak = "Kŕdeľ šťastných ďatľov učí pri ústí Váhu mĺkveho koňa obhrýzať kôru a žrať čerstvé mäso."; + public const string Slovak = + "Kŕdeľ šťastných ďatľov učí pri ústí Váhu mĺkveho koňa obhrýzať kôru a žrať čerstvé mäso."; /// A pangram that contains all (or most) Slovenian characters. public const string Slovenian = "Besni dirkač iz formule žuga cehu poštarjev."; /// A pangram that contains all (or most) Spanish characters. - public const string Spanish = "El veloz murciélago hindú comía feliz cardillo y kiwi. La cigüeña tocaba el saxofón detrás del palenque de paja."; + public const string Spanish = + "El veloz murciélago hindú comía feliz cardillo y kiwi. La cigüeña tocaba el saxofón detrás del palenque de paja." + ; /// A pangram that contains all (or most) Swedish characters. public const string Swedish = "Flygande bäckasiner söka hwila på mjuka tuvor."; /// A pangram that contains all (or most) Turkish characters. @@ -118,5 +138,4 @@ namespace Claunia.Encoding /// A pangram that contains all (or most) Welsh characters. public const string Welsh = "Parciais fy jac codi baw hud llawn dŵr ger tŷ Mabon."; } -} - +} \ No newline at end of file diff --git a/Claunia.Encoding/ZX80.cs b/Claunia.Encoding/ZX80.cs index e818453..5712cf5 100644 --- a/Claunia.Encoding/ZX80.cs +++ b/Claunia.Encoding/ZX80.cs @@ -29,7 +29,7 @@ using System; namespace Claunia.Encoding { /// - /// Represents a ZX80 character encoding of Unicode characters. + /// Represents a ZX80 character encoding of Unicode characters. /// public class ZX80 : Encoding { @@ -48,105 +48,151 @@ namespace Claunia.Encoding const bool singleByte = true; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. + /// The ZX80 to Unicode character map. /// - public override bool IsBrowserDisplay { - get { return browserDisplay; } - } + static readonly char[] ZX80Table = + { + // 0x00 + '\u0020', '\u0022', '\u258C', '\u2584', '\u2598', '\u259D', '\u2596', '\u2597', + // 0x08 + '\u259E', '\u2592', '\uFFFD', '\uFFFD', '\u00A3', '\u0024', '\u003A', '\u003F', + // 0x10 + '\u0028', '\u0029', '\u002D', '\u002B', '\u002A', '\u002F', '\u003D', '\u003E', + // 0x18 + '\u003C', '\u003B', '\u002C', '\u002E', '\u0030', '\u0031', '\u0032', '\u0033', + // 0x20 + '\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039', '\u0041', '\u0042', + // 0x28 + '\u0043', '\u0044', '\u0045', '\u0046', '\u0047', '\u0048', '\u0049', '\u004A', + // 0x30 + '\u004B', '\u004C', '\u004D', '\u004E', '\u004F', '\u0050', '\u0051', '\u0052', + // 0x38 + '\u0053', '\u0054', '\u0055', '\u0056', '\u0057', '\u0058', '\u0059', '\u005A', + // 0x40 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0x48 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0x50 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0x58 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0x60 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0x68 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0x70 + '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\u000D', '\uFFFD', '\u000A', '\u0008', + // 0x78 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0x80 + '\u2588', '\uFFFD', '\u2590', '\u2580', '\u2599', '\u259C', '\u259B', '\u259A', + // 0x88 + '\u2592', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', + // 0x90 + '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', + // 0x98 + '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', + // 0xA0 + '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', + // 0xA8 + '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', + // 0xB0 + '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', + // 0xB8 + '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', + // 0xC0 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xC8 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0xD0 + '\u0000', '\u0000', '\u0000', '\u0000', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', + // 0xD8 + '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', + // 0xE0 + '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', + // 0xE8 + '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', + // 0xF0 + '\uFFFF', '\u0000', '\u0000', '\uFFFF', '\uFFFF', '\u0000', '\uFFFF', '\uFFFF', + // 0xF8 + '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\u0000' + }; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. + /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. /// - public override bool IsBrowserSave { - get { return browserSave; } - } + public override bool IsBrowserDisplay => browserDisplay; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. + /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. /// - public override bool IsMailNewsDisplay { - get { return mailNewsDisplay; } - } + public override bool IsBrowserSave => browserSave; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. /// - public override bool IsMailNewsSave { - get { return mailNewsSave; } - } + public override bool IsMailNewsDisplay => mailNewsDisplay; /// - /// Gets a value indicating whether the current encoding is read-only. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// + public override bool IsMailNewsSave => mailNewsSave; + + /// + /// Gets a value indicating whether the current encoding is read-only. /// /// The is single byte. - public override bool IsReadOnly { - get { return readOnly; } - } + public override bool IsReadOnly => readOnly; /// - /// Gets a value indicating whether the current encoding uses single-byte code points. + /// Gets a value indicating whether the current encoding uses single-byte code points. /// - public override bool IsSingleByte { - get { return singleByte; } - } + public override bool IsSingleByte => singleByte; /// - /// Gets the code page identifier of the current Encoding. + /// Gets the code page identifier of the current Encoding. /// - public override int CodePage { - get { return _codepage; } - } + public override int CodePage => _codepage; /// - /// Gets a name for the current encoding that can be used with mail agent body tags + /// Gets a name for the current encoding that can be used with mail agent body tags /// - public override string BodyName { - get { return _bodyname; } - } + public override string BodyName => _bodyname; /// - /// Gets a name for the current encoding that can be used with mail agent header tags + /// Gets a name for the current encoding that can be used with mail agent header tags /// - public override string HeaderName { - get { return _headername; } - } + public override string HeaderName => _headername; /// - /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. + /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. /// - public override string WebName { - get { return _webname; } - } + public override string WebName => _webname; /// - /// Gets the human-readable description of the current encoding. + /// Gets the human-readable description of the current encoding. /// - public override string EncodingName { - get { return _encodingname; } - } + public override string EncodingName => _encodingname; /// - /// Gets the Windows operating system code page that most closely corresponds to the current encoding. + /// Gets the Windows operating system code page that most closely corresponds to the current encoding. /// - public override int WindowsCodePage { - get { return _windowsCodepage; } - } + public override int WindowsCodePage => _windowsCodepage; /// - /// Calculates the number of bytes produced by encoding the characters in the specified . + /// Calculates the number of bytes produced by encoding the characters in the specified . /// /// The number of bytes produced by encoding the specified characters. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. public override int GetByteCount(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return s.Length; } /// - /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. + /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. /// /// The number of bytes produced by encoding the specified characters. /// The character array containing the set of characters to encode. @@ -154,36 +200,32 @@ namespace Claunia.Encoding /// The number of characters to encode. public override int GetByteCount(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0 || index >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0 || index >= chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0 || index + count > chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(count < 0 || index + count > chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); return count; } /// - /// Calculates the number of bytes produced by encoding all the characters in the specified character array. + /// Calculates the number of bytes produced by encoding all the characters in the specified character array. /// /// The number of bytes produced by encoding all the characters in the specified character array. /// The character array containing the characters to encode. public override int GetByteCount(char[] chars) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); return chars.Length; } /// - /// Encodes a set of characters from the specified into the specified byte array. + /// Encodes a set of characters from the specified into the specified byte array. /// /// The actual number of bytes written into bytes. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. /// The index of the first character to encode. /// The number of characters to encode. /// The byte array to contain the resulting sequence of bytes. @@ -194,20 +236,19 @@ namespace Claunia.Encoding } /// - /// Encodes all the characters in the specified string into a sequence of bytes. + /// Encodes all the characters in the specified string into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The string containing the characters to encode. public override byte[] GetBytes(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return GetBytes(s.ToCharArray(), 0, s.Length); } /// - /// Encodes a set of characters from the specified character array into the specified byte array. + /// Encodes a set of characters from the specified character array into the specified byte array. /// /// The actual number of bytes written into bytes. /// The character array containing the set of characters to encode. @@ -217,43 +258,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting sequence of bytes. public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount + charIndex > chars.Length) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount + charIndex > chars.Length) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteIndex + charCount > bytes.Length) - throw new ArgumentException(nameof(bytes)); + if(byteIndex + charCount > bytes.Length) throw new ArgumentException(nameof(bytes)); byte[] temp = GetBytes(chars, charIndex, charCount); - for(int i = 0; i < temp.Length; i++) - bytes[i + byteIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) bytes[i + byteIndex] = temp[i]; return charCount; } /// - /// Encodes a set of characters from the specified character array into a sequence of bytes. + /// Encodes a set of characters from the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the set of characters to encode. @@ -261,28 +292,23 @@ namespace Claunia.Encoding /// The number of characters to encode. public override byte[] GetBytes(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > chars.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > chars.Length) throw new ArgumentOutOfRangeException(nameof(count)); byte[] bytes = new byte[count]; - for(int i = 0; i < count; i++) - bytes[i] = GetByte(chars[index + i]); + for(int i = 0; i < count; i++) bytes[i] = GetByte(chars[index + i]); return bytes; } /// - /// Encodes all the characters in the specified character array into a sequence of bytes. + /// Encodes all the characters in the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the characters to encode. @@ -292,7 +318,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. + /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -302,7 +328,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. + /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -310,23 +336,19 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override int GetCharCount(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); return count; } /// - /// Decodes a sequence of bytes from the specified byte array into the specified character array. + /// Decodes a sequence of bytes from the specified byte array into the specified character array. /// /// The actual number of characters written into chars. /// The byte array containing the sequence of bytes to decode. @@ -336,43 +358,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting set of characters. public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount + byteIndex > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount + byteIndex > bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charIndex + byteCount > chars.Length) - throw new ArgumentException(nameof(chars)); + if(charIndex + byteCount > chars.Length) throw new ArgumentException(nameof(chars)); char[] temp = GetChars(bytes, byteIndex, byteCount); - for(int i = 0; i < temp.Length; i++) - chars[i + charIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) chars[i + charIndex] = temp[i]; return byteCount; } /// - /// Decodes all the bytes in the specified byte array into a set of characters. + /// Decodes all the bytes in the specified byte array into a set of characters. /// /// A character array containing the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -382,7 +394,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a set of characters. + /// Decodes a sequence of bytes from the specified byte array into a set of characters. /// /// The chars. /// The byte array containing the sequence of bytes to decode. @@ -390,54 +402,47 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override char[] GetChars(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); char[] chars = new char[count]; - for(int i = 0; i < count; i++) - chars[i] = GetChar(bytes[index + i]); + for(int i = 0; i < count; i++) chars[i] = GetChar(bytes[index + i]); return chars; } /// - /// Calculates the maximum number of bytes produced by encoding the specified number of characters. + /// Calculates the maximum number of bytes produced by encoding the specified number of characters. /// /// The maximum number of bytes produced by encoding the specified number of characters. /// The number of characters to encode. public override int GetMaxByteCount(int charCount) { - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); return charCount; } /// - /// Calculates the maximum number of characters produced by decoding the specified number of bytes. + /// Calculates the maximum number of characters produced by decoding the specified number of bytes. /// /// The maximum number of characters produced by decoding the specified number of bytes. /// The number of bytes to decode. public override int GetMaxCharCount(int byteCount) { - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); return byteCount; } /// - /// Returns a sequence of bytes that specifies the encoding used. + /// Returns a sequence of bytes that specifies the encoding used. /// /// A byte array of length zero, as a preamble is not required. public override byte[] GetPreamble() @@ -446,7 +451,7 @@ namespace Claunia.Encoding } /// - /// Decodes all the bytes in the specified byte array into a string. + /// Decodes all the bytes in the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -456,7 +461,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a string. + /// Decodes a sequence of bytes from the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -468,77 +473,7 @@ namespace Claunia.Encoding } /// - /// The ZX80 to Unicode character map. - /// - static readonly char[] ZX80Table = { - // 0x00 - '\u0020','\u0022','\u258C','\u2584','\u2598','\u259D','\u2596','\u2597', - // 0x08 - '\u259E','\u2592','\uFFFD','\uFFFD','\u00A3','\u0024','\u003A','\u003F', - // 0x10 - '\u0028','\u0029','\u002D','\u002B','\u002A','\u002F','\u003D','\u003E', - // 0x18 - '\u003C','\u003B','\u002C','\u002E','\u0030','\u0031','\u0032','\u0033', - // 0x20 - '\u0034','\u0035','\u0036','\u0037','\u0038','\u0039','\u0041','\u0042', - // 0x28 - '\u0043','\u0044','\u0045','\u0046','\u0047','\u0048','\u0049','\u004A', - // 0x30 - '\u004B','\u004C','\u004D','\u004E','\u004F','\u0050','\u0051','\u0052', - // 0x38 - '\u0053','\u0054','\u0055','\u0056','\u0057','\u0058','\u0059','\u005A', - // 0x40 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0x48 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0x50 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0x58 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0x60 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0x68 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0x70 - '\uFFFF','\uFFFF','\uFFFF','\uFFFF','\u000D','\uFFFD','\u000A','\u0008', - // 0x78 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0x80 - '\u2588','\uFFFD','\u2590','\u2580','\u2599','\u259C','\u259B','\u259A', - // 0x88 - '\u2592','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD', - // 0x90 - '\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD', - // 0x98 - '\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD', - // 0xA0 - '\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD', - // 0xA8 - '\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD', - // 0xB0 - '\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD', - // 0xB8 - '\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD', - // 0xC0 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xC8 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0xD0 - '\u0000','\u0000','\u0000','\u0000','\uFFFF','\uFFFF','\uFFFF','\uFFFF', - // 0xD8 - '\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF', - // 0xE0 - '\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF', - // 0xE8 - '\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF', - // 0xF0 - '\uFFFF','\u0000','\u0000','\uFFFF','\uFFFF','\u0000','\uFFFF','\uFFFF', - // 0xF8 - '\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\u0000' - }; - - /// - /// Converts a ZX80 character to an Unicode character + /// Converts a ZX80 character to an Unicode character /// /// Unicode character. /// ZX80 character. @@ -548,159 +483,87 @@ namespace Claunia.Encoding } /// - /// Converts a Unicode character to an ZX80 character + /// Converts a Unicode character to an ZX80 character /// /// ZX80 character. /// Unicode character. static byte GetByte(char character) { - switch(character) { - case '\u0020': - return 0x00; - case '\u0022': - return 0x01; - case '\u258C': - return 0x02; - case '\u2584': - return 0x03; - case '\u2598': - return 0x04; - case '\u259D': - return 0x05; - case '\u2596': - return 0x06; - case '\u2597': - return 0x07; - case '\u259E': - return 0x08; - case '\u2592': - return 0x09; - case '\u00A3': - return 0x0C; - case '\u0024': - return 0x0D; - case '\u003A': - return 0x0E; - case '\u003F': - return 0x0F; - case '\u0028': - return 0x10; - case '\u0029': - return 0x11; - case '\u002D': - return 0x12; - case '\u002B': - return 0x13; - case '\u002A': - return 0x14; - case '\u002F': - return 0x15; - case '\u003D': - return 0x16; - case '\u003E': - return 0x17; - case '\u003C': - return 0x18; - case '\u003B': - return 0x19; - case '\u002C': - return 0x1A; - case '\u002E': - return 0x1B; - case '\u0030': - return 0x1C; - case '\u0031': - return 0x1D; - case '\u0032': - return 0x1E; - case '\u0033': - return 0x1F; - case '\u0034': - return 0x20; - case '\u0035': - return 0x21; - case '\u0036': - return 0x22; - case '\u0037': - return 0x23; - case '\u0038': - return 0x24; - case '\u0039': - return 0x25; - case '\u0041': - return 0x26; - case '\u0042': - return 0x27; - case '\u0043': - return 0x28; - case '\u0044': - return 0x29; - case '\u0045': - return 0x2A; - case '\u0046': - return 0x2B; - case '\u0047': - return 0x2C; - case '\u0048': - return 0x2D; - case '\u0049': - return 0x2E; - case '\u004A': - return 0x2F; - case '\u004B': - return 0x30; - case '\u004C': - return 0x31; - case '\u004D': - return 0x32; - case '\u004E': - return 0x33; - case '\u004F': - return 0x34; - case '\u0050': - return 0x35; - case '\u0051': - return 0x36; - case '\u0052': - return 0x37; - case '\u0053': - return 0x38; - case '\u0054': - return 0x39; - case '\u0055': - return 0x3A; - case '\u0056': - return 0x3B; - case '\u0057': - return 0x3C; - case '\u0058': - return 0x3D; - case '\u0059': - return 0x3E; - case '\u005A': - return 0x3F; - case '\u000D': - return 0x74; - case '\u000A': - return 0x76; - case '\u0008': - return 0x77; - case '\u2588': - return 0x80; - case '\u2590': - return 0x82; - case '\u2580': - return 0x83; - case '\u259F': - return 0x84; - case '\u2599': - return 0x85; - case '\u259C': - return 0x86; - case '\u259B': - return 0x87; - case '\u259A': - return 0x88; + switch(character) + { + case '\u0020': return 0x00; + case '\u0022': return 0x01; + case '\u258C': return 0x02; + case '\u2584': return 0x03; + case '\u2598': return 0x04; + case '\u259D': return 0x05; + case '\u2596': return 0x06; + case '\u2597': return 0x07; + case '\u259E': return 0x08; + case '\u2592': return 0x09; + case '\u00A3': return 0x0C; + case '\u0024': return 0x0D; + case '\u003A': return 0x0E; + case '\u003F': return 0x0F; + case '\u0028': return 0x10; + case '\u0029': return 0x11; + case '\u002D': return 0x12; + case '\u002B': return 0x13; + case '\u002A': return 0x14; + case '\u002F': return 0x15; + case '\u003D': return 0x16; + case '\u003E': return 0x17; + case '\u003C': return 0x18; + case '\u003B': return 0x19; + case '\u002C': return 0x1A; + case '\u002E': return 0x1B; + case '\u0030': return 0x1C; + case '\u0031': return 0x1D; + case '\u0032': return 0x1E; + case '\u0033': return 0x1F; + case '\u0034': return 0x20; + case '\u0035': return 0x21; + case '\u0036': return 0x22; + case '\u0037': return 0x23; + case '\u0038': return 0x24; + case '\u0039': return 0x25; + case '\u0041': return 0x26; + case '\u0042': return 0x27; + case '\u0043': return 0x28; + case '\u0044': return 0x29; + case '\u0045': return 0x2A; + case '\u0046': return 0x2B; + case '\u0047': return 0x2C; + case '\u0048': return 0x2D; + case '\u0049': return 0x2E; + case '\u004A': return 0x2F; + case '\u004B': return 0x30; + case '\u004C': return 0x31; + case '\u004D': return 0x32; + case '\u004E': return 0x33; + case '\u004F': return 0x34; + case '\u0050': return 0x35; + case '\u0051': return 0x36; + case '\u0052': return 0x37; + case '\u0053': return 0x38; + case '\u0054': return 0x39; + case '\u0055': return 0x3A; + case '\u0056': return 0x3B; + case '\u0057': return 0x3C; + case '\u0058': return 0x3D; + case '\u0059': return 0x3E; + case '\u005A': return 0x3F; + case '\u000D': return 0x74; + case '\u000A': return 0x76; + case '\u0008': return 0x77; + case '\u2588': return 0x80; + case '\u2590': return 0x82; + case '\u2580': return 0x83; + case '\u259F': return 0x84; + case '\u2599': return 0x85; + case '\u259C': return 0x86; + case '\u259B': return 0x87; + case '\u259A': return 0x88; default: // Fallback to '?' return 0x0F; diff --git a/Claunia.Encoding/ZX81.cs b/Claunia.Encoding/ZX81.cs index 244212b..d2beab4 100644 --- a/Claunia.Encoding/ZX81.cs +++ b/Claunia.Encoding/ZX81.cs @@ -29,7 +29,7 @@ using System; namespace Claunia.Encoding { /// - /// Represents a ZX81 character encoding of Unicode characters. + /// Represents a ZX81 character encoding of Unicode characters. /// public class ZX81 : Encoding { @@ -48,105 +48,151 @@ namespace Claunia.Encoding const bool singleByte = true; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. + /// The ZX81 to Unicode character map. /// - public override bool IsBrowserDisplay { - get { return browserDisplay; } - } + static readonly char[] ZX81Table = + { + // 0x00 + '\u0020', '\u2598', '\u259D', '\u2580', '\u2596', '\u258C', '\u259E', '\u259B', + // 0x08 + '\u2592', '\uFFFD', '\uFFFD', '\u0022', '\u00A3', '\u0024', '\u003A', '\u003F', + // 0x10 + '\u0028', '\u0029', '\u003E', '\u003C', '\u003D', '\u002B', '\u002D', '\u002A', + // 0x18 + '\u002F', '\u003B', '\u002C', '\u002E', '\u0030', '\u0031', '\u0032', '\u0033', + // 0x20 + '\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039', '\u0041', '\u0042', + // 0x28 + '\u0043', '\u0044', '\u0045', '\u0046', '\u0047', '\u0048', '\u0049', '\u004A', + // 0x30 + '\u004B', '\u004C', '\u004D', '\u004E', '\u004F', '\u0050', '\u0051', '\u0052', + // 0x38 + '\u0053', '\u0054', '\u0055', '\u0056', '\u0057', '\u0058', '\u0059', '\u005A', + // 0x40 + '\uFFFF', '\uFFFF', '\uFFFF', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0x48 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0x50 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0x58 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0x60 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0x68 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0x70 + '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\u000A', '\u0008', + // 0x78 + '\uFFFF', '\uFFFF', '\u0000', '\u0000', '\u0000', '\u0000', '\uFFFF', '\uFFFF', + // 0x80 + '\u2588', '\u259F', '\u2599', '\u2584', '\u259C', '\u2590', '\u259A', '\u2597', + // 0x88 + '\u2592', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', + // 0x90 + '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', + // 0x98 + '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', + // 0xA0 + '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', + // 0xA8 + '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', + // 0xB0 + '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', + // 0xB8 + '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', + // 0xC0 + '\uFFFF', '\uFFFF', '\uFFFF', '\u0000', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', + // 0xC8 + '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', + // 0xD0 + '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', + // 0xD8 + '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', + // 0xE0 + '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', + // 0xE8 + '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', + // 0xF0 + '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', + // 0xF8 + '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF' + }; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. + /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. /// - public override bool IsBrowserSave { - get { return browserSave; } - } + public override bool IsBrowserDisplay => browserDisplay; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. + /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. /// - public override bool IsMailNewsDisplay { - get { return mailNewsDisplay; } - } + public override bool IsBrowserSave => browserSave; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. /// - public override bool IsMailNewsSave { - get { return mailNewsSave; } - } + public override bool IsMailNewsDisplay => mailNewsDisplay; /// - /// Gets a value indicating whether the current encoding is read-only. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// + public override bool IsMailNewsSave => mailNewsSave; + + /// + /// Gets a value indicating whether the current encoding is read-only. /// /// The is single byte. - public override bool IsReadOnly { - get { return readOnly; } - } + public override bool IsReadOnly => readOnly; /// - /// Gets a value indicating whether the current encoding uses single-byte code points. + /// Gets a value indicating whether the current encoding uses single-byte code points. /// - public override bool IsSingleByte { - get { return singleByte; } - } + public override bool IsSingleByte => singleByte; /// - /// Gets the code page identifier of the current Encoding. + /// Gets the code page identifier of the current Encoding. /// - public override int CodePage { - get { return _codepage; } - } + public override int CodePage => _codepage; /// - /// Gets a name for the current encoding that can be used with mail agent body tags + /// Gets a name for the current encoding that can be used with mail agent body tags /// - public override string BodyName { - get { return _bodyname; } - } + public override string BodyName => _bodyname; /// - /// Gets a name for the current encoding that can be used with mail agent header tags + /// Gets a name for the current encoding that can be used with mail agent header tags /// - public override string HeaderName { - get { return _headername; } - } + public override string HeaderName => _headername; /// - /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. + /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. /// - public override string WebName { - get { return _webname; } - } + public override string WebName => _webname; /// - /// Gets the human-readable description of the current encoding. + /// Gets the human-readable description of the current encoding. /// - public override string EncodingName { - get { return _encodingname; } - } + public override string EncodingName => _encodingname; /// - /// Gets the Windows operating system code page that most closely corresponds to the current encoding. + /// Gets the Windows operating system code page that most closely corresponds to the current encoding. /// - public override int WindowsCodePage { - get { return _windowsCodepage; } - } + public override int WindowsCodePage => _windowsCodepage; /// - /// Calculates the number of bytes produced by encoding the characters in the specified . + /// Calculates the number of bytes produced by encoding the characters in the specified . /// /// The number of bytes produced by encoding the specified characters. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. public override int GetByteCount(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return s.Length; } /// - /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. + /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. /// /// The number of bytes produced by encoding the specified characters. /// The character array containing the set of characters to encode. @@ -154,36 +200,32 @@ namespace Claunia.Encoding /// The number of characters to encode. public override int GetByteCount(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0 || index >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0 || index >= chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0 || index + count > chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(count < 0 || index + count > chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); return count; } /// - /// Calculates the number of bytes produced by encoding all the characters in the specified character array. + /// Calculates the number of bytes produced by encoding all the characters in the specified character array. /// /// The number of bytes produced by encoding all the characters in the specified character array. /// The character array containing the characters to encode. public override int GetByteCount(char[] chars) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); return chars.Length; } /// - /// Encodes a set of characters from the specified into the specified byte array. + /// Encodes a set of characters from the specified into the specified byte array. /// /// The actual number of bytes written into bytes. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. /// The index of the first character to encode. /// The number of characters to encode. /// The byte array to contain the resulting sequence of bytes. @@ -194,20 +236,19 @@ namespace Claunia.Encoding } /// - /// Encodes all the characters in the specified string into a sequence of bytes. + /// Encodes all the characters in the specified string into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The string containing the characters to encode. public override byte[] GetBytes(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return GetBytes(s.ToCharArray(), 0, s.Length); } /// - /// Encodes a set of characters from the specified character array into the specified byte array. + /// Encodes a set of characters from the specified character array into the specified byte array. /// /// The actual number of bytes written into bytes. /// The character array containing the set of characters to encode. @@ -217,43 +258,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting sequence of bytes. public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount + charIndex > chars.Length) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount + charIndex > chars.Length) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteIndex + charCount > bytes.Length) - throw new ArgumentException(nameof(bytes)); + if(byteIndex + charCount > bytes.Length) throw new ArgumentException(nameof(bytes)); byte[] temp = GetBytes(chars, charIndex, charCount); - for(int i = 0; i < temp.Length; i++) - bytes[i + byteIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) bytes[i + byteIndex] = temp[i]; return charCount; } /// - /// Encodes a set of characters from the specified character array into a sequence of bytes. + /// Encodes a set of characters from the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the set of characters to encode. @@ -261,28 +292,23 @@ namespace Claunia.Encoding /// The number of characters to encode. public override byte[] GetBytes(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > chars.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > chars.Length) throw new ArgumentOutOfRangeException(nameof(count)); byte[] bytes = new byte[count]; - for(int i = 0; i < count; i++) - bytes[i] = GetByte(chars[index + i]); + for(int i = 0; i < count; i++) bytes[i] = GetByte(chars[index + i]); return bytes; } /// - /// Encodes all the characters in the specified character array into a sequence of bytes. + /// Encodes all the characters in the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the characters to encode. @@ -292,7 +318,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. + /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -302,7 +328,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. + /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -310,23 +336,19 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override int GetCharCount(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); return count; } /// - /// Decodes a sequence of bytes from the specified byte array into the specified character array. + /// Decodes a sequence of bytes from the specified byte array into the specified character array. /// /// The actual number of characters written into chars. /// The byte array containing the sequence of bytes to decode. @@ -336,43 +358,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting set of characters. public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount + byteIndex > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount + byteIndex > bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charIndex + byteCount > chars.Length) - throw new ArgumentException(nameof(chars)); + if(charIndex + byteCount > chars.Length) throw new ArgumentException(nameof(chars)); char[] temp = GetChars(bytes, byteIndex, byteCount); - for(int i = 0; i < temp.Length; i++) - chars[i + charIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) chars[i + charIndex] = temp[i]; return byteCount; } /// - /// Decodes all the bytes in the specified byte array into a set of characters. + /// Decodes all the bytes in the specified byte array into a set of characters. /// /// A character array containing the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -382,7 +394,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a set of characters. + /// Decodes a sequence of bytes from the specified byte array into a set of characters. /// /// The chars. /// The byte array containing the sequence of bytes to decode. @@ -390,54 +402,47 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override char[] GetChars(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); char[] chars = new char[count]; - for(int i = 0; i < count; i++) - chars[i] = GetChar(bytes[index + i]); + for(int i = 0; i < count; i++) chars[i] = GetChar(bytes[index + i]); return chars; } /// - /// Calculates the maximum number of bytes produced by encoding the specified number of characters. + /// Calculates the maximum number of bytes produced by encoding the specified number of characters. /// /// The maximum number of bytes produced by encoding the specified number of characters. /// The number of characters to encode. public override int GetMaxByteCount(int charCount) { - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); return charCount; } /// - /// Calculates the maximum number of characters produced by decoding the specified number of bytes. + /// Calculates the maximum number of characters produced by decoding the specified number of bytes. /// /// The maximum number of characters produced by decoding the specified number of bytes. /// The number of bytes to decode. public override int GetMaxCharCount(int byteCount) { - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); return byteCount; } /// - /// Returns a sequence of bytes that specifies the encoding used. + /// Returns a sequence of bytes that specifies the encoding used. /// /// A byte array of length zero, as a preamble is not required. public override byte[] GetPreamble() @@ -446,7 +451,7 @@ namespace Claunia.Encoding } /// - /// Decodes all the bytes in the specified byte array into a string. + /// Decodes all the bytes in the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -456,7 +461,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a string. + /// Decodes a sequence of bytes from the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -468,77 +473,7 @@ namespace Claunia.Encoding } /// - /// The ZX81 to Unicode character map. - /// - static readonly char[] ZX81Table = { - // 0x00 - '\u0020','\u2598','\u259D','\u2580','\u2596','\u258C','\u259E','\u259B', - // 0x08 - '\u2592','\uFFFD','\uFFFD','\u0022','\u00A3','\u0024','\u003A','\u003F', - // 0x10 - '\u0028','\u0029','\u003E','\u003C','\u003D','\u002B','\u002D','\u002A', - // 0x18 - '\u002F','\u003B','\u002C','\u002E','\u0030','\u0031','\u0032','\u0033', - // 0x20 - '\u0034','\u0035','\u0036','\u0037','\u0038','\u0039','\u0041','\u0042', - // 0x28 - '\u0043','\u0044','\u0045','\u0046','\u0047','\u0048','\u0049','\u004A', - // 0x30 - '\u004B','\u004C','\u004D','\u004E','\u004F','\u0050','\u0051','\u0052', - // 0x38 - '\u0053','\u0054','\u0055','\u0056','\u0057','\u0058','\u0059','\u005A', - // 0x40 - '\uFFFF','\uFFFF','\uFFFF','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0x48 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0x50 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0x58 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0x60 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0x68 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0x70 - '\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\u000A','\u0008', - // 0x78 - '\uFFFF','\uFFFF','\u0000','\u0000','\u0000','\u0000','\uFFFF','\uFFFF', - // 0x80 - '\u2588','\u259F','\u2599','\u2584','\u259C','\u2590','\u259A','\u2597', - // 0x88 - '\u2592','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD', - // 0x90 - '\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD', - // 0x98 - '\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD', - // 0xA0 - '\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD', - // 0xA8 - '\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD', - // 0xB0 - '\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD', - // 0xB8 - '\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD', - // 0xC0 - '\uFFFF','\uFFFF','\uFFFF','\u0000','\uFFFF','\uFFFF','\uFFFF','\uFFFF', - // 0xC8 - '\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF', - // 0xD0 - '\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF', - // 0xD8 - '\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF', - // 0xE0 - '\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF', - // 0xE8 - '\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF', - // 0xF0 - '\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF', - // 0xF8 - '\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF' - }; - - /// - /// Converts a ZX81 character to an Unicode character + /// Converts a ZX81 character to an Unicode character /// /// Unicode character. /// ZX81 character. @@ -548,159 +483,87 @@ namespace Claunia.Encoding } /// - /// Converts a Unicode character to an ZX81 character + /// Converts a Unicode character to an ZX81 character /// /// ZX81 character. /// Unicode character. static byte GetByte(char character) { - switch(character) { - case '\u0020': - return 0x00; - case '\u2598': - return 0x01; - case '\u259D': - return 0x02; - case '\u2580': - return 0x03; - case '\u2596': - return 0x04; - case '\u258C': - return 0x05; - case '\u259E': - return 0x06; - case '\u259B': - return 0x07; - case '\u2592': - return 0x08; - case '\u0022': - return 0x0B; - case '\u00A3': - return 0x0C; - case '\u0024': - return 0x0D; - case '\u003A': - return 0x0E; - case '\u003F': - return 0x0F; - case '\u0028': - return 0x10; - case '\u0029': - return 0x11; - case '\u003E': - return 0x12; - case '\u003C': - return 0x13; - case '\u003D': - return 0x14; - case '\u002B': - return 0x15; - case '\u002D': - return 0x16; - case '\u002A': - return 0x17; - case '\u002F': - return 0x18; - case '\u003B': - return 0x19; - case '\u002C': - return 0x1A; - case '\u002E': - return 0x1B; - case '\u0030': - return 0x1C; - case '\u0031': - return 0x1D; - case '\u0032': - return 0x1E; - case '\u0033': - return 0x1F; - case '\u0034': - return 0x20; - case '\u0035': - return 0x21; - case '\u0036': - return 0x22; - case '\u0037': - return 0x23; - case '\u0038': - return 0x24; - case '\u0039': - return 0x25; - case '\u0041': - return 0x26; - case '\u0042': - return 0x27; - case '\u0043': - return 0x28; - case '\u0044': - return 0x29; - case '\u0045': - return 0x2A; - case '\u0046': - return 0x2B; - case '\u0047': - return 0x2C; - case '\u0048': - return 0x2D; - case '\u0049': - return 0x2E; - case '\u004A': - return 0x2F; - case '\u004B': - return 0x30; - case '\u004C': - return 0x31; - case '\u004D': - return 0x32; - case '\u004E': - return 0x33; - case '\u004F': - return 0x34; - case '\u0050': - return 0x35; - case '\u0051': - return 0x36; - case '\u0052': - return 0x37; - case '\u0053': - return 0x38; - case '\u0054': - return 0x39; - case '\u0055': - return 0x3A; - case '\u0056': - return 0x3B; - case '\u0057': - return 0x3C; - case '\u0058': - return 0x3D; - case '\u0059': - return 0x3E; - case '\u005A': - return 0x3F; - case '\u000D': - return 0x74; - case '\u000A': - return 0x76; - case '\u0008': - return 0x77; - case '\u2588': - return 0x80; - case '\u259F': - return 0x81; - case '\u2599': - return 0x82; - case '\u2584': - return 0x83; - case '\u259C': - return 0x84; - case '\u2590': - return 0x85; - case '\u259A': - return 0x86; - case '\u2597': - return 0x87; + switch(character) + { + case '\u0020': return 0x00; + case '\u2598': return 0x01; + case '\u259D': return 0x02; + case '\u2580': return 0x03; + case '\u2596': return 0x04; + case '\u258C': return 0x05; + case '\u259E': return 0x06; + case '\u259B': return 0x07; + case '\u2592': return 0x08; + case '\u0022': return 0x0B; + case '\u00A3': return 0x0C; + case '\u0024': return 0x0D; + case '\u003A': return 0x0E; + case '\u003F': return 0x0F; + case '\u0028': return 0x10; + case '\u0029': return 0x11; + case '\u003E': return 0x12; + case '\u003C': return 0x13; + case '\u003D': return 0x14; + case '\u002B': return 0x15; + case '\u002D': return 0x16; + case '\u002A': return 0x17; + case '\u002F': return 0x18; + case '\u003B': return 0x19; + case '\u002C': return 0x1A; + case '\u002E': return 0x1B; + case '\u0030': return 0x1C; + case '\u0031': return 0x1D; + case '\u0032': return 0x1E; + case '\u0033': return 0x1F; + case '\u0034': return 0x20; + case '\u0035': return 0x21; + case '\u0036': return 0x22; + case '\u0037': return 0x23; + case '\u0038': return 0x24; + case '\u0039': return 0x25; + case '\u0041': return 0x26; + case '\u0042': return 0x27; + case '\u0043': return 0x28; + case '\u0044': return 0x29; + case '\u0045': return 0x2A; + case '\u0046': return 0x2B; + case '\u0047': return 0x2C; + case '\u0048': return 0x2D; + case '\u0049': return 0x2E; + case '\u004A': return 0x2F; + case '\u004B': return 0x30; + case '\u004C': return 0x31; + case '\u004D': return 0x32; + case '\u004E': return 0x33; + case '\u004F': return 0x34; + case '\u0050': return 0x35; + case '\u0051': return 0x36; + case '\u0052': return 0x37; + case '\u0053': return 0x38; + case '\u0054': return 0x39; + case '\u0055': return 0x3A; + case '\u0056': return 0x3B; + case '\u0057': return 0x3C; + case '\u0058': return 0x3D; + case '\u0059': return 0x3E; + case '\u005A': return 0x3F; + case '\u000D': return 0x74; + case '\u000A': return 0x76; + case '\u0008': return 0x77; + case '\u2588': return 0x80; + case '\u259F': return 0x81; + case '\u2599': return 0x82; + case '\u2584': return 0x83; + case '\u259C': return 0x84; + case '\u2590': return 0x85; + case '\u259A': return 0x86; + case '\u2597': return 0x87; default: // Fallback to '?' return 0x0F; diff --git a/Claunia.Encoding/ZXSpectrum.cs b/Claunia.Encoding/ZXSpectrum.cs index 9aaddee..fa044f2 100644 --- a/Claunia.Encoding/ZXSpectrum.cs +++ b/Claunia.Encoding/ZXSpectrum.cs @@ -29,7 +29,7 @@ using System; namespace Claunia.Encoding { /// - /// Represents an ZX Spectrum character encoding of Unicode characters. + /// Represents an ZX Spectrum character encoding of Unicode characters. /// public class ZXSpectrum : Encoding { @@ -48,105 +48,151 @@ namespace Claunia.Encoding const bool singleByte = true; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. + /// The ZX Spectrum to Unicode character map. /// - public override bool IsBrowserDisplay { - get { return browserDisplay; } - } + static readonly char[] ZXSpectrumTable = + { + // 0x00 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0009', '\u0000', + // 0x08 + '\uFFFF', '\uFFFF', '\u0000', '\u0000', '\u0000', '\u000D', '\uFFFF', '\u0000', + // 0x10 + '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\u0009', + // 0x18 + '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', + // 0x20 + '\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027', + // 0x28 + '\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F', + // 0x30 + '\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', + // 0x38 + '\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F', + // 0x40 + '\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047', + // 0x48 + '\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F', + // 0x50 + '\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057', + // 0x58 + '\u0058', '\u0059', '\u005A', '\u005B', '\u005C', '\u005D', '\u2191', '\u005F', + // 0x60 + '\u00A3', '\u0061', '\u0062', '\u0063', '\u0064', '\u0065', '\u0066', '\u0067', + // 0x68 + '\u0068', '\u0069', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F', + // 0x70 + '\u0070', '\u0071', '\u0072', '\u0073', '\u0074', '\u0075', '\u0076', '\u0077', + // 0x78 + '\u0078', '\u0079', '\u007A', '\u007B', '\u007C', '\u007D', '\u007E', '\u00A9', + // 0x80 + '\u0020', '\u259D', '\u2598', '\u2580', '\u2597', '\u2590', '\u259A', '\u259C', + // 0x88 + '\u2596', '\u259E', '\u258C', '\u259B', '\u2584', '\u259F', '\u2599', '\u2588', + // 0x90 + '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', + // 0x98 + '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', + // 0xA0 + '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFF', '\uFFFF', '\uFFFF', + // 0xA8 + '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', + // 0xB0 + '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', + // 0xB8 + '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', + // 0xC0 + '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', + // 0xC8 + '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', + // 0xD0 + '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', + // 0xD8 + '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', + // 0xE0 + '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', + // 0xE8 + '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', + // 0xF0 + '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', + // 0xF8 + '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF' + }; /// - /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. + /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. /// - public override bool IsBrowserSave { - get { return browserSave; } - } + public override bool IsBrowserDisplay => browserDisplay; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. + /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. /// - public override bool IsMailNewsDisplay { - get { return mailNewsDisplay; } - } + public override bool IsBrowserSave => browserSave; /// - /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. /// - public override bool IsMailNewsSave { - get { return mailNewsSave; } - } + public override bool IsMailNewsDisplay => mailNewsDisplay; /// - /// Gets a value indicating whether the current encoding is read-only. + /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// + public override bool IsMailNewsSave => mailNewsSave; + + /// + /// Gets a value indicating whether the current encoding is read-only. /// /// The is single byte. - public override bool IsReadOnly { - get { return readOnly; } - } + public override bool IsReadOnly => readOnly; /// - /// Gets a value indicating whether the current encoding uses single-byte code points. + /// Gets a value indicating whether the current encoding uses single-byte code points. /// - public override bool IsSingleByte { - get { return singleByte; } - } + public override bool IsSingleByte => singleByte; /// - /// Gets the code page identifier of the current Encoding. + /// Gets the code page identifier of the current Encoding. /// - public override int CodePage { - get { return _codepage; } - } + public override int CodePage => _codepage; /// - /// Gets a name for the current encoding that can be used with mail agent body tags + /// Gets a name for the current encoding that can be used with mail agent body tags /// - public override string BodyName { - get { return _bodyname; } - } + public override string BodyName => _bodyname; /// - /// Gets a name for the current encoding that can be used with mail agent header tags + /// Gets a name for the current encoding that can be used with mail agent header tags /// - public override string HeaderName { - get { return _headername; } - } + public override string HeaderName => _headername; /// - /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. + /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. /// - public override string WebName { - get { return _webname; } - } + public override string WebName => _webname; /// - /// Gets the human-readable description of the current encoding. + /// Gets the human-readable description of the current encoding. /// - public override string EncodingName { - get { return _encodingname; } - } + public override string EncodingName => _encodingname; /// - /// Gets the Windows operating system code page that most closely corresponds to the current encoding. + /// Gets the Windows operating system code page that most closely corresponds to the current encoding. /// - public override int WindowsCodePage { - get { return _windowsCodepage; } - } + public override int WindowsCodePage => _windowsCodepage; /// - /// Calculates the number of bytes produced by encoding the characters in the specified . + /// Calculates the number of bytes produced by encoding the characters in the specified . /// /// The number of bytes produced by encoding the specified characters. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. public override int GetByteCount(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return s.Length; } /// - /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. + /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. /// /// The number of bytes produced by encoding the specified characters. /// The character array containing the set of characters to encode. @@ -154,36 +200,32 @@ namespace Claunia.Encoding /// The number of characters to encode. public override int GetByteCount(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0 || index >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0 || index >= chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0 || index + count > chars.Length) - throw new ArgumentOutOfRangeException(nameof(index)); + if(count < 0 || index + count > chars.Length) throw new ArgumentOutOfRangeException(nameof(index)); return count; } /// - /// Calculates the number of bytes produced by encoding all the characters in the specified character array. + /// Calculates the number of bytes produced by encoding all the characters in the specified character array. /// /// The number of bytes produced by encoding all the characters in the specified character array. /// The character array containing the characters to encode. public override int GetByteCount(char[] chars) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); return chars.Length; } /// - /// Encodes a set of characters from the specified into the specified byte array. + /// Encodes a set of characters from the specified into the specified byte array. /// /// The actual number of bytes written into bytes. - /// The containing the set of characters to encode. + /// The containing the set of characters to encode. /// The index of the first character to encode. /// The number of characters to encode. /// The byte array to contain the resulting sequence of bytes. @@ -194,20 +236,19 @@ namespace Claunia.Encoding } /// - /// Encodes all the characters in the specified string into a sequence of bytes. + /// Encodes all the characters in the specified string into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The string containing the characters to encode. public override byte[] GetBytes(string s) { - if(s == null) - throw new ArgumentNullException(nameof(s)); + if(s == null) throw new ArgumentNullException(nameof(s)); return GetBytes(s.ToCharArray(), 0, s.Length); } /// - /// Encodes a set of characters from the specified character array into the specified byte array. + /// Encodes a set of characters from the specified character array into the specified byte array. /// /// The actual number of bytes written into bytes. /// The character array containing the set of characters to encode. @@ -217,43 +258,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting sequence of bytes. public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charCount + charIndex > chars.Length) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount + charIndex > chars.Length) throw new ArgumentOutOfRangeException(nameof(charCount)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteIndex + charCount > bytes.Length) - throw new ArgumentException(nameof(bytes)); + if(byteIndex + charCount > bytes.Length) throw new ArgumentException(nameof(bytes)); byte[] temp = GetBytes(chars, charIndex, charCount); - for(int i = 0; i < temp.Length; i++) - bytes[i + byteIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) bytes[i + byteIndex] = temp[i]; return charCount; } /// - /// Encodes a set of characters from the specified character array into a sequence of bytes. + /// Encodes a set of characters from the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the set of characters to encode. @@ -261,28 +292,23 @@ namespace Claunia.Encoding /// The number of characters to encode. public override byte[] GetBytes(char[] chars, int index, int count) { - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > chars.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > chars.Length) throw new ArgumentOutOfRangeException(nameof(count)); byte[] bytes = new byte[count]; - for(int i = 0; i < count; i++) - bytes[i] = GetByte(chars[index + i]); + for(int i = 0; i < count; i++) bytes[i] = GetByte(chars[index + i]); return bytes; } /// - /// Encodes all the characters in the specified character array into a sequence of bytes. + /// Encodes all the characters in the specified character array into a sequence of bytes. /// /// A byte array containing the results of encoding the specified set of characters. /// The character array containing the characters to encode. @@ -292,7 +318,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. + /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -302,7 +328,7 @@ namespace Claunia.Encoding } /// - /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. + /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. /// /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -310,23 +336,19 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override int GetCharCount(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); return count; } /// - /// Decodes a sequence of bytes from the specified byte array into the specified character array. + /// Decodes a sequence of bytes from the specified byte array into the specified character array. /// /// The actual number of characters written into chars. /// The byte array containing the sequence of bytes to decode. @@ -336,43 +358,33 @@ namespace Claunia.Encoding /// The index at which to start writing the resulting set of characters. public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(chars == null) - throw new ArgumentNullException(nameof(chars)); + if(chars == null) throw new ArgumentNullException(nameof(chars)); - if(byteIndex < 0) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex < 0) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(byteIndex >= bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteIndex)); + if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex)); - if(byteCount + byteIndex > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount + byteIndex > bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteCount)); - if(charIndex >= chars.Length) - throw new ArgumentOutOfRangeException(nameof(charIndex)); + if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex)); - if(charIndex + byteCount > chars.Length) - throw new ArgumentException(nameof(chars)); + if(charIndex + byteCount > chars.Length) throw new ArgumentException(nameof(chars)); char[] temp = GetChars(bytes, byteIndex, byteCount); - for(int i = 0; i < temp.Length; i++) - chars[i + charIndex] = temp[i]; + for(int i = 0; i < temp.Length; i++) chars[i + charIndex] = temp[i]; return byteCount; } /// - /// Decodes all the bytes in the specified byte array into a set of characters. + /// Decodes all the bytes in the specified byte array into a set of characters. /// /// A character array containing the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -382,7 +394,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a set of characters. + /// Decodes a sequence of bytes from the specified byte array into a set of characters. /// /// The chars. /// The byte array containing the sequence of bytes to decode. @@ -390,54 +402,47 @@ namespace Claunia.Encoding /// The number of bytes to decode. public override char[] GetChars(byte[] bytes, int index, int count) { - if(bytes == null) - throw new ArgumentNullException(nameof(bytes)); + if(bytes == null) throw new ArgumentNullException(nameof(bytes)); - if(index < 0) - throw new ArgumentOutOfRangeException(nameof(index)); + if(index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - if(count < 0) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - if(count + index > bytes.Length) - throw new ArgumentOutOfRangeException(nameof(count)); + if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count)); char[] chars = new char[count]; - for(int i = 0; i < count; i++) - chars[i] = GetChar(bytes[index + i]); + for(int i = 0; i < count; i++) chars[i] = GetChar(bytes[index + i]); return chars; } /// - /// Calculates the maximum number of bytes produced by encoding the specified number of characters. + /// Calculates the maximum number of bytes produced by encoding the specified number of characters. /// /// The maximum number of bytes produced by encoding the specified number of characters. /// The number of characters to encode. public override int GetMaxByteCount(int charCount) { - if(charCount < 0) - throw new ArgumentOutOfRangeException(nameof(charCount)); + if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount)); return charCount; } /// - /// Calculates the maximum number of characters produced by decoding the specified number of bytes. + /// Calculates the maximum number of characters produced by decoding the specified number of bytes. /// /// The maximum number of characters produced by decoding the specified number of bytes. /// The number of bytes to decode. public override int GetMaxCharCount(int byteCount) { - if(byteCount < 0) - throw new ArgumentOutOfRangeException(nameof(byteCount)); + if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount)); return byteCount; } /// - /// Returns a sequence of bytes that specifies the encoding used. + /// Returns a sequence of bytes that specifies the encoding used. /// /// A byte array of length zero, as a preamble is not required. public override byte[] GetPreamble() @@ -446,7 +451,7 @@ namespace Claunia.Encoding } /// - /// Decodes all the bytes in the specified byte array into a string. + /// Decodes all the bytes in the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -456,7 +461,7 @@ namespace Claunia.Encoding } /// - /// Decodes a sequence of bytes from the specified byte array into a string. + /// Decodes a sequence of bytes from the specified byte array into a string. /// /// A string that contains the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. @@ -468,77 +473,7 @@ namespace Claunia.Encoding } /// - /// The ZX Spectrum to Unicode character map. - /// - static readonly char[] ZXSpectrumTable = { - // 0x00 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0009','\u0000', - // 0x08 - '\uFFFF','\uFFFF','\u0000','\u0000','\u0000','\u000D','\uFFFF','\u0000', - // 0x10 - '\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\u0009', - // 0x18 - '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', - // 0x20 - '\u0020','\u0021','\u0022','\u0023','\u0024','\u0025','\u0026','\u0027', - // 0x28 - '\u0028','\u0029','\u002A','\u002B','\u002C','\u002D','\u002E','\u002F', - // 0x30 - '\u0030','\u0031','\u0032','\u0033','\u0034','\u0035','\u0036','\u0037', - // 0x38 - '\u0038','\u0039','\u003A','\u003B','\u003C','\u003D','\u003E','\u003F', - // 0x40 - '\u0040','\u0041','\u0042','\u0043','\u0044','\u0045','\u0046','\u0047', - // 0x48 - '\u0048','\u0049','\u004A','\u004B','\u004C','\u004D','\u004E','\u004F', - // 0x50 - '\u0050','\u0051','\u0052','\u0053','\u0054','\u0055','\u0056','\u0057', - // 0x58 - '\u0058','\u0059','\u005A','\u005B','\u005C','\u005D','\u2191','\u005F', - // 0x60 - '\u00A3','\u0061','\u0062','\u0063','\u0064','\u0065','\u0066','\u0067', - // 0x68 - '\u0068','\u0069','\u006A','\u006B','\u006C','\u006D','\u006E','\u006F', - // 0x70 - '\u0070','\u0071','\u0072','\u0073','\u0074','\u0075','\u0076','\u0077', - // 0x78 - '\u0078','\u0079','\u007A','\u007B','\u007C','\u007D','\u007E','\u00A9', - // 0x80 - '\u0020','\u259D','\u2598','\u2580','\u2597','\u2590','\u259A','\u259C', - // 0x88 - '\u2596','\u259E','\u258C','\u259B','\u2584','\u259F','\u2599','\u2588', - // 0x90 - '\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD', - // 0x98 - '\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD', - // 0xA0 - '\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFF','\uFFFF','\uFFFF', - // 0xA8 - '\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF', - // 0xB0 - '\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF', - // 0xB8 - '\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF', - // 0xC0 - '\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF', - // 0xC8 - '\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF', - // 0xD0 - '\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF', - // 0xD8 - '\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF', - // 0xE0 - '\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF', - // 0xE8 - '\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF', - // 0xF0 - '\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF', - // 0xF8 - '\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF' - }; - - /// - /// Converts a ZX Spectrum character to an Unicode character + /// Converts a ZX Spectrum character to an Unicode character /// /// Unicode character. /// ZX Spectrum character. @@ -548,239 +483,127 @@ namespace Claunia.Encoding } /// - /// Converts a Unicode character to an ZX Spectrum character + /// Converts a Unicode character to an ZX Spectrum character /// /// ZX Spectrum character. /// Unicode character. static byte GetByte(char character) { - switch(character) { - case '\u0009': - return 0x06; - case '\u000D': - return 0x0D; - case '\u0020': - return 0x20; - case '\u0021': - return 0x21; - case '\u0022': - return 0x22; - case '\u0023': - return 0x23; - case '\u0024': - return 0x24; - case '\u0025': - return 0x25; - case '\u0026': - return 0x26; - case '\u0027': - return 0x27; - case '\u0028': - return 0x28; - case '\u0029': - return 0x29; - case '\u002A': - return 0x2A; - case '\u002B': - return 0x2B; - case '\u002C': - return 0x2C; - case '\u002D': - return 0x2D; - case '\u002E': - return 0x2E; - case '\u002F': - return 0x2F; - case '\u0030': - return 0x30; - case '\u0031': - return 0x31; - case '\u0032': - return 0x32; - case '\u0033': - return 0x33; - case '\u0034': - return 0x34; - case '\u0035': - return 0x35; - case '\u0036': - return 0x36; - case '\u0037': - return 0x37; - case '\u0038': - return 0x38; - case '\u0039': - return 0x39; - case '\u003A': - return 0x3A; - case '\u003B': - return 0x3B; - case '\u003C': - return 0x3C; - case '\u003D': - return 0x3D; - case '\u003E': - return 0x3E; - case '\u003F': - return 0x3F; - case '\u0040': - return 0x40; - case '\u0041': - return 0x41; - case '\u0042': - return 0x42; - case '\u0043': - return 0x43; - case '\u0044': - return 0x44; - case '\u0045': - return 0x45; - case '\u0046': - return 0x46; - case '\u0047': - return 0x47; - case '\u0048': - return 0x48; - case '\u0049': - return 0x49; - case '\u004A': - return 0x4A; - case '\u004B': - return 0x4B; - case '\u004C': - return 0x4C; - case '\u004D': - return 0x4D; - case '\u004E': - return 0x4E; - case '\u004F': - return 0x4F; - case '\u0050': - return 0x50; - case '\u0051': - return 0x51; - case '\u0052': - return 0x52; - case '\u0053': - return 0x53; - case '\u0054': - return 0x54; - case '\u0055': - return 0x55; - case '\u0056': - return 0x56; - case '\u0057': - return 0x57; - case '\u0058': - return 0x58; - case '\u0059': - return 0x59; - case '\u005A': - return 0x5A; - case '\u005B': - return 0x5B; - case '\u005C': - return 0x5C; - case '\u005D': - return 0x5D; - case '\u2191': - return 0x5E; - case '\u005F': - return 0x5F; - case '\u00A3': - return 0x60; - case '\u0061': - return 0x61; - case '\u0062': - return 0x62; - case '\u0063': - return 0x63; - case '\u0064': - return 0x64; - case '\u0065': - return 0x65; - case '\u0066': - return 0x66; - case '\u0067': - return 0x67; - case '\u0068': - return 0x68; - case '\u0069': - return 0x69; - case '\u006A': - return 0x6A; - case '\u006B': - return 0x6B; - case '\u006C': - return 0x6C; - case '\u006D': - return 0x6D; - case '\u006E': - return 0x6E; - case '\u006F': - return 0x6F; - case '\u0070': - return 0x70; - case '\u0071': - return 0x71; - case '\u0072': - return 0x72; - case '\u0073': - return 0x73; - case '\u0074': - return 0x74; - case '\u0075': - return 0x75; - case '\u0076': - return 0x76; - case '\u0077': - return 0x77; - case '\u0078': - return 0x78; - case '\u0079': - return 0x79; - case '\u007A': - return 0x7A; - case '\u007B': - return 0x7B; - case '\u007C': - return 0x7C; - case '\u007D': - return 0x7D; - case '\u007E': - return 0x7E; - case '\u00A9': - return 0x7F; - case '\u259D': - return 0x81; - case '\u2598': - return 0x82; - case '\u2580': - return 0x83; - case '\u2597': - return 0x84; - case '\u2590': - return 0x85; - case '\u259A': - return 0x86; - case '\u259C': - return 0x87; - case '\u2596': - return 0x88; - case '\u259E': - return 0x89; - case '\u258C': - return 0x8A; - case '\u259B': - return 0x8B; - case '\u2584': - return 0x8C; - case '\u259F': - return 0x8D; - case '\u2599': - return 0x8E; - case '\u2588': - return 0x8F; + switch(character) + { + case '\u0009': return 0x06; + case '\u000D': return 0x0D; + case '\u0020': return 0x20; + case '\u0021': return 0x21; + case '\u0022': return 0x22; + case '\u0023': return 0x23; + case '\u0024': return 0x24; + case '\u0025': return 0x25; + case '\u0026': return 0x26; + case '\u0027': return 0x27; + case '\u0028': return 0x28; + case '\u0029': return 0x29; + case '\u002A': return 0x2A; + case '\u002B': return 0x2B; + case '\u002C': return 0x2C; + case '\u002D': return 0x2D; + case '\u002E': return 0x2E; + case '\u002F': return 0x2F; + case '\u0030': return 0x30; + case '\u0031': return 0x31; + case '\u0032': return 0x32; + case '\u0033': return 0x33; + case '\u0034': return 0x34; + case '\u0035': return 0x35; + case '\u0036': return 0x36; + case '\u0037': return 0x37; + case '\u0038': return 0x38; + case '\u0039': return 0x39; + case '\u003A': return 0x3A; + case '\u003B': return 0x3B; + case '\u003C': return 0x3C; + case '\u003D': return 0x3D; + case '\u003E': return 0x3E; + case '\u003F': return 0x3F; + case '\u0040': return 0x40; + case '\u0041': return 0x41; + case '\u0042': return 0x42; + case '\u0043': return 0x43; + case '\u0044': return 0x44; + case '\u0045': return 0x45; + case '\u0046': return 0x46; + case '\u0047': return 0x47; + case '\u0048': return 0x48; + case '\u0049': return 0x49; + case '\u004A': return 0x4A; + case '\u004B': return 0x4B; + case '\u004C': return 0x4C; + case '\u004D': return 0x4D; + case '\u004E': return 0x4E; + case '\u004F': return 0x4F; + case '\u0050': return 0x50; + case '\u0051': return 0x51; + case '\u0052': return 0x52; + case '\u0053': return 0x53; + case '\u0054': return 0x54; + case '\u0055': return 0x55; + case '\u0056': return 0x56; + case '\u0057': return 0x57; + case '\u0058': return 0x58; + case '\u0059': return 0x59; + case '\u005A': return 0x5A; + case '\u005B': return 0x5B; + case '\u005C': return 0x5C; + case '\u005D': return 0x5D; + case '\u2191': return 0x5E; + case '\u005F': return 0x5F; + case '\u00A3': return 0x60; + case '\u0061': return 0x61; + case '\u0062': return 0x62; + case '\u0063': return 0x63; + case '\u0064': return 0x64; + case '\u0065': return 0x65; + case '\u0066': return 0x66; + case '\u0067': return 0x67; + case '\u0068': return 0x68; + case '\u0069': return 0x69; + case '\u006A': return 0x6A; + case '\u006B': return 0x6B; + case '\u006C': return 0x6C; + case '\u006D': return 0x6D; + case '\u006E': return 0x6E; + case '\u006F': return 0x6F; + case '\u0070': return 0x70; + case '\u0071': return 0x71; + case '\u0072': return 0x72; + case '\u0073': return 0x73; + case '\u0074': return 0x74; + case '\u0075': return 0x75; + case '\u0076': return 0x76; + case '\u0077': return 0x77; + case '\u0078': return 0x78; + case '\u0079': return 0x79; + case '\u007A': return 0x7A; + case '\u007B': return 0x7B; + case '\u007C': return 0x7C; + case '\u007D': return 0x7D; + case '\u007E': return 0x7E; + case '\u00A9': return 0x7F; + case '\u259D': return 0x81; + case '\u2598': return 0x82; + case '\u2580': return 0x83; + case '\u2597': return 0x84; + case '\u2590': return 0x85; + case '\u259A': return 0x86; + case '\u259C': return 0x87; + case '\u2596': return 0x88; + case '\u259E': return 0x89; + case '\u258C': return 0x8A; + case '\u259B': return 0x8B; + case '\u2584': return 0x8C; + case '\u259F': return 0x8D; + case '\u2599': return 0x8E; + case '\u2588': return 0x8F; default: // Fallback to '?' return 0x3F;