Refactor and code cleanup.

This commit is contained in:
2017-12-26 18:45:47 +00:00
parent d292daec2b
commit 88ee61203c
25 changed files with 7710 additions and 13130 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -29,7 +29,7 @@ using System;
namespace Claunia.Encoding namespace Claunia.Encoding
{ {
/// <summary> /// <summary>
/// Represents an Apple II character encoding of Unicode characters. /// Represents an Apple II character encoding of Unicode characters.
/// </summary> /// </summary>
public class Apple2 : Encoding public class Apple2 : Encoding
{ {
@@ -48,105 +48,151 @@ namespace Claunia.Encoding
const bool singleByte = true; const bool singleByte = true;
/// <summary> /// <summary>
/// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. /// The Apple II to Unicode character map.
/// </summary> /// </summary>
public override bool IsBrowserDisplay { static readonly char[] Apple2Table =
get { return browserDisplay; } {
} // 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'
};
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override bool IsBrowserSave { public override bool IsBrowserDisplay => browserDisplay;
get { return browserSave; }
}
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override bool IsMailNewsDisplay { public override bool IsBrowserSave => browserSave;
get { return mailNewsDisplay; }
}
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override bool IsMailNewsSave { public override bool IsMailNewsDisplay => mailNewsDisplay;
get { return mailNewsSave; }
}
/// <summary> /// <summary>
/// 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.
/// </summary>
public override bool IsMailNewsSave => mailNewsSave;
/// <summary>
/// Gets a value indicating whether the current encoding is read-only.
/// </summary> /// </summary>
/// <value>The is single byte.</value> /// <value>The is single byte.</value>
public override bool IsReadOnly { public override bool IsReadOnly => readOnly;
get { return readOnly; }
}
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override bool IsSingleByte { public override bool IsSingleByte => singleByte;
get { return singleByte; }
}
/// <summary> /// <summary>
/// Gets the code page identifier of the current Encoding. /// Gets the code page identifier of the current Encoding.
/// </summary> /// </summary>
public override int CodePage { public override int CodePage => _codepage;
get { return _codepage; }
}
/// <summary> /// <summary>
/// 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
/// </summary> /// </summary>
public override string BodyName { public override string BodyName => _bodyname;
get { return _bodyname; }
}
/// <summary> /// <summary>
/// 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
/// </summary> /// </summary>
public override string HeaderName { public override string HeaderName => _headername;
get { return _headername; }
}
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override string WebName { public override string WebName => _webname;
get { return _webname; }
}
/// <summary> /// <summary>
/// Gets the human-readable description of the current encoding. /// Gets the human-readable description of the current encoding.
/// </summary> /// </summary>
public override string EncodingName { public override string EncodingName => _encodingname;
get { return _encodingname; }
}
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override int WindowsCodePage { public override int WindowsCodePage => _windowsCodepage;
get { return _windowsCodepage; }
}
/// <summary> /// <summary>
/// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string"/>. /// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string" />.
/// </summary> /// </summary>
/// <returns>The number of bytes produced by encoding the specified characters.</returns> /// <returns>The number of bytes produced by encoding the specified characters.</returns>
/// <param name="s">The <see cref="string"/> containing the set of characters to encode.</param> /// <param name="s">The <see cref="string" /> containing the set of characters to encode.</param>
public override int GetByteCount(string s) public override int GetByteCount(string s)
{ {
if(s == null) if(s == null) throw new ArgumentNullException(nameof(s));
throw new ArgumentNullException(nameof(s));
return s.Length; return s.Length;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The number of bytes produced by encoding the specified characters.</returns> /// <returns>The number of bytes produced by encoding the specified characters.</returns>
/// <param name="chars">The character array containing the set of characters to encode.</param> /// <param name="chars">The character array containing the set of characters to encode.</param>
@@ -154,36 +200,32 @@ namespace Claunia.Encoding
/// <param name="count">The number of characters to encode.</param> /// <param name="count">The number of characters to encode.</param>
public override int GetByteCount(char[] chars, int index, int count) public override int GetByteCount(char[] chars, int index, int count)
{ {
if(chars == null) if(chars == null) throw new ArgumentNullException(nameof(chars));
throw new ArgumentNullException(nameof(chars));
if(index < 0 || index >= chars.Length) if(index < 0 || index >= chars.Length) throw new ArgumentOutOfRangeException(nameof(index));
throw new ArgumentOutOfRangeException(nameof(index));
if(count < 0 || index + count > chars.Length) if(count < 0 || index + count > chars.Length) throw new ArgumentOutOfRangeException(nameof(index));
throw new ArgumentOutOfRangeException(nameof(index));
return count; return count;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The number of bytes produced by encoding all the characters in the specified character array.</returns> /// <returns>The number of bytes produced by encoding all the characters in the specified character array.</returns>
/// <param name="chars">The character array containing the characters to encode.</param> /// <param name="chars">The character array containing the characters to encode.</param>
public override int GetByteCount(char[] chars) public override int GetByteCount(char[] chars)
{ {
if(chars == null) if(chars == null) throw new ArgumentNullException(nameof(chars));
throw new ArgumentNullException(nameof(chars));
return chars.Length; return chars.Length;
} }
/// <summary> /// <summary>
/// Encodes a set of characters from the specified <see cref="string"/> into the specified byte array. /// Encodes a set of characters from the specified <see cref="string" /> into the specified byte array.
/// </summary> /// </summary>
/// <returns>The actual number of bytes written into bytes.</returns> /// <returns>The actual number of bytes written into bytes.</returns>
/// <param name="s">The <see cref="string"/> containing the set of characters to encode.</param> /// <param name="s">The <see cref="string" /> containing the set of characters to encode.</param>
/// <param name="charIndex">The index of the first character to encode.</param> /// <param name="charIndex">The index of the first character to encode.</param>
/// <param name="charCount">The number of characters to encode.</param> /// <param name="charCount">The number of characters to encode.</param>
/// <param name="bytes">The byte array to contain the resulting sequence of bytes.</param> /// <param name="bytes">The byte array to contain the resulting sequence of bytes.</param>
@@ -194,20 +236,19 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>A byte array containing the results of encoding the specified set of characters.</returns> /// <returns>A byte array containing the results of encoding the specified set of characters.</returns>
/// <param name="s">The string containing the characters to encode.</param> /// <param name="s">The string containing the characters to encode.</param>
public override byte[] GetBytes(string s) public override byte[] GetBytes(string s)
{ {
if(s == null) if(s == null) throw new ArgumentNullException(nameof(s));
throw new ArgumentNullException(nameof(s));
return GetBytes(s.ToCharArray(), 0, s.Length); return GetBytes(s.ToCharArray(), 0, s.Length);
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The actual number of bytes written into bytes.</returns> /// <returns>The actual number of bytes written into bytes.</returns>
/// <param name="chars">The character array containing the set of characters to encode.</param> /// <param name="chars">The character array containing the set of characters to encode.</param>
@@ -217,43 +258,33 @@ namespace Claunia.Encoding
/// <param name="byteIndex">The index at which to start writing the resulting sequence of bytes.</param> /// <param name="byteIndex">The index at which to start writing the resulting sequence of bytes.</param>
public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
{ {
if(chars == null) if(chars == null) throw new ArgumentNullException(nameof(chars));
throw new ArgumentNullException(nameof(chars));
if(bytes == null) if(bytes == null) throw new ArgumentNullException(nameof(bytes));
throw new ArgumentNullException(nameof(bytes));
if(charIndex < 0) if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex));
throw new ArgumentOutOfRangeException(nameof(charIndex));
if(charCount < 0) if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount));
throw new ArgumentOutOfRangeException(nameof(charCount));
if(byteIndex < 0) if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex));
throw new ArgumentOutOfRangeException(nameof(byteIndex));
if(charIndex >= chars.Length) if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex));
throw new ArgumentOutOfRangeException(nameof(charIndex));
if(charCount + charIndex > chars.Length) if(charCount + charIndex > chars.Length) throw new ArgumentOutOfRangeException(nameof(charCount));
throw new ArgumentOutOfRangeException(nameof(charCount));
if(byteIndex >= bytes.Length) if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex));
throw new ArgumentOutOfRangeException(nameof(byteIndex));
if(byteIndex + charCount > bytes.Length) if(byteIndex + charCount > bytes.Length) throw new ArgumentException(nameof(bytes));
throw new ArgumentException(nameof(bytes));
byte[] temp = GetBytes(chars, charIndex, charCount); byte[] temp = GetBytes(chars, charIndex, charCount);
for(int i = 0; i < temp.Length; i++) for(int i = 0; i < temp.Length; i++) bytes[i + byteIndex] = temp[i];
bytes[i + byteIndex] = temp[i];
return charCount; return charCount;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>A byte array containing the results of encoding the specified set of characters.</returns> /// <returns>A byte array containing the results of encoding the specified set of characters.</returns>
/// <param name="chars">The character array containing the set of characters to encode.</param> /// <param name="chars">The character array containing the set of characters to encode.</param>
@@ -261,28 +292,23 @@ namespace Claunia.Encoding
/// <param name="count">The number of characters to encode.</param> /// <param name="count">The number of characters to encode.</param>
public override byte[] GetBytes(char[] chars, int index, int count) public override byte[] GetBytes(char[] chars, int index, int count)
{ {
if(chars == null) if(chars == null) throw new ArgumentNullException(nameof(chars));
throw new ArgumentNullException(nameof(chars));
if(index < 0) if(index < 0) throw new ArgumentOutOfRangeException(nameof(index));
throw new ArgumentOutOfRangeException(nameof(index));
if(count < 0) if(count < 0) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
if(count + index > chars.Length) if(count + index > chars.Length) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
byte[] bytes = new byte[count]; byte[] bytes = new byte[count];
for(int i = 0; i < count; i++) for(int i = 0; i < count; i++) bytes[i] = GetByte(chars[index + i]);
bytes[i] = GetByte(chars[index + i]);
return bytes; return bytes;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>A byte array containing the results of encoding the specified set of characters.</returns> /// <returns>A byte array containing the results of encoding the specified set of characters.</returns>
/// <param name="chars">The character array containing the characters to encode.</param> /// <param name="chars">The character array containing the characters to encode.</param>
@@ -292,7 +318,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The number of characters produced by decoding the specified sequence of bytes.</returns> /// <returns>The number of characters produced by decoding the specified sequence of bytes.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -302,7 +328,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The number of characters produced by decoding the specified sequence of bytes.</returns> /// <returns>The number of characters produced by decoding the specified sequence of bytes.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -310,23 +336,19 @@ namespace Claunia.Encoding
/// <param name="count">The number of bytes to decode.</param> /// <param name="count">The number of bytes to decode.</param>
public override int GetCharCount(byte[] bytes, int index, int count) public override int GetCharCount(byte[] bytes, int index, int count)
{ {
if(bytes == null) if(bytes == null) throw new ArgumentNullException(nameof(bytes));
throw new ArgumentNullException(nameof(bytes));
if(index < 0) if(index < 0) throw new ArgumentOutOfRangeException(nameof(index));
throw new ArgumentOutOfRangeException(nameof(index));
if(count < 0) if(count < 0) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
if(count + index > bytes.Length) if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
return count; return count;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The actual number of characters written into chars.</returns> /// <returns>The actual number of characters written into chars.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -336,43 +358,33 @@ namespace Claunia.Encoding
/// <param name="charIndex">The index at which to start writing the resulting set of characters.</param> /// <param name="charIndex">The index at which to start writing the resulting set of characters.</param>
public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
{ {
if(bytes == null) if(bytes == null) throw new ArgumentNullException(nameof(bytes));
throw new ArgumentNullException(nameof(bytes));
if(chars == null) if(chars == null) throw new ArgumentNullException(nameof(chars));
throw new ArgumentNullException(nameof(chars));
if(byteIndex < 0) if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex));
throw new ArgumentOutOfRangeException(nameof(byteIndex));
if(byteCount < 0) if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount));
throw new ArgumentOutOfRangeException(nameof(byteCount));
if(charIndex < 0) if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex));
throw new ArgumentOutOfRangeException(nameof(charIndex));
if(byteIndex >= bytes.Length) if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex));
throw new ArgumentOutOfRangeException(nameof(byteIndex));
if(byteCount + byteIndex > bytes.Length) if(byteCount + byteIndex > bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteCount));
throw new ArgumentOutOfRangeException(nameof(byteCount));
if(charIndex >= chars.Length) if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex));
throw new ArgumentOutOfRangeException(nameof(charIndex));
if(charIndex + byteCount > chars.Length) if(charIndex + byteCount > chars.Length) throw new ArgumentException(nameof(chars));
throw new ArgumentException(nameof(chars));
char[] temp = GetChars(bytes, byteIndex, byteCount); char[] temp = GetChars(bytes, byteIndex, byteCount);
for(int i = 0; i < temp.Length; i++) for(int i = 0; i < temp.Length; i++) chars[i + charIndex] = temp[i];
chars[i + charIndex] = temp[i];
return byteCount; return byteCount;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>A character array containing the results of decoding the specified sequence of bytes.</returns> /// <returns>A character array containing the results of decoding the specified sequence of bytes.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -382,7 +394,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The chars.</returns> /// <returns>The chars.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -390,54 +402,47 @@ namespace Claunia.Encoding
/// <param name="count">The number of bytes to decode.</param> /// <param name="count">The number of bytes to decode.</param>
public override char[] GetChars(byte[] bytes, int index, int count) public override char[] GetChars(byte[] bytes, int index, int count)
{ {
if(bytes == null) if(bytes == null) throw new ArgumentNullException(nameof(bytes));
throw new ArgumentNullException(nameof(bytes));
if(index < 0) if(index < 0) throw new ArgumentOutOfRangeException(nameof(index));
throw new ArgumentOutOfRangeException(nameof(index));
if(count < 0) if(count < 0) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
if(count + index > bytes.Length) if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
char[] chars = new char[count]; char[] chars = new char[count];
for(int i = 0; i < count; i++) for(int i = 0; i < count; i++) chars[i] = GetChar(bytes[index + i]);
chars[i] = GetChar(bytes[index + i]);
return chars; return chars;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The maximum number of bytes produced by encoding the specified number of characters.</returns> /// <returns>The maximum number of bytes produced by encoding the specified number of characters.</returns>
/// <param name="charCount">The number of characters to encode.</param> /// <param name="charCount">The number of characters to encode.</param>
public override int GetMaxByteCount(int charCount) public override int GetMaxByteCount(int charCount)
{ {
if(charCount < 0) if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount));
throw new ArgumentOutOfRangeException(nameof(charCount));
return charCount; return charCount;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The maximum number of characters produced by decoding the specified number of bytes.</returns> /// <returns>The maximum number of characters produced by decoding the specified number of bytes.</returns>
/// <param name="byteCount">The number of bytes to decode.</param> /// <param name="byteCount">The number of bytes to decode.</param>
public override int GetMaxCharCount(int byteCount) public override int GetMaxCharCount(int byteCount)
{ {
if(byteCount < 0) if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount));
throw new ArgumentOutOfRangeException(nameof(byteCount));
return byteCount; return byteCount;
} }
/// <summary> /// <summary>
/// Returns a sequence of bytes that specifies the encoding used. /// Returns a sequence of bytes that specifies the encoding used.
/// </summary> /// </summary>
/// <returns>A byte array of length zero, as a preamble is not required.</returns> /// <returns>A byte array of length zero, as a preamble is not required.</returns>
public override byte[] GetPreamble() public override byte[] GetPreamble()
@@ -446,7 +451,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// Decodes all the bytes in the specified byte array into a string. /// Decodes all the bytes in the specified byte array into a string.
/// </summary> /// </summary>
/// <returns>A string that contains the results of decoding the specified sequence of bytes.</returns> /// <returns>A string that contains the results of decoding the specified sequence of bytes.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -456,7 +461,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>A string that contains the results of decoding the specified sequence of bytes.</returns> /// <returns>A string that contains the results of decoding the specified sequence of bytes.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -468,77 +473,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// The Apple II to Unicode character map. /// Converts a Apple II character to an Unicode character
/// </summary>
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',
};
/// <summary>
/// Converts a Apple II character to an Unicode character
/// </summary> /// </summary>
/// <returns>Unicode character.</returns> /// <returns>Unicode character.</returns>
/// <param name="character">Apple II character.</param> /// <param name="character">Apple II character.</param>
@@ -548,145 +483,82 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// Converts a Unicode character to an Apple II character /// Converts a Unicode character to an Apple II character
/// </summary> /// </summary>
/// <returns>Apple II character.</returns> /// <returns>Apple II character.</returns>
/// <param name="character">Unicode character.</param> /// <param name="character">Unicode character.</param>
static byte GetByte(char character) static byte GetByte(char character)
{ {
switch(character) { switch(character)
case '\u0020': {
return 0x20; case '\u0020': return 0x20;
case '\u0021': case '\u0021': return 0x21;
return 0x21; case '\u0022': return 0x22;
case '\u0022': case '\u0023': return 0x23;
return 0x22; case '\u0024': return 0x24;
case '\u0023': case '\u0025': return 0x25;
return 0x23; case '\u0026': return 0x26;
case '\u0024': case '\u0027': return 0x27;
return 0x24; case '\u0028': return 0x28;
case '\u0025': case '\u0029': return 0x29;
return 0x25; case '\u002A': return 0x2A;
case '\u0026': case '\u002B': return 0x2B;
return 0x26; case '\u002C': return 0x2C;
case '\u0027': case '\u002D': return 0x2D;
return 0x27; case '\u002E': return 0x2E;
case '\u0028': case '\u002F': return 0x2F;
return 0x28; case '\u0030': return 0x30;
case '\u0029': case '\u0031': return 0x31;
return 0x29; case '\u0032': return 0x32;
case '\u002A': case '\u0033': return 0x33;
return 0x2A; case '\u0034': return 0x34;
case '\u002B': case '\u0035': return 0x35;
return 0x2B; case '\u0036': return 0x36;
case '\u002C': case '\u0037': return 0x37;
return 0x2C; case '\u0038': return 0x38;
case '\u002D': case '\u0039': return 0x39;
return 0x2D; case '\u003A': return 0x3A;
case '\u002E': case '\u003B': return 0x3B;
return 0x2E; case '\u003C': return 0x3C;
case '\u002F': case '\u003D': return 0x3D;
return 0x2F; case '\u003E': return 0x3E;
case '\u0030': case '\u003F': return 0x3F;
return 0x30; case '\u0040': return 0x40;
case '\u0031': case '\u0041': return 0x41;
return 0x31; case '\u0042': return 0x42;
case '\u0032': case '\u0043': return 0x43;
return 0x32; case '\u0044': return 0x44;
case '\u0033': case '\u0045': return 0x45;
return 0x33; case '\u0046': return 0x46;
case '\u0034': case '\u0047': return 0x47;
return 0x34; case '\u0048': return 0x48;
case '\u0035': case '\u0049': return 0x49;
return 0x35; case '\u004A': return 0x4A;
case '\u0036': case '\u004B': return 0x4B;
return 0x36; case '\u004C': return 0x4C;
case '\u0037': case '\u004D': return 0x4D;
return 0x37; case '\u004E': return 0x4E;
case '\u0038': case '\u004F': return 0x4F;
return 0x38; case '\u0050': return 0x50;
case '\u0039': case '\u0051': return 0x51;
return 0x39; case '\u0052': return 0x52;
case '\u003A': case '\u0053': return 0x53;
return 0x3A; case '\u0054': return 0x54;
case '\u003B': case '\u0055': return 0x55;
return 0x3B; case '\u0056': return 0x56;
case '\u003C': case '\u0057': return 0x57;
return 0x3C; case '\u0058': return 0x58;
case '\u003D': case '\u0059': return 0x59;
return 0x3D; case '\u005A': return 0x5A;
case '\u003E': case '\u005B': return 0x5B;
return 0x3E; case '\u005C': return 0x5C;
case '\u003F': case '\u005D': return 0x5D;
return 0x3F; case '\u005E': return 0x5E;
case '\u0040': case '\u005F': return 0x5F;
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: default:
// Fallback to '?' // Fallback to '?'
return 0x3F; return 0x3F;
} }
} }
} }
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -29,7 +29,7 @@ using System;
namespace Claunia.Encoding namespace Claunia.Encoding
{ {
/// <summary> /// <summary>
/// Represents an Apple IIgs character encoding of Unicode characters. /// Represents an Apple IIgs character encoding of Unicode characters.
/// </summary> /// </summary>
public class Apple2gs : Encoding public class Apple2gs : Encoding
{ {
@@ -48,105 +48,152 @@ namespace Claunia.Encoding
const bool singleByte = true; const bool singleByte = true;
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override bool IsBrowserDisplay { static readonly char[] Apple2gsTable =
get { return browserDisplay; } {
} // 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'
};
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override bool IsBrowserSave { public override bool IsBrowserDisplay => browserDisplay;
get { return browserSave; }
}
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override bool IsMailNewsDisplay { public override bool IsBrowserSave => browserSave;
get { return mailNewsDisplay; }
}
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override bool IsMailNewsSave { public override bool IsMailNewsDisplay => mailNewsDisplay;
get { return mailNewsSave; }
}
/// <summary> /// <summary>
/// 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.
/// </summary>
public override bool IsMailNewsSave => mailNewsSave;
/// <summary>
/// Gets a value indicating whether the current encoding is read-only.
/// </summary> /// </summary>
/// <value>The is single byte.</value> /// <value>The is single byte.</value>
public override bool IsReadOnly { public override bool IsReadOnly => readOnly;
get { return readOnly; }
}
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override bool IsSingleByte { public override bool IsSingleByte => singleByte;
get { return singleByte; }
}
/// <summary> /// <summary>
/// Gets the code page identifier of the current Encoding. /// Gets the code page identifier of the current Encoding.
/// </summary> /// </summary>
public override int CodePage { public override int CodePage => _codepage;
get { return _codepage; }
}
/// <summary> /// <summary>
/// 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
/// </summary> /// </summary>
public override string BodyName { public override string BodyName => _bodyname;
get { return _bodyname; }
}
/// <summary> /// <summary>
/// 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
/// </summary> /// </summary>
public override string HeaderName { public override string HeaderName => _headername;
get { return _headername; }
}
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override string WebName { public override string WebName => _webname;
get { return _webname; }
}
/// <summary> /// <summary>
/// Gets the human-readable description of the current encoding. /// Gets the human-readable description of the current encoding.
/// </summary> /// </summary>
public override string EncodingName { public override string EncodingName => _encodingname;
get { return _encodingname; }
}
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override int WindowsCodePage { public override int WindowsCodePage => _windowsCodepage;
get { return _windowsCodepage; }
}
/// <summary> /// <summary>
/// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string"/>. /// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string" />.
/// </summary> /// </summary>
/// <returns>The number of bytes produced by encoding the specified characters.</returns> /// <returns>The number of bytes produced by encoding the specified characters.</returns>
/// <param name="s">The <see cref="string"/> containing the set of characters to encode.</param> /// <param name="s">The <see cref="string" /> containing the set of characters to encode.</param>
public override int GetByteCount(string s) public override int GetByteCount(string s)
{ {
if(s == null) if(s == null) throw new ArgumentNullException(nameof(s));
throw new ArgumentNullException(nameof(s));
return s.Length; return s.Length;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The number of bytes produced by encoding the specified characters.</returns> /// <returns>The number of bytes produced by encoding the specified characters.</returns>
/// <param name="chars">The character array containing the set of characters to encode.</param> /// <param name="chars">The character array containing the set of characters to encode.</param>
@@ -154,36 +201,32 @@ namespace Claunia.Encoding
/// <param name="count">The number of characters to encode.</param> /// <param name="count">The number of characters to encode.</param>
public override int GetByteCount(char[] chars, int index, int count) public override int GetByteCount(char[] chars, int index, int count)
{ {
if(chars == null) if(chars == null) throw new ArgumentNullException(nameof(chars));
throw new ArgumentNullException(nameof(chars));
if(index < 0 || index >= chars.Length) if(index < 0 || index >= chars.Length) throw new ArgumentOutOfRangeException(nameof(index));
throw new ArgumentOutOfRangeException(nameof(index));
if(count < 0 || index + count > chars.Length) if(count < 0 || index + count > chars.Length) throw new ArgumentOutOfRangeException(nameof(index));
throw new ArgumentOutOfRangeException(nameof(index));
return count; return count;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The number of bytes produced by encoding all the characters in the specified character array.</returns> /// <returns>The number of bytes produced by encoding all the characters in the specified character array.</returns>
/// <param name="chars">The character array containing the characters to encode.</param> /// <param name="chars">The character array containing the characters to encode.</param>
public override int GetByteCount(char[] chars) public override int GetByteCount(char[] chars)
{ {
if(chars == null) if(chars == null) throw new ArgumentNullException(nameof(chars));
throw new ArgumentNullException(nameof(chars));
return chars.Length; return chars.Length;
} }
/// <summary> /// <summary>
/// Encodes a set of characters from the specified <see cref="string"/> into the specified byte array. /// Encodes a set of characters from the specified <see cref="string" /> into the specified byte array.
/// </summary> /// </summary>
/// <returns>The actual number of bytes written into bytes.</returns> /// <returns>The actual number of bytes written into bytes.</returns>
/// <param name="s">The <see cref="string"/> containing the set of characters to encode.</param> /// <param name="s">The <see cref="string" /> containing the set of characters to encode.</param>
/// <param name="charIndex">The index of the first character to encode.</param> /// <param name="charIndex">The index of the first character to encode.</param>
/// <param name="charCount">The number of characters to encode.</param> /// <param name="charCount">The number of characters to encode.</param>
/// <param name="bytes">The byte array to contain the resulting sequence of bytes.</param> /// <param name="bytes">The byte array to contain the resulting sequence of bytes.</param>
@@ -194,20 +237,19 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>A byte array containing the results of encoding the specified set of characters.</returns> /// <returns>A byte array containing the results of encoding the specified set of characters.</returns>
/// <param name="s">The string containing the characters to encode.</param> /// <param name="s">The string containing the characters to encode.</param>
public override byte[] GetBytes(string s) public override byte[] GetBytes(string s)
{ {
if(s == null) if(s == null) throw new ArgumentNullException(nameof(s));
throw new ArgumentNullException(nameof(s));
return GetBytes(s.ToCharArray(), 0, s.Length); return GetBytes(s.ToCharArray(), 0, s.Length);
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The actual number of bytes written into bytes.</returns> /// <returns>The actual number of bytes written into bytes.</returns>
/// <param name="chars">The character array containing the set of characters to encode.</param> /// <param name="chars">The character array containing the set of characters to encode.</param>
@@ -217,43 +259,33 @@ namespace Claunia.Encoding
/// <param name="byteIndex">The index at which to start writing the resulting sequence of bytes.</param> /// <param name="byteIndex">The index at which to start writing the resulting sequence of bytes.</param>
public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
{ {
if(chars == null) if(chars == null) throw new ArgumentNullException(nameof(chars));
throw new ArgumentNullException(nameof(chars));
if(bytes == null) if(bytes == null) throw new ArgumentNullException(nameof(bytes));
throw new ArgumentNullException(nameof(bytes));
if(charIndex < 0) if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex));
throw new ArgumentOutOfRangeException(nameof(charIndex));
if(charCount < 0) if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount));
throw new ArgumentOutOfRangeException(nameof(charCount));
if(byteIndex < 0) if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex));
throw new ArgumentOutOfRangeException(nameof(byteIndex));
if(charIndex >= chars.Length) if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex));
throw new ArgumentOutOfRangeException(nameof(charIndex));
if(charCount + charIndex > chars.Length) if(charCount + charIndex > chars.Length) throw new ArgumentOutOfRangeException(nameof(charCount));
throw new ArgumentOutOfRangeException(nameof(charCount));
if(byteIndex >= bytes.Length) if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex));
throw new ArgumentOutOfRangeException(nameof(byteIndex));
if(byteIndex + charCount > bytes.Length) if(byteIndex + charCount > bytes.Length) throw new ArgumentException(nameof(bytes));
throw new ArgumentException(nameof(bytes));
byte[] temp = GetBytes(chars, charIndex, charCount); byte[] temp = GetBytes(chars, charIndex, charCount);
for(int i = 0; i < temp.Length; i++) for(int i = 0; i < temp.Length; i++) bytes[i + byteIndex] = temp[i];
bytes[i + byteIndex] = temp[i];
return charCount; return charCount;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>A byte array containing the results of encoding the specified set of characters.</returns> /// <returns>A byte array containing the results of encoding the specified set of characters.</returns>
/// <param name="chars">The character array containing the set of characters to encode.</param> /// <param name="chars">The character array containing the set of characters to encode.</param>
@@ -261,28 +293,23 @@ namespace Claunia.Encoding
/// <param name="count">The number of characters to encode.</param> /// <param name="count">The number of characters to encode.</param>
public override byte[] GetBytes(char[] chars, int index, int count) public override byte[] GetBytes(char[] chars, int index, int count)
{ {
if(chars == null) if(chars == null) throw new ArgumentNullException(nameof(chars));
throw new ArgumentNullException(nameof(chars));
if(index < 0) if(index < 0) throw new ArgumentOutOfRangeException(nameof(index));
throw new ArgumentOutOfRangeException(nameof(index));
if(count < 0) if(count < 0) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
if(count + index > chars.Length) if(count + index > chars.Length) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
byte[] bytes = new byte[count]; byte[] bytes = new byte[count];
for(int i = 0; i < count; i++) for(int i = 0; i < count; i++) bytes[i] = GetByte(chars[index + i]);
bytes[i] = GetByte(chars[index + i]);
return bytes; return bytes;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>A byte array containing the results of encoding the specified set of characters.</returns> /// <returns>A byte array containing the results of encoding the specified set of characters.</returns>
/// <param name="chars">The character array containing the characters to encode.</param> /// <param name="chars">The character array containing the characters to encode.</param>
@@ -292,7 +319,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The number of characters produced by decoding the specified sequence of bytes.</returns> /// <returns>The number of characters produced by decoding the specified sequence of bytes.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -302,7 +329,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The number of characters produced by decoding the specified sequence of bytes.</returns> /// <returns>The number of characters produced by decoding the specified sequence of bytes.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -310,23 +337,19 @@ namespace Claunia.Encoding
/// <param name="count">The number of bytes to decode.</param> /// <param name="count">The number of bytes to decode.</param>
public override int GetCharCount(byte[] bytes, int index, int count) public override int GetCharCount(byte[] bytes, int index, int count)
{ {
if(bytes == null) if(bytes == null) throw new ArgumentNullException(nameof(bytes));
throw new ArgumentNullException(nameof(bytes));
if(index < 0) if(index < 0) throw new ArgumentOutOfRangeException(nameof(index));
throw new ArgumentOutOfRangeException(nameof(index));
if(count < 0) if(count < 0) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
if(count + index > bytes.Length) if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
return count; return count;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The actual number of characters written into chars.</returns> /// <returns>The actual number of characters written into chars.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -336,43 +359,33 @@ namespace Claunia.Encoding
/// <param name="charIndex">The index at which to start writing the resulting set of characters.</param> /// <param name="charIndex">The index at which to start writing the resulting set of characters.</param>
public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
{ {
if(bytes == null) if(bytes == null) throw new ArgumentNullException(nameof(bytes));
throw new ArgumentNullException(nameof(bytes));
if(chars == null) if(chars == null) throw new ArgumentNullException(nameof(chars));
throw new ArgumentNullException(nameof(chars));
if(byteIndex < 0) if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex));
throw new ArgumentOutOfRangeException(nameof(byteIndex));
if(byteCount < 0) if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount));
throw new ArgumentOutOfRangeException(nameof(byteCount));
if(charIndex < 0) if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex));
throw new ArgumentOutOfRangeException(nameof(charIndex));
if(byteIndex >= bytes.Length) if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex));
throw new ArgumentOutOfRangeException(nameof(byteIndex));
if(byteCount + byteIndex > bytes.Length) if(byteCount + byteIndex > bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteCount));
throw new ArgumentOutOfRangeException(nameof(byteCount));
if(charIndex >= chars.Length) if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex));
throw new ArgumentOutOfRangeException(nameof(charIndex));
if(charIndex + byteCount > chars.Length) if(charIndex + byteCount > chars.Length) throw new ArgumentException(nameof(chars));
throw new ArgumentException(nameof(chars));
char[] temp = GetChars(bytes, byteIndex, byteCount); char[] temp = GetChars(bytes, byteIndex, byteCount);
for(int i = 0; i < temp.Length; i++) for(int i = 0; i < temp.Length; i++) chars[i + charIndex] = temp[i];
chars[i + charIndex] = temp[i];
return byteCount; return byteCount;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>A character array containing the results of decoding the specified sequence of bytes.</returns> /// <returns>A character array containing the results of decoding the specified sequence of bytes.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -382,7 +395,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The chars.</returns> /// <returns>The chars.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -390,54 +403,47 @@ namespace Claunia.Encoding
/// <param name="count">The number of bytes to decode.</param> /// <param name="count">The number of bytes to decode.</param>
public override char[] GetChars(byte[] bytes, int index, int count) public override char[] GetChars(byte[] bytes, int index, int count)
{ {
if(bytes == null) if(bytes == null) throw new ArgumentNullException(nameof(bytes));
throw new ArgumentNullException(nameof(bytes));
if(index < 0) if(index < 0) throw new ArgumentOutOfRangeException(nameof(index));
throw new ArgumentOutOfRangeException(nameof(index));
if(count < 0) if(count < 0) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
if(count + index > bytes.Length) if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
char[] chars = new char[count]; char[] chars = new char[count];
for(int i = 0; i < count; i++) for(int i = 0; i < count; i++) chars[i] = GetChar(bytes[index + i]);
chars[i] = GetChar(bytes[index + i]);
return chars; return chars;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The maximum number of bytes produced by encoding the specified number of characters.</returns> /// <returns>The maximum number of bytes produced by encoding the specified number of characters.</returns>
/// <param name="charCount">The number of characters to encode.</param> /// <param name="charCount">The number of characters to encode.</param>
public override int GetMaxByteCount(int charCount) public override int GetMaxByteCount(int charCount)
{ {
if(charCount < 0) if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount));
throw new ArgumentOutOfRangeException(nameof(charCount));
return charCount; return charCount;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The maximum number of characters produced by decoding the specified number of bytes.</returns> /// <returns>The maximum number of characters produced by decoding the specified number of bytes.</returns>
/// <param name="byteCount">The number of bytes to decode.</param> /// <param name="byteCount">The number of bytes to decode.</param>
public override int GetMaxCharCount(int byteCount) public override int GetMaxCharCount(int byteCount)
{ {
if(byteCount < 0) if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount));
throw new ArgumentOutOfRangeException(nameof(byteCount));
return byteCount; return byteCount;
} }
/// <summary> /// <summary>
/// Returns a sequence of bytes that specifies the encoding used. /// Returns a sequence of bytes that specifies the encoding used.
/// </summary> /// </summary>
/// <returns>A byte array of length zero, as a preamble is not required.</returns> /// <returns>A byte array of length zero, as a preamble is not required.</returns>
public override byte[] GetPreamble() public override byte[] GetPreamble()
@@ -446,7 +452,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// Decodes all the bytes in the specified byte array into a string. /// Decodes all the bytes in the specified byte array into a string.
/// </summary> /// </summary>
/// <returns>A string that contains the results of decoding the specified sequence of bytes.</returns> /// <returns>A string that contains the results of decoding the specified sequence of bytes.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -456,7 +462,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>A string that contains the results of decoding the specified sequence of bytes.</returns> /// <returns>A string that contains the results of decoding the specified sequence of bytes.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -468,78 +474,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// The Apple IIgs to Unicode character map. /// Converts a Apple IIgs character to an Unicode character
/// Inverted screen characters are mapped to normal characters.
/// </summary>
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'
};
/// <summary>
/// Converts a Apple IIgs character to an Unicode character
/// </summary> /// </summary>
/// <returns>Unicode character.</returns> /// <returns>Unicode character.</returns>
/// <param name="character">Apple IIgs character.</param> /// <param name="character">Apple IIgs character.</param>
@@ -549,227 +484,123 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// Converts a Unicode character to an Apple IIgs character /// Converts a Unicode character to an Apple IIgs character
/// </summary> /// </summary>
/// <returns>Apple IIgs character.</returns> /// <returns>Apple IIgs character.</returns>
/// <param name="character">Unicode character.</param> /// <param name="character">Unicode character.</param>
static byte GetByte(char character) static byte GetByte(char character)
{ {
switch(character) { switch(character)
case '\u2588': {
return 0x20; case '\u2588': return 0x20;
case '\u231B': case '\u231B': return 0x43;
return 0x43; case '\u2713': return 0x44;
case '\u2713': case '\u2190': return 0x48;
return 0x44; case '\u2026': return 0x49;
case '\u2190': case '\u2193': return 0x4A;
return 0x48; case '\u2191': return 0x4B;
case '\u2026': case '\u21B5': return 0x4D;
return 0x49; case '\u2192': return 0x55;
case '\u2193': case '\u25C6': return 0x5B;
return 0x4A; case '\u0040': return 0x80;
case '\u2191': case '\u0041': return 0x81;
return 0x4B; case '\u0042': return 0x82;
case '\u21B5': case '\u0043': return 0x83;
return 0x4D; case '\u0044': return 0x84;
case '\u2192': case '\u0045': return 0x85;
return 0x55; case '\u0046': return 0x86;
case '\u25C6': case '\u0047': return 0x87;
return 0x5B; case '\u0048': return 0x88;
case '\u0040': case '\u0049': return 0x89;
return 0x80; case '\u004A': return 0x8A;
case '\u0041': case '\u004B': return 0x8B;
return 0x81; case '\u004C': return 0x8C;
case '\u0042': case '\u004D': return 0x8D;
return 0x82; case '\u004E': return 0x8E;
case '\u0043': case '\u004F': return 0x8F;
return 0x83; case '\u0050': return 0x90;
case '\u0044': case '\u0051': return 0x91;
return 0x84; case '\u0052': return 0x92;
case '\u0045': case '\u0053': return 0x93;
return 0x85; case '\u0054': return 0x94;
case '\u0046': case '\u0055': return 0x95;
return 0x86; case '\u0056': return 0x96;
case '\u0047': case '\u0057': return 0x97;
return 0x87; case '\u0058': return 0x98;
case '\u0048': case '\u0059': return 0x99;
return 0x88; case '\u005A': return 0x9A;
case '\u0049': case '\u005B': return 0x9B;
return 0x89; case '\u005C': return 0x9C;
case '\u004A': case '\u005D': return 0x9D;
return 0x8A; case '\u005E': return 0x9E;
case '\u004B': case '\u005F': return 0x9F;
return 0x8B; case '\u0020': return 0xA0;
case '\u004C': case '\u0021': return 0xA1;
return 0x8C; case '\u0022': return 0xA2;
case '\u004D': case '\u0023': return 0xA3;
return 0x8D; case '\u0024': return 0xA4;
case '\u004E': case '\u2025': return 0xA5;
return 0x8E; case '\u0026': return 0xA6;
case '\u004F': case '\u0027': return 0xA7;
return 0x8F; case '\u0028': return 0xA8;
case '\u0050': case '\u0029': return 0xA9;
return 0x90; case '\u002A': return 0xAA;
case '\u0051': case '\u002B': return 0xAB;
return 0x91; case '\u002C': return 0xAC;
case '\u0052': case '\u002D': return 0xAD;
return 0x92; case '\u002E': return 0xAE;
case '\u0053': case '\u002F': return 0xAF;
return 0x93; case '\u0030': return 0xB0;
case '\u0054': case '\u0031': return 0xB1;
return 0x94; case '\u0032': return 0xB2;
case '\u0055': case '\u0033': return 0xB3;
return 0x95; case '\u0034': return 0xB4;
case '\u0056': case '\u0035': return 0xB5;
return 0x96; case '\u0036': return 0xB6;
case '\u0057': case '\u0037': return 0xB7;
return 0x97; case '\u0038': return 0xB8;
case '\u0058': case '\u0039': return 0xB9;
return 0x98; case '\u003A': return 0xBA;
case '\u0059': case '\u003B': return 0xBB;
return 0x99; case '\u003C': return 0xBC;
case '\u005A': case '\u003D': return 0xBD;
return 0x9A; case '\u003E': return 0xBE;
case '\u005B': case '\u003F': return 0xBF;
return 0x9B; case '\u0060': return 0xE0;
case '\u005C': case '\u0061': return 0xE1;
return 0x9C; case '\u0062': return 0xE2;
case '\u005D': case '\u0063': return 0xE3;
return 0x9D; case '\u0064': return 0xE4;
case '\u005E': case '\u0065': return 0xE5;
return 0x9E; case '\u0066': return 0xE6;
case '\u005F': case '\u0067': return 0xE7;
return 0x9F; case '\u0068': return 0xE8;
case '\u0020': case '\u0069': return 0xE9;
return 0xA0; case '\u006A': return 0xEA;
case '\u0021': case '\u006B': return 0xEB;
return 0xA1; case '\u006C': return 0xEC;
case '\u0022': case '\u006D': return 0xED;
return 0xA2; case '\u006E': return 0xEE;
case '\u0023': case '\u006F': return 0xEF;
return 0xA3; case '\u0070': return 0xF0;
case '\u0024': case '\u0071': return 0xF1;
return 0xA4; case '\u0072': return 0xF2;
case '\u2025': case '\u0073': return 0xF3;
return 0xA5; case '\u0074': return 0xF4;
case '\u0026': case '\u0075': return 0xF5;
return 0xA6; case '\u0076': return 0xF6;
case '\u0027': case '\u0077': return 0xF7;
return 0xA7; case '\u0078': return 0xF8;
case '\u0028': case '\u0079': return 0xF9;
return 0xA8; case '\u007A': return 0xFA;
case '\u0029': case '\u007B': return 0xFB;
return 0xA9; case '\u007C': return 0xFC;
case '\u002A': case '\u007D': return 0xFD;
return 0xAA; case '\u007E': return 0xFE;
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: default:
// Fallback to '?' // Fallback to '?'
return 0xBF; return 0xBF;
} }
} }
} }
} }

File diff suppressed because it is too large Load Diff

View File

@@ -24,130 +24,127 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Reflection; using System.Reflection;
namespace Claunia.Encoding namespace Claunia.Encoding
{ {
/// <summary> /// <summary>
/// This class contains static instances of the supported encodings. /// This class contains static instances of the supported encodings.
/// </summary> /// </summary>
public abstract class Encoding : System.Text.Encoding public abstract class Encoding : System.Text.Encoding
{ {
/// <summary> /// <summary>
/// Static instance for the LisaRoman encoding /// Static instance for the LisaRoman encoding
/// </summary> /// </summary>
public static System.Text.Encoding LisaEncoding = new LisaRoman(); public static System.Text.Encoding LisaEncoding = new LisaRoman();
/// <summary> /// <summary>
/// Static instance for the ATASCII encoding /// Static instance for the ATASCII encoding
/// </summary> /// </summary>
public static System.Text.Encoding AtariEncoding = new ATASCII(); public static System.Text.Encoding AtariEncoding = new ATASCII();
/// <summary> /// <summary>
/// Static instance for the Atari ST encoding /// Static instance for the Atari ST encoding
/// </summary> /// </summary>
public static System.Text.Encoding AtariSTEncoding = new AtariST(); public static System.Text.Encoding AtariSTEncoding = new AtariST();
/// <summary> /// <summary>
/// Static instance for the PETSCII encoding /// Static instance for the PETSCII encoding
/// </summary> /// </summary>
public static System.Text.Encoding PETEncoding = new PETSCII(); public static System.Text.Encoding PETEncoding = new PETSCII();
/// <summary> /// <summary>
/// Returns an array that contains all encodings. /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content.
/// </summary>
/// <returns>An array that contains all encodings.</returns>
public static EncodingInfo[] GetEncodings()
{
List<EncodingInfo> encodings = new List<EncodingInfo>();
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();
}
/// <summary>
/// Returns the encoding associated with the specified code page name.
/// </summary>
/// <returns>The encoding associated with the specified code page.</returns>
/// <param name="name">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.</param>
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);
}
/// <summary>
/// Gets a value indicating whether the current encoding can be used by browser clients for displaying content.
/// </summary> /// </summary>
public abstract bool IsBrowserDisplay { get; } public abstract bool IsBrowserDisplay { get; }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public abstract bool IsBrowserSave{ get; } public abstract bool IsBrowserSave { get; }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public abstract bool IsMailNewsDisplay{ get; } public abstract bool IsMailNewsDisplay { get; }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public abstract bool IsMailNewsSave{ get; } public abstract bool IsMailNewsSave { get; }
/// <summary> /// <summary>
/// Gets a value indicating whether the current encoding is read-only. /// Gets a value indicating whether the current encoding is read-only.
/// </summary> /// </summary>
/// <value>The is single byte.</value> /// <value>The is single byte.</value>
public abstract bool IsReadOnly{ get; } public abstract bool IsReadOnly { get; }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public abstract bool IsSingleByte{ get; } public abstract bool IsSingleByte { get; }
/// <summary> /// <summary>
/// Gets the code page identifier of the current Encoding. /// Gets the code page identifier of the current Encoding.
/// </summary> /// </summary>
public abstract int CodePage{ get; } public abstract int CodePage { get; }
/// <summary> /// <summary>
/// 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
/// </summary> /// </summary>
public abstract string BodyName{ get; } public abstract string BodyName { get; }
/// <summary> /// <summary>
/// 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
/// </summary> /// </summary>
public abstract string HeaderName{ get; } public abstract string HeaderName { get; }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public abstract override string WebName{ get; } public abstract override string WebName { get; }
/// <summary> /// <summary>
/// Gets the human-readable description of the current encoding. /// Gets the human-readable description of the current encoding.
/// </summary> /// </summary>
public abstract string EncodingName{ get; } public abstract string EncodingName { get; }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public abstract int WindowsCodePage{ get; } public abstract int WindowsCodePage { get; }
/// <summary>
/// Returns an array that contains all encodings.
/// </summary>
/// <returns>An array that contains all encodings.</returns>
public static IEnumerable<EncodingInfo> 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();
}
/// <summary>
/// Returns the encoding associated with the specified code page name.
/// </summary>
/// <returns>The encoding associated with the specified code page.</returns>
/// <param name="name">
/// 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.
/// </param>
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);
}
} }
} }

View File

@@ -7,85 +7,73 @@ using System;
namespace Claunia.Encoding namespace Claunia.Encoding
{ {
/// <summary> /// <summary>
/// Provides basic information about an encoding. /// Provides basic information about an encoding.
/// </summary> /// </summary>
public sealed class EncodingInfo public sealed class EncodingInfo
{ {
private int iCodePage; // Code Page # bool isSystem;
private string strEncodingName; // Short name (web name) Type thisType;
private string strDisplayName; // Full localized name
private bool isSystem;
private 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; CodePage = codePage;
strEncodingName = name; Name = name;
strDisplayName = displayName; DisplayName = displayName;
isSystem = system; isSystem = system;
thisType = internalType; thisType = internalType;
} }
/// <summary> /// <summary>
/// Gets the code page identifier of the encoding. /// Gets the code page identifier of the encoding.
/// </summary> /// </summary>
/// <value>The code page identifier of the encoding.</value> /// <value>The code page identifier of the encoding.</value>
public int CodePage { public int CodePage { get; }
get {
return iCodePage;
}
}
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <value>The IANA name for the encoding. For more information about the IANA, see www.iana.org.</value> /// <value>The IANA name for the encoding. For more information about the IANA, see www.iana.org.</value>
public string Name { public string Name { get; }
get {
return strEncodingName;
}
}
/// <summary> /// <summary>
/// Gets the human-readable description of the encoding. /// Gets the human-readable description of the encoding.
/// </summary> /// </summary>
/// <value>The human-readable description of the encoding.</value> /// <value>The human-readable description of the encoding.</value>
public string DisplayName { public string DisplayName { get; }
get {
return strDisplayName;
}
}
/// <summary> /// <summary>
/// Returns a Encoding object that corresponds to the current EncodingInfo object. /// Returns a Encoding object that corresponds to the current EncodingInfo object.
/// </summary> /// </summary>
/// <returns>A <see cref="T:Claunia.Encoding.Encoding"/> object that corresponds to the current <see cref="T:Claunia.Encoding.EncodingInfo"/> object.</returns> /// <returns>
/// A <see cref="T:Claunia.Encoding.Encoding" /> object that corresponds to the current
/// <see cref="T:Claunia.Encoding.EncodingInfo" /> object.
/// </returns>
public Encoding GetEncoding() public Encoding GetEncoding()
{ {
return (Encoding)thisType.GetConstructor(new Type[] { }).Invoke(new object[] { }); return (Encoding)thisType.GetConstructor(new Type[] { }).Invoke(new object[] { });
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <param name="value">An object to compare to the current <see cref="T:Claunia.Encoding.EncodingInfo"/> object.</param> /// <param name="value">An object to compare to the current <see cref="T:Claunia.Encoding.EncodingInfo" /> object.</param>
/// <returns><c>true</c> if value is a <see cref="T:Claunia.Encoding.EncodingInfo"/> and is equal to the current <see cref="T:Claunia.Encoding.EncodingInfo"/>; otherwise, <c>false</c>.</returns> /// <returns>
public override bool Equals(Object value) /// <c>true</c> if value is a <see cref="T:Claunia.Encoding.EncodingInfo" /> and is equal to the current
/// <see cref="T:Claunia.Encoding.EncodingInfo" />; otherwise, <c>false</c>.
/// </returns>
public override bool Equals(object value)
{ {
EncodingInfo that = value as EncodingInfo; return value is EncodingInfo that && CodePage == that.CodePage;
if(that != null) {
return (this.CodePage == that.CodePage);
}
return (false);
} }
/// <summary> /// <summary>
/// Returns the hash code for the current EncodingInfo object. /// Returns the hash code for the current EncodingInfo object.
/// </summary> /// </summary>
/// <returns>A 32-bit signed integer hash code.</returns> /// <returns>A 32-bit signed integer hash code.</returns>
public override int GetHashCode() public override int GetHashCode()
{ {
return this.CodePage; return CodePage;
} }
} }
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -29,7 +29,8 @@ using System;
namespace Claunia.Encoding namespace Claunia.Encoding
{ {
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public class PETSCII : Encoding public class PETSCII : Encoding
{ {
@@ -48,116 +49,151 @@ namespace Claunia.Encoding
const bool singleByte = true; const bool singleByte = true;
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override bool IsBrowserDisplay /// <remarks>Reference used: http://style64.org/petscii/ and others.</remarks>
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'
};
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override bool IsBrowserSave public override bool IsBrowserDisplay => browserDisplay;
{
get { return browserSave; }
}
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override bool IsMailNewsDisplay public override bool IsBrowserSave => browserSave;
{
get { return mailNewsDisplay; }
}
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override bool IsMailNewsSave public override bool IsMailNewsDisplay => mailNewsDisplay;
{
get { return mailNewsSave; }
}
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override bool IsReadOnly public override bool IsMailNewsSave => mailNewsSave;
{
get { return readOnly; }
}
/// <summary> /// <summary>
/// Gets a value indicating whether the current encoding uses single-byte code points. /// Gets a value indicating whether the current encoding is read-only.
/// </summary> /// </summary>
public override bool IsSingleByte public override bool IsReadOnly => readOnly;
{
get { return singleByte; }
}
/// <summary> /// <summary>
/// Gets the code page identifier of the current Encoding. /// Gets a value indicating whether the current encoding uses single-byte code points.
/// </summary> /// </summary>
public override int CodePage public override bool IsSingleByte => singleByte;
{
get { return _codepage; }
}
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override string BodyName public override int CodePage => _codepage;
{
get { return _bodyname; }
}
/// <summary> /// <summary>
/// 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
/// </summary> /// </summary>
public override string HeaderName public override string BodyName => _bodyname;
{
get { return _headername; }
}
/// <summary> /// <summary>
/// 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
/// </summary> /// </summary>
public override string WebName public override string HeaderName => _headername;
{
get { return _webname; }
}
/// <summary> /// <summary>
/// Gets the human-readable description of the current encoding. /// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.
/// </summary> /// </summary>
public override string EncodingName public override string WebName => _webname;
{
get { return _encodingname; }
}
/// <summary> /// <summary>
/// Gets the Windows operating system code page that most closely corresponds to the current encoding. /// Gets the human-readable description of the current encoding.
/// </summary> /// </summary>
public override int WindowsCodePage public override string EncodingName => _encodingname;
{
get { return _windowsCodepage; }
}
/// <summary> /// <summary>
/// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string"/>. /// Gets the Windows operating system code page that most closely corresponds to the current encoding.
/// </summary>
public override int WindowsCodePage => _windowsCodepage;
/// <summary>
/// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string" />.
/// </summary> /// </summary>
/// <returns>The number of bytes produced by encoding the specified characters.</returns> /// <returns>The number of bytes produced by encoding the specified characters.</returns>
/// <param name="s">The <see cref="string"/> containing the set of characters to encode.</param> /// <param name="s">The <see cref="string" /> containing the set of characters to encode.</param>
public override int GetByteCount(string s) public override int GetByteCount(string s)
{ {
if (s == null) if(s == null) throw new ArgumentNullException(nameof(s));
throw new ArgumentNullException(nameof(s));
return s.Length; return s.Length;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The number of bytes produced by encoding the specified characters.</returns> /// <returns>The number of bytes produced by encoding the specified characters.</returns>
/// <param name="chars">The character array containing the set of characters to encode.</param> /// <param name="chars">The character array containing the set of characters to encode.</param>
@@ -165,36 +201,32 @@ namespace Claunia.Encoding
/// <param name="count">The number of characters to encode.</param> /// <param name="count">The number of characters to encode.</param>
public override int GetByteCount(char[] chars, int index, int count) public override int GetByteCount(char[] chars, int index, int count)
{ {
if (chars == null) if(chars == null) throw new ArgumentNullException(nameof(chars));
throw new ArgumentNullException(nameof(chars));
if (index < 0 || index >= chars.Length) if(index < 0 || index >= chars.Length) throw new ArgumentOutOfRangeException(nameof(index));
throw new ArgumentOutOfRangeException(nameof(index));
if (count < 0 || index + count > chars.Length) if(count < 0 || index + count > chars.Length) throw new ArgumentOutOfRangeException(nameof(index));
throw new ArgumentOutOfRangeException(nameof(index));
return count; return count;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The number of bytes produced by encoding all the characters in the specified character array.</returns> /// <returns>The number of bytes produced by encoding all the characters in the specified character array.</returns>
/// <param name="chars">The character array containing the characters to encode.</param> /// <param name="chars">The character array containing the characters to encode.</param>
public override int GetByteCount(char[] chars) public override int GetByteCount(char[] chars)
{ {
if (chars == null) if(chars == null) throw new ArgumentNullException(nameof(chars));
throw new ArgumentNullException(nameof(chars));
return chars.Length; return chars.Length;
} }
/// <summary> /// <summary>
/// Encodes a set of characters from the specified <see cref="string"/> into the specified byte array. /// Encodes a set of characters from the specified <see cref="string" /> into the specified byte array.
/// </summary> /// </summary>
/// <returns>The actual number of bytes written into bytes.</returns> /// <returns>The actual number of bytes written into bytes.</returns>
/// <param name="s">The <see cref="string"/> containing the set of characters to encode.</param> /// <param name="s">The <see cref="string" /> containing the set of characters to encode.</param>
/// <param name="charIndex">The index of the first character to encode.</param> /// <param name="charIndex">The index of the first character to encode.</param>
/// <param name="charCount">The number of characters to encode.</param> /// <param name="charCount">The number of characters to encode.</param>
/// <param name="bytes">The byte array to contain the resulting sequence of bytes.</param> /// <param name="bytes">The byte array to contain the resulting sequence of bytes.</param>
@@ -205,20 +237,19 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>A byte array containing the results of encoding the specified set of characters.</returns> /// <returns>A byte array containing the results of encoding the specified set of characters.</returns>
/// <param name="s">The string containing the characters to encode.</param> /// <param name="s">The string containing the characters to encode.</param>
public override byte[] GetBytes(string s) public override byte[] GetBytes(string s)
{ {
if (s == null) if(s == null) throw new ArgumentNullException(nameof(s));
throw new ArgumentNullException(nameof(s));
return GetBytes(s.ToCharArray(), 0, s.Length); return GetBytes(s.ToCharArray(), 0, s.Length);
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The actual number of bytes written into bytes.</returns> /// <returns>The actual number of bytes written into bytes.</returns>
/// <param name="chars">The character array containing the set of characters to encode.</param> /// <param name="chars">The character array containing the set of characters to encode.</param>
@@ -228,43 +259,33 @@ namespace Claunia.Encoding
/// <param name="byteIndex">The index at which to start writing the resulting sequence of bytes.</param> /// <param name="byteIndex">The index at which to start writing the resulting sequence of bytes.</param>
public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
{ {
if (chars == null) if(chars == null) throw new ArgumentNullException(nameof(chars));
throw new ArgumentNullException(nameof(chars));
if (bytes == null) if(bytes == null) throw new ArgumentNullException(nameof(bytes));
throw new ArgumentNullException(nameof(bytes));
if (charIndex < 0) if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex));
throw new ArgumentOutOfRangeException(nameof(charIndex));
if (charCount < 0) if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount));
throw new ArgumentOutOfRangeException(nameof(charCount));
if (byteIndex < 0) if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex));
throw new ArgumentOutOfRangeException(nameof(byteIndex));
if (charIndex >= chars.Length) if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex));
throw new ArgumentOutOfRangeException(nameof(charIndex));
if (charCount + charIndex > chars.Length) if(charCount + charIndex > chars.Length) throw new ArgumentOutOfRangeException(nameof(charCount));
throw new ArgumentOutOfRangeException(nameof(charCount));
if (byteIndex >= bytes.Length) if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex));
throw new ArgumentOutOfRangeException(nameof(byteIndex));
if (byteIndex + charCount > bytes.Length) if(byteIndex + charCount > bytes.Length) throw new ArgumentException(nameof(bytes));
throw new ArgumentException(nameof(bytes));
byte[] temp = GetBytes(chars, charIndex, charCount); byte[] temp = GetBytes(chars, charIndex, charCount);
for (int i = 0; i < temp.Length; i++) for(int i = 0; i < temp.Length; i++) bytes[i + byteIndex] = temp[i];
bytes[i + byteIndex] = temp[i];
return charCount; return charCount;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>A byte array containing the results of encoding the specified set of characters.</returns> /// <returns>A byte array containing the results of encoding the specified set of characters.</returns>
/// <param name="chars">The character array containing the set of characters to encode.</param> /// <param name="chars">The character array containing the set of characters to encode.</param>
@@ -272,28 +293,23 @@ namespace Claunia.Encoding
/// <param name="count">The number of characters to encode.</param> /// <param name="count">The number of characters to encode.</param>
public override byte[] GetBytes(char[] chars, int index, int count) public override byte[] GetBytes(char[] chars, int index, int count)
{ {
if (chars == null) if(chars == null) throw new ArgumentNullException(nameof(chars));
throw new ArgumentNullException(nameof(chars));
if (index < 0) if(index < 0) throw new ArgumentOutOfRangeException(nameof(index));
throw new ArgumentOutOfRangeException(nameof(index));
if (count < 0) if(count < 0) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
if (count + index > chars.Length) if(count + index > chars.Length) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
byte[] bytes = new byte[count]; byte[] bytes = new byte[count];
for (int i = 0; i < count; i++) for(int i = 0; i < count; i++) bytes[i] = GetByte(chars[index + i]);
bytes[i] = GetByte(chars[index + i]);
return bytes; return bytes;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>A byte array containing the results of encoding the specified set of characters.</returns> /// <returns>A byte array containing the results of encoding the specified set of characters.</returns>
/// <param name="chars">The character array containing the characters to encode.</param> /// <param name="chars">The character array containing the characters to encode.</param>
@@ -303,7 +319,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The number of characters produced by decoding the specified sequence of bytes.</returns> /// <returns>The number of characters produced by decoding the specified sequence of bytes.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -313,7 +329,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The number of characters produced by decoding the specified sequence of bytes.</returns> /// <returns>The number of characters produced by decoding the specified sequence of bytes.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -321,23 +337,19 @@ namespace Claunia.Encoding
/// <param name="count">The number of bytes to decode.</param> /// <param name="count">The number of bytes to decode.</param>
public override int GetCharCount(byte[] bytes, int index, int count) public override int GetCharCount(byte[] bytes, int index, int count)
{ {
if (bytes == null) if(bytes == null) throw new ArgumentNullException(nameof(bytes));
throw new ArgumentNullException(nameof(bytes));
if (index < 0) if(index < 0) throw new ArgumentOutOfRangeException(nameof(index));
throw new ArgumentOutOfRangeException(nameof(index));
if (count < 0) if(count < 0) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
if (count + index > bytes.Length) if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
return count; return count;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The actual number of characters written into chars.</returns> /// <returns>The actual number of characters written into chars.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -347,43 +359,33 @@ namespace Claunia.Encoding
/// <param name="charIndex">The index at which to start writing the resulting set of characters.</param> /// <param name="charIndex">The index at which to start writing the resulting set of characters.</param>
public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
{ {
if (bytes == null) if(bytes == null) throw new ArgumentNullException(nameof(bytes));
throw new ArgumentNullException(nameof(bytes));
if (chars == null) if(chars == null) throw new ArgumentNullException(nameof(chars));
throw new ArgumentNullException(nameof(chars));
if (byteIndex < 0) if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex));
throw new ArgumentOutOfRangeException(nameof(byteIndex));
if (byteCount < 0) if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount));
throw new ArgumentOutOfRangeException(nameof(byteCount));
if (charIndex < 0) if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex));
throw new ArgumentOutOfRangeException(nameof(charIndex));
if (byteIndex >= bytes.Length) if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex));
throw new ArgumentOutOfRangeException(nameof(byteIndex));
if (byteCount + byteIndex > bytes.Length) if(byteCount + byteIndex > bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteCount));
throw new ArgumentOutOfRangeException(nameof(byteCount));
if (charIndex >= chars.Length) if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex));
throw new ArgumentOutOfRangeException(nameof(charIndex));
if (charIndex + byteCount > chars.Length) if(charIndex + byteCount > chars.Length) throw new ArgumentException(nameof(chars));
throw new ArgumentException(nameof(chars));
char[] temp = GetChars(bytes, byteIndex, byteCount); char[] temp = GetChars(bytes, byteIndex, byteCount);
for (int i = 0; i < temp.Length; i++) for(int i = 0; i < temp.Length; i++) chars[i + charIndex] = temp[i];
chars[i + charIndex] = temp[i];
return byteCount; return byteCount;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>A character array containing the results of decoding the specified sequence of bytes.</returns> /// <returns>A character array containing the results of decoding the specified sequence of bytes.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -393,7 +395,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The chars.</returns> /// <returns>The chars.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -401,54 +403,47 @@ namespace Claunia.Encoding
/// <param name="count">The number of bytes to decode.</param> /// <param name="count">The number of bytes to decode.</param>
public override char[] GetChars(byte[] bytes, int index, int count) public override char[] GetChars(byte[] bytes, int index, int count)
{ {
if (bytes == null) if(bytes == null) throw new ArgumentNullException(nameof(bytes));
throw new ArgumentNullException(nameof(bytes));
if (index < 0) if(index < 0) throw new ArgumentOutOfRangeException(nameof(index));
throw new ArgumentOutOfRangeException(nameof(index));
if (count < 0) if(count < 0) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
if (count + index > bytes.Length) if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
char[] chars = new char[count]; char[] chars = new char[count];
for (int i = 0; i < count; i++) for(int i = 0; i < count; i++) chars[i] = GetChar(bytes[index + i]);
chars[i] = GetChar(bytes[index + i]);
return chars; return chars;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The maximum number of bytes produced by encoding the specified number of characters.</returns> /// <returns>The maximum number of bytes produced by encoding the specified number of characters.</returns>
/// <param name="charCount">The number of characters to encode.</param> /// <param name="charCount">The number of characters to encode.</param>
public override int GetMaxByteCount(int charCount) public override int GetMaxByteCount(int charCount)
{ {
if (charCount < 0) if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount));
throw new ArgumentOutOfRangeException(nameof(charCount));
return charCount; return charCount;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The maximum number of characters produced by decoding the specified number of bytes.</returns> /// <returns>The maximum number of characters produced by decoding the specified number of bytes.</returns>
/// <param name="byteCount">The number of bytes to decode.</param> /// <param name="byteCount">The number of bytes to decode.</param>
public override int GetMaxCharCount(int byteCount) public override int GetMaxCharCount(int byteCount)
{ {
if (byteCount < 0) if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount));
throw new ArgumentOutOfRangeException(nameof(byteCount));
return byteCount; return byteCount;
} }
/// <summary> /// <summary>
/// Returns a sequence of bytes that specifies the encoding used. /// Returns a sequence of bytes that specifies the encoding used.
/// </summary> /// </summary>
/// <returns>A byte array of length zero, as a preamble is not required.</returns> /// <returns>A byte array of length zero, as a preamble is not required.</returns>
public override byte[] GetPreamble() public override byte[] GetPreamble()
@@ -457,7 +452,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// Decodes all the bytes in the specified byte array into a string. /// Decodes all the bytes in the specified byte array into a string.
/// </summary> /// </summary>
/// <returns>A string that contains the results of decoding the specified sequence of bytes.</returns> /// <returns>A string that contains the results of decoding the specified sequence of bytes.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -467,7 +462,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>A string that contains the results of decoding the specified sequence of bytes.</returns> /// <returns>A string that contains the results of decoding the specified sequence of bytes.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -479,78 +474,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// The PETSCII to Unicode character map, unshifted (default) variant. /// Converts a PETSCII character to an Unicode character
/// </summary>
/// <remarks>Reference used: http://style64.org/petscii/ and others.</remarks>
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',
};
/// <summary>
/// Converts a PETSCII character to an Unicode character
/// </summary> /// </summary>
/// <returns>Unicode character.</returns> /// <returns>Unicode character.</returns>
/// <param name="character">PETSCII character.</param> /// <param name="character">PETSCII character.</param>
@@ -560,24 +484,17 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// Converts a Unicode character to an PETSCII character /// Converts a Unicode character to an PETSCII character
/// </summary> /// </summary>
/// <returns>PETSCII character.</returns> /// <returns>PETSCII character.</returns>
/// <param name="character">Unicode character.</param> /// <param name="character">Unicode character.</param>
static byte GetByte(char character) static byte GetByte(char character)
{ {
if (character == 0x0000) if(character == 0x0000) return 0x3F;
{
// TODO: would returning 0x00 be more correct?
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? // TODO: convert this to a gigantic switch statement too?
if (PETSCIITable[i] == character) if(PETSCIITable[i] == character) return (byte)i;
return (byte)i;
}
// Fallback to '?' // Fallback to '?'
return 0x3F; return 0x3F;

View File

@@ -23,26 +23,29 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // 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 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
using System;
namespace Claunia.Encoding namespace Claunia.Encoding
{ {
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public static class Pangrams public static class Pangrams
{ {
/// <summary>A pangram that contains all (or most) Arabic characters.</summary> /// <summary>A pangram that contains all (or most) Arabic characters.</summary>
public const string Arabic = "صِف خَلقَ خَودِ كَمِثلِ الشَمسِ إِذ بَزَغَت — يَحظى الضَجيعُ بِها نَجلاءَ مِعطارِ"; public const string Arabic =
"صِف خَلقَ خَودِ كَمِثلِ الشَمسِ إِذ بَزَغَت — يَحظى الضَجيعُ بِها نَجلاءَ مِعطارِ";
/// <summary>A pangram that contains all (or most) Azeri characters.</summary> /// <summary>A pangram that contains all (or most) Azeri characters.</summary>
public const string Azeri = "Zəfər, jaketini də papağını da götür, bu axşam hava çox soyuq olacaq."; public const string Azeri = "Zəfər, jaketini də papağını da götür, bu axşam hava çox soyuq olacaq.";
/// <summary>A pangram that contains all (or most) Basque characters.</summary> /// <summary>A pangram that contains all (or most) Basque characters.</summary>
public const string Basque = "Vaudeville itxurako filmean, yogi ñaño bat jipoitzen dute Quebec-en, whiski truk"; public const string Basque = "Vaudeville itxurako filmean, yogi ñaño bat jipoitzen dute Quebec-en, whiski truk";
/// <summary>A pangram that contains all (or most) Breton characters.</summary> /// <summary>A pangram that contains all (or most) Breton characters.</summary>
public const string Breton = "Yeched mat Jakez ! Skarzhit ar gwerennoù-mañ, kavet e vo gwin betek fin ho puhez."; public const string Breton =
"Yeched mat Jakez ! Skarzhit ar gwerennoù-mañ, kavet e vo gwin betek fin ho puhez.";
/// <summary>A pangram that contains all (or most) Bulgarian characters.</summary> /// <summary>A pangram that contains all (or most) Bulgarian characters.</summary>
public const string Bulgarian = "Хълцащ змей плюе шофьор стигнал чуждия бивак."; public const string Bulgarian = "Хълцащ змей плюе шофьор стигнал чуждия бивак.";
/// <summary>A pangram that contains all (or most) Catalan characters.</summary> /// <summary>A pangram that contains all (or most) Catalan characters.</summary>
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 donze 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 donze kWh.";
/// <summary>A pangram that contains Traditional Chinese characters.</summary> /// <summary>A pangram that contains Traditional Chinese characters.</summary>
public const string ChineseTraditional = "視野無限廣,窗外有藍天"; public const string ChineseTraditional = "視野無限廣,窗外有藍天";
/// <summary>A pangram that contains Simplified Chinese characters.</summary> /// <summary>A pangram that contains Simplified Chinese characters.</summary>
@@ -50,9 +53,11 @@ namespace Claunia.Encoding
/// <summary>A pangram that contains all (or most) Croatian characters.</summary> /// <summary>A pangram that contains all (or most) Croatian characters.</summary>
public const string Croatian = "Gojazni đačić s biciklom drži hmelj i finu vatu u džepu nošnje."; public const string Croatian = "Gojazni đačić s biciklom drži hmelj i finu vatu u džepu nošnje.";
/// <summary>A pangram that contains all (or most) Czech characters.</summary> /// <summary>A pangram that contains all (or most) Czech characters.</summary>
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.";
/// <summary>A pangram that contains all (or most) Danish characters.</summary> /// <summary>A pangram that contains all (or most) Danish characters.</summary>
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.";
/// <summary>A pangram that contains all (or most) Dutch characters.</summary> /// <summary>A pangram that contains all (or most) Dutch characters.</summary>
public const string Dutch = "Pas wijze lynx bezag vroom het fikse aquaduct."; public const string Dutch = "Pas wijze lynx bezag vroom het fikse aquaduct.";
/// <summary>A pangram that contains all (or most) English characters.</summary> /// <summary>A pangram that contains all (or most) English characters.</summary>
@@ -62,17 +67,26 @@ namespace Claunia.Encoding
/// <summary>A pangram that contains all (or most) Estonian characters.</summary> /// <summary>A pangram that contains all (or most) Estonian characters.</summary>
public const string Estonian = "Põdur Zagrebi tšellomängija-följetonist Ciqo külmetas kehvas garaažis."; public const string Estonian = "Põdur Zagrebi tšellomängija-följetonist Ciqo külmetas kehvas garaažis.";
/// <summary>A pangram that contains all (or most) Finnish characters.</summary> /// <summary>A pangram that contains all (or most) Finnish characters.</summary>
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."
;
/// <summary>A pangram that contains all (or most) French characters.</summary> /// <summary>A pangram that contains all (or most) French characters.</summary>
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æ."
;
/// <summary>A pangram that contains all (or most) Galician characters.</summary> /// <summary>A pangram that contains all (or most) Galician characters.</summary>
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.";
/// <summary>A pangram that contains all (or most) German characters.</summary> /// <summary>A pangram that contains all (or most) German characters.</summary>
public const string German = "Falsches Üben von Xylophonmusik quält jeden größeren Zwerg."; public const string German = "Falsches Üben von Xylophonmusik quält jeden größeren Zwerg.";
/// <summary>A pangram that contains all (or most) Greek characters.</summary> /// <summary>A pangram that contains all (or most) Greek characters.</summary>
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."
;
/// <summary>A pangram that contains all (or most) Hebrew characters.</summary> /// <summary>A pangram that contains all (or most) Hebrew characters.</summary>
public const string Hebrew = "לכן חכו לי נאם יהוה ליום קומי לעד, כי משפטי לאסף גוים לקבצי ממלכות, לשפך עליהם זעמי כל חרון אפי, כי באש קנאתי תאכל כל הארץ"; public const string Hebrew =
"לכן חכו לי נאם יהוה ליום קומי לעד, כי משפטי לאסף גוים לקבצי ממלכות, לשפך עליהם זעמי כל חרון אפי, כי באש קנאתי תאכל כל הארץ"
;
/// <summary>A pangram that contains all (or most) Hungarian characters.</summary> /// <summary>A pangram that contains all (or most) Hungarian characters.</summary>
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."; 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.";
/// <summary>A pangram that contains all (or most) Icelandic characters.</summary> /// <summary>A pangram that contains all (or most) Icelandic characters.</summary>
@@ -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"; public const string Irish = "Ċuaiġ bé ṁórṡáċ le dlúṫspád fíorḟinn trí hata mo ḋea-ṗorcáin ḃig";
/// <summary>A pangram that contains all (or most) Japanese kanas.</summary> /// <summary>A pangram that contains all (or most) Japanese kanas.</summary>
public const string Japanese = "いろはにほへと ちりぬるを わかよたれそ つねならむ うゐのおくやま けふこえて あさきゆめみし ゑひもせす(ん)"; public const string Japanese = "いろはにほへと ちりぬるを わかよたれそ つねならむ うゐのおくやま けふこえて あさきゆめみし ゑひもせす(ん)";
/// <summary><see cref="Japanese"/> using Kanjis</summary> /// <summary><see cref="Japanese" /> using Kanjis</summary>
public const string JapaneseKanji = "色は匂へど 散りぬるを 我が世誰ぞ 常ならむ 有為の奥山 今日越えて 浅き夢見じ 酔ひもせず(ん)"; public const string JapaneseKanji = "色は匂へど 散りぬるを 我が世誰ぞ 常ならむ 有為の奥山 今日越えて 浅き夢見じ 酔ひもせず(ん)";
/// <summary>A pangram that contains all (or most) Korean characters.</summary> /// <summary>A pangram that contains all (or most) Korean characters.</summary>
public const string Korean = "키스의 고유조건은 입술끼리 만나야 하고 특별한 기술은 필요치 않다"; public const string Korean = "키스의 고유조건은 입술끼리 만나야 하고 특별한 기술은 필요치 않다";
@@ -96,21 +110,27 @@ namespace Claunia.Encoding
/// <summary>A pangram that contains all (or most) Polish characters.</summary> /// <summary>A pangram that contains all (or most) Polish characters.</summary>
public const string Polish = "Jeżu klątw, spłódź Finom część gry hańb!"; public const string Polish = "Jeżu klątw, spłódź Finom część gry hańb!";
/// <summary>A pangram that contains all (or most) Portuguese characters.</summary> /// <summary>A pangram that contains all (or most) Portuguese characters.</summary>
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."
;
/// <summary>A pangram that contains all (or most) Romanian characters.</summary> /// <summary>A pangram that contains all (or most) Romanian characters.</summary>
public const string Romanian = "Înjurând pițigăiat, zoofobul comandă vexat whisky și tequila."; public const string Romanian = "Înjurând pițigăiat, zoofobul comandă vexat whisky și tequila.";
/// <summary>A pangram that contains all (or most) Russian characters.</summary> /// <summary>A pangram that contains all (or most) Russian characters.</summary>
public const string Russian = "Широкая электрификация южных губерний даст мощный толчок подъёму сельского хозяйства."; public const string Russian =
"Широкая электрификация южных губерний даст мощный толчок подъёму сельского хозяйства.";
/// <summary>A pangram that contains all (or most) Scottish Gaelic characters.</summary> /// <summary>A pangram that contains all (or most) Scottish Gaelic characters.</summary>
public const string Scottish = "Mus dfhàg Cèit-Ùna ròp Ì le ob."; public const string Scottish = "Mus dfhàg Cèit-Ùna ròp Ì le ob.";
/// <summary>A pangram that contains all (or most) Serbian characters.</summary> /// <summary>A pangram that contains all (or most) Serbian characters.</summary>
public const string Serbian = "Gojazni đačić s biciklom drži hmelj i finu vatu u džepu nošnje."; public const string Serbian = "Gojazni đačić s biciklom drži hmelj i finu vatu u džepu nošnje.";
/// <summary>A pangram that contains all (or most) Slovak characters.</summary> /// <summary>A pangram that contains all (or most) Slovak characters.</summary>
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.";
/// <summary>A pangram that contains all (or most) Slovenian characters.</summary> /// <summary>A pangram that contains all (or most) Slovenian characters.</summary>
public const string Slovenian = "Besni dirkač iz formule žuga cehu poštarjev."; public const string Slovenian = "Besni dirkač iz formule žuga cehu poštarjev.";
/// <summary>A pangram that contains all (or most) Spanish characters.</summary> /// <summary>A pangram that contains all (or most) Spanish characters.</summary>
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."
;
/// <summary>A pangram that contains all (or most) Swedish characters.</summary> /// <summary>A pangram that contains all (or most) Swedish characters.</summary>
public const string Swedish = "Flygande bäckasiner söka hwila på mjuka tuvor."; public const string Swedish = "Flygande bäckasiner söka hwila på mjuka tuvor.";
/// <summary>A pangram that contains all (or most) Turkish characters.</summary> /// <summary>A pangram that contains all (or most) Turkish characters.</summary>
@@ -118,5 +138,4 @@ namespace Claunia.Encoding
/// <summary>A pangram that contains all (or most) Welsh characters.</summary> /// <summary>A pangram that contains all (or most) Welsh characters.</summary>
public const string Welsh = "Parciais fy jac codi baw hud llawn dŵr ger tŷ Mabon."; public const string Welsh = "Parciais fy jac codi baw hud llawn dŵr ger tŷ Mabon.";
} }
} }

View File

@@ -29,7 +29,7 @@ using System;
namespace Claunia.Encoding namespace Claunia.Encoding
{ {
/// <summary> /// <summary>
/// Represents a ZX80 character encoding of Unicode characters. /// Represents a ZX80 character encoding of Unicode characters.
/// </summary> /// </summary>
public class ZX80 : Encoding public class ZX80 : Encoding
{ {
@@ -48,105 +48,151 @@ namespace Claunia.Encoding
const bool singleByte = true; const bool singleByte = true;
/// <summary> /// <summary>
/// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. /// The ZX80 to Unicode character map.
/// </summary> /// </summary>
public override bool IsBrowserDisplay { static readonly char[] ZX80Table =
get { return browserDisplay; } {
} // 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'
};
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override bool IsBrowserSave { public override bool IsBrowserDisplay => browserDisplay;
get { return browserSave; }
}
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override bool IsMailNewsDisplay { public override bool IsBrowserSave => browserSave;
get { return mailNewsDisplay; }
}
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override bool IsMailNewsSave { public override bool IsMailNewsDisplay => mailNewsDisplay;
get { return mailNewsSave; }
}
/// <summary> /// <summary>
/// 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.
/// </summary>
public override bool IsMailNewsSave => mailNewsSave;
/// <summary>
/// Gets a value indicating whether the current encoding is read-only.
/// </summary> /// </summary>
/// <value>The is single byte.</value> /// <value>The is single byte.</value>
public override bool IsReadOnly { public override bool IsReadOnly => readOnly;
get { return readOnly; }
}
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override bool IsSingleByte { public override bool IsSingleByte => singleByte;
get { return singleByte; }
}
/// <summary> /// <summary>
/// Gets the code page identifier of the current Encoding. /// Gets the code page identifier of the current Encoding.
/// </summary> /// </summary>
public override int CodePage { public override int CodePage => _codepage;
get { return _codepage; }
}
/// <summary> /// <summary>
/// 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
/// </summary> /// </summary>
public override string BodyName { public override string BodyName => _bodyname;
get { return _bodyname; }
}
/// <summary> /// <summary>
/// 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
/// </summary> /// </summary>
public override string HeaderName { public override string HeaderName => _headername;
get { return _headername; }
}
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override string WebName { public override string WebName => _webname;
get { return _webname; }
}
/// <summary> /// <summary>
/// Gets the human-readable description of the current encoding. /// Gets the human-readable description of the current encoding.
/// </summary> /// </summary>
public override string EncodingName { public override string EncodingName => _encodingname;
get { return _encodingname; }
}
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override int WindowsCodePage { public override int WindowsCodePage => _windowsCodepage;
get { return _windowsCodepage; }
}
/// <summary> /// <summary>
/// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string"/>. /// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string" />.
/// </summary> /// </summary>
/// <returns>The number of bytes produced by encoding the specified characters.</returns> /// <returns>The number of bytes produced by encoding the specified characters.</returns>
/// <param name="s">The <see cref="string"/> containing the set of characters to encode.</param> /// <param name="s">The <see cref="string" /> containing the set of characters to encode.</param>
public override int GetByteCount(string s) public override int GetByteCount(string s)
{ {
if(s == null) if(s == null) throw new ArgumentNullException(nameof(s));
throw new ArgumentNullException(nameof(s));
return s.Length; return s.Length;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The number of bytes produced by encoding the specified characters.</returns> /// <returns>The number of bytes produced by encoding the specified characters.</returns>
/// <param name="chars">The character array containing the set of characters to encode.</param> /// <param name="chars">The character array containing the set of characters to encode.</param>
@@ -154,36 +200,32 @@ namespace Claunia.Encoding
/// <param name="count">The number of characters to encode.</param> /// <param name="count">The number of characters to encode.</param>
public override int GetByteCount(char[] chars, int index, int count) public override int GetByteCount(char[] chars, int index, int count)
{ {
if(chars == null) if(chars == null) throw new ArgumentNullException(nameof(chars));
throw new ArgumentNullException(nameof(chars));
if(index < 0 || index >= chars.Length) if(index < 0 || index >= chars.Length) throw new ArgumentOutOfRangeException(nameof(index));
throw new ArgumentOutOfRangeException(nameof(index));
if(count < 0 || index + count > chars.Length) if(count < 0 || index + count > chars.Length) throw new ArgumentOutOfRangeException(nameof(index));
throw new ArgumentOutOfRangeException(nameof(index));
return count; return count;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The number of bytes produced by encoding all the characters in the specified character array.</returns> /// <returns>The number of bytes produced by encoding all the characters in the specified character array.</returns>
/// <param name="chars">The character array containing the characters to encode.</param> /// <param name="chars">The character array containing the characters to encode.</param>
public override int GetByteCount(char[] chars) public override int GetByteCount(char[] chars)
{ {
if(chars == null) if(chars == null) throw new ArgumentNullException(nameof(chars));
throw new ArgumentNullException(nameof(chars));
return chars.Length; return chars.Length;
} }
/// <summary> /// <summary>
/// Encodes a set of characters from the specified <see cref="string"/> into the specified byte array. /// Encodes a set of characters from the specified <see cref="string" /> into the specified byte array.
/// </summary> /// </summary>
/// <returns>The actual number of bytes written into bytes.</returns> /// <returns>The actual number of bytes written into bytes.</returns>
/// <param name="s">The <see cref="string"/> containing the set of characters to encode.</param> /// <param name="s">The <see cref="string" /> containing the set of characters to encode.</param>
/// <param name="charIndex">The index of the first character to encode.</param> /// <param name="charIndex">The index of the first character to encode.</param>
/// <param name="charCount">The number of characters to encode.</param> /// <param name="charCount">The number of characters to encode.</param>
/// <param name="bytes">The byte array to contain the resulting sequence of bytes.</param> /// <param name="bytes">The byte array to contain the resulting sequence of bytes.</param>
@@ -194,20 +236,19 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>A byte array containing the results of encoding the specified set of characters.</returns> /// <returns>A byte array containing the results of encoding the specified set of characters.</returns>
/// <param name="s">The string containing the characters to encode.</param> /// <param name="s">The string containing the characters to encode.</param>
public override byte[] GetBytes(string s) public override byte[] GetBytes(string s)
{ {
if(s == null) if(s == null) throw new ArgumentNullException(nameof(s));
throw new ArgumentNullException(nameof(s));
return GetBytes(s.ToCharArray(), 0, s.Length); return GetBytes(s.ToCharArray(), 0, s.Length);
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The actual number of bytes written into bytes.</returns> /// <returns>The actual number of bytes written into bytes.</returns>
/// <param name="chars">The character array containing the set of characters to encode.</param> /// <param name="chars">The character array containing the set of characters to encode.</param>
@@ -217,43 +258,33 @@ namespace Claunia.Encoding
/// <param name="byteIndex">The index at which to start writing the resulting sequence of bytes.</param> /// <param name="byteIndex">The index at which to start writing the resulting sequence of bytes.</param>
public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
{ {
if(chars == null) if(chars == null) throw new ArgumentNullException(nameof(chars));
throw new ArgumentNullException(nameof(chars));
if(bytes == null) if(bytes == null) throw new ArgumentNullException(nameof(bytes));
throw new ArgumentNullException(nameof(bytes));
if(charIndex < 0) if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex));
throw new ArgumentOutOfRangeException(nameof(charIndex));
if(charCount < 0) if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount));
throw new ArgumentOutOfRangeException(nameof(charCount));
if(byteIndex < 0) if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex));
throw new ArgumentOutOfRangeException(nameof(byteIndex));
if(charIndex >= chars.Length) if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex));
throw new ArgumentOutOfRangeException(nameof(charIndex));
if(charCount + charIndex > chars.Length) if(charCount + charIndex > chars.Length) throw new ArgumentOutOfRangeException(nameof(charCount));
throw new ArgumentOutOfRangeException(nameof(charCount));
if(byteIndex >= bytes.Length) if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex));
throw new ArgumentOutOfRangeException(nameof(byteIndex));
if(byteIndex + charCount > bytes.Length) if(byteIndex + charCount > bytes.Length) throw new ArgumentException(nameof(bytes));
throw new ArgumentException(nameof(bytes));
byte[] temp = GetBytes(chars, charIndex, charCount); byte[] temp = GetBytes(chars, charIndex, charCount);
for(int i = 0; i < temp.Length; i++) for(int i = 0; i < temp.Length; i++) bytes[i + byteIndex] = temp[i];
bytes[i + byteIndex] = temp[i];
return charCount; return charCount;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>A byte array containing the results of encoding the specified set of characters.</returns> /// <returns>A byte array containing the results of encoding the specified set of characters.</returns>
/// <param name="chars">The character array containing the set of characters to encode.</param> /// <param name="chars">The character array containing the set of characters to encode.</param>
@@ -261,28 +292,23 @@ namespace Claunia.Encoding
/// <param name="count">The number of characters to encode.</param> /// <param name="count">The number of characters to encode.</param>
public override byte[] GetBytes(char[] chars, int index, int count) public override byte[] GetBytes(char[] chars, int index, int count)
{ {
if(chars == null) if(chars == null) throw new ArgumentNullException(nameof(chars));
throw new ArgumentNullException(nameof(chars));
if(index < 0) if(index < 0) throw new ArgumentOutOfRangeException(nameof(index));
throw new ArgumentOutOfRangeException(nameof(index));
if(count < 0) if(count < 0) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
if(count + index > chars.Length) if(count + index > chars.Length) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
byte[] bytes = new byte[count]; byte[] bytes = new byte[count];
for(int i = 0; i < count; i++) for(int i = 0; i < count; i++) bytes[i] = GetByte(chars[index + i]);
bytes[i] = GetByte(chars[index + i]);
return bytes; return bytes;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>A byte array containing the results of encoding the specified set of characters.</returns> /// <returns>A byte array containing the results of encoding the specified set of characters.</returns>
/// <param name="chars">The character array containing the characters to encode.</param> /// <param name="chars">The character array containing the characters to encode.</param>
@@ -292,7 +318,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The number of characters produced by decoding the specified sequence of bytes.</returns> /// <returns>The number of characters produced by decoding the specified sequence of bytes.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -302,7 +328,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The number of characters produced by decoding the specified sequence of bytes.</returns> /// <returns>The number of characters produced by decoding the specified sequence of bytes.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -310,23 +336,19 @@ namespace Claunia.Encoding
/// <param name="count">The number of bytes to decode.</param> /// <param name="count">The number of bytes to decode.</param>
public override int GetCharCount(byte[] bytes, int index, int count) public override int GetCharCount(byte[] bytes, int index, int count)
{ {
if(bytes == null) if(bytes == null) throw new ArgumentNullException(nameof(bytes));
throw new ArgumentNullException(nameof(bytes));
if(index < 0) if(index < 0) throw new ArgumentOutOfRangeException(nameof(index));
throw new ArgumentOutOfRangeException(nameof(index));
if(count < 0) if(count < 0) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
if(count + index > bytes.Length) if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
return count; return count;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The actual number of characters written into chars.</returns> /// <returns>The actual number of characters written into chars.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -336,43 +358,33 @@ namespace Claunia.Encoding
/// <param name="charIndex">The index at which to start writing the resulting set of characters.</param> /// <param name="charIndex">The index at which to start writing the resulting set of characters.</param>
public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
{ {
if(bytes == null) if(bytes == null) throw new ArgumentNullException(nameof(bytes));
throw new ArgumentNullException(nameof(bytes));
if(chars == null) if(chars == null) throw new ArgumentNullException(nameof(chars));
throw new ArgumentNullException(nameof(chars));
if(byteIndex < 0) if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex));
throw new ArgumentOutOfRangeException(nameof(byteIndex));
if(byteCount < 0) if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount));
throw new ArgumentOutOfRangeException(nameof(byteCount));
if(charIndex < 0) if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex));
throw new ArgumentOutOfRangeException(nameof(charIndex));
if(byteIndex >= bytes.Length) if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex));
throw new ArgumentOutOfRangeException(nameof(byteIndex));
if(byteCount + byteIndex > bytes.Length) if(byteCount + byteIndex > bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteCount));
throw new ArgumentOutOfRangeException(nameof(byteCount));
if(charIndex >= chars.Length) if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex));
throw new ArgumentOutOfRangeException(nameof(charIndex));
if(charIndex + byteCount > chars.Length) if(charIndex + byteCount > chars.Length) throw new ArgumentException(nameof(chars));
throw new ArgumentException(nameof(chars));
char[] temp = GetChars(bytes, byteIndex, byteCount); char[] temp = GetChars(bytes, byteIndex, byteCount);
for(int i = 0; i < temp.Length; i++) for(int i = 0; i < temp.Length; i++) chars[i + charIndex] = temp[i];
chars[i + charIndex] = temp[i];
return byteCount; return byteCount;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>A character array containing the results of decoding the specified sequence of bytes.</returns> /// <returns>A character array containing the results of decoding the specified sequence of bytes.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -382,7 +394,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The chars.</returns> /// <returns>The chars.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -390,54 +402,47 @@ namespace Claunia.Encoding
/// <param name="count">The number of bytes to decode.</param> /// <param name="count">The number of bytes to decode.</param>
public override char[] GetChars(byte[] bytes, int index, int count) public override char[] GetChars(byte[] bytes, int index, int count)
{ {
if(bytes == null) if(bytes == null) throw new ArgumentNullException(nameof(bytes));
throw new ArgumentNullException(nameof(bytes));
if(index < 0) if(index < 0) throw new ArgumentOutOfRangeException(nameof(index));
throw new ArgumentOutOfRangeException(nameof(index));
if(count < 0) if(count < 0) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
if(count + index > bytes.Length) if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
char[] chars = new char[count]; char[] chars = new char[count];
for(int i = 0; i < count; i++) for(int i = 0; i < count; i++) chars[i] = GetChar(bytes[index + i]);
chars[i] = GetChar(bytes[index + i]);
return chars; return chars;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The maximum number of bytes produced by encoding the specified number of characters.</returns> /// <returns>The maximum number of bytes produced by encoding the specified number of characters.</returns>
/// <param name="charCount">The number of characters to encode.</param> /// <param name="charCount">The number of characters to encode.</param>
public override int GetMaxByteCount(int charCount) public override int GetMaxByteCount(int charCount)
{ {
if(charCount < 0) if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount));
throw new ArgumentOutOfRangeException(nameof(charCount));
return charCount; return charCount;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The maximum number of characters produced by decoding the specified number of bytes.</returns> /// <returns>The maximum number of characters produced by decoding the specified number of bytes.</returns>
/// <param name="byteCount">The number of bytes to decode.</param> /// <param name="byteCount">The number of bytes to decode.</param>
public override int GetMaxCharCount(int byteCount) public override int GetMaxCharCount(int byteCount)
{ {
if(byteCount < 0) if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount));
throw new ArgumentOutOfRangeException(nameof(byteCount));
return byteCount; return byteCount;
} }
/// <summary> /// <summary>
/// Returns a sequence of bytes that specifies the encoding used. /// Returns a sequence of bytes that specifies the encoding used.
/// </summary> /// </summary>
/// <returns>A byte array of length zero, as a preamble is not required.</returns> /// <returns>A byte array of length zero, as a preamble is not required.</returns>
public override byte[] GetPreamble() public override byte[] GetPreamble()
@@ -446,7 +451,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// Decodes all the bytes in the specified byte array into a string. /// Decodes all the bytes in the specified byte array into a string.
/// </summary> /// </summary>
/// <returns>A string that contains the results of decoding the specified sequence of bytes.</returns> /// <returns>A string that contains the results of decoding the specified sequence of bytes.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -456,7 +461,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>A string that contains the results of decoding the specified sequence of bytes.</returns> /// <returns>A string that contains the results of decoding the specified sequence of bytes.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -468,77 +473,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// The ZX80 to Unicode character map. /// Converts a ZX80 character to an Unicode character
/// </summary>
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'
};
/// <summary>
/// Converts a ZX80 character to an Unicode character
/// </summary> /// </summary>
/// <returns>Unicode character.</returns> /// <returns>Unicode character.</returns>
/// <param name="character">ZX80 character.</param> /// <param name="character">ZX80 character.</param>
@@ -548,159 +483,87 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// Converts a Unicode character to an ZX80 character /// Converts a Unicode character to an ZX80 character
/// </summary> /// </summary>
/// <returns>ZX80 character.</returns> /// <returns>ZX80 character.</returns>
/// <param name="character">Unicode character.</param> /// <param name="character">Unicode character.</param>
static byte GetByte(char character) static byte GetByte(char character)
{ {
switch(character) { switch(character)
case '\u0020': {
return 0x00; case '\u0020': return 0x00;
case '\u0022': case '\u0022': return 0x01;
return 0x01; case '\u258C': return 0x02;
case '\u258C': case '\u2584': return 0x03;
return 0x02; case '\u2598': return 0x04;
case '\u2584': case '\u259D': return 0x05;
return 0x03; case '\u2596': return 0x06;
case '\u2598': case '\u2597': return 0x07;
return 0x04; case '\u259E': return 0x08;
case '\u259D': case '\u2592': return 0x09;
return 0x05; case '\u00A3': return 0x0C;
case '\u2596': case '\u0024': return 0x0D;
return 0x06; case '\u003A': return 0x0E;
case '\u2597': case '\u003F': return 0x0F;
return 0x07; case '\u0028': return 0x10;
case '\u259E': case '\u0029': return 0x11;
return 0x08; case '\u002D': return 0x12;
case '\u2592': case '\u002B': return 0x13;
return 0x09; case '\u002A': return 0x14;
case '\u00A3': case '\u002F': return 0x15;
return 0x0C; case '\u003D': return 0x16;
case '\u0024': case '\u003E': return 0x17;
return 0x0D; case '\u003C': return 0x18;
case '\u003A': case '\u003B': return 0x19;
return 0x0E; case '\u002C': return 0x1A;
case '\u003F': case '\u002E': return 0x1B;
return 0x0F; case '\u0030': return 0x1C;
case '\u0028': case '\u0031': return 0x1D;
return 0x10; case '\u0032': return 0x1E;
case '\u0029': case '\u0033': return 0x1F;
return 0x11; case '\u0034': return 0x20;
case '\u002D': case '\u0035': return 0x21;
return 0x12; case '\u0036': return 0x22;
case '\u002B': case '\u0037': return 0x23;
return 0x13; case '\u0038': return 0x24;
case '\u002A': case '\u0039': return 0x25;
return 0x14; case '\u0041': return 0x26;
case '\u002F': case '\u0042': return 0x27;
return 0x15; case '\u0043': return 0x28;
case '\u003D': case '\u0044': return 0x29;
return 0x16; case '\u0045': return 0x2A;
case '\u003E': case '\u0046': return 0x2B;
return 0x17; case '\u0047': return 0x2C;
case '\u003C': case '\u0048': return 0x2D;
return 0x18; case '\u0049': return 0x2E;
case '\u003B': case '\u004A': return 0x2F;
return 0x19; case '\u004B': return 0x30;
case '\u002C': case '\u004C': return 0x31;
return 0x1A; case '\u004D': return 0x32;
case '\u002E': case '\u004E': return 0x33;
return 0x1B; case '\u004F': return 0x34;
case '\u0030': case '\u0050': return 0x35;
return 0x1C; case '\u0051': return 0x36;
case '\u0031': case '\u0052': return 0x37;
return 0x1D; case '\u0053': return 0x38;
case '\u0032': case '\u0054': return 0x39;
return 0x1E; case '\u0055': return 0x3A;
case '\u0033': case '\u0056': return 0x3B;
return 0x1F; case '\u0057': return 0x3C;
case '\u0034': case '\u0058': return 0x3D;
return 0x20; case '\u0059': return 0x3E;
case '\u0035': case '\u005A': return 0x3F;
return 0x21; case '\u000D': return 0x74;
case '\u0036': case '\u000A': return 0x76;
return 0x22; case '\u0008': return 0x77;
case '\u0037': case '\u2588': return 0x80;
return 0x23; case '\u2590': return 0x82;
case '\u0038': case '\u2580': return 0x83;
return 0x24; case '\u259F': return 0x84;
case '\u0039': case '\u2599': return 0x85;
return 0x25; case '\u259C': return 0x86;
case '\u0041': case '\u259B': return 0x87;
return 0x26; case '\u259A': return 0x88;
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: default:
// Fallback to '?' // Fallback to '?'
return 0x0F; return 0x0F;

View File

@@ -29,7 +29,7 @@ using System;
namespace Claunia.Encoding namespace Claunia.Encoding
{ {
/// <summary> /// <summary>
/// Represents a ZX81 character encoding of Unicode characters. /// Represents a ZX81 character encoding of Unicode characters.
/// </summary> /// </summary>
public class ZX81 : Encoding public class ZX81 : Encoding
{ {
@@ -48,105 +48,151 @@ namespace Claunia.Encoding
const bool singleByte = true; const bool singleByte = true;
/// <summary> /// <summary>
/// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. /// The ZX81 to Unicode character map.
/// </summary> /// </summary>
public override bool IsBrowserDisplay { static readonly char[] ZX81Table =
get { return browserDisplay; } {
} // 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'
};
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override bool IsBrowserSave { public override bool IsBrowserDisplay => browserDisplay;
get { return browserSave; }
}
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override bool IsMailNewsDisplay { public override bool IsBrowserSave => browserSave;
get { return mailNewsDisplay; }
}
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override bool IsMailNewsSave { public override bool IsMailNewsDisplay => mailNewsDisplay;
get { return mailNewsSave; }
}
/// <summary> /// <summary>
/// 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.
/// </summary>
public override bool IsMailNewsSave => mailNewsSave;
/// <summary>
/// Gets a value indicating whether the current encoding is read-only.
/// </summary> /// </summary>
/// <value>The is single byte.</value> /// <value>The is single byte.</value>
public override bool IsReadOnly { public override bool IsReadOnly => readOnly;
get { return readOnly; }
}
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override bool IsSingleByte { public override bool IsSingleByte => singleByte;
get { return singleByte; }
}
/// <summary> /// <summary>
/// Gets the code page identifier of the current Encoding. /// Gets the code page identifier of the current Encoding.
/// </summary> /// </summary>
public override int CodePage { public override int CodePage => _codepage;
get { return _codepage; }
}
/// <summary> /// <summary>
/// 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
/// </summary> /// </summary>
public override string BodyName { public override string BodyName => _bodyname;
get { return _bodyname; }
}
/// <summary> /// <summary>
/// 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
/// </summary> /// </summary>
public override string HeaderName { public override string HeaderName => _headername;
get { return _headername; }
}
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override string WebName { public override string WebName => _webname;
get { return _webname; }
}
/// <summary> /// <summary>
/// Gets the human-readable description of the current encoding. /// Gets the human-readable description of the current encoding.
/// </summary> /// </summary>
public override string EncodingName { public override string EncodingName => _encodingname;
get { return _encodingname; }
}
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override int WindowsCodePage { public override int WindowsCodePage => _windowsCodepage;
get { return _windowsCodepage; }
}
/// <summary> /// <summary>
/// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string"/>. /// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string" />.
/// </summary> /// </summary>
/// <returns>The number of bytes produced by encoding the specified characters.</returns> /// <returns>The number of bytes produced by encoding the specified characters.</returns>
/// <param name="s">The <see cref="string"/> containing the set of characters to encode.</param> /// <param name="s">The <see cref="string" /> containing the set of characters to encode.</param>
public override int GetByteCount(string s) public override int GetByteCount(string s)
{ {
if(s == null) if(s == null) throw new ArgumentNullException(nameof(s));
throw new ArgumentNullException(nameof(s));
return s.Length; return s.Length;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The number of bytes produced by encoding the specified characters.</returns> /// <returns>The number of bytes produced by encoding the specified characters.</returns>
/// <param name="chars">The character array containing the set of characters to encode.</param> /// <param name="chars">The character array containing the set of characters to encode.</param>
@@ -154,36 +200,32 @@ namespace Claunia.Encoding
/// <param name="count">The number of characters to encode.</param> /// <param name="count">The number of characters to encode.</param>
public override int GetByteCount(char[] chars, int index, int count) public override int GetByteCount(char[] chars, int index, int count)
{ {
if(chars == null) if(chars == null) throw new ArgumentNullException(nameof(chars));
throw new ArgumentNullException(nameof(chars));
if(index < 0 || index >= chars.Length) if(index < 0 || index >= chars.Length) throw new ArgumentOutOfRangeException(nameof(index));
throw new ArgumentOutOfRangeException(nameof(index));
if(count < 0 || index + count > chars.Length) if(count < 0 || index + count > chars.Length) throw new ArgumentOutOfRangeException(nameof(index));
throw new ArgumentOutOfRangeException(nameof(index));
return count; return count;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The number of bytes produced by encoding all the characters in the specified character array.</returns> /// <returns>The number of bytes produced by encoding all the characters in the specified character array.</returns>
/// <param name="chars">The character array containing the characters to encode.</param> /// <param name="chars">The character array containing the characters to encode.</param>
public override int GetByteCount(char[] chars) public override int GetByteCount(char[] chars)
{ {
if(chars == null) if(chars == null) throw new ArgumentNullException(nameof(chars));
throw new ArgumentNullException(nameof(chars));
return chars.Length; return chars.Length;
} }
/// <summary> /// <summary>
/// Encodes a set of characters from the specified <see cref="string"/> into the specified byte array. /// Encodes a set of characters from the specified <see cref="string" /> into the specified byte array.
/// </summary> /// </summary>
/// <returns>The actual number of bytes written into bytes.</returns> /// <returns>The actual number of bytes written into bytes.</returns>
/// <param name="s">The <see cref="string"/> containing the set of characters to encode.</param> /// <param name="s">The <see cref="string" /> containing the set of characters to encode.</param>
/// <param name="charIndex">The index of the first character to encode.</param> /// <param name="charIndex">The index of the first character to encode.</param>
/// <param name="charCount">The number of characters to encode.</param> /// <param name="charCount">The number of characters to encode.</param>
/// <param name="bytes">The byte array to contain the resulting sequence of bytes.</param> /// <param name="bytes">The byte array to contain the resulting sequence of bytes.</param>
@@ -194,20 +236,19 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>A byte array containing the results of encoding the specified set of characters.</returns> /// <returns>A byte array containing the results of encoding the specified set of characters.</returns>
/// <param name="s">The string containing the characters to encode.</param> /// <param name="s">The string containing the characters to encode.</param>
public override byte[] GetBytes(string s) public override byte[] GetBytes(string s)
{ {
if(s == null) if(s == null) throw new ArgumentNullException(nameof(s));
throw new ArgumentNullException(nameof(s));
return GetBytes(s.ToCharArray(), 0, s.Length); return GetBytes(s.ToCharArray(), 0, s.Length);
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The actual number of bytes written into bytes.</returns> /// <returns>The actual number of bytes written into bytes.</returns>
/// <param name="chars">The character array containing the set of characters to encode.</param> /// <param name="chars">The character array containing the set of characters to encode.</param>
@@ -217,43 +258,33 @@ namespace Claunia.Encoding
/// <param name="byteIndex">The index at which to start writing the resulting sequence of bytes.</param> /// <param name="byteIndex">The index at which to start writing the resulting sequence of bytes.</param>
public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
{ {
if(chars == null) if(chars == null) throw new ArgumentNullException(nameof(chars));
throw new ArgumentNullException(nameof(chars));
if(bytes == null) if(bytes == null) throw new ArgumentNullException(nameof(bytes));
throw new ArgumentNullException(nameof(bytes));
if(charIndex < 0) if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex));
throw new ArgumentOutOfRangeException(nameof(charIndex));
if(charCount < 0) if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount));
throw new ArgumentOutOfRangeException(nameof(charCount));
if(byteIndex < 0) if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex));
throw new ArgumentOutOfRangeException(nameof(byteIndex));
if(charIndex >= chars.Length) if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex));
throw new ArgumentOutOfRangeException(nameof(charIndex));
if(charCount + charIndex > chars.Length) if(charCount + charIndex > chars.Length) throw new ArgumentOutOfRangeException(nameof(charCount));
throw new ArgumentOutOfRangeException(nameof(charCount));
if(byteIndex >= bytes.Length) if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex));
throw new ArgumentOutOfRangeException(nameof(byteIndex));
if(byteIndex + charCount > bytes.Length) if(byteIndex + charCount > bytes.Length) throw new ArgumentException(nameof(bytes));
throw new ArgumentException(nameof(bytes));
byte[] temp = GetBytes(chars, charIndex, charCount); byte[] temp = GetBytes(chars, charIndex, charCount);
for(int i = 0; i < temp.Length; i++) for(int i = 0; i < temp.Length; i++) bytes[i + byteIndex] = temp[i];
bytes[i + byteIndex] = temp[i];
return charCount; return charCount;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>A byte array containing the results of encoding the specified set of characters.</returns> /// <returns>A byte array containing the results of encoding the specified set of characters.</returns>
/// <param name="chars">The character array containing the set of characters to encode.</param> /// <param name="chars">The character array containing the set of characters to encode.</param>
@@ -261,28 +292,23 @@ namespace Claunia.Encoding
/// <param name="count">The number of characters to encode.</param> /// <param name="count">The number of characters to encode.</param>
public override byte[] GetBytes(char[] chars, int index, int count) public override byte[] GetBytes(char[] chars, int index, int count)
{ {
if(chars == null) if(chars == null) throw new ArgumentNullException(nameof(chars));
throw new ArgumentNullException(nameof(chars));
if(index < 0) if(index < 0) throw new ArgumentOutOfRangeException(nameof(index));
throw new ArgumentOutOfRangeException(nameof(index));
if(count < 0) if(count < 0) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
if(count + index > chars.Length) if(count + index > chars.Length) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
byte[] bytes = new byte[count]; byte[] bytes = new byte[count];
for(int i = 0; i < count; i++) for(int i = 0; i < count; i++) bytes[i] = GetByte(chars[index + i]);
bytes[i] = GetByte(chars[index + i]);
return bytes; return bytes;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>A byte array containing the results of encoding the specified set of characters.</returns> /// <returns>A byte array containing the results of encoding the specified set of characters.</returns>
/// <param name="chars">The character array containing the characters to encode.</param> /// <param name="chars">The character array containing the characters to encode.</param>
@@ -292,7 +318,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The number of characters produced by decoding the specified sequence of bytes.</returns> /// <returns>The number of characters produced by decoding the specified sequence of bytes.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -302,7 +328,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The number of characters produced by decoding the specified sequence of bytes.</returns> /// <returns>The number of characters produced by decoding the specified sequence of bytes.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -310,23 +336,19 @@ namespace Claunia.Encoding
/// <param name="count">The number of bytes to decode.</param> /// <param name="count">The number of bytes to decode.</param>
public override int GetCharCount(byte[] bytes, int index, int count) public override int GetCharCount(byte[] bytes, int index, int count)
{ {
if(bytes == null) if(bytes == null) throw new ArgumentNullException(nameof(bytes));
throw new ArgumentNullException(nameof(bytes));
if(index < 0) if(index < 0) throw new ArgumentOutOfRangeException(nameof(index));
throw new ArgumentOutOfRangeException(nameof(index));
if(count < 0) if(count < 0) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
if(count + index > bytes.Length) if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
return count; return count;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The actual number of characters written into chars.</returns> /// <returns>The actual number of characters written into chars.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -336,43 +358,33 @@ namespace Claunia.Encoding
/// <param name="charIndex">The index at which to start writing the resulting set of characters.</param> /// <param name="charIndex">The index at which to start writing the resulting set of characters.</param>
public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
{ {
if(bytes == null) if(bytes == null) throw new ArgumentNullException(nameof(bytes));
throw new ArgumentNullException(nameof(bytes));
if(chars == null) if(chars == null) throw new ArgumentNullException(nameof(chars));
throw new ArgumentNullException(nameof(chars));
if(byteIndex < 0) if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex));
throw new ArgumentOutOfRangeException(nameof(byteIndex));
if(byteCount < 0) if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount));
throw new ArgumentOutOfRangeException(nameof(byteCount));
if(charIndex < 0) if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex));
throw new ArgumentOutOfRangeException(nameof(charIndex));
if(byteIndex >= bytes.Length) if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex));
throw new ArgumentOutOfRangeException(nameof(byteIndex));
if(byteCount + byteIndex > bytes.Length) if(byteCount + byteIndex > bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteCount));
throw new ArgumentOutOfRangeException(nameof(byteCount));
if(charIndex >= chars.Length) if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex));
throw new ArgumentOutOfRangeException(nameof(charIndex));
if(charIndex + byteCount > chars.Length) if(charIndex + byteCount > chars.Length) throw new ArgumentException(nameof(chars));
throw new ArgumentException(nameof(chars));
char[] temp = GetChars(bytes, byteIndex, byteCount); char[] temp = GetChars(bytes, byteIndex, byteCount);
for(int i = 0; i < temp.Length; i++) for(int i = 0; i < temp.Length; i++) chars[i + charIndex] = temp[i];
chars[i + charIndex] = temp[i];
return byteCount; return byteCount;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>A character array containing the results of decoding the specified sequence of bytes.</returns> /// <returns>A character array containing the results of decoding the specified sequence of bytes.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -382,7 +394,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The chars.</returns> /// <returns>The chars.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -390,54 +402,47 @@ namespace Claunia.Encoding
/// <param name="count">The number of bytes to decode.</param> /// <param name="count">The number of bytes to decode.</param>
public override char[] GetChars(byte[] bytes, int index, int count) public override char[] GetChars(byte[] bytes, int index, int count)
{ {
if(bytes == null) if(bytes == null) throw new ArgumentNullException(nameof(bytes));
throw new ArgumentNullException(nameof(bytes));
if(index < 0) if(index < 0) throw new ArgumentOutOfRangeException(nameof(index));
throw new ArgumentOutOfRangeException(nameof(index));
if(count < 0) if(count < 0) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
if(count + index > bytes.Length) if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
char[] chars = new char[count]; char[] chars = new char[count];
for(int i = 0; i < count; i++) for(int i = 0; i < count; i++) chars[i] = GetChar(bytes[index + i]);
chars[i] = GetChar(bytes[index + i]);
return chars; return chars;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The maximum number of bytes produced by encoding the specified number of characters.</returns> /// <returns>The maximum number of bytes produced by encoding the specified number of characters.</returns>
/// <param name="charCount">The number of characters to encode.</param> /// <param name="charCount">The number of characters to encode.</param>
public override int GetMaxByteCount(int charCount) public override int GetMaxByteCount(int charCount)
{ {
if(charCount < 0) if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount));
throw new ArgumentOutOfRangeException(nameof(charCount));
return charCount; return charCount;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The maximum number of characters produced by decoding the specified number of bytes.</returns> /// <returns>The maximum number of characters produced by decoding the specified number of bytes.</returns>
/// <param name="byteCount">The number of bytes to decode.</param> /// <param name="byteCount">The number of bytes to decode.</param>
public override int GetMaxCharCount(int byteCount) public override int GetMaxCharCount(int byteCount)
{ {
if(byteCount < 0) if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount));
throw new ArgumentOutOfRangeException(nameof(byteCount));
return byteCount; return byteCount;
} }
/// <summary> /// <summary>
/// Returns a sequence of bytes that specifies the encoding used. /// Returns a sequence of bytes that specifies the encoding used.
/// </summary> /// </summary>
/// <returns>A byte array of length zero, as a preamble is not required.</returns> /// <returns>A byte array of length zero, as a preamble is not required.</returns>
public override byte[] GetPreamble() public override byte[] GetPreamble()
@@ -446,7 +451,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// Decodes all the bytes in the specified byte array into a string. /// Decodes all the bytes in the specified byte array into a string.
/// </summary> /// </summary>
/// <returns>A string that contains the results of decoding the specified sequence of bytes.</returns> /// <returns>A string that contains the results of decoding the specified sequence of bytes.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -456,7 +461,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>A string that contains the results of decoding the specified sequence of bytes.</returns> /// <returns>A string that contains the results of decoding the specified sequence of bytes.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -468,77 +473,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// The ZX81 to Unicode character map. /// Converts a ZX81 character to an Unicode character
/// </summary>
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'
};
/// <summary>
/// Converts a ZX81 character to an Unicode character
/// </summary> /// </summary>
/// <returns>Unicode character.</returns> /// <returns>Unicode character.</returns>
/// <param name="character">ZX81 character.</param> /// <param name="character">ZX81 character.</param>
@@ -548,159 +483,87 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// Converts a Unicode character to an ZX81 character /// Converts a Unicode character to an ZX81 character
/// </summary> /// </summary>
/// <returns>ZX81 character.</returns> /// <returns>ZX81 character.</returns>
/// <param name="character">Unicode character.</param> /// <param name="character">Unicode character.</param>
static byte GetByte(char character) static byte GetByte(char character)
{ {
switch(character) { switch(character)
case '\u0020': {
return 0x00; case '\u0020': return 0x00;
case '\u2598': case '\u2598': return 0x01;
return 0x01; case '\u259D': return 0x02;
case '\u259D': case '\u2580': return 0x03;
return 0x02; case '\u2596': return 0x04;
case '\u2580': case '\u258C': return 0x05;
return 0x03; case '\u259E': return 0x06;
case '\u2596': case '\u259B': return 0x07;
return 0x04; case '\u2592': return 0x08;
case '\u258C': case '\u0022': return 0x0B;
return 0x05; case '\u00A3': return 0x0C;
case '\u259E': case '\u0024': return 0x0D;
return 0x06; case '\u003A': return 0x0E;
case '\u259B': case '\u003F': return 0x0F;
return 0x07; case '\u0028': return 0x10;
case '\u2592': case '\u0029': return 0x11;
return 0x08; case '\u003E': return 0x12;
case '\u0022': case '\u003C': return 0x13;
return 0x0B; case '\u003D': return 0x14;
case '\u00A3': case '\u002B': return 0x15;
return 0x0C; case '\u002D': return 0x16;
case '\u0024': case '\u002A': return 0x17;
return 0x0D; case '\u002F': return 0x18;
case '\u003A': case '\u003B': return 0x19;
return 0x0E; case '\u002C': return 0x1A;
case '\u003F': case '\u002E': return 0x1B;
return 0x0F; case '\u0030': return 0x1C;
case '\u0028': case '\u0031': return 0x1D;
return 0x10; case '\u0032': return 0x1E;
case '\u0029': case '\u0033': return 0x1F;
return 0x11; case '\u0034': return 0x20;
case '\u003E': case '\u0035': return 0x21;
return 0x12; case '\u0036': return 0x22;
case '\u003C': case '\u0037': return 0x23;
return 0x13; case '\u0038': return 0x24;
case '\u003D': case '\u0039': return 0x25;
return 0x14; case '\u0041': return 0x26;
case '\u002B': case '\u0042': return 0x27;
return 0x15; case '\u0043': return 0x28;
case '\u002D': case '\u0044': return 0x29;
return 0x16; case '\u0045': return 0x2A;
case '\u002A': case '\u0046': return 0x2B;
return 0x17; case '\u0047': return 0x2C;
case '\u002F': case '\u0048': return 0x2D;
return 0x18; case '\u0049': return 0x2E;
case '\u003B': case '\u004A': return 0x2F;
return 0x19; case '\u004B': return 0x30;
case '\u002C': case '\u004C': return 0x31;
return 0x1A; case '\u004D': return 0x32;
case '\u002E': case '\u004E': return 0x33;
return 0x1B; case '\u004F': return 0x34;
case '\u0030': case '\u0050': return 0x35;
return 0x1C; case '\u0051': return 0x36;
case '\u0031': case '\u0052': return 0x37;
return 0x1D; case '\u0053': return 0x38;
case '\u0032': case '\u0054': return 0x39;
return 0x1E; case '\u0055': return 0x3A;
case '\u0033': case '\u0056': return 0x3B;
return 0x1F; case '\u0057': return 0x3C;
case '\u0034': case '\u0058': return 0x3D;
return 0x20; case '\u0059': return 0x3E;
case '\u0035': case '\u005A': return 0x3F;
return 0x21; case '\u000D': return 0x74;
case '\u0036': case '\u000A': return 0x76;
return 0x22; case '\u0008': return 0x77;
case '\u0037': case '\u2588': return 0x80;
return 0x23; case '\u259F': return 0x81;
case '\u0038': case '\u2599': return 0x82;
return 0x24; case '\u2584': return 0x83;
case '\u0039': case '\u259C': return 0x84;
return 0x25; case '\u2590': return 0x85;
case '\u0041': case '\u259A': return 0x86;
return 0x26; case '\u2597': return 0x87;
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: default:
// Fallback to '?' // Fallback to '?'
return 0x0F; return 0x0F;

View File

@@ -29,7 +29,7 @@ using System;
namespace Claunia.Encoding namespace Claunia.Encoding
{ {
/// <summary> /// <summary>
/// Represents an ZX Spectrum character encoding of Unicode characters. /// Represents an ZX Spectrum character encoding of Unicode characters.
/// </summary> /// </summary>
public class ZXSpectrum : Encoding public class ZXSpectrum : Encoding
{ {
@@ -48,105 +48,151 @@ namespace Claunia.Encoding
const bool singleByte = true; const bool singleByte = true;
/// <summary> /// <summary>
/// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. /// The ZX Spectrum to Unicode character map.
/// </summary> /// </summary>
public override bool IsBrowserDisplay { static readonly char[] ZXSpectrumTable =
get { return browserDisplay; } {
} // 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'
};
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override bool IsBrowserSave { public override bool IsBrowserDisplay => browserDisplay;
get { return browserSave; }
}
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override bool IsMailNewsDisplay { public override bool IsBrowserSave => browserSave;
get { return mailNewsDisplay; }
}
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override bool IsMailNewsSave { public override bool IsMailNewsDisplay => mailNewsDisplay;
get { return mailNewsSave; }
}
/// <summary> /// <summary>
/// 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.
/// </summary>
public override bool IsMailNewsSave => mailNewsSave;
/// <summary>
/// Gets a value indicating whether the current encoding is read-only.
/// </summary> /// </summary>
/// <value>The is single byte.</value> /// <value>The is single byte.</value>
public override bool IsReadOnly { public override bool IsReadOnly => readOnly;
get { return readOnly; }
}
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override bool IsSingleByte { public override bool IsSingleByte => singleByte;
get { return singleByte; }
}
/// <summary> /// <summary>
/// Gets the code page identifier of the current Encoding. /// Gets the code page identifier of the current Encoding.
/// </summary> /// </summary>
public override int CodePage { public override int CodePage => _codepage;
get { return _codepage; }
}
/// <summary> /// <summary>
/// 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
/// </summary> /// </summary>
public override string BodyName { public override string BodyName => _bodyname;
get { return _bodyname; }
}
/// <summary> /// <summary>
/// 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
/// </summary> /// </summary>
public override string HeaderName { public override string HeaderName => _headername;
get { return _headername; }
}
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override string WebName { public override string WebName => _webname;
get { return _webname; }
}
/// <summary> /// <summary>
/// Gets the human-readable description of the current encoding. /// Gets the human-readable description of the current encoding.
/// </summary> /// </summary>
public override string EncodingName { public override string EncodingName => _encodingname;
get { return _encodingname; }
}
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public override int WindowsCodePage { public override int WindowsCodePage => _windowsCodepage;
get { return _windowsCodepage; }
}
/// <summary> /// <summary>
/// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string"/>. /// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string" />.
/// </summary> /// </summary>
/// <returns>The number of bytes produced by encoding the specified characters.</returns> /// <returns>The number of bytes produced by encoding the specified characters.</returns>
/// <param name="s">The <see cref="string"/> containing the set of characters to encode.</param> /// <param name="s">The <see cref="string" /> containing the set of characters to encode.</param>
public override int GetByteCount(string s) public override int GetByteCount(string s)
{ {
if(s == null) if(s == null) throw new ArgumentNullException(nameof(s));
throw new ArgumentNullException(nameof(s));
return s.Length; return s.Length;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The number of bytes produced by encoding the specified characters.</returns> /// <returns>The number of bytes produced by encoding the specified characters.</returns>
/// <param name="chars">The character array containing the set of characters to encode.</param> /// <param name="chars">The character array containing the set of characters to encode.</param>
@@ -154,36 +200,32 @@ namespace Claunia.Encoding
/// <param name="count">The number of characters to encode.</param> /// <param name="count">The number of characters to encode.</param>
public override int GetByteCount(char[] chars, int index, int count) public override int GetByteCount(char[] chars, int index, int count)
{ {
if(chars == null) if(chars == null) throw new ArgumentNullException(nameof(chars));
throw new ArgumentNullException(nameof(chars));
if(index < 0 || index >= chars.Length) if(index < 0 || index >= chars.Length) throw new ArgumentOutOfRangeException(nameof(index));
throw new ArgumentOutOfRangeException(nameof(index));
if(count < 0 || index + count > chars.Length) if(count < 0 || index + count > chars.Length) throw new ArgumentOutOfRangeException(nameof(index));
throw new ArgumentOutOfRangeException(nameof(index));
return count; return count;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The number of bytes produced by encoding all the characters in the specified character array.</returns> /// <returns>The number of bytes produced by encoding all the characters in the specified character array.</returns>
/// <param name="chars">The character array containing the characters to encode.</param> /// <param name="chars">The character array containing the characters to encode.</param>
public override int GetByteCount(char[] chars) public override int GetByteCount(char[] chars)
{ {
if(chars == null) if(chars == null) throw new ArgumentNullException(nameof(chars));
throw new ArgumentNullException(nameof(chars));
return chars.Length; return chars.Length;
} }
/// <summary> /// <summary>
/// Encodes a set of characters from the specified <see cref="string"/> into the specified byte array. /// Encodes a set of characters from the specified <see cref="string" /> into the specified byte array.
/// </summary> /// </summary>
/// <returns>The actual number of bytes written into bytes.</returns> /// <returns>The actual number of bytes written into bytes.</returns>
/// <param name="s">The <see cref="string"/> containing the set of characters to encode.</param> /// <param name="s">The <see cref="string" /> containing the set of characters to encode.</param>
/// <param name="charIndex">The index of the first character to encode.</param> /// <param name="charIndex">The index of the first character to encode.</param>
/// <param name="charCount">The number of characters to encode.</param> /// <param name="charCount">The number of characters to encode.</param>
/// <param name="bytes">The byte array to contain the resulting sequence of bytes.</param> /// <param name="bytes">The byte array to contain the resulting sequence of bytes.</param>
@@ -194,20 +236,19 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>A byte array containing the results of encoding the specified set of characters.</returns> /// <returns>A byte array containing the results of encoding the specified set of characters.</returns>
/// <param name="s">The string containing the characters to encode.</param> /// <param name="s">The string containing the characters to encode.</param>
public override byte[] GetBytes(string s) public override byte[] GetBytes(string s)
{ {
if(s == null) if(s == null) throw new ArgumentNullException(nameof(s));
throw new ArgumentNullException(nameof(s));
return GetBytes(s.ToCharArray(), 0, s.Length); return GetBytes(s.ToCharArray(), 0, s.Length);
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The actual number of bytes written into bytes.</returns> /// <returns>The actual number of bytes written into bytes.</returns>
/// <param name="chars">The character array containing the set of characters to encode.</param> /// <param name="chars">The character array containing the set of characters to encode.</param>
@@ -217,43 +258,33 @@ namespace Claunia.Encoding
/// <param name="byteIndex">The index at which to start writing the resulting sequence of bytes.</param> /// <param name="byteIndex">The index at which to start writing the resulting sequence of bytes.</param>
public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
{ {
if(chars == null) if(chars == null) throw new ArgumentNullException(nameof(chars));
throw new ArgumentNullException(nameof(chars));
if(bytes == null) if(bytes == null) throw new ArgumentNullException(nameof(bytes));
throw new ArgumentNullException(nameof(bytes));
if(charIndex < 0) if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex));
throw new ArgumentOutOfRangeException(nameof(charIndex));
if(charCount < 0) if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount));
throw new ArgumentOutOfRangeException(nameof(charCount));
if(byteIndex < 0) if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex));
throw new ArgumentOutOfRangeException(nameof(byteIndex));
if(charIndex >= chars.Length) if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex));
throw new ArgumentOutOfRangeException(nameof(charIndex));
if(charCount + charIndex > chars.Length) if(charCount + charIndex > chars.Length) throw new ArgumentOutOfRangeException(nameof(charCount));
throw new ArgumentOutOfRangeException(nameof(charCount));
if(byteIndex >= bytes.Length) if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex));
throw new ArgumentOutOfRangeException(nameof(byteIndex));
if(byteIndex + charCount > bytes.Length) if(byteIndex + charCount > bytes.Length) throw new ArgumentException(nameof(bytes));
throw new ArgumentException(nameof(bytes));
byte[] temp = GetBytes(chars, charIndex, charCount); byte[] temp = GetBytes(chars, charIndex, charCount);
for(int i = 0; i < temp.Length; i++) for(int i = 0; i < temp.Length; i++) bytes[i + byteIndex] = temp[i];
bytes[i + byteIndex] = temp[i];
return charCount; return charCount;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>A byte array containing the results of encoding the specified set of characters.</returns> /// <returns>A byte array containing the results of encoding the specified set of characters.</returns>
/// <param name="chars">The character array containing the set of characters to encode.</param> /// <param name="chars">The character array containing the set of characters to encode.</param>
@@ -261,28 +292,23 @@ namespace Claunia.Encoding
/// <param name="count">The number of characters to encode.</param> /// <param name="count">The number of characters to encode.</param>
public override byte[] GetBytes(char[] chars, int index, int count) public override byte[] GetBytes(char[] chars, int index, int count)
{ {
if(chars == null) if(chars == null) throw new ArgumentNullException(nameof(chars));
throw new ArgumentNullException(nameof(chars));
if(index < 0) if(index < 0) throw new ArgumentOutOfRangeException(nameof(index));
throw new ArgumentOutOfRangeException(nameof(index));
if(count < 0) if(count < 0) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
if(count + index > chars.Length) if(count + index > chars.Length) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
byte[] bytes = new byte[count]; byte[] bytes = new byte[count];
for(int i = 0; i < count; i++) for(int i = 0; i < count; i++) bytes[i] = GetByte(chars[index + i]);
bytes[i] = GetByte(chars[index + i]);
return bytes; return bytes;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>A byte array containing the results of encoding the specified set of characters.</returns> /// <returns>A byte array containing the results of encoding the specified set of characters.</returns>
/// <param name="chars">The character array containing the characters to encode.</param> /// <param name="chars">The character array containing the characters to encode.</param>
@@ -292,7 +318,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The number of characters produced by decoding the specified sequence of bytes.</returns> /// <returns>The number of characters produced by decoding the specified sequence of bytes.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -302,7 +328,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The number of characters produced by decoding the specified sequence of bytes.</returns> /// <returns>The number of characters produced by decoding the specified sequence of bytes.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -310,23 +336,19 @@ namespace Claunia.Encoding
/// <param name="count">The number of bytes to decode.</param> /// <param name="count">The number of bytes to decode.</param>
public override int GetCharCount(byte[] bytes, int index, int count) public override int GetCharCount(byte[] bytes, int index, int count)
{ {
if(bytes == null) if(bytes == null) throw new ArgumentNullException(nameof(bytes));
throw new ArgumentNullException(nameof(bytes));
if(index < 0) if(index < 0) throw new ArgumentOutOfRangeException(nameof(index));
throw new ArgumentOutOfRangeException(nameof(index));
if(count < 0) if(count < 0) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
if(count + index > bytes.Length) if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
return count; return count;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The actual number of characters written into chars.</returns> /// <returns>The actual number of characters written into chars.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -336,43 +358,33 @@ namespace Claunia.Encoding
/// <param name="charIndex">The index at which to start writing the resulting set of characters.</param> /// <param name="charIndex">The index at which to start writing the resulting set of characters.</param>
public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
{ {
if(bytes == null) if(bytes == null) throw new ArgumentNullException(nameof(bytes));
throw new ArgumentNullException(nameof(bytes));
if(chars == null) if(chars == null) throw new ArgumentNullException(nameof(chars));
throw new ArgumentNullException(nameof(chars));
if(byteIndex < 0) if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex));
throw new ArgumentOutOfRangeException(nameof(byteIndex));
if(byteCount < 0) if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount));
throw new ArgumentOutOfRangeException(nameof(byteCount));
if(charIndex < 0) if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex));
throw new ArgumentOutOfRangeException(nameof(charIndex));
if(byteIndex >= bytes.Length) if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex));
throw new ArgumentOutOfRangeException(nameof(byteIndex));
if(byteCount + byteIndex > bytes.Length) if(byteCount + byteIndex > bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteCount));
throw new ArgumentOutOfRangeException(nameof(byteCount));
if(charIndex >= chars.Length) if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex));
throw new ArgumentOutOfRangeException(nameof(charIndex));
if(charIndex + byteCount > chars.Length) if(charIndex + byteCount > chars.Length) throw new ArgumentException(nameof(chars));
throw new ArgumentException(nameof(chars));
char[] temp = GetChars(bytes, byteIndex, byteCount); char[] temp = GetChars(bytes, byteIndex, byteCount);
for(int i = 0; i < temp.Length; i++) for(int i = 0; i < temp.Length; i++) chars[i + charIndex] = temp[i];
chars[i + charIndex] = temp[i];
return byteCount; return byteCount;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>A character array containing the results of decoding the specified sequence of bytes.</returns> /// <returns>A character array containing the results of decoding the specified sequence of bytes.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -382,7 +394,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The chars.</returns> /// <returns>The chars.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -390,54 +402,47 @@ namespace Claunia.Encoding
/// <param name="count">The number of bytes to decode.</param> /// <param name="count">The number of bytes to decode.</param>
public override char[] GetChars(byte[] bytes, int index, int count) public override char[] GetChars(byte[] bytes, int index, int count)
{ {
if(bytes == null) if(bytes == null) throw new ArgumentNullException(nameof(bytes));
throw new ArgumentNullException(nameof(bytes));
if(index < 0) if(index < 0) throw new ArgumentOutOfRangeException(nameof(index));
throw new ArgumentOutOfRangeException(nameof(index));
if(count < 0) if(count < 0) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
if(count + index > bytes.Length) if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count));
throw new ArgumentOutOfRangeException(nameof(count));
char[] chars = new char[count]; char[] chars = new char[count];
for(int i = 0; i < count; i++) for(int i = 0; i < count; i++) chars[i] = GetChar(bytes[index + i]);
chars[i] = GetChar(bytes[index + i]);
return chars; return chars;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The maximum number of bytes produced by encoding the specified number of characters.</returns> /// <returns>The maximum number of bytes produced by encoding the specified number of characters.</returns>
/// <param name="charCount">The number of characters to encode.</param> /// <param name="charCount">The number of characters to encode.</param>
public override int GetMaxByteCount(int charCount) public override int GetMaxByteCount(int charCount)
{ {
if(charCount < 0) if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount));
throw new ArgumentOutOfRangeException(nameof(charCount));
return charCount; return charCount;
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>The maximum number of characters produced by decoding the specified number of bytes.</returns> /// <returns>The maximum number of characters produced by decoding the specified number of bytes.</returns>
/// <param name="byteCount">The number of bytes to decode.</param> /// <param name="byteCount">The number of bytes to decode.</param>
public override int GetMaxCharCount(int byteCount) public override int GetMaxCharCount(int byteCount)
{ {
if(byteCount < 0) if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount));
throw new ArgumentOutOfRangeException(nameof(byteCount));
return byteCount; return byteCount;
} }
/// <summary> /// <summary>
/// Returns a sequence of bytes that specifies the encoding used. /// Returns a sequence of bytes that specifies the encoding used.
/// </summary> /// </summary>
/// <returns>A byte array of length zero, as a preamble is not required.</returns> /// <returns>A byte array of length zero, as a preamble is not required.</returns>
public override byte[] GetPreamble() public override byte[] GetPreamble()
@@ -446,7 +451,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// Decodes all the bytes in the specified byte array into a string. /// Decodes all the bytes in the specified byte array into a string.
/// </summary> /// </summary>
/// <returns>A string that contains the results of decoding the specified sequence of bytes.</returns> /// <returns>A string that contains the results of decoding the specified sequence of bytes.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -456,7 +461,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <returns>A string that contains the results of decoding the specified sequence of bytes.</returns> /// <returns>A string that contains the results of decoding the specified sequence of bytes.</returns>
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param> /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
@@ -468,77 +473,7 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// The ZX Spectrum to Unicode character map. /// Converts a ZX Spectrum character to an Unicode character
/// </summary>
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'
};
/// <summary>
/// Converts a ZX Spectrum character to an Unicode character
/// </summary> /// </summary>
/// <returns>Unicode character.</returns> /// <returns>Unicode character.</returns>
/// <param name="character">ZX Spectrum character.</param> /// <param name="character">ZX Spectrum character.</param>
@@ -548,239 +483,127 @@ namespace Claunia.Encoding
} }
/// <summary> /// <summary>
/// Converts a Unicode character to an ZX Spectrum character /// Converts a Unicode character to an ZX Spectrum character
/// </summary> /// </summary>
/// <returns>ZX Spectrum character.</returns> /// <returns>ZX Spectrum character.</returns>
/// <param name="character">Unicode character.</param> /// <param name="character">Unicode character.</param>
static byte GetByte(char character) static byte GetByte(char character)
{ {
switch(character) { switch(character)
case '\u0009': {
return 0x06; case '\u0009': return 0x06;
case '\u000D': case '\u000D': return 0x0D;
return 0x0D; case '\u0020': return 0x20;
case '\u0020': case '\u0021': return 0x21;
return 0x20; case '\u0022': return 0x22;
case '\u0021': case '\u0023': return 0x23;
return 0x21; case '\u0024': return 0x24;
case '\u0022': case '\u0025': return 0x25;
return 0x22; case '\u0026': return 0x26;
case '\u0023': case '\u0027': return 0x27;
return 0x23; case '\u0028': return 0x28;
case '\u0024': case '\u0029': return 0x29;
return 0x24; case '\u002A': return 0x2A;
case '\u0025': case '\u002B': return 0x2B;
return 0x25; case '\u002C': return 0x2C;
case '\u0026': case '\u002D': return 0x2D;
return 0x26; case '\u002E': return 0x2E;
case '\u0027': case '\u002F': return 0x2F;
return 0x27; case '\u0030': return 0x30;
case '\u0028': case '\u0031': return 0x31;
return 0x28; case '\u0032': return 0x32;
case '\u0029': case '\u0033': return 0x33;
return 0x29; case '\u0034': return 0x34;
case '\u002A': case '\u0035': return 0x35;
return 0x2A; case '\u0036': return 0x36;
case '\u002B': case '\u0037': return 0x37;
return 0x2B; case '\u0038': return 0x38;
case '\u002C': case '\u0039': return 0x39;
return 0x2C; case '\u003A': return 0x3A;
case '\u002D': case '\u003B': return 0x3B;
return 0x2D; case '\u003C': return 0x3C;
case '\u002E': case '\u003D': return 0x3D;
return 0x2E; case '\u003E': return 0x3E;
case '\u002F': case '\u003F': return 0x3F;
return 0x2F; case '\u0040': return 0x40;
case '\u0030': case '\u0041': return 0x41;
return 0x30; case '\u0042': return 0x42;
case '\u0031': case '\u0043': return 0x43;
return 0x31; case '\u0044': return 0x44;
case '\u0032': case '\u0045': return 0x45;
return 0x32; case '\u0046': return 0x46;
case '\u0033': case '\u0047': return 0x47;
return 0x33; case '\u0048': return 0x48;
case '\u0034': case '\u0049': return 0x49;
return 0x34; case '\u004A': return 0x4A;
case '\u0035': case '\u004B': return 0x4B;
return 0x35; case '\u004C': return 0x4C;
case '\u0036': case '\u004D': return 0x4D;
return 0x36; case '\u004E': return 0x4E;
case '\u0037': case '\u004F': return 0x4F;
return 0x37; case '\u0050': return 0x50;
case '\u0038': case '\u0051': return 0x51;
return 0x38; case '\u0052': return 0x52;
case '\u0039': case '\u0053': return 0x53;
return 0x39; case '\u0054': return 0x54;
case '\u003A': case '\u0055': return 0x55;
return 0x3A; case '\u0056': return 0x56;
case '\u003B': case '\u0057': return 0x57;
return 0x3B; case '\u0058': return 0x58;
case '\u003C': case '\u0059': return 0x59;
return 0x3C; case '\u005A': return 0x5A;
case '\u003D': case '\u005B': return 0x5B;
return 0x3D; case '\u005C': return 0x5C;
case '\u003E': case '\u005D': return 0x5D;
return 0x3E; case '\u2191': return 0x5E;
case '\u003F': case '\u005F': return 0x5F;
return 0x3F; case '\u00A3': return 0x60;
case '\u0040': case '\u0061': return 0x61;
return 0x40; case '\u0062': return 0x62;
case '\u0041': case '\u0063': return 0x63;
return 0x41; case '\u0064': return 0x64;
case '\u0042': case '\u0065': return 0x65;
return 0x42; case '\u0066': return 0x66;
case '\u0043': case '\u0067': return 0x67;
return 0x43; case '\u0068': return 0x68;
case '\u0044': case '\u0069': return 0x69;
return 0x44; case '\u006A': return 0x6A;
case '\u0045': case '\u006B': return 0x6B;
return 0x45; case '\u006C': return 0x6C;
case '\u0046': case '\u006D': return 0x6D;
return 0x46; case '\u006E': return 0x6E;
case '\u0047': case '\u006F': return 0x6F;
return 0x47; case '\u0070': return 0x70;
case '\u0048': case '\u0071': return 0x71;
return 0x48; case '\u0072': return 0x72;
case '\u0049': case '\u0073': return 0x73;
return 0x49; case '\u0074': return 0x74;
case '\u004A': case '\u0075': return 0x75;
return 0x4A; case '\u0076': return 0x76;
case '\u004B': case '\u0077': return 0x77;
return 0x4B; case '\u0078': return 0x78;
case '\u004C': case '\u0079': return 0x79;
return 0x4C; case '\u007A': return 0x7A;
case '\u004D': case '\u007B': return 0x7B;
return 0x4D; case '\u007C': return 0x7C;
case '\u004E': case '\u007D': return 0x7D;
return 0x4E; case '\u007E': return 0x7E;
case '\u004F': case '\u00A9': return 0x7F;
return 0x4F; case '\u259D': return 0x81;
case '\u0050': case '\u2598': return 0x82;
return 0x50; case '\u2580': return 0x83;
case '\u0051': case '\u2597': return 0x84;
return 0x51; case '\u2590': return 0x85;
case '\u0052': case '\u259A': return 0x86;
return 0x52; case '\u259C': return 0x87;
case '\u0053': case '\u2596': return 0x88;
return 0x53; case '\u259E': return 0x89;
case '\u0054': case '\u258C': return 0x8A;
return 0x54; case '\u259B': return 0x8B;
case '\u0055': case '\u2584': return 0x8C;
return 0x55; case '\u259F': return 0x8D;
case '\u0056': case '\u2599': return 0x8E;
return 0x56; case '\u2588': return 0x8F;
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: default:
// Fallback to '?' // Fallback to '?'
return 0x3F; return 0x3F;