mirror of
https://github.com/claunia/Claunia.Encoding.git
synced 2025-12-16 19:24:43 +00:00
Added Apple II, IIc, IIe and IIgs character sets.
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
<RootNamespace>Claunia.Encoding.Tests</RootNamespace>
|
<RootNamespace>Claunia.Encoding.Tests</RootNamespace>
|
||||||
<AssemblyName>Claunia.Encoding.Tests</AssemblyName>
|
<AssemblyName>Claunia.Encoding.Tests</AssemblyName>
|
||||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||||
<ReleaseVersion>1.2.9.1</ReleaseVersion>
|
<ReleaseVersion>1.3</ReleaseVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
|||||||
@@ -29,6 +29,6 @@ Global
|
|||||||
$2.TabsToSpaces = True
|
$2.TabsToSpaces = True
|
||||||
$0.CSharpFormattingPolicy = $3
|
$0.CSharpFormattingPolicy = $3
|
||||||
$3.scope = text/x-csharp
|
$3.scope = text/x-csharp
|
||||||
version = 1.2.9.1
|
version = 1.3
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|||||||
692
Claunia.Encoding/Apple2.cs
Normal file
692
Claunia.Encoding/Apple2.cs
Normal file
@@ -0,0 +1,692 @@
|
|||||||
|
//
|
||||||
|
// Apple II.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Natalia Portillo <claunia@claunia.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2016 © Claunia.com
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Claunia.Encoding
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents an Apple II character encoding of Unicode characters.
|
||||||
|
/// </summary>
|
||||||
|
public class Apple2 : Encoding
|
||||||
|
{
|
||||||
|
const string _bodyname = "apple2";
|
||||||
|
const int _codepage = 0;
|
||||||
|
const string _encodingname = "Western European (Apple II)";
|
||||||
|
const string _headername = "macintosh";
|
||||||
|
const string _webname = "";
|
||||||
|
const int _windowsCodepage = 0;
|
||||||
|
|
||||||
|
const bool browserDisplay = false;
|
||||||
|
const bool browserSave = false;
|
||||||
|
const bool mailNewsDisplay = false;
|
||||||
|
const bool mailNewsSave = false;
|
||||||
|
const bool readOnly = false;
|
||||||
|
const bool singleByte = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the current encoding can be used by browser clients for displaying content.
|
||||||
|
/// </summary>
|
||||||
|
public override bool IsBrowserDisplay {
|
||||||
|
get { return browserDisplay; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the current encoding can be used by browser clients for saving content.
|
||||||
|
/// </summary>
|
||||||
|
public override bool IsBrowserSave {
|
||||||
|
get { return browserSave; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content.
|
||||||
|
/// </summary>
|
||||||
|
public override bool IsMailNewsDisplay {
|
||||||
|
get { return mailNewsDisplay; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content.
|
||||||
|
/// </summary>
|
||||||
|
public override bool IsMailNewsSave {
|
||||||
|
get { return mailNewsSave; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the current encoding is read-only.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The is single byte.</value>
|
||||||
|
public override bool IsReadOnly {
|
||||||
|
get { return readOnly; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the current encoding uses single-byte code points.
|
||||||
|
/// </summary>
|
||||||
|
public override bool IsSingleByte {
|
||||||
|
get { return singleByte; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the code page identifier of the current Encoding.
|
||||||
|
/// </summary>
|
||||||
|
public override int CodePage {
|
||||||
|
get { return _codepage; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a name for the current encoding that can be used with mail agent body tags
|
||||||
|
/// </summary>
|
||||||
|
public override string BodyName {
|
||||||
|
get { return _bodyname; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a name for the current encoding that can be used with mail agent header tags
|
||||||
|
/// </summary>
|
||||||
|
public override string HeaderName {
|
||||||
|
get { return _headername; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.
|
||||||
|
/// </summary>
|
||||||
|
public override string WebName {
|
||||||
|
get { return _webname; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the human-readable description of the current encoding.
|
||||||
|
/// </summary>
|
||||||
|
public override string EncodingName {
|
||||||
|
get { return _encodingname; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the Windows operating system code page that most closely corresponds to the current encoding.
|
||||||
|
/// </summary>
|
||||||
|
public override int WindowsCodePage {
|
||||||
|
get { return _windowsCodepage; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public override int GetByteCount(string s)
|
||||||
|
{
|
||||||
|
if(s == null)
|
||||||
|
throw new ArgumentNullException(nameof(s));
|
||||||
|
|
||||||
|
return s.Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the number of bytes produced by encoding a set of characters from the specified character array.
|
||||||
|
/// </summary>
|
||||||
|
/// <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="index">The index of the first character to encode.</param>
|
||||||
|
/// <param name="count">The number of characters to encode.</param>
|
||||||
|
public override int GetByteCount(char[] chars, int index, int count)
|
||||||
|
{
|
||||||
|
if(chars == null)
|
||||||
|
throw new ArgumentNullException(nameof(chars));
|
||||||
|
|
||||||
|
if(index < 0 || index >= chars.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(index));
|
||||||
|
|
||||||
|
if(count < 0 || index + count > chars.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(index));
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the number of bytes produced by encoding all the characters in the specified character array.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public override int GetByteCount(char[] chars)
|
||||||
|
{
|
||||||
|
if(chars == null)
|
||||||
|
throw new ArgumentNullException(nameof(chars));
|
||||||
|
|
||||||
|
return chars.Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Encodes a set of characters from the specified <see cref="string"/> into the specified byte array.
|
||||||
|
/// </summary>
|
||||||
|
/// <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="charIndex">The index of the first character 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="byteIndex">The index at which to start writing the resulting sequence of bytes.</param>
|
||||||
|
public override int GetBytes(string s, int charIndex, int charCount, byte[] bytes, int byteIndex)
|
||||||
|
{
|
||||||
|
return GetBytes(s.ToCharArray(), charIndex, charCount, bytes, byteIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Encodes all the characters in the specified string into a sequence of bytes.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public override byte[] GetBytes(string s)
|
||||||
|
{
|
||||||
|
if(s == null)
|
||||||
|
throw new ArgumentNullException(nameof(s));
|
||||||
|
|
||||||
|
return GetBytes(s.ToCharArray(), 0, s.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Encodes a set of characters from the specified character array into the specified byte array.
|
||||||
|
/// </summary>
|
||||||
|
/// <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="charIndex">The index of the first character 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="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)
|
||||||
|
{
|
||||||
|
if(chars == null)
|
||||||
|
throw new ArgumentNullException(nameof(chars));
|
||||||
|
|
||||||
|
if(bytes == null)
|
||||||
|
throw new ArgumentNullException(nameof(bytes));
|
||||||
|
|
||||||
|
if(charIndex < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||||
|
|
||||||
|
if(charCount < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(charCount));
|
||||||
|
|
||||||
|
if(byteIndex < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||||
|
|
||||||
|
if(charIndex >= chars.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||||
|
|
||||||
|
if(charCount + charIndex > chars.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(charCount));
|
||||||
|
|
||||||
|
if(byteIndex >= bytes.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||||
|
|
||||||
|
if(byteIndex + charCount > bytes.Length)
|
||||||
|
throw new ArgumentException(nameof(bytes));
|
||||||
|
|
||||||
|
byte[] temp = GetBytes(chars, charIndex, charCount);
|
||||||
|
|
||||||
|
for(int i = 0; i < temp.Length; i++)
|
||||||
|
bytes[i + byteIndex] = temp[i];
|
||||||
|
|
||||||
|
return charCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Encodes a set of characters from the specified character array into a sequence of bytes.
|
||||||
|
/// </summary>
|
||||||
|
/// <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="index">The index of the first character to encode.</param>
|
||||||
|
/// <param name="count">The number of characters to encode.</param>
|
||||||
|
public override byte[] GetBytes(char[] chars, int index, int count)
|
||||||
|
{
|
||||||
|
if(chars == null)
|
||||||
|
throw new ArgumentNullException(nameof(chars));
|
||||||
|
|
||||||
|
if(index < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(index));
|
||||||
|
|
||||||
|
if(count < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(count));
|
||||||
|
|
||||||
|
if(count + index > chars.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(count));
|
||||||
|
|
||||||
|
byte[] bytes = new byte[count];
|
||||||
|
|
||||||
|
for(int i = 0; i < count; i++)
|
||||||
|
bytes[i] = GetByte(chars[index + i]);
|
||||||
|
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Encodes all the characters in the specified character array into a sequence of bytes.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public override byte[] GetBytes(char[] chars)
|
||||||
|
{
|
||||||
|
return GetBytes(chars, 0, chars.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the number of characters produced by decoding all the bytes in the specified byte array.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public override int GetCharCount(byte[] bytes)
|
||||||
|
{
|
||||||
|
return GetCharCount(bytes, 0, bytes.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array.
|
||||||
|
/// </summary>
|
||||||
|
/// <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="index">The index of the first byte to decode.</param>
|
||||||
|
/// <param name="count">The number of bytes to decode.</param>
|
||||||
|
public override int GetCharCount(byte[] bytes, int index, int count)
|
||||||
|
{
|
||||||
|
if(bytes == null)
|
||||||
|
throw new ArgumentNullException(nameof(bytes));
|
||||||
|
|
||||||
|
if(index < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(index));
|
||||||
|
|
||||||
|
if(count < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(count));
|
||||||
|
|
||||||
|
if(count + index > bytes.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(count));
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Decodes a sequence of bytes from the specified byte array into the specified character array.
|
||||||
|
/// </summary>
|
||||||
|
/// <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="byteIndex">The index of the first byte to decode.</param>
|
||||||
|
/// <param name="byteCount">The number of bytes to decode.</param>
|
||||||
|
/// <param name="chars">The character array to contain 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)
|
||||||
|
{
|
||||||
|
if(bytes == null)
|
||||||
|
throw new ArgumentNullException(nameof(bytes));
|
||||||
|
|
||||||
|
if(chars == null)
|
||||||
|
throw new ArgumentNullException(nameof(chars));
|
||||||
|
|
||||||
|
if(byteIndex < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||||
|
|
||||||
|
if(byteCount < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(byteCount));
|
||||||
|
|
||||||
|
if(charIndex < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||||
|
|
||||||
|
if(byteIndex >= bytes.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||||
|
|
||||||
|
if(byteCount + byteIndex > bytes.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(byteCount));
|
||||||
|
|
||||||
|
if(charIndex >= chars.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||||
|
|
||||||
|
if(charIndex + byteCount > chars.Length)
|
||||||
|
throw new ArgumentException(nameof(chars));
|
||||||
|
|
||||||
|
char[] temp = GetChars(bytes, byteIndex, byteCount);
|
||||||
|
|
||||||
|
for(int i = 0; i < temp.Length; i++)
|
||||||
|
chars[i + charIndex] = temp[i];
|
||||||
|
|
||||||
|
return byteCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Decodes all the bytes in the specified byte array into a set of characters.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public override char[] GetChars(byte[] bytes)
|
||||||
|
{
|
||||||
|
return GetChars(bytes, 0, bytes.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Decodes a sequence of bytes from the specified byte array into a set of characters.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The chars.</returns>
|
||||||
|
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
|
||||||
|
/// <param name="index">The index of the first byte to decode.</param>
|
||||||
|
/// <param name="count">The number of bytes to decode.</param>
|
||||||
|
public override char[] GetChars(byte[] bytes, int index, int count)
|
||||||
|
{
|
||||||
|
if(bytes == null)
|
||||||
|
throw new ArgumentNullException(nameof(bytes));
|
||||||
|
|
||||||
|
if(index < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(index));
|
||||||
|
|
||||||
|
if(count < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(count));
|
||||||
|
|
||||||
|
if(count + index > bytes.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(count));
|
||||||
|
|
||||||
|
char[] chars = new char[count];
|
||||||
|
|
||||||
|
for(int i = 0; i < count; i++)
|
||||||
|
chars[i] = GetChar(bytes[index + i]);
|
||||||
|
|
||||||
|
return chars;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the maximum number of bytes produced by encoding the specified number of characters.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public override int GetMaxByteCount(int charCount)
|
||||||
|
{
|
||||||
|
if(charCount < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(charCount));
|
||||||
|
|
||||||
|
return charCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the maximum number of characters produced by decoding the specified number of bytes.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public override int GetMaxCharCount(int byteCount)
|
||||||
|
{
|
||||||
|
if(byteCount < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(byteCount));
|
||||||
|
|
||||||
|
return byteCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a sequence of bytes that specifies the encoding used.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A byte array of length zero, as a preamble is not required.</returns>
|
||||||
|
public override byte[] GetPreamble()
|
||||||
|
{
|
||||||
|
return new byte[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Decodes all the bytes in the specified byte array into a string.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public string GetString(byte[] bytes)
|
||||||
|
{
|
||||||
|
return GetString(bytes, 0, bytes.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Decodes a sequence of bytes from the specified byte array into a string.
|
||||||
|
/// </summary>
|
||||||
|
/// <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="index">The index of the first byte to decode.</param>
|
||||||
|
/// <param name="count">The number of bytes to decode.</param>
|
||||||
|
public override string GetString(byte[] bytes, int index, int count)
|
||||||
|
{
|
||||||
|
return new string(GetChars(bytes, index, count));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Apple II to Unicode character map.
|
||||||
|
/// </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>
|
||||||
|
/// <returns>Unicode character.</returns>
|
||||||
|
/// <param name="character">Apple II character.</param>
|
||||||
|
static char GetChar(byte character)
|
||||||
|
{
|
||||||
|
return Apple2Table[character];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts a Unicode character to an Apple II character
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Apple II character.</returns>
|
||||||
|
/// <param name="character">Unicode character.</param>
|
||||||
|
static byte GetByte(char character)
|
||||||
|
{
|
||||||
|
switch(character) {
|
||||||
|
case '\u0020':
|
||||||
|
return 0x20;
|
||||||
|
case '\u0021':
|
||||||
|
return 0x21;
|
||||||
|
case '\u0022':
|
||||||
|
return 0x22;
|
||||||
|
case '\u0023':
|
||||||
|
return 0x23;
|
||||||
|
case '\u0024':
|
||||||
|
return 0x24;
|
||||||
|
case '\u0025':
|
||||||
|
return 0x25;
|
||||||
|
case '\u0026':
|
||||||
|
return 0x26;
|
||||||
|
case '\u0027':
|
||||||
|
return 0x27;
|
||||||
|
case '\u0028':
|
||||||
|
return 0x28;
|
||||||
|
case '\u0029':
|
||||||
|
return 0x29;
|
||||||
|
case '\u002A':
|
||||||
|
return 0x2A;
|
||||||
|
case '\u002B':
|
||||||
|
return 0x2B;
|
||||||
|
case '\u002C':
|
||||||
|
return 0x2C;
|
||||||
|
case '\u002D':
|
||||||
|
return 0x2D;
|
||||||
|
case '\u002E':
|
||||||
|
return 0x2E;
|
||||||
|
case '\u002F':
|
||||||
|
return 0x2F;
|
||||||
|
case '\u0030':
|
||||||
|
return 0x30;
|
||||||
|
case '\u0031':
|
||||||
|
return 0x31;
|
||||||
|
case '\u0032':
|
||||||
|
return 0x32;
|
||||||
|
case '\u0033':
|
||||||
|
return 0x33;
|
||||||
|
case '\u0034':
|
||||||
|
return 0x34;
|
||||||
|
case '\u0035':
|
||||||
|
return 0x35;
|
||||||
|
case '\u0036':
|
||||||
|
return 0x36;
|
||||||
|
case '\u0037':
|
||||||
|
return 0x37;
|
||||||
|
case '\u0038':
|
||||||
|
return 0x38;
|
||||||
|
case '\u0039':
|
||||||
|
return 0x39;
|
||||||
|
case '\u003A':
|
||||||
|
return 0x3A;
|
||||||
|
case '\u003B':
|
||||||
|
return 0x3B;
|
||||||
|
case '\u003C':
|
||||||
|
return 0x3C;
|
||||||
|
case '\u003D':
|
||||||
|
return 0x3D;
|
||||||
|
case '\u003E':
|
||||||
|
return 0x3E;
|
||||||
|
case '\u003F':
|
||||||
|
return 0x3F;
|
||||||
|
case '\u0040':
|
||||||
|
return 0x40;
|
||||||
|
case '\u0041':
|
||||||
|
return 0x41;
|
||||||
|
case '\u0042':
|
||||||
|
return 0x42;
|
||||||
|
case '\u0043':
|
||||||
|
return 0x43;
|
||||||
|
case '\u0044':
|
||||||
|
return 0x44;
|
||||||
|
case '\u0045':
|
||||||
|
return 0x45;
|
||||||
|
case '\u0046':
|
||||||
|
return 0x46;
|
||||||
|
case '\u0047':
|
||||||
|
return 0x47;
|
||||||
|
case '\u0048':
|
||||||
|
return 0x48;
|
||||||
|
case '\u0049':
|
||||||
|
return 0x49;
|
||||||
|
case '\u004A':
|
||||||
|
return 0x4A;
|
||||||
|
case '\u004B':
|
||||||
|
return 0x4B;
|
||||||
|
case '\u004C':
|
||||||
|
return 0x4C;
|
||||||
|
case '\u004D':
|
||||||
|
return 0x4D;
|
||||||
|
case '\u004E':
|
||||||
|
return 0x4E;
|
||||||
|
case '\u004F':
|
||||||
|
return 0x4F;
|
||||||
|
case '\u0050':
|
||||||
|
return 0x50;
|
||||||
|
case '\u0051':
|
||||||
|
return 0x51;
|
||||||
|
case '\u0052':
|
||||||
|
return 0x52;
|
||||||
|
case '\u0053':
|
||||||
|
return 0x53;
|
||||||
|
case '\u0054':
|
||||||
|
return 0x54;
|
||||||
|
case '\u0055':
|
||||||
|
return 0x55;
|
||||||
|
case '\u0056':
|
||||||
|
return 0x56;
|
||||||
|
case '\u0057':
|
||||||
|
return 0x57;
|
||||||
|
case '\u0058':
|
||||||
|
return 0x58;
|
||||||
|
case '\u0059':
|
||||||
|
return 0x59;
|
||||||
|
case '\u005A':
|
||||||
|
return 0x5A;
|
||||||
|
case '\u005B':
|
||||||
|
return 0x5B;
|
||||||
|
case '\u005C':
|
||||||
|
return 0x5C;
|
||||||
|
case '\u005D':
|
||||||
|
return 0x5D;
|
||||||
|
case '\u005E':
|
||||||
|
return 0x5E;
|
||||||
|
case '\u005F':
|
||||||
|
return 0x5F;
|
||||||
|
default:
|
||||||
|
// Fallback to '?'
|
||||||
|
return 0x3F;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
841
Claunia.Encoding/Apple2c.cs
Normal file
841
Claunia.Encoding/Apple2c.cs
Normal file
@@ -0,0 +1,841 @@
|
|||||||
|
//
|
||||||
|
// Apple IIc.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Natalia Portillo <claunia@claunia.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2016 © Claunia.com
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Claunia.Encoding
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents an Apple IIc character encoding of Unicode characters.
|
||||||
|
/// </summary>
|
||||||
|
public class Apple2c : Encoding
|
||||||
|
{
|
||||||
|
const string _bodyname = "apple2c";
|
||||||
|
const int _codepage = 0;
|
||||||
|
const string _encodingname = "Western European (Apple IIc)";
|
||||||
|
const string _headername = "apple2c";
|
||||||
|
const string _webname = "";
|
||||||
|
const int _windowsCodepage = 0;
|
||||||
|
|
||||||
|
const bool browserDisplay = false;
|
||||||
|
const bool browserSave = false;
|
||||||
|
const bool mailNewsDisplay = false;
|
||||||
|
const bool mailNewsSave = false;
|
||||||
|
const bool readOnly = true;
|
||||||
|
const bool singleByte = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the current encoding can be used by browser clients for displaying content.
|
||||||
|
/// </summary>
|
||||||
|
public override bool IsBrowserDisplay {
|
||||||
|
get { return browserDisplay; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the current encoding can be used by browser clients for saving content.
|
||||||
|
/// </summary>
|
||||||
|
public override bool IsBrowserSave {
|
||||||
|
get { return browserSave; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content.
|
||||||
|
/// </summary>
|
||||||
|
public override bool IsMailNewsDisplay {
|
||||||
|
get { return mailNewsDisplay; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content.
|
||||||
|
/// </summary>
|
||||||
|
public override bool IsMailNewsSave {
|
||||||
|
get { return mailNewsSave; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the current encoding is read-only.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The is single byte.</value>
|
||||||
|
public override bool IsReadOnly {
|
||||||
|
get { return readOnly; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the current encoding uses single-byte code points.
|
||||||
|
/// </summary>
|
||||||
|
public override bool IsSingleByte {
|
||||||
|
get { return singleByte; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the code page identifier of the current Encoding.
|
||||||
|
/// </summary>
|
||||||
|
public override int CodePage {
|
||||||
|
get { return _codepage; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a name for the current encoding that can be used with mail agent body tags
|
||||||
|
/// </summary>
|
||||||
|
public override string BodyName {
|
||||||
|
get { return _bodyname; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a name for the current encoding that can be used with mail agent header tags
|
||||||
|
/// </summary>
|
||||||
|
public override string HeaderName {
|
||||||
|
get { return _headername; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.
|
||||||
|
/// </summary>
|
||||||
|
public override string WebName {
|
||||||
|
get { return _webname; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the human-readable description of the current encoding.
|
||||||
|
/// </summary>
|
||||||
|
public override string EncodingName {
|
||||||
|
get { return _encodingname; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the Windows operating system code page that most closely corresponds to the current encoding.
|
||||||
|
/// </summary>
|
||||||
|
public override int WindowsCodePage {
|
||||||
|
get { return _windowsCodepage; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public override int GetByteCount(string s)
|
||||||
|
{
|
||||||
|
if(s == null)
|
||||||
|
throw new ArgumentNullException(nameof(s));
|
||||||
|
|
||||||
|
return s.Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the number of bytes produced by encoding a set of characters from the specified character array.
|
||||||
|
/// </summary>
|
||||||
|
/// <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="index">The index of the first character to encode.</param>
|
||||||
|
/// <param name="count">The number of characters to encode.</param>
|
||||||
|
public override int GetByteCount(char[] chars, int index, int count)
|
||||||
|
{
|
||||||
|
if(chars == null)
|
||||||
|
throw new ArgumentNullException(nameof(chars));
|
||||||
|
|
||||||
|
if(index < 0 || index >= chars.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(index));
|
||||||
|
|
||||||
|
if(count < 0 || index + count > chars.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(index));
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the number of bytes produced by encoding all the characters in the specified character array.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public override int GetByteCount(char[] chars)
|
||||||
|
{
|
||||||
|
if(chars == null)
|
||||||
|
throw new ArgumentNullException(nameof(chars));
|
||||||
|
|
||||||
|
return chars.Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Encodes a set of characters from the specified <see cref="string"/> into the specified byte array.
|
||||||
|
/// </summary>
|
||||||
|
/// <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="charIndex">The index of the first character 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="byteIndex">The index at which to start writing the resulting sequence of bytes.</param>
|
||||||
|
public override int GetBytes(string s, int charIndex, int charCount, byte[] bytes, int byteIndex)
|
||||||
|
{
|
||||||
|
return GetBytes(s.ToCharArray(), charIndex, charCount, bytes, byteIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Encodes all the characters in the specified string into a sequence of bytes.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public override byte[] GetBytes(string s)
|
||||||
|
{
|
||||||
|
if(s == null)
|
||||||
|
throw new ArgumentNullException(nameof(s));
|
||||||
|
|
||||||
|
return GetBytes(s.ToCharArray(), 0, s.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Encodes a set of characters from the specified character array into the specified byte array.
|
||||||
|
/// </summary>
|
||||||
|
/// <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="charIndex">The index of the first character 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="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)
|
||||||
|
{
|
||||||
|
if(chars == null)
|
||||||
|
throw new ArgumentNullException(nameof(chars));
|
||||||
|
|
||||||
|
if(bytes == null)
|
||||||
|
throw new ArgumentNullException(nameof(bytes));
|
||||||
|
|
||||||
|
if(charIndex < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||||
|
|
||||||
|
if(charCount < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(charCount));
|
||||||
|
|
||||||
|
if(byteIndex < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||||
|
|
||||||
|
if(charIndex >= chars.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||||
|
|
||||||
|
if(charCount + charIndex > chars.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(charCount));
|
||||||
|
|
||||||
|
if(byteIndex >= bytes.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||||
|
|
||||||
|
if(byteIndex + charCount > bytes.Length)
|
||||||
|
throw new ArgumentException(nameof(bytes));
|
||||||
|
|
||||||
|
byte[] temp = GetBytes(chars, charIndex, charCount);
|
||||||
|
|
||||||
|
for(int i = 0; i < temp.Length; i++)
|
||||||
|
bytes[i + byteIndex] = temp[i];
|
||||||
|
|
||||||
|
return charCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Encodes a set of characters from the specified character array into a sequence of bytes.
|
||||||
|
/// </summary>
|
||||||
|
/// <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="index">The index of the first character to encode.</param>
|
||||||
|
/// <param name="count">The number of characters to encode.</param>
|
||||||
|
public override byte[] GetBytes(char[] chars, int index, int count)
|
||||||
|
{
|
||||||
|
if(chars == null)
|
||||||
|
throw new ArgumentNullException(nameof(chars));
|
||||||
|
|
||||||
|
if(index < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(index));
|
||||||
|
|
||||||
|
if(count < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(count));
|
||||||
|
|
||||||
|
if(count + index > chars.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(count));
|
||||||
|
|
||||||
|
byte[] bytes = new byte[count];
|
||||||
|
|
||||||
|
for(int i = 0; i < count; i++)
|
||||||
|
bytes[i] = GetByte(chars[index + i]);
|
||||||
|
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Encodes all the characters in the specified character array into a sequence of bytes.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public override byte[] GetBytes(char[] chars)
|
||||||
|
{
|
||||||
|
return GetBytes(chars, 0, chars.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the number of characters produced by decoding all the bytes in the specified byte array.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public override int GetCharCount(byte[] bytes)
|
||||||
|
{
|
||||||
|
return GetCharCount(bytes, 0, bytes.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array.
|
||||||
|
/// </summary>
|
||||||
|
/// <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="index">The index of the first byte to decode.</param>
|
||||||
|
/// <param name="count">The number of bytes to decode.</param>
|
||||||
|
public override int GetCharCount(byte[] bytes, int index, int count)
|
||||||
|
{
|
||||||
|
if(bytes == null)
|
||||||
|
throw new ArgumentNullException(nameof(bytes));
|
||||||
|
|
||||||
|
if(index < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(index));
|
||||||
|
|
||||||
|
if(count < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(count));
|
||||||
|
|
||||||
|
if(count + index > bytes.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(count));
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Decodes a sequence of bytes from the specified byte array into the specified character array.
|
||||||
|
/// </summary>
|
||||||
|
/// <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="byteIndex">The index of the first byte to decode.</param>
|
||||||
|
/// <param name="byteCount">The number of bytes to decode.</param>
|
||||||
|
/// <param name="chars">The character array to contain 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)
|
||||||
|
{
|
||||||
|
if(bytes == null)
|
||||||
|
throw new ArgumentNullException(nameof(bytes));
|
||||||
|
|
||||||
|
if(chars == null)
|
||||||
|
throw new ArgumentNullException(nameof(chars));
|
||||||
|
|
||||||
|
if(byteIndex < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||||
|
|
||||||
|
if(byteCount < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(byteCount));
|
||||||
|
|
||||||
|
if(charIndex < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||||
|
|
||||||
|
if(byteIndex >= bytes.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||||
|
|
||||||
|
if(byteCount + byteIndex > bytes.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(byteCount));
|
||||||
|
|
||||||
|
if(charIndex >= chars.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||||
|
|
||||||
|
if(charIndex + byteCount > chars.Length)
|
||||||
|
throw new ArgumentException(nameof(chars));
|
||||||
|
|
||||||
|
char[] temp = GetChars(bytes, byteIndex, byteCount);
|
||||||
|
|
||||||
|
for(int i = 0; i < temp.Length; i++)
|
||||||
|
chars[i + charIndex] = temp[i];
|
||||||
|
|
||||||
|
return byteCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Decodes all the bytes in the specified byte array into a set of characters.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public override char[] GetChars(byte[] bytes)
|
||||||
|
{
|
||||||
|
return GetChars(bytes, 0, bytes.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Decodes a sequence of bytes from the specified byte array into a set of characters.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The chars.</returns>
|
||||||
|
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
|
||||||
|
/// <param name="index">The index of the first byte to decode.</param>
|
||||||
|
/// <param name="count">The number of bytes to decode.</param>
|
||||||
|
public override char[] GetChars(byte[] bytes, int index, int count)
|
||||||
|
{
|
||||||
|
if(bytes == null)
|
||||||
|
throw new ArgumentNullException(nameof(bytes));
|
||||||
|
|
||||||
|
if(index < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(index));
|
||||||
|
|
||||||
|
if(count < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(count));
|
||||||
|
|
||||||
|
if(count + index > bytes.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(count));
|
||||||
|
|
||||||
|
char[] chars = new char[count];
|
||||||
|
|
||||||
|
for(int i = 0; i < count; i++)
|
||||||
|
chars[i] = GetChar(bytes[index + i]);
|
||||||
|
|
||||||
|
return chars;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the maximum number of bytes produced by encoding the specified number of characters.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public override int GetMaxByteCount(int charCount)
|
||||||
|
{
|
||||||
|
if(charCount < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(charCount));
|
||||||
|
|
||||||
|
return charCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the maximum number of characters produced by decoding the specified number of bytes.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public override int GetMaxCharCount(int byteCount)
|
||||||
|
{
|
||||||
|
if(byteCount < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(byteCount));
|
||||||
|
|
||||||
|
return byteCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a sequence of bytes that specifies the encoding used.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A byte array of length zero, as a preamble is not required.</returns>
|
||||||
|
public override byte[] GetPreamble()
|
||||||
|
{
|
||||||
|
return new byte[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Decodes all the bytes in the specified byte array into a string.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public string GetString(byte[] bytes)
|
||||||
|
{
|
||||||
|
return GetString(bytes, 0, bytes.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Decodes a sequence of bytes from the specified byte array into a string.
|
||||||
|
/// </summary>
|
||||||
|
/// <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="index">The index of the first byte to decode.</param>
|
||||||
|
/// <param name="count">The number of bytes to decode.</param>
|
||||||
|
public override string GetString(byte[] bytes, int index, int count)
|
||||||
|
{
|
||||||
|
return new string(GetChars(bytes, index, count));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Apple IIc to Unicode character map.
|
||||||
|
/// Inverted screen characters are mapped to normal characters.
|
||||||
|
/// </summary>
|
||||||
|
static readonly char[] Apple2cTable = {
|
||||||
|
// 0x00
|
||||||
|
'\u0000','\u0001','\u0002','\u0003','\u0004','\u0005','\u0006','\u0007',
|
||||||
|
// 0x08
|
||||||
|
'\u0008','\u0009','\u000A','\u000B','\u000C','\u000D','\u000E','\u000F',
|
||||||
|
// 0x10
|
||||||
|
'\u0010','\u0011','\u0012','\u0013','\u0014','\u0015','\u0016','\u0017',
|
||||||
|
// 0x18
|
||||||
|
'\u0018','\u0019','\u001A','\u001B','\u001C','\u001D','\u001E','\u001F',
|
||||||
|
// 0x20
|
||||||
|
'\u0020','\u0021','\u0022','\u0023','\u0024','\u0025','\u0026','\u0027',
|
||||||
|
// 0x28
|
||||||
|
'\u0028','\u0029','\u002A','\u002B','\u002C','\u002D','\u002E','\u002F',
|
||||||
|
// 0x30
|
||||||
|
'\u0030','\u0031','\u0032','\u0033','\u0034','\u0035','\u0036','\u0037',
|
||||||
|
// 0x38
|
||||||
|
'\u0038','\u0039','\u003A','\u003B','\u003C','\u003D','\u003E','\u003F',
|
||||||
|
// 0x40
|
||||||
|
'\u0040','\u0041','\u0042','\u0043','\u0044','\u0045','\u0046','\u0047',
|
||||||
|
// 0x48
|
||||||
|
'\u0048','\u0049','\u004A','\u004B','\u004C','\u004D','\u004E','\u004F',
|
||||||
|
// 0x50
|
||||||
|
'\u0050','\u0051','\u0052','\u0053','\u0054','\u0055','\u0056','\u0057',
|
||||||
|
// 0x58
|
||||||
|
'\u0058','\u0059','\u005A','\u005B','\u00A3','\u005D','\u005E','\u005F',
|
||||||
|
// 0x60
|
||||||
|
'\u0060','\u0061','\u0062','\u0063','\u0064','\u0065','\u0066','\u0067',
|
||||||
|
// 0x68
|
||||||
|
'\u0068','\u0069','\u006A','\u006B','\u006C','\u006D','\u006E','\u006F',
|
||||||
|
// 0x70
|
||||||
|
'\u0070','\u0071','\u0072','\u0073','\u0074','\u0075','\u0076','\u0077',
|
||||||
|
// 0x78
|
||||||
|
'\u0078','\u0079','\u007A','\u007B','\u007C','\u007D','\u007E','\u007F',
|
||||||
|
// 0x80
|
||||||
|
'\u0040','\u0041','\u0042','\u0043','\u0044','\u0045','\u0046','\u0047',
|
||||||
|
// 0x88
|
||||||
|
'\u0048','\u0049','\u004A','\u004B','\u004C','\u004D','\u004E','\u004F',
|
||||||
|
// 0x90
|
||||||
|
'\u0050','\u0051','\u0052','\u0053','\u0054','\u0055','\u0056','\u0057',
|
||||||
|
// 0x98
|
||||||
|
'\u0058','\u0059','\u005A','\u005B','\u00A3','\u005D','\u005E','\u0020',
|
||||||
|
// 0xA0
|
||||||
|
'\u2588','\u0021','\u0022','\u0023','\u0024','\u0025','\u0026','\u0027',
|
||||||
|
// 0xA8
|
||||||
|
'\u0028','\u0029','\u002A','\u002B','\u002C','\u002D','\u002E','\u002F',
|
||||||
|
// 0xB0
|
||||||
|
'\u0030','\u0031','\u0032','\u0033','\u0034','\u0035','\u0036','\u0037',
|
||||||
|
// 0xB8
|
||||||
|
'\u0030','\u0031','\u0032','\u0033','\u0034','\u0035','\u0036','\u0037',
|
||||||
|
// 0xC0
|
||||||
|
'\u0000','\u0000','\u0000','\u231B','\u2713','\u0000','\u0000','\u0000',
|
||||||
|
// 0xC8
|
||||||
|
'\u2190','\u2026','\u2193','\u2191','\u0000','\u21B5','\u0000','\u0000',
|
||||||
|
// 0xD0
|
||||||
|
'\u0000','\u0000','\u0000','\u0000','\u0000','\u2192','\u0000','\u0000',
|
||||||
|
// 0xD8
|
||||||
|
'\u0000','\u0000','\u0000','\u25c6','\u0000','\u0000','\u0000','\u0000',
|
||||||
|
// 0xE0
|
||||||
|
'\u0060','\u0061','\u0062','\u0063','\u0064','\u0065','\u0066','\u0067',
|
||||||
|
// 0xE8
|
||||||
|
'\u0068','\u0069','\u006A','\u006B','\u006C','\u006D','\u006E','\u006F',
|
||||||
|
// 0xF0
|
||||||
|
'\u0070','\u0071','\u0072','\u0073','\u0074','\u0075','\u0076','\u0077',
|
||||||
|
// 0xF8
|
||||||
|
'\u0078','\u0079','\u007A','\u007B','\u007C','\u007D','\u007E','\u007F',
|
||||||
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts a Apple IIc character to an Unicode character
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Unicode character.</returns>
|
||||||
|
/// <param name="character">Apple IIc character.</param>
|
||||||
|
static char GetChar(byte character)
|
||||||
|
{
|
||||||
|
return Apple2cTable[character];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts a Unicode character to an Apple IIc character
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Apple IIc character.</returns>
|
||||||
|
/// <param name="character">Unicode character.</param>
|
||||||
|
static byte GetByte(char character)
|
||||||
|
{
|
||||||
|
switch(character) {
|
||||||
|
case '\u0000':
|
||||||
|
return 0x00;
|
||||||
|
case '\u0001':
|
||||||
|
return 0x01;
|
||||||
|
case '\u0002':
|
||||||
|
return 0x02;
|
||||||
|
case '\u0003':
|
||||||
|
return 0x03;
|
||||||
|
case '\u0004':
|
||||||
|
return 0x04;
|
||||||
|
case '\u0005':
|
||||||
|
return 0x05;
|
||||||
|
case '\u0006':
|
||||||
|
return 0x06;
|
||||||
|
case '\u0007':
|
||||||
|
return 0x07;
|
||||||
|
case '\u0008':
|
||||||
|
return 0x08;
|
||||||
|
case '\u0009':
|
||||||
|
return 0x09;
|
||||||
|
case '\u000A':
|
||||||
|
return 0x0A;
|
||||||
|
case '\u000B':
|
||||||
|
return 0x0B;
|
||||||
|
case '\u000C':
|
||||||
|
return 0x0C;
|
||||||
|
case '\u000D':
|
||||||
|
return 0x0D;
|
||||||
|
case '\u000E':
|
||||||
|
return 0x0E;
|
||||||
|
case '\u000F':
|
||||||
|
return 0x0F;
|
||||||
|
case '\u0010':
|
||||||
|
return 0x10;
|
||||||
|
case '\u0011':
|
||||||
|
return 0x11;
|
||||||
|
case '\u0012':
|
||||||
|
return 0x12;
|
||||||
|
case '\u0013':
|
||||||
|
return 0x13;
|
||||||
|
case '\u0014':
|
||||||
|
return 0x14;
|
||||||
|
case '\u0015':
|
||||||
|
return 0x15;
|
||||||
|
case '\u0016':
|
||||||
|
return 0x16;
|
||||||
|
case '\u0017':
|
||||||
|
return 0x17;
|
||||||
|
case '\u0018':
|
||||||
|
return 0x18;
|
||||||
|
case '\u0019':
|
||||||
|
return 0x19;
|
||||||
|
case '\u001A':
|
||||||
|
return 0x1A;
|
||||||
|
case '\u001B':
|
||||||
|
return 0x1B;
|
||||||
|
case '\u001C':
|
||||||
|
return 0x1C;
|
||||||
|
case '\u001D':
|
||||||
|
return 0x1D;
|
||||||
|
case '\u001E':
|
||||||
|
return 0x1E;
|
||||||
|
case '\u001F':
|
||||||
|
return 0x1F;
|
||||||
|
case '\u0020':
|
||||||
|
return 0x20;
|
||||||
|
case '\u0021':
|
||||||
|
return 0x21;
|
||||||
|
case '\u0022':
|
||||||
|
return 0x22;
|
||||||
|
case '\u0023':
|
||||||
|
return 0x23;
|
||||||
|
case '\u0024':
|
||||||
|
return 0x24;
|
||||||
|
case '\u0025':
|
||||||
|
return 0x25;
|
||||||
|
case '\u0026':
|
||||||
|
return 0x26;
|
||||||
|
case '\u0027':
|
||||||
|
return 0x27;
|
||||||
|
case '\u0028':
|
||||||
|
return 0x28;
|
||||||
|
case '\u0029':
|
||||||
|
return 0x29;
|
||||||
|
case '\u002A':
|
||||||
|
return 0x2A;
|
||||||
|
case '\u002B':
|
||||||
|
return 0x2B;
|
||||||
|
case '\u002C':
|
||||||
|
return 0x2C;
|
||||||
|
case '\u002D':
|
||||||
|
return 0x2D;
|
||||||
|
case '\u002E':
|
||||||
|
return 0x2E;
|
||||||
|
case '\u002F':
|
||||||
|
return 0x2F;
|
||||||
|
case '\u0030':
|
||||||
|
return 0x30;
|
||||||
|
case '\u0031':
|
||||||
|
return 0x31;
|
||||||
|
case '\u0032':
|
||||||
|
return 0x32;
|
||||||
|
case '\u0033':
|
||||||
|
return 0x33;
|
||||||
|
case '\u0034':
|
||||||
|
return 0x34;
|
||||||
|
case '\u0035':
|
||||||
|
return 0x35;
|
||||||
|
case '\u0036':
|
||||||
|
return 0x36;
|
||||||
|
case '\u0037':
|
||||||
|
return 0x37;
|
||||||
|
case '\u0038':
|
||||||
|
return 0x38;
|
||||||
|
case '\u0039':
|
||||||
|
return 0x39;
|
||||||
|
case '\u003A':
|
||||||
|
return 0x3A;
|
||||||
|
case '\u003B':
|
||||||
|
return 0x3B;
|
||||||
|
case '\u003C':
|
||||||
|
return 0x3C;
|
||||||
|
case '\u003D':
|
||||||
|
return 0x3D;
|
||||||
|
case '\u003E':
|
||||||
|
return 0x3E;
|
||||||
|
case '\u003F':
|
||||||
|
return 0x3F;
|
||||||
|
case '\u0040':
|
||||||
|
return 0x40;
|
||||||
|
case '\u0041':
|
||||||
|
return 0x41;
|
||||||
|
case '\u0042':
|
||||||
|
return 0x42;
|
||||||
|
case '\u0043':
|
||||||
|
return 0x43;
|
||||||
|
case '\u0044':
|
||||||
|
return 0x44;
|
||||||
|
case '\u0045':
|
||||||
|
return 0x45;
|
||||||
|
case '\u0046':
|
||||||
|
return 0x46;
|
||||||
|
case '\u0047':
|
||||||
|
return 0x47;
|
||||||
|
case '\u0048':
|
||||||
|
return 0x48;
|
||||||
|
case '\u0049':
|
||||||
|
return 0x49;
|
||||||
|
case '\u004A':
|
||||||
|
return 0x4A;
|
||||||
|
case '\u004B':
|
||||||
|
return 0x4B;
|
||||||
|
case '\u004C':
|
||||||
|
return 0x4C;
|
||||||
|
case '\u004D':
|
||||||
|
return 0x4D;
|
||||||
|
case '\u004E':
|
||||||
|
return 0x4E;
|
||||||
|
case '\u004F':
|
||||||
|
return 0x4F;
|
||||||
|
case '\u0050':
|
||||||
|
return 0x50;
|
||||||
|
case '\u0051':
|
||||||
|
return 0x51;
|
||||||
|
case '\u0052':
|
||||||
|
return 0x52;
|
||||||
|
case '\u0053':
|
||||||
|
return 0x53;
|
||||||
|
case '\u0054':
|
||||||
|
return 0x54;
|
||||||
|
case '\u0055':
|
||||||
|
return 0x55;
|
||||||
|
case '\u0056':
|
||||||
|
return 0x56;
|
||||||
|
case '\u0057':
|
||||||
|
return 0x57;
|
||||||
|
case '\u0058':
|
||||||
|
return 0x58;
|
||||||
|
case '\u0059':
|
||||||
|
return 0x59;
|
||||||
|
case '\u005A':
|
||||||
|
return 0x5A;
|
||||||
|
case '\u005B':
|
||||||
|
return 0x5B;
|
||||||
|
case '\u00A3':
|
||||||
|
return 0x5C;
|
||||||
|
case '\u005D':
|
||||||
|
return 0x5D;
|
||||||
|
case '\u005E':
|
||||||
|
return 0x5E;
|
||||||
|
case '\u005F':
|
||||||
|
return 0x5F;
|
||||||
|
case '\u0060':
|
||||||
|
return 0x60;
|
||||||
|
case '\u0061':
|
||||||
|
return 0x61;
|
||||||
|
case '\u0062':
|
||||||
|
return 0x62;
|
||||||
|
case '\u0063':
|
||||||
|
return 0x63;
|
||||||
|
case '\u0064':
|
||||||
|
return 0x64;
|
||||||
|
case '\u0065':
|
||||||
|
return 0x65;
|
||||||
|
case '\u0066':
|
||||||
|
return 0x66;
|
||||||
|
case '\u0067':
|
||||||
|
return 0x67;
|
||||||
|
case '\u0068':
|
||||||
|
return 0x68;
|
||||||
|
case '\u0069':
|
||||||
|
return 0x69;
|
||||||
|
case '\u006A':
|
||||||
|
return 0x6A;
|
||||||
|
case '\u006B':
|
||||||
|
return 0x6B;
|
||||||
|
case '\u006C':
|
||||||
|
return 0x6C;
|
||||||
|
case '\u006D':
|
||||||
|
return 0x6D;
|
||||||
|
case '\u006E':
|
||||||
|
return 0x6E;
|
||||||
|
case '\u006F':
|
||||||
|
return 0x6F;
|
||||||
|
case '\u0070':
|
||||||
|
return 0x70;
|
||||||
|
case '\u0071':
|
||||||
|
return 0x71;
|
||||||
|
case '\u0072':
|
||||||
|
return 0x72;
|
||||||
|
case '\u0073':
|
||||||
|
return 0x73;
|
||||||
|
case '\u0074':
|
||||||
|
return 0x74;
|
||||||
|
case '\u0075':
|
||||||
|
return 0x75;
|
||||||
|
case '\u0076':
|
||||||
|
return 0x76;
|
||||||
|
case '\u0077':
|
||||||
|
return 0x77;
|
||||||
|
case '\u0078':
|
||||||
|
return 0x78;
|
||||||
|
case '\u0079':
|
||||||
|
return 0x79;
|
||||||
|
case '\u007A':
|
||||||
|
return 0x7A;
|
||||||
|
case '\u007B':
|
||||||
|
return 0x7B;
|
||||||
|
case '\u007C':
|
||||||
|
return 0x7C;
|
||||||
|
case '\u007D':
|
||||||
|
return 0x7D;
|
||||||
|
case '\u007E':
|
||||||
|
return 0x7E;
|
||||||
|
case '\u007F':
|
||||||
|
return 0x7F;
|
||||||
|
case '\u2588':
|
||||||
|
return 0xA0;
|
||||||
|
case '\u231B':
|
||||||
|
return 0xC3;
|
||||||
|
case '\u2713':
|
||||||
|
return 0xC4;
|
||||||
|
case '\u2190':
|
||||||
|
return 0xC8;
|
||||||
|
case '\u2026':
|
||||||
|
return 0xC9;
|
||||||
|
case '\u2193':
|
||||||
|
return 0xCA;
|
||||||
|
case '\u2191':
|
||||||
|
return 0xCB;
|
||||||
|
case '\u21B5':
|
||||||
|
return 0xCD;
|
||||||
|
case '\u2192':
|
||||||
|
return 0xD5;
|
||||||
|
case '\u25C6':
|
||||||
|
return 0xDB;
|
||||||
|
default:
|
||||||
|
// Fallback to '?'
|
||||||
|
return 0x3F;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
814
Claunia.Encoding/Apple2e.cs
Normal file
814
Claunia.Encoding/Apple2e.cs
Normal file
@@ -0,0 +1,814 @@
|
|||||||
|
//
|
||||||
|
// Apple IIe.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Natalia Portillo <claunia@claunia.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2016 © Claunia.com
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Claunia.Encoding
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents an Apple IIe character encoding of Unicode characters.
|
||||||
|
/// </summary>
|
||||||
|
public class Apple2e : Encoding
|
||||||
|
{
|
||||||
|
const string _bodyname = "apple2e";
|
||||||
|
const int _codepage = 0;
|
||||||
|
const string _encodingname = "Western European (Apple IIe)";
|
||||||
|
const string _headername = "apple2e";
|
||||||
|
const string _webname = "";
|
||||||
|
const int _windowsCodepage = 0;
|
||||||
|
|
||||||
|
const bool browserDisplay = false;
|
||||||
|
const bool browserSave = false;
|
||||||
|
const bool mailNewsDisplay = false;
|
||||||
|
const bool mailNewsSave = false;
|
||||||
|
const bool readOnly = true;
|
||||||
|
const bool singleByte = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the current encoding can be used by browser clients for displaying content.
|
||||||
|
/// </summary>
|
||||||
|
public override bool IsBrowserDisplay {
|
||||||
|
get { return browserDisplay; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the current encoding can be used by browser clients for saving content.
|
||||||
|
/// </summary>
|
||||||
|
public override bool IsBrowserSave {
|
||||||
|
get { return browserSave; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content.
|
||||||
|
/// </summary>
|
||||||
|
public override bool IsMailNewsDisplay {
|
||||||
|
get { return mailNewsDisplay; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content.
|
||||||
|
/// </summary>
|
||||||
|
public override bool IsMailNewsSave {
|
||||||
|
get { return mailNewsSave; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the current encoding is read-only.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The is single byte.</value>
|
||||||
|
public override bool IsReadOnly {
|
||||||
|
get { return readOnly; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the current encoding uses single-byte code points.
|
||||||
|
/// </summary>
|
||||||
|
public override bool IsSingleByte {
|
||||||
|
get { return singleByte; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the code page identifier of the current Encoding.
|
||||||
|
/// </summary>
|
||||||
|
public override int CodePage {
|
||||||
|
get { return _codepage; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a name for the current encoding that can be used with mail agent body tags
|
||||||
|
/// </summary>
|
||||||
|
public override string BodyName {
|
||||||
|
get { return _bodyname; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a name for the current encoding that can be used with mail agent header tags
|
||||||
|
/// </summary>
|
||||||
|
public override string HeaderName {
|
||||||
|
get { return _headername; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.
|
||||||
|
/// </summary>
|
||||||
|
public override string WebName {
|
||||||
|
get { return _webname; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the human-readable description of the current encoding.
|
||||||
|
/// </summary>
|
||||||
|
public override string EncodingName {
|
||||||
|
get { return _encodingname; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the Windows operating system code page that most closely corresponds to the current encoding.
|
||||||
|
/// </summary>
|
||||||
|
public override int WindowsCodePage {
|
||||||
|
get { return _windowsCodepage; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public override int GetByteCount(string s)
|
||||||
|
{
|
||||||
|
if(s == null)
|
||||||
|
throw new ArgumentNullException(nameof(s));
|
||||||
|
|
||||||
|
return s.Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the number of bytes produced by encoding a set of characters from the specified character array.
|
||||||
|
/// </summary>
|
||||||
|
/// <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="index">The index of the first character to encode.</param>
|
||||||
|
/// <param name="count">The number of characters to encode.</param>
|
||||||
|
public override int GetByteCount(char[] chars, int index, int count)
|
||||||
|
{
|
||||||
|
if(chars == null)
|
||||||
|
throw new ArgumentNullException(nameof(chars));
|
||||||
|
|
||||||
|
if(index < 0 || index >= chars.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(index));
|
||||||
|
|
||||||
|
if(count < 0 || index + count > chars.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(index));
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the number of bytes produced by encoding all the characters in the specified character array.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public override int GetByteCount(char[] chars)
|
||||||
|
{
|
||||||
|
if(chars == null)
|
||||||
|
throw new ArgumentNullException(nameof(chars));
|
||||||
|
|
||||||
|
return chars.Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Encodes a set of characters from the specified <see cref="string"/> into the specified byte array.
|
||||||
|
/// </summary>
|
||||||
|
/// <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="charIndex">The index of the first character 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="byteIndex">The index at which to start writing the resulting sequence of bytes.</param>
|
||||||
|
public override int GetBytes(string s, int charIndex, int charCount, byte[] bytes, int byteIndex)
|
||||||
|
{
|
||||||
|
return GetBytes(s.ToCharArray(), charIndex, charCount, bytes, byteIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Encodes all the characters in the specified string into a sequence of bytes.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public override byte[] GetBytes(string s)
|
||||||
|
{
|
||||||
|
if(s == null)
|
||||||
|
throw new ArgumentNullException(nameof(s));
|
||||||
|
|
||||||
|
return GetBytes(s.ToCharArray(), 0, s.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Encodes a set of characters from the specified character array into the specified byte array.
|
||||||
|
/// </summary>
|
||||||
|
/// <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="charIndex">The index of the first character 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="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)
|
||||||
|
{
|
||||||
|
if(chars == null)
|
||||||
|
throw new ArgumentNullException(nameof(chars));
|
||||||
|
|
||||||
|
if(bytes == null)
|
||||||
|
throw new ArgumentNullException(nameof(bytes));
|
||||||
|
|
||||||
|
if(charIndex < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||||
|
|
||||||
|
if(charCount < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(charCount));
|
||||||
|
|
||||||
|
if(byteIndex < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||||
|
|
||||||
|
if(charIndex >= chars.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||||
|
|
||||||
|
if(charCount + charIndex > chars.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(charCount));
|
||||||
|
|
||||||
|
if(byteIndex >= bytes.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||||
|
|
||||||
|
if(byteIndex + charCount > bytes.Length)
|
||||||
|
throw new ArgumentException(nameof(bytes));
|
||||||
|
|
||||||
|
byte[] temp = GetBytes(chars, charIndex, charCount);
|
||||||
|
|
||||||
|
for(int i = 0; i < temp.Length; i++)
|
||||||
|
bytes[i + byteIndex] = temp[i];
|
||||||
|
|
||||||
|
return charCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Encodes a set of characters from the specified character array into a sequence of bytes.
|
||||||
|
/// </summary>
|
||||||
|
/// <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="index">The index of the first character to encode.</param>
|
||||||
|
/// <param name="count">The number of characters to encode.</param>
|
||||||
|
public override byte[] GetBytes(char[] chars, int index, int count)
|
||||||
|
{
|
||||||
|
if(chars == null)
|
||||||
|
throw new ArgumentNullException(nameof(chars));
|
||||||
|
|
||||||
|
if(index < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(index));
|
||||||
|
|
||||||
|
if(count < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(count));
|
||||||
|
|
||||||
|
if(count + index > chars.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(count));
|
||||||
|
|
||||||
|
byte[] bytes = new byte[count];
|
||||||
|
|
||||||
|
for(int i = 0; i < count; i++)
|
||||||
|
bytes[i] = GetByte(chars[index + i]);
|
||||||
|
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Encodes all the characters in the specified character array into a sequence of bytes.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public override byte[] GetBytes(char[] chars)
|
||||||
|
{
|
||||||
|
return GetBytes(chars, 0, chars.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the number of characters produced by decoding all the bytes in the specified byte array.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public override int GetCharCount(byte[] bytes)
|
||||||
|
{
|
||||||
|
return GetCharCount(bytes, 0, bytes.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array.
|
||||||
|
/// </summary>
|
||||||
|
/// <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="index">The index of the first byte to decode.</param>
|
||||||
|
/// <param name="count">The number of bytes to decode.</param>
|
||||||
|
public override int GetCharCount(byte[] bytes, int index, int count)
|
||||||
|
{
|
||||||
|
if(bytes == null)
|
||||||
|
throw new ArgumentNullException(nameof(bytes));
|
||||||
|
|
||||||
|
if(index < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(index));
|
||||||
|
|
||||||
|
if(count < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(count));
|
||||||
|
|
||||||
|
if(count + index > bytes.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(count));
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Decodes a sequence of bytes from the specified byte array into the specified character array.
|
||||||
|
/// </summary>
|
||||||
|
/// <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="byteIndex">The index of the first byte to decode.</param>
|
||||||
|
/// <param name="byteCount">The number of bytes to decode.</param>
|
||||||
|
/// <param name="chars">The character array to contain 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)
|
||||||
|
{
|
||||||
|
if(bytes == null)
|
||||||
|
throw new ArgumentNullException(nameof(bytes));
|
||||||
|
|
||||||
|
if(chars == null)
|
||||||
|
throw new ArgumentNullException(nameof(chars));
|
||||||
|
|
||||||
|
if(byteIndex < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||||
|
|
||||||
|
if(byteCount < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(byteCount));
|
||||||
|
|
||||||
|
if(charIndex < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||||
|
|
||||||
|
if(byteIndex >= bytes.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||||
|
|
||||||
|
if(byteCount + byteIndex > bytes.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(byteCount));
|
||||||
|
|
||||||
|
if(charIndex >= chars.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||||
|
|
||||||
|
if(charIndex + byteCount > chars.Length)
|
||||||
|
throw new ArgumentException(nameof(chars));
|
||||||
|
|
||||||
|
char[] temp = GetChars(bytes, byteIndex, byteCount);
|
||||||
|
|
||||||
|
for(int i = 0; i < temp.Length; i++)
|
||||||
|
chars[i + charIndex] = temp[i];
|
||||||
|
|
||||||
|
return byteCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Decodes all the bytes in the specified byte array into a set of characters.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public override char[] GetChars(byte[] bytes)
|
||||||
|
{
|
||||||
|
return GetChars(bytes, 0, bytes.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Decodes a sequence of bytes from the specified byte array into a set of characters.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The chars.</returns>
|
||||||
|
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
|
||||||
|
/// <param name="index">The index of the first byte to decode.</param>
|
||||||
|
/// <param name="count">The number of bytes to decode.</param>
|
||||||
|
public override char[] GetChars(byte[] bytes, int index, int count)
|
||||||
|
{
|
||||||
|
if(bytes == null)
|
||||||
|
throw new ArgumentNullException(nameof(bytes));
|
||||||
|
|
||||||
|
if(index < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(index));
|
||||||
|
|
||||||
|
if(count < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(count));
|
||||||
|
|
||||||
|
if(count + index > bytes.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(count));
|
||||||
|
|
||||||
|
char[] chars = new char[count];
|
||||||
|
|
||||||
|
for(int i = 0; i < count; i++)
|
||||||
|
chars[i] = GetChar(bytes[index + i]);
|
||||||
|
|
||||||
|
return chars;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the maximum number of bytes produced by encoding the specified number of characters.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public override int GetMaxByteCount(int charCount)
|
||||||
|
{
|
||||||
|
if(charCount < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(charCount));
|
||||||
|
|
||||||
|
return charCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the maximum number of characters produced by decoding the specified number of bytes.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public override int GetMaxCharCount(int byteCount)
|
||||||
|
{
|
||||||
|
if(byteCount < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(byteCount));
|
||||||
|
|
||||||
|
return byteCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a sequence of bytes that specifies the encoding used.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A byte array of length zero, as a preamble is not required.</returns>
|
||||||
|
public override byte[] GetPreamble()
|
||||||
|
{
|
||||||
|
return new byte[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Decodes all the bytes in the specified byte array into a string.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public string GetString(byte[] bytes)
|
||||||
|
{
|
||||||
|
return GetString(bytes, 0, bytes.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Decodes a sequence of bytes from the specified byte array into a string.
|
||||||
|
/// </summary>
|
||||||
|
/// <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="index">The index of the first byte to decode.</param>
|
||||||
|
/// <param name="count">The number of bytes to decode.</param>
|
||||||
|
public override string GetString(byte[] bytes, int index, int count)
|
||||||
|
{
|
||||||
|
return new string(GetChars(bytes, index, count));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Apple IIe to Unicode character map.
|
||||||
|
/// </summary>
|
||||||
|
static readonly char[] Apple2eTable = {
|
||||||
|
// 0x00
|
||||||
|
'\u0020','\u0021','\u0022','\u0023','\u0024','\u0025','\u0026','\u0027',
|
||||||
|
// 0x08
|
||||||
|
'\u0028','\u0029','\u002A','\u002B','\u002C','\u002D','\u002E','\u002F',
|
||||||
|
// 0x10
|
||||||
|
'\u0030','\u0031','\u0032','\u0033','\u0034','\u0035','\u0036','\u0037',
|
||||||
|
// 0x18
|
||||||
|
'\u0038','\u0039','\u003A','\u003B','\u003C','\u003D','\u003E','\u003F',
|
||||||
|
// 0x20
|
||||||
|
'\u0040','\u0061','\u0062','\u0063','\u0064','\u0065','\u0066','\u0067',
|
||||||
|
// 0x28
|
||||||
|
'\u0068','\u0069','\u006A','\u006B','\u006C','\u006D','\u006E','\u006F',
|
||||||
|
// 0x30
|
||||||
|
'\u0070','\u0071','\u0072','\u0073','\u0074','\u0075','\u0076','\u0077',
|
||||||
|
// 0x38
|
||||||
|
'\u0078','\u0079','\u007A','\u005B','\u005C','\u005D','\u005E','\u005F',
|
||||||
|
// 0x40
|
||||||
|
'\u00A0','\u2575','\u2574','\u2577','\u2576','\u2518','\u2510','\u250C',
|
||||||
|
// 0x48
|
||||||
|
'\u2514','\u2500','\u2502','\u2534','\u2524','\u252C','\u251C','\u253C',
|
||||||
|
// 0x50
|
||||||
|
'\u25E4','\u25E5','\u2592','\u2598','\u259D','\u2580','\u2596','\u2597',
|
||||||
|
// 0x58
|
||||||
|
'\u259A','\u258C','\u0000','\u0000','\u2190','\u2191','\u2192','\u2193',
|
||||||
|
// 0x60
|
||||||
|
'\u03C0','\u0041','\u0042','\u0043','\u0044','\u0045','\u0046','\u0047',
|
||||||
|
// 0x68
|
||||||
|
'\u0048','\u0049','\u004A','\u004B','\u004C','\u004D','\u004E','\u004F',
|
||||||
|
// 0x70
|
||||||
|
'\u0050','\u0051','\u0052','\u0053','\u0054','\u0055','\u0056','\u0057',
|
||||||
|
// 0x78
|
||||||
|
'\u0058','\u0059','\u005A','\u007B','\u007C','\u007D','\u007E','\u0000',
|
||||||
|
// 0x80
|
||||||
|
'\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000',
|
||||||
|
// 0x88
|
||||||
|
'\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000',
|
||||||
|
// 0x90
|
||||||
|
'\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000',
|
||||||
|
// 0x98
|
||||||
|
'\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000',
|
||||||
|
// 0xA0
|
||||||
|
'\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000',
|
||||||
|
// 0xA8
|
||||||
|
'\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000',
|
||||||
|
// 0xB0
|
||||||
|
'\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000',
|
||||||
|
// 0xB8
|
||||||
|
'\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000',
|
||||||
|
// 0xC0
|
||||||
|
'\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000',
|
||||||
|
// 0xC8
|
||||||
|
'\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000',
|
||||||
|
// 0xD0
|
||||||
|
'\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000',
|
||||||
|
// 0xD8
|
||||||
|
'\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000',
|
||||||
|
// 0xE0
|
||||||
|
'\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000',
|
||||||
|
// 0xE8
|
||||||
|
'\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000',
|
||||||
|
// 0xF0
|
||||||
|
'\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000',
|
||||||
|
// 0xF8
|
||||||
|
'\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000'
|
||||||
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts a Apple IIe character to an Unicode character
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Unicode character.</returns>
|
||||||
|
/// <param name="character">Apple IIe character.</param>
|
||||||
|
static char GetChar(byte character)
|
||||||
|
{
|
||||||
|
return Apple2eTable[character];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts a Unicode character to an Apple IIe character
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Apple IIe character.</returns>
|
||||||
|
/// <param name="character">Unicode character.</param>
|
||||||
|
static byte GetByte(char character)
|
||||||
|
{
|
||||||
|
switch(character) {
|
||||||
|
case '\u0020':
|
||||||
|
return 0x00;
|
||||||
|
case '\u0021':
|
||||||
|
return 0x01;
|
||||||
|
case '\u0022':
|
||||||
|
return 0x02;
|
||||||
|
case '\u0023':
|
||||||
|
return 0x03;
|
||||||
|
case '\u0024':
|
||||||
|
return 0x04;
|
||||||
|
case '\u0025':
|
||||||
|
return 0x05;
|
||||||
|
case '\u0026':
|
||||||
|
return 0x06;
|
||||||
|
case '\u0027':
|
||||||
|
return 0x07;
|
||||||
|
case '\u0028':
|
||||||
|
return 0x08;
|
||||||
|
case '\u0029':
|
||||||
|
return 0x09;
|
||||||
|
case '\u002A':
|
||||||
|
return 0x0A;
|
||||||
|
case '\u002B':
|
||||||
|
return 0x0B;
|
||||||
|
case '\u002C':
|
||||||
|
return 0x0C;
|
||||||
|
case '\u002D':
|
||||||
|
return 0x0D;
|
||||||
|
case '\u002E':
|
||||||
|
return 0x0E;
|
||||||
|
case '\u002F':
|
||||||
|
return 0x0F;
|
||||||
|
case '\u0030':
|
||||||
|
return 0x10;
|
||||||
|
case '\u0031':
|
||||||
|
return 0x11;
|
||||||
|
case '\u0032':
|
||||||
|
return 0x12;
|
||||||
|
case '\u0033':
|
||||||
|
return 0x13;
|
||||||
|
case '\u0034':
|
||||||
|
return 0x14;
|
||||||
|
case '\u0035':
|
||||||
|
return 0x15;
|
||||||
|
case '\u0036':
|
||||||
|
return 0x16;
|
||||||
|
case '\u0037':
|
||||||
|
return 0x17;
|
||||||
|
case '\u0038':
|
||||||
|
return 0x18;
|
||||||
|
case '\u0039':
|
||||||
|
return 0x19;
|
||||||
|
case '\u003A':
|
||||||
|
return 0x1A;
|
||||||
|
case '\u003B':
|
||||||
|
return 0x1B;
|
||||||
|
case '\u003C':
|
||||||
|
return 0x1C;
|
||||||
|
case '\u003D':
|
||||||
|
return 0x1D;
|
||||||
|
case '\u003E':
|
||||||
|
return 0x1E;
|
||||||
|
case '\u003F':
|
||||||
|
return 0x1F;
|
||||||
|
case '\u0040':
|
||||||
|
return 0x20;
|
||||||
|
case '\u0061':
|
||||||
|
return 0x21;
|
||||||
|
case '\u0062':
|
||||||
|
return 0x22;
|
||||||
|
case '\u0063':
|
||||||
|
return 0x23;
|
||||||
|
case '\u0064':
|
||||||
|
return 0x24;
|
||||||
|
case '\u0065':
|
||||||
|
return 0x25;
|
||||||
|
case '\u0066':
|
||||||
|
return 0x26;
|
||||||
|
case '\u0067':
|
||||||
|
return 0x27;
|
||||||
|
case '\u0068':
|
||||||
|
return 0x28;
|
||||||
|
case '\u0069':
|
||||||
|
return 0x29;
|
||||||
|
case '\u006A':
|
||||||
|
return 0x2A;
|
||||||
|
case '\u006B':
|
||||||
|
return 0x2B;
|
||||||
|
case '\u006C':
|
||||||
|
return 0x2C;
|
||||||
|
case '\u006D':
|
||||||
|
return 0x2D;
|
||||||
|
case '\u006E':
|
||||||
|
return 0x2E;
|
||||||
|
case '\u006F':
|
||||||
|
return 0x2F;
|
||||||
|
case '\u0070':
|
||||||
|
return 0x30;
|
||||||
|
case '\u0071':
|
||||||
|
return 0x31;
|
||||||
|
case '\u0072':
|
||||||
|
return 0x32;
|
||||||
|
case '\u0073':
|
||||||
|
return 0x33;
|
||||||
|
case '\u0074':
|
||||||
|
return 0x34;
|
||||||
|
case '\u0075':
|
||||||
|
return 0x35;
|
||||||
|
case '\u0076':
|
||||||
|
return 0x36;
|
||||||
|
case '\u0077':
|
||||||
|
return 0x37;
|
||||||
|
case '\u0078':
|
||||||
|
return 0x38;
|
||||||
|
case '\u0079':
|
||||||
|
return 0x39;
|
||||||
|
case '\u007A':
|
||||||
|
return 0x3A;
|
||||||
|
case '\u005B':
|
||||||
|
return 0x3B;
|
||||||
|
case '\u005C':
|
||||||
|
return 0x3C;
|
||||||
|
case '\u005D':
|
||||||
|
return 0x3D;
|
||||||
|
case '\u005E':
|
||||||
|
return 0x3E;
|
||||||
|
case '\u005F':
|
||||||
|
return 0x3F;
|
||||||
|
case '\u00A0':
|
||||||
|
return 0x40;
|
||||||
|
case '\u2575':
|
||||||
|
return 0x41;
|
||||||
|
case '\u2574':
|
||||||
|
return 0x42;
|
||||||
|
case '\u2577':
|
||||||
|
return 0x43;
|
||||||
|
case '\u2576':
|
||||||
|
return 0x44;
|
||||||
|
case '\u2518':
|
||||||
|
return 0x45;
|
||||||
|
case '\u2510':
|
||||||
|
return 0x46;
|
||||||
|
case '\u250C':
|
||||||
|
return 0x47;
|
||||||
|
case '\u2514':
|
||||||
|
return 0x48;
|
||||||
|
case '\u2500':
|
||||||
|
return 0x49;
|
||||||
|
case '\u2502':
|
||||||
|
return 0x4A;
|
||||||
|
case '\u2534':
|
||||||
|
return 0x4B;
|
||||||
|
case '\u2524':
|
||||||
|
return 0x4C;
|
||||||
|
case '\u252C':
|
||||||
|
return 0x4D;
|
||||||
|
case '\u251C':
|
||||||
|
return 0x4E;
|
||||||
|
case '\u253C':
|
||||||
|
return 0x4F;
|
||||||
|
case '\u25E4':
|
||||||
|
return 0x50;
|
||||||
|
case '\u25E5':
|
||||||
|
return 0x51;
|
||||||
|
case '\u2592':
|
||||||
|
return 0x52;
|
||||||
|
case '\u2598':
|
||||||
|
return 0x53;
|
||||||
|
case '\u259D':
|
||||||
|
return 0x54;
|
||||||
|
case '\u2580':
|
||||||
|
return 0x55;
|
||||||
|
case '\u2596':
|
||||||
|
return 0x56;
|
||||||
|
case '\u2597':
|
||||||
|
return 0x57;
|
||||||
|
case '\u259A':
|
||||||
|
return 0x58;
|
||||||
|
case '\u258C':
|
||||||
|
return 0x59;
|
||||||
|
case '\u2190':
|
||||||
|
return 0x5C;
|
||||||
|
case '\u2191':
|
||||||
|
return 0x5D;
|
||||||
|
case '\u2192':
|
||||||
|
return 0x5E;
|
||||||
|
case '\u2193':
|
||||||
|
return 0x5F;
|
||||||
|
case '\u03C0':
|
||||||
|
return 0x60;
|
||||||
|
case '\u0041':
|
||||||
|
return 0x61;
|
||||||
|
case '\u0042':
|
||||||
|
return 0x62;
|
||||||
|
case '\u0043':
|
||||||
|
return 0x63;
|
||||||
|
case '\u0044':
|
||||||
|
return 0x64;
|
||||||
|
case '\u0045':
|
||||||
|
return 0x65;
|
||||||
|
case '\u0046':
|
||||||
|
return 0x66;
|
||||||
|
case '\u0047':
|
||||||
|
return 0x67;
|
||||||
|
case '\u0048':
|
||||||
|
return 0x68;
|
||||||
|
case '\u0049':
|
||||||
|
return 0x69;
|
||||||
|
case '\u004A':
|
||||||
|
return 0x6A;
|
||||||
|
case '\u004B':
|
||||||
|
return 0x6B;
|
||||||
|
case '\u004C':
|
||||||
|
return 0x6C;
|
||||||
|
case '\u004D':
|
||||||
|
return 0x6D;
|
||||||
|
case '\u004E':
|
||||||
|
return 0x6E;
|
||||||
|
case '\u004F':
|
||||||
|
return 0x6F;
|
||||||
|
case '\u0050':
|
||||||
|
return 0x70;
|
||||||
|
case '\u0051':
|
||||||
|
return 0x71;
|
||||||
|
case '\u0052':
|
||||||
|
return 0x72;
|
||||||
|
case '\u0053':
|
||||||
|
return 0x73;
|
||||||
|
case '\u0054':
|
||||||
|
return 0x74;
|
||||||
|
case '\u0055':
|
||||||
|
return 0x75;
|
||||||
|
case '\u0056':
|
||||||
|
return 0x76;
|
||||||
|
case '\u0057':
|
||||||
|
return 0x77;
|
||||||
|
case '\u0058':
|
||||||
|
return 0x78;
|
||||||
|
case '\u0059':
|
||||||
|
return 0x79;
|
||||||
|
case '\u005A':
|
||||||
|
return 0x7A;
|
||||||
|
case '\u007B':
|
||||||
|
return 0x7B;
|
||||||
|
case '\u007C':
|
||||||
|
return 0x7C;
|
||||||
|
case '\u007D':
|
||||||
|
return 0x7D;
|
||||||
|
case '\u007E':
|
||||||
|
return 0x7E;
|
||||||
|
default:
|
||||||
|
// Fallback to '?'
|
||||||
|
return 0x3F;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
775
Claunia.Encoding/Apple2gs.cs
Normal file
775
Claunia.Encoding/Apple2gs.cs
Normal file
@@ -0,0 +1,775 @@
|
|||||||
|
//
|
||||||
|
// Apple IIgs.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Natalia Portillo <claunia@claunia.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2016 © Claunia.com
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Claunia.Encoding
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents an Apple IIgs character encoding of Unicode characters.
|
||||||
|
/// </summary>
|
||||||
|
public class Apple2gs : Encoding
|
||||||
|
{
|
||||||
|
const string _bodyname = "apple2gs";
|
||||||
|
const int _codepage = 0;
|
||||||
|
const string _encodingname = "Western European (Apple IIgs)";
|
||||||
|
const string _headername = "apple2gs";
|
||||||
|
const string _webname = "";
|
||||||
|
const int _windowsCodepage = 0;
|
||||||
|
|
||||||
|
const bool browserDisplay = false;
|
||||||
|
const bool browserSave = false;
|
||||||
|
const bool mailNewsDisplay = false;
|
||||||
|
const bool mailNewsSave = false;
|
||||||
|
const bool readOnly = true;
|
||||||
|
const bool singleByte = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the current encoding can be used by browser clients for displaying content.
|
||||||
|
/// </summary>
|
||||||
|
public override bool IsBrowserDisplay {
|
||||||
|
get { return browserDisplay; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the current encoding can be used by browser clients for saving content.
|
||||||
|
/// </summary>
|
||||||
|
public override bool IsBrowserSave {
|
||||||
|
get { return browserSave; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content.
|
||||||
|
/// </summary>
|
||||||
|
public override bool IsMailNewsDisplay {
|
||||||
|
get { return mailNewsDisplay; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content.
|
||||||
|
/// </summary>
|
||||||
|
public override bool IsMailNewsSave {
|
||||||
|
get { return mailNewsSave; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the current encoding is read-only.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The is single byte.</value>
|
||||||
|
public override bool IsReadOnly {
|
||||||
|
get { return readOnly; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the current encoding uses single-byte code points.
|
||||||
|
/// </summary>
|
||||||
|
public override bool IsSingleByte {
|
||||||
|
get { return singleByte; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the code page identifier of the current Encoding.
|
||||||
|
/// </summary>
|
||||||
|
public override int CodePage {
|
||||||
|
get { return _codepage; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a name for the current encoding that can be used with mail agent body tags
|
||||||
|
/// </summary>
|
||||||
|
public override string BodyName {
|
||||||
|
get { return _bodyname; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a name for the current encoding that can be used with mail agent header tags
|
||||||
|
/// </summary>
|
||||||
|
public override string HeaderName {
|
||||||
|
get { return _headername; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.
|
||||||
|
/// </summary>
|
||||||
|
public override string WebName {
|
||||||
|
get { return _webname; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the human-readable description of the current encoding.
|
||||||
|
/// </summary>
|
||||||
|
public override string EncodingName {
|
||||||
|
get { return _encodingname; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the Windows operating system code page that most closely corresponds to the current encoding.
|
||||||
|
/// </summary>
|
||||||
|
public override int WindowsCodePage {
|
||||||
|
get { return _windowsCodepage; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public override int GetByteCount(string s)
|
||||||
|
{
|
||||||
|
if(s == null)
|
||||||
|
throw new ArgumentNullException(nameof(s));
|
||||||
|
|
||||||
|
return s.Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the number of bytes produced by encoding a set of characters from the specified character array.
|
||||||
|
/// </summary>
|
||||||
|
/// <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="index">The index of the first character to encode.</param>
|
||||||
|
/// <param name="count">The number of characters to encode.</param>
|
||||||
|
public override int GetByteCount(char[] chars, int index, int count)
|
||||||
|
{
|
||||||
|
if(chars == null)
|
||||||
|
throw new ArgumentNullException(nameof(chars));
|
||||||
|
|
||||||
|
if(index < 0 || index >= chars.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(index));
|
||||||
|
|
||||||
|
if(count < 0 || index + count > chars.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(index));
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the number of bytes produced by encoding all the characters in the specified character array.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public override int GetByteCount(char[] chars)
|
||||||
|
{
|
||||||
|
if(chars == null)
|
||||||
|
throw new ArgumentNullException(nameof(chars));
|
||||||
|
|
||||||
|
return chars.Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Encodes a set of characters from the specified <see cref="string"/> into the specified byte array.
|
||||||
|
/// </summary>
|
||||||
|
/// <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="charIndex">The index of the first character 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="byteIndex">The index at which to start writing the resulting sequence of bytes.</param>
|
||||||
|
public override int GetBytes(string s, int charIndex, int charCount, byte[] bytes, int byteIndex)
|
||||||
|
{
|
||||||
|
return GetBytes(s.ToCharArray(), charIndex, charCount, bytes, byteIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Encodes all the characters in the specified string into a sequence of bytes.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public override byte[] GetBytes(string s)
|
||||||
|
{
|
||||||
|
if(s == null)
|
||||||
|
throw new ArgumentNullException(nameof(s));
|
||||||
|
|
||||||
|
return GetBytes(s.ToCharArray(), 0, s.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Encodes a set of characters from the specified character array into the specified byte array.
|
||||||
|
/// </summary>
|
||||||
|
/// <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="charIndex">The index of the first character 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="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)
|
||||||
|
{
|
||||||
|
if(chars == null)
|
||||||
|
throw new ArgumentNullException(nameof(chars));
|
||||||
|
|
||||||
|
if(bytes == null)
|
||||||
|
throw new ArgumentNullException(nameof(bytes));
|
||||||
|
|
||||||
|
if(charIndex < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||||
|
|
||||||
|
if(charCount < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(charCount));
|
||||||
|
|
||||||
|
if(byteIndex < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||||
|
|
||||||
|
if(charIndex >= chars.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||||
|
|
||||||
|
if(charCount + charIndex > chars.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(charCount));
|
||||||
|
|
||||||
|
if(byteIndex >= bytes.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||||
|
|
||||||
|
if(byteIndex + charCount > bytes.Length)
|
||||||
|
throw new ArgumentException(nameof(bytes));
|
||||||
|
|
||||||
|
byte[] temp = GetBytes(chars, charIndex, charCount);
|
||||||
|
|
||||||
|
for(int i = 0; i < temp.Length; i++)
|
||||||
|
bytes[i + byteIndex] = temp[i];
|
||||||
|
|
||||||
|
return charCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Encodes a set of characters from the specified character array into a sequence of bytes.
|
||||||
|
/// </summary>
|
||||||
|
/// <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="index">The index of the first character to encode.</param>
|
||||||
|
/// <param name="count">The number of characters to encode.</param>
|
||||||
|
public override byte[] GetBytes(char[] chars, int index, int count)
|
||||||
|
{
|
||||||
|
if(chars == null)
|
||||||
|
throw new ArgumentNullException(nameof(chars));
|
||||||
|
|
||||||
|
if(index < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(index));
|
||||||
|
|
||||||
|
if(count < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(count));
|
||||||
|
|
||||||
|
if(count + index > chars.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(count));
|
||||||
|
|
||||||
|
byte[] bytes = new byte[count];
|
||||||
|
|
||||||
|
for(int i = 0; i < count; i++)
|
||||||
|
bytes[i] = GetByte(chars[index + i]);
|
||||||
|
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Encodes all the characters in the specified character array into a sequence of bytes.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public override byte[] GetBytes(char[] chars)
|
||||||
|
{
|
||||||
|
return GetBytes(chars, 0, chars.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the number of characters produced by decoding all the bytes in the specified byte array.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public override int GetCharCount(byte[] bytes)
|
||||||
|
{
|
||||||
|
return GetCharCount(bytes, 0, bytes.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array.
|
||||||
|
/// </summary>
|
||||||
|
/// <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="index">The index of the first byte to decode.</param>
|
||||||
|
/// <param name="count">The number of bytes to decode.</param>
|
||||||
|
public override int GetCharCount(byte[] bytes, int index, int count)
|
||||||
|
{
|
||||||
|
if(bytes == null)
|
||||||
|
throw new ArgumentNullException(nameof(bytes));
|
||||||
|
|
||||||
|
if(index < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(index));
|
||||||
|
|
||||||
|
if(count < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(count));
|
||||||
|
|
||||||
|
if(count + index > bytes.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(count));
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Decodes a sequence of bytes from the specified byte array into the specified character array.
|
||||||
|
/// </summary>
|
||||||
|
/// <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="byteIndex">The index of the first byte to decode.</param>
|
||||||
|
/// <param name="byteCount">The number of bytes to decode.</param>
|
||||||
|
/// <param name="chars">The character array to contain 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)
|
||||||
|
{
|
||||||
|
if(bytes == null)
|
||||||
|
throw new ArgumentNullException(nameof(bytes));
|
||||||
|
|
||||||
|
if(chars == null)
|
||||||
|
throw new ArgumentNullException(nameof(chars));
|
||||||
|
|
||||||
|
if(byteIndex < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||||
|
|
||||||
|
if(byteCount < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(byteCount));
|
||||||
|
|
||||||
|
if(charIndex < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||||
|
|
||||||
|
if(byteIndex >= bytes.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||||
|
|
||||||
|
if(byteCount + byteIndex > bytes.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(byteCount));
|
||||||
|
|
||||||
|
if(charIndex >= chars.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||||
|
|
||||||
|
if(charIndex + byteCount > chars.Length)
|
||||||
|
throw new ArgumentException(nameof(chars));
|
||||||
|
|
||||||
|
char[] temp = GetChars(bytes, byteIndex, byteCount);
|
||||||
|
|
||||||
|
for(int i = 0; i < temp.Length; i++)
|
||||||
|
chars[i + charIndex] = temp[i];
|
||||||
|
|
||||||
|
return byteCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Decodes all the bytes in the specified byte array into a set of characters.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public override char[] GetChars(byte[] bytes)
|
||||||
|
{
|
||||||
|
return GetChars(bytes, 0, bytes.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Decodes a sequence of bytes from the specified byte array into a set of characters.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The chars.</returns>
|
||||||
|
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
|
||||||
|
/// <param name="index">The index of the first byte to decode.</param>
|
||||||
|
/// <param name="count">The number of bytes to decode.</param>
|
||||||
|
public override char[] GetChars(byte[] bytes, int index, int count)
|
||||||
|
{
|
||||||
|
if(bytes == null)
|
||||||
|
throw new ArgumentNullException(nameof(bytes));
|
||||||
|
|
||||||
|
if(index < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(index));
|
||||||
|
|
||||||
|
if(count < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(count));
|
||||||
|
|
||||||
|
if(count + index > bytes.Length)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(count));
|
||||||
|
|
||||||
|
char[] chars = new char[count];
|
||||||
|
|
||||||
|
for(int i = 0; i < count; i++)
|
||||||
|
chars[i] = GetChar(bytes[index + i]);
|
||||||
|
|
||||||
|
return chars;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the maximum number of bytes produced by encoding the specified number of characters.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public override int GetMaxByteCount(int charCount)
|
||||||
|
{
|
||||||
|
if(charCount < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(charCount));
|
||||||
|
|
||||||
|
return charCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the maximum number of characters produced by decoding the specified number of bytes.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public override int GetMaxCharCount(int byteCount)
|
||||||
|
{
|
||||||
|
if(byteCount < 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(byteCount));
|
||||||
|
|
||||||
|
return byteCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a sequence of bytes that specifies the encoding used.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A byte array of length zero, as a preamble is not required.</returns>
|
||||||
|
public override byte[] GetPreamble()
|
||||||
|
{
|
||||||
|
return new byte[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Decodes all the bytes in the specified byte array into a string.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>
|
||||||
|
public string GetString(byte[] bytes)
|
||||||
|
{
|
||||||
|
return GetString(bytes, 0, bytes.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Decodes a sequence of bytes from the specified byte array into a string.
|
||||||
|
/// </summary>
|
||||||
|
/// <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="index">The index of the first byte to decode.</param>
|
||||||
|
/// <param name="count">The number of bytes to decode.</param>
|
||||||
|
public override string GetString(byte[] bytes, int index, int count)
|
||||||
|
{
|
||||||
|
return new string(GetChars(bytes, index, count));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Apple IIgs to Unicode character map.
|
||||||
|
/// 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>
|
||||||
|
/// <returns>Unicode character.</returns>
|
||||||
|
/// <param name="character">Apple IIgs character.</param>
|
||||||
|
static char GetChar(byte character)
|
||||||
|
{
|
||||||
|
return Apple2gsTable[character];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts a Unicode character to an Apple IIgs character
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Apple IIgs character.</returns>
|
||||||
|
/// <param name="character">Unicode character.</param>
|
||||||
|
static byte GetByte(char character)
|
||||||
|
{
|
||||||
|
switch(character) {
|
||||||
|
case '\u2588':
|
||||||
|
return 0x20;
|
||||||
|
case '\u231B':
|
||||||
|
return 0x43;
|
||||||
|
case '\u2713':
|
||||||
|
return 0x44;
|
||||||
|
case '\u2190':
|
||||||
|
return 0x48;
|
||||||
|
case '\u2026':
|
||||||
|
return 0x49;
|
||||||
|
case '\u2193':
|
||||||
|
return 0x4A;
|
||||||
|
case '\u2191':
|
||||||
|
return 0x4B;
|
||||||
|
case '\u21B5':
|
||||||
|
return 0x4D;
|
||||||
|
case '\u2192':
|
||||||
|
return 0x55;
|
||||||
|
case '\u25C6':
|
||||||
|
return 0x5B;
|
||||||
|
case '\u0040':
|
||||||
|
return 0x80;
|
||||||
|
case '\u0041':
|
||||||
|
return 0x81;
|
||||||
|
case '\u0042':
|
||||||
|
return 0x82;
|
||||||
|
case '\u0043':
|
||||||
|
return 0x83;
|
||||||
|
case '\u0044':
|
||||||
|
return 0x84;
|
||||||
|
case '\u0045':
|
||||||
|
return 0x85;
|
||||||
|
case '\u0046':
|
||||||
|
return 0x86;
|
||||||
|
case '\u0047':
|
||||||
|
return 0x87;
|
||||||
|
case '\u0048':
|
||||||
|
return 0x88;
|
||||||
|
case '\u0049':
|
||||||
|
return 0x89;
|
||||||
|
case '\u004A':
|
||||||
|
return 0x8A;
|
||||||
|
case '\u004B':
|
||||||
|
return 0x8B;
|
||||||
|
case '\u004C':
|
||||||
|
return 0x8C;
|
||||||
|
case '\u004D':
|
||||||
|
return 0x8D;
|
||||||
|
case '\u004E':
|
||||||
|
return 0x8E;
|
||||||
|
case '\u004F':
|
||||||
|
return 0x8F;
|
||||||
|
case '\u0050':
|
||||||
|
return 0x90;
|
||||||
|
case '\u0051':
|
||||||
|
return 0x91;
|
||||||
|
case '\u0052':
|
||||||
|
return 0x92;
|
||||||
|
case '\u0053':
|
||||||
|
return 0x93;
|
||||||
|
case '\u0054':
|
||||||
|
return 0x94;
|
||||||
|
case '\u0055':
|
||||||
|
return 0x95;
|
||||||
|
case '\u0056':
|
||||||
|
return 0x96;
|
||||||
|
case '\u0057':
|
||||||
|
return 0x97;
|
||||||
|
case '\u0058':
|
||||||
|
return 0x98;
|
||||||
|
case '\u0059':
|
||||||
|
return 0x99;
|
||||||
|
case '\u005A':
|
||||||
|
return 0x9A;
|
||||||
|
case '\u005B':
|
||||||
|
return 0x9B;
|
||||||
|
case '\u005C':
|
||||||
|
return 0x9C;
|
||||||
|
case '\u005D':
|
||||||
|
return 0x9D;
|
||||||
|
case '\u005E':
|
||||||
|
return 0x9E;
|
||||||
|
case '\u005F':
|
||||||
|
return 0x9F;
|
||||||
|
case '\u0020':
|
||||||
|
return 0xA0;
|
||||||
|
case '\u0021':
|
||||||
|
return 0xA1;
|
||||||
|
case '\u0022':
|
||||||
|
return 0xA2;
|
||||||
|
case '\u0023':
|
||||||
|
return 0xA3;
|
||||||
|
case '\u0024':
|
||||||
|
return 0xA4;
|
||||||
|
case '\u2025':
|
||||||
|
return 0xA5;
|
||||||
|
case '\u0026':
|
||||||
|
return 0xA6;
|
||||||
|
case '\u0027':
|
||||||
|
return 0xA7;
|
||||||
|
case '\u0028':
|
||||||
|
return 0xA8;
|
||||||
|
case '\u0029':
|
||||||
|
return 0xA9;
|
||||||
|
case '\u002A':
|
||||||
|
return 0xAA;
|
||||||
|
case '\u002B':
|
||||||
|
return 0xAB;
|
||||||
|
case '\u002C':
|
||||||
|
return 0xAC;
|
||||||
|
case '\u002D':
|
||||||
|
return 0xAD;
|
||||||
|
case '\u002E':
|
||||||
|
return 0xAE;
|
||||||
|
case '\u002F':
|
||||||
|
return 0xAF;
|
||||||
|
case '\u0030':
|
||||||
|
return 0xB0;
|
||||||
|
case '\u0031':
|
||||||
|
return 0xB1;
|
||||||
|
case '\u0032':
|
||||||
|
return 0xB2;
|
||||||
|
case '\u0033':
|
||||||
|
return 0xB3;
|
||||||
|
case '\u0034':
|
||||||
|
return 0xB4;
|
||||||
|
case '\u0035':
|
||||||
|
return 0xB5;
|
||||||
|
case '\u0036':
|
||||||
|
return 0xB6;
|
||||||
|
case '\u0037':
|
||||||
|
return 0xB7;
|
||||||
|
case '\u0038':
|
||||||
|
return 0xB8;
|
||||||
|
case '\u0039':
|
||||||
|
return 0xB9;
|
||||||
|
case '\u003A':
|
||||||
|
return 0xBA;
|
||||||
|
case '\u003B':
|
||||||
|
return 0xBB;
|
||||||
|
case '\u003C':
|
||||||
|
return 0xBC;
|
||||||
|
case '\u003D':
|
||||||
|
return 0xBD;
|
||||||
|
case '\u003E':
|
||||||
|
return 0xBE;
|
||||||
|
case '\u003F':
|
||||||
|
return 0xBF;
|
||||||
|
case '\u0060':
|
||||||
|
return 0xE0;
|
||||||
|
case '\u0061':
|
||||||
|
return 0xE1;
|
||||||
|
case '\u0062':
|
||||||
|
return 0xE2;
|
||||||
|
case '\u0063':
|
||||||
|
return 0xE3;
|
||||||
|
case '\u0064':
|
||||||
|
return 0xE4;
|
||||||
|
case '\u0065':
|
||||||
|
return 0xE5;
|
||||||
|
case '\u0066':
|
||||||
|
return 0xE6;
|
||||||
|
case '\u0067':
|
||||||
|
return 0xE7;
|
||||||
|
case '\u0068':
|
||||||
|
return 0xE8;
|
||||||
|
case '\u0069':
|
||||||
|
return 0xE9;
|
||||||
|
case '\u006A':
|
||||||
|
return 0xEA;
|
||||||
|
case '\u006B':
|
||||||
|
return 0xEB;
|
||||||
|
case '\u006C':
|
||||||
|
return 0xEC;
|
||||||
|
case '\u006D':
|
||||||
|
return 0xED;
|
||||||
|
case '\u006E':
|
||||||
|
return 0xEE;
|
||||||
|
case '\u006F':
|
||||||
|
return 0xEF;
|
||||||
|
case '\u0070':
|
||||||
|
return 0xF0;
|
||||||
|
case '\u0071':
|
||||||
|
return 0xF1;
|
||||||
|
case '\u0072':
|
||||||
|
return 0xF2;
|
||||||
|
case '\u0073':
|
||||||
|
return 0xF3;
|
||||||
|
case '\u0074':
|
||||||
|
return 0xF4;
|
||||||
|
case '\u0075':
|
||||||
|
return 0xF5;
|
||||||
|
case '\u0076':
|
||||||
|
return 0xF6;
|
||||||
|
case '\u0077':
|
||||||
|
return 0xF7;
|
||||||
|
case '\u0078':
|
||||||
|
return 0xF8;
|
||||||
|
case '\u0079':
|
||||||
|
return 0xF9;
|
||||||
|
case '\u007A':
|
||||||
|
return 0xFA;
|
||||||
|
case '\u007B':
|
||||||
|
return 0xFB;
|
||||||
|
case '\u007C':
|
||||||
|
return 0xFC;
|
||||||
|
case '\u007D':
|
||||||
|
return 0xFD;
|
||||||
|
case '\u007E':
|
||||||
|
return 0xFE;
|
||||||
|
default:
|
||||||
|
// Fallback to '?'
|
||||||
|
return 0xBF;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<Import Project="..\packages\NuGet.Build.Packaging.0.2.0\build\NuGet.Build.Packaging.props" Condition="Exists('..\packages\NuGet.Build.Packaging.0.2.0\build\NuGet.Build.Packaging.props')" />
|
<Import Project="..\packages\NuGet.Build.Packaging.0.2.2\build\NuGet.Build.Packaging.props" Condition="Exists('..\packages\NuGet.Build.Packaging.0.2.2\build\NuGet.Build.Packaging.props')" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
<TargetFrameworkProfile>Profile136</TargetFrameworkProfile>
|
<TargetFrameworkProfile>Profile136</TargetFrameworkProfile>
|
||||||
<PackOnBuild>true</PackOnBuild>
|
<PackOnBuild>true</PackOnBuild>
|
||||||
<PackageId>Claunia.Encoding</PackageId>
|
<PackageId>Claunia.Encoding</PackageId>
|
||||||
<PackageVersion>1.2.9.1</PackageVersion>
|
<PackageVersion>1.3</PackageVersion>
|
||||||
<Authors>Natalia Portillo</Authors>
|
<Authors>Natalia Portillo</Authors>
|
||||||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
|
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
|
||||||
<Owners>Natalia Portillo</Owners>
|
<Owners>Natalia Portillo</Owners>
|
||||||
@@ -22,8 +22,8 @@
|
|||||||
<Title>Claunia.Encoding</Title>
|
<Title>Claunia.Encoding</Title>
|
||||||
<Description>Library to provide codepage conversion to and from archaic and old computer systems and Unicode.</Description>
|
<Description>Library to provide codepage conversion to and from archaic and old computer systems and Unicode.</Description>
|
||||||
<PackageLicenseUrl>https://raw.githubusercontent.com/claunia/Claunia.Encoding/master/LICENSE.MIT</PackageLicenseUrl>
|
<PackageLicenseUrl>https://raw.githubusercontent.com/claunia/Claunia.Encoding/master/LICENSE.MIT</PackageLicenseUrl>
|
||||||
<ReleaseVersion>1.2.9.1</ReleaseVersion>
|
<ReleaseVersion>1.3</ReleaseVersion>
|
||||||
<PackageReleaseNotes>Added MacRomanian.</PackageReleaseNotes>
|
<PackageReleaseNotes>Added Apple II, IIc, IIe and IIgs.</PackageReleaseNotes>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
@@ -45,6 +45,10 @@
|
|||||||
<ConsolePause>false</ConsolePause>
|
<ConsolePause>false</ConsolePause>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Apple2.cs" />
|
||||||
|
<Compile Include="Apple2c.cs" />
|
||||||
|
<Compile Include="Apple2e.cs" />
|
||||||
|
<Compile Include="Apple2gs.cs" />
|
||||||
<Compile Include="PETSCII.cs" />
|
<Compile Include="PETSCII.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="LisaRoman.cs" />
|
<Compile Include="LisaRoman.cs" />
|
||||||
@@ -92,5 +96,5 @@
|
|||||||
</Properties>
|
</Properties>
|
||||||
</MonoDevelop>
|
</MonoDevelop>
|
||||||
</ProjectExtensions>
|
</ProjectExtensions>
|
||||||
<Import Project="..\packages\NuGet.Build.Packaging.0.2.0\build\NuGet.Build.Packaging.targets" Condition="Exists('..\packages\NuGet.Build.Packaging.0.2.0\build\NuGet.Build.Packaging.targets')" />
|
<Import Project="..\packages\NuGet.Build.Packaging.0.2.2\build\NuGet.Build.Packaging.targets" Condition="Exists('..\packages\NuGet.Build.Packaging.0.2.2\build\NuGet.Build.Packaging.targets')" />
|
||||||
</Project>
|
</Project>
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="NuGet.Build.Packaging" version="0.2.0" targetFramework="portable40-net40+sl5+win8+wp8" developmentDependency="true" />
|
<package id="NuGet.Build.Packaging" version="0.2.2" targetFramework="portable40-net40+sl5+win8+wp8" developmentDependency="true" />
|
||||||
</packages>
|
</packages>
|
||||||
@@ -3,10 +3,11 @@
|
|||||||
|
|
||||||
Library to provide codepage conversion to and from archaic and old computer systems and Unicode.
|
Library to provide codepage conversion to and from archaic and old computer systems and Unicode.
|
||||||
|
|
||||||
Copyright © 2016-2017 Natalia Portillo <claunia@claunia.com>
|
Copyright © 2016-2018 Natalia Portillo <claunia@claunia.com>
|
||||||
|
|
||||||
Supported encodings
|
Supported encodings
|
||||||
==============================
|
==============================
|
||||||
|
* Apple II, IIc, IIe and IIgs
|
||||||
* Apple Lisa
|
* Apple Lisa
|
||||||
* Atari Standard Code for Information Interchange (ATASCII)
|
* Atari Standard Code for Information Interchange (ATASCII)
|
||||||
* Atari ST character set
|
* Atari ST character set
|
||||||
|
|||||||
Reference in New Issue
Block a user