mirror of
https://github.com/claunia/Claunia.Encoding.git
synced 2026-07-09 02:16:28 +00:00
Compare commits
36 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
3e34e567c4
|
|||
|
2465b149ef
|
|||
|
60596ec513
|
|||
|
33e889ed02
|
|||
|
a295d6a9de
|
|||
|
663bb8c4c4
|
|||
|
01dceea917
|
|||
|
bd24b9be74
|
|||
|
21a0aa6349
|
|||
|
33d27e098f
|
|||
|
967687dfd1
|
|||
|
e9f4aae440
|
|||
|
4cdbe9dda9
|
|||
|
f7a073cd27
|
|||
|
88ee61203c
|
|||
|
d292daec2b
|
|||
|
74b593aff1
|
|||
| ad90cf06e2 | |||
| 788615826b | |||
| 68d8af6750 | |||
| 159bfb697d | |||
| 4a0faa5b62 | |||
| 802c106d82 | |||
| 5a83382bcd | |||
| 15e9b9b432 | |||
| d17336f244 | |||
| e3886723a3 | |||
| 48bff1514e | |||
| e3b6c08008 | |||
| 19698c7191 | |||
| 5832c3c487 | |||
| f5e340412b | |||
| 74ec94cd4c | |||
| b5867d9212 | |||
| 1bef17c7a0 | |||
| d873345124 |
86
.idea/.idea.Claunia.Encoding/.idea/markdown-navigator.xml
generated
Normal file
86
.idea/.idea.Claunia.Encoding/.idea/markdown-navigator.xml
generated
Normal file
@@ -0,0 +1,86 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="MarkdownProjectSettings" wasCopied="false">
|
||||
<PreviewSettings splitEditorLayout="SPLIT" splitEditorPreview="PREVIEW" useGrayscaleRendering="false" zoomFactor="1.0" maxImageWidth="0" showGitHubPageIfSynced="false" allowBrowsingInPreview="false" synchronizePreviewPosition="true" highlightPreviewType="NONE" highlightFadeOut="5" highlightOnTyping="true" synchronizeSourcePosition="true" verticallyAlignSourceAndPreviewSyncPosition="true" showSearchHighlightsInPreview="false" showSelectionInPreview="true" openRemoteLinks="true" replaceUnicodeEmoji="false" lastLayoutSetsDefault="false">
|
||||
<PanelProvider>
|
||||
<provider providerId="com.vladsch.idea.multimarkdown.editor.swing.html.panel" providerName="Default - Swing" />
|
||||
</PanelProvider>
|
||||
</PreviewSettings>
|
||||
<ParserSettings gitHubSyntaxChange="false" emojiShortcuts="1" emojiImages="0">
|
||||
<PegdownExtensions>
|
||||
<option name="ABBREVIATIONS" value="false" />
|
||||
<option name="ANCHORLINKS" value="true" />
|
||||
<option name="ASIDE" value="false" />
|
||||
<option name="ATXHEADERSPACE" value="true" />
|
||||
<option name="AUTOLINKS" value="false" />
|
||||
<option name="DEFINITIONS" value="false" />
|
||||
<option name="DEFINITION_BREAK_DOUBLE_BLANK_LINE" value="false" />
|
||||
<option name="FENCED_CODE_BLOCKS" value="true" />
|
||||
<option name="FOOTNOTES" value="false" />
|
||||
<option name="HARDWRAPS" value="false" />
|
||||
<option name="HTML_DEEP_PARSER" value="false" />
|
||||
<option name="INSERTED" value="false" />
|
||||
<option name="QUOTES" value="false" />
|
||||
<option name="RELAXEDHRULES" value="true" />
|
||||
<option name="SMARTS" value="false" />
|
||||
<option name="STRIKETHROUGH" value="true" />
|
||||
<option name="SUBSCRIPT" value="false" />
|
||||
<option name="SUPERSCRIPT" value="false" />
|
||||
<option name="SUPPRESS_HTML_BLOCKS" value="false" />
|
||||
<option name="SUPPRESS_INLINE_HTML" value="false" />
|
||||
<option name="TABLES" value="true" />
|
||||
<option name="TASKLISTITEMS" value="true" />
|
||||
<option name="TOC" value="false" />
|
||||
<option name="WIKILINKS" value="false" />
|
||||
</PegdownExtensions>
|
||||
<ParserOptions>
|
||||
<option name="ADMONITION_EXT" value="false" />
|
||||
<option name="ATTRIBUTES_EXT" value="false" />
|
||||
<option name="COMMONMARK_LISTS" value="true" />
|
||||
<option name="DUMMY" value="false" />
|
||||
<option name="EMOJI_SHORTCUTS" value="true" />
|
||||
<option name="ENUMERATED_REFERENCES_EXT" value="false" />
|
||||
<option name="FLEXMARK_FRONT_MATTER" value="false" />
|
||||
<option name="GFM_LOOSE_BLANK_LINE_AFTER_ITEM_PARA" value="false" />
|
||||
<option name="GFM_TABLE_RENDERING" value="true" />
|
||||
<option name="GITBOOK_URL_ENCODING" value="false" />
|
||||
<option name="GITHUB_LISTS" value="false" />
|
||||
<option name="GITHUB_WIKI_LINKS" value="false" />
|
||||
<option name="GITLAB_EXT" value="false" />
|
||||
<option name="GITLAB_MATH_EXT" value="false" />
|
||||
<option name="GITLAB_MERMAID_EXT" value="false" />
|
||||
<option name="HEADER_ID_NON_ASCII_TO_LOWERCASE" value="false" />
|
||||
<option name="HEADER_ID_NO_DUPED_DASHES" value="false" />
|
||||
<option name="JEKYLL_FRONT_MATTER" value="false" />
|
||||
<option name="MACROS_EXT" value="false" />
|
||||
<option name="NO_TEXT_ATTRIBUTES" value="false" />
|
||||
<option name="PARSE_HTML_ANCHOR_ID" value="false" />
|
||||
<option name="PLANTUML_FENCED_CODE" value="false" />
|
||||
<option name="PUML_FENCED_CODE" value="false" />
|
||||
<option name="SIM_TOC_BLANK_LINE_SPACER" value="true" />
|
||||
</ParserOptions>
|
||||
</ParserSettings>
|
||||
<HtmlSettings headerTopEnabled="false" headerBottomEnabled="false" bodyTopEnabled="false" bodyBottomEnabled="false" embedUrlContent="false" addPageHeader="true" embedImages="false" embedHttpImages="false" imageUriSerials="false" addDocTypeHtml="true" noParaTags="false" plantUmlConversion="0" mathConversion="0">
|
||||
<GeneratorProvider>
|
||||
<provider providerId="com.vladsch.idea.multimarkdown.editor.swing.html.generator" providerName="Default Swing HTML Generator" />
|
||||
</GeneratorProvider>
|
||||
<headerTop />
|
||||
<headerBottom />
|
||||
<bodyTop />
|
||||
<bodyBottom />
|
||||
</HtmlSettings>
|
||||
<CssSettings previewScheme="UI_SCHEME" cssUri="" isCssUriEnabled="false" isCssUriSerial="true" isCssTextEnabled="false" isDynamicPageWidth="true">
|
||||
<StylesheetProvider>
|
||||
<provider providerId="com.vladsch.idea.multimarkdown.editor.swing.html.css" providerName="Default Swing Stylesheet" />
|
||||
</StylesheetProvider>
|
||||
<ScriptProviders />
|
||||
<cssText />
|
||||
<cssUriHistory />
|
||||
</CssSettings>
|
||||
<AnnotatorSettings targetHasSpaces="true" linkCaseMismatch="true" wikiCaseMismatch="true" wikiLinkHasDashes="true" notUnderWikiHome="true" targetNotWikiPageExt="true" notUnderSourceWikiHome="true" targetNameHasAnchor="true" targetPathHasAnchor="true" wikiLinkHasSlash="true" wikiLinkHasSubdir="true" wikiLinkHasOnlyAnchor="true" linkTargetsWikiHasExt="true" linkTargetsWikiHasBadExt="true" notUnderSameRepo="true" targetNotUnderVcs="false" linkNeedsExt="true" linkHasBadExt="true" linkTargetNeedsExt="true" linkTargetHasBadExt="true" wikiLinkNotInWiki="true" imageTargetNotInRaw="true" repoRelativeAcrossVcsRoots="true" multipleWikiTargetsMatch="true" unresolvedLinkReference="true" linkIsIgnored="true" anchorIsIgnored="true" anchorIsUnresolved="true" anchorLineReferenceIsUnresolved="true" anchorLineReferenceFormat="true" anchorHasDuplicates="true" abbreviationDuplicates="true" abbreviationNotUsed="true" attributeIdDuplicateDefinition="true" attributeIdNotUsed="true" footnoteDuplicateDefinition="true" footnoteUnresolved="true" footnoteDuplicates="true" footnoteNotUsed="true" macroDuplicateDefinition="true" macroUnresolved="true" macroDuplicates="true" macroNotUsed="true" referenceDuplicateDefinition="true" referenceUnresolved="true" referenceDuplicates="true" referenceNotUsed="true" referenceUnresolvedNumericId="true" enumRefDuplicateDefinition="true" enumRefUnresolved="true" enumRefDuplicates="true" enumRefNotUsed="true" enumRefLinkUnresolved="true" enumRefLinkDuplicates="true" simTocUpdateNeeded="true" simTocTitleSpaceNeeded="true" />
|
||||
<HtmlExportSettings updateOnSave="false" parentDir="" targetDir="" cssDir="css" scriptDir="js" plainHtml="false" imageDir="" copyLinkedImages="false" imageUniquifyType="0" targetPathType="2" targetExt="" useTargetExt="false" noCssNoScripts="false" useElementStyleAttribute="false" linkToExportedHtml="true" exportOnSettingsChange="true" regenerateOnProjectOpen="false" linkFormatType="HTTP_ABSOLUTE" />
|
||||
<LinkMapSettings>
|
||||
<textMaps />
|
||||
</LinkMapSettings>
|
||||
</component>
|
||||
</project>
|
||||
3
.idea/.idea.Claunia.Encoding/.idea/markdown-navigator/profiles_settings.xml
generated
Normal file
3
.idea/.idea.Claunia.Encoding/.idea/markdown-navigator/profiles_settings.xml
generated
Normal file
@@ -0,0 +1,3 @@
|
||||
<component name="MarkdownNavigator.ProfileManager">
|
||||
<settings default="" pdf-export="" plain-text-search-scope="Project Files" />
|
||||
</component>
|
||||
9
.idea/.idea.Claunia.Encoding/.idea/misc.xml
generated
Normal file
9
.idea/.idea.Claunia.Encoding/.idea/misc.xml
generated
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="MacroExpansionManager">
|
||||
<option name="directoryName" value="MFTKhOEq" />
|
||||
</component>
|
||||
<component name="com.jetbrains.rider.android.RiderAndroidMiscFileCreationComponent">
|
||||
<option name="ENSURE_MISC_FILE_EXISTS" value="true" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -4,7 +4,7 @@
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright (c) 2016 © Claunia.com
|
||||
// Copyright © 2016-2019 Natalia Portillo
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -32,45 +32,46 @@ namespace Claunia.Encoding.Tests
|
||||
public class ATASCII
|
||||
{
|
||||
const string Punctuations = "!\"#$%&'()*+,-./:;<=>?@[\\]^_|";
|
||||
readonly byte[] PunctuationsBytes = { 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E,
|
||||
0x3F, 0x40, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x7C };
|
||||
const string Digits = "0123456789";
|
||||
readonly byte[] DigitsBytes = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39 };
|
||||
const string UpperLatin = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
readonly byte[] UpperLatinBytes = { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54,
|
||||
0x55, 0x56, 0x57, 0x58, 0x59, 0x5A };
|
||||
readonly byte[] PunctuationsBytes =
|
||||
{
|
||||
0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x3A, 0x3B,
|
||||
0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x7C
|
||||
};
|
||||
const string Digits = "0123456789";
|
||||
readonly byte[] DigitsBytes = {0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39};
|
||||
const string UpperLatin = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
readonly byte[] UpperLatinBytes =
|
||||
{
|
||||
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51,
|
||||
0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A
|
||||
};
|
||||
const string LowerLatin = "abcdefghijklmnopqrstuvwxyz";
|
||||
readonly byte[] LowerLatinBytes = { 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74,
|
||||
0x75, 0x76, 0x77, 0x78, 0x79, 0x7A };
|
||||
readonly byte[] LowerLatinBytes =
|
||||
{
|
||||
0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71,
|
||||
0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A
|
||||
};
|
||||
|
||||
const string Graphics = "├┘┤┐╱╲◢▗◣▝▘▂▖┌─┼●▄▎┬┴▌└";
|
||||
readonly byte[] GraphicsBytes = { 0x01, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0E, 0x0F, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
|
||||
0x18, 0x19, 0x1A};
|
||||
const string Arrows = "↑↓←→↰◀▶";
|
||||
readonly byte[] ArrowsBytes = { 0x1C, 0x1D, 0x1E, 0x1F, 0x7D, 0x7E, 0x7F };
|
||||
const string Decks = "♥♣♦♠";
|
||||
readonly byte[] DecksBytes = { 0x00, 0x10, 0x60, 0x7B };
|
||||
readonly byte[] GraphicsBytes =
|
||||
{
|
||||
0x01, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0E, 0x0F, 0x11, 0x12, 0x13, 0x14,
|
||||
0x15, 0x16, 0x17, 0x18, 0x19, 0x1A
|
||||
};
|
||||
const string Arrows = "↑↓←→↰◀▶";
|
||||
readonly byte[] ArrowsBytes = {0x1C, 0x1D, 0x1E, 0x1F, 0x7D, 0x7E, 0x7F};
|
||||
const string Decks = "♥♣♦♠";
|
||||
readonly byte[] DecksBytes = {0x00, 0x10, 0x60, 0x7B};
|
||||
|
||||
[Test]
|
||||
public void UnicodeToAtari()
|
||||
public void AtariPangrams()
|
||||
{
|
||||
byte[] byteArray;
|
||||
string testString;
|
||||
|
||||
byteArray = Encoding.AtariEncoding.GetBytes(Punctuations);
|
||||
Assert.AreEqual(PunctuationsBytes, byteArray);
|
||||
byteArray = Encoding.AtariEncoding.GetBytes(Digits);
|
||||
Assert.AreEqual(DigitsBytes, byteArray);
|
||||
byteArray = Encoding.AtariEncoding.GetBytes(UpperLatin);
|
||||
Assert.AreEqual(UpperLatinBytes, byteArray);
|
||||
byteArray = Encoding.AtariEncoding.GetBytes(LowerLatin);
|
||||
Assert.AreEqual(LowerLatinBytes, byteArray);
|
||||
|
||||
byteArray = Encoding.AtariEncoding.GetBytes(Graphics);
|
||||
Assert.AreEqual(GraphicsBytes, byteArray);
|
||||
byteArray = Encoding.AtariEncoding.GetBytes(Arrows);
|
||||
Assert.AreEqual(ArrowsBytes, byteArray);
|
||||
byteArray = Encoding.AtariEncoding.GetBytes(Decks);
|
||||
Assert.AreEqual(DecksBytes, byteArray);
|
||||
byteArray = Encoding.AtariEncoding.GetBytes(Pangrams.English);
|
||||
testString = Encoding.AtariEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.English, testString);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -96,14 +97,25 @@ namespace Claunia.Encoding.Tests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AtariPangrams()
|
||||
public void UnicodeToAtari()
|
||||
{
|
||||
byte[] byteArray;
|
||||
string testString;
|
||||
|
||||
byteArray = Encoding.AtariEncoding.GetBytes(Pangrams.English);
|
||||
testString = Encoding.AtariEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.English, testString);
|
||||
byteArray = Encoding.AtariEncoding.GetBytes(Punctuations);
|
||||
Assert.AreEqual(PunctuationsBytes, byteArray);
|
||||
byteArray = Encoding.AtariEncoding.GetBytes(Digits);
|
||||
Assert.AreEqual(DigitsBytes, byteArray);
|
||||
byteArray = Encoding.AtariEncoding.GetBytes(UpperLatin);
|
||||
Assert.AreEqual(UpperLatinBytes, byteArray);
|
||||
byteArray = Encoding.AtariEncoding.GetBytes(LowerLatin);
|
||||
Assert.AreEqual(LowerLatinBytes, byteArray);
|
||||
|
||||
byteArray = Encoding.AtariEncoding.GetBytes(Graphics);
|
||||
Assert.AreEqual(GraphicsBytes, byteArray);
|
||||
byteArray = Encoding.AtariEncoding.GetBytes(Arrows);
|
||||
Assert.AreEqual(ArrowsBytes, byteArray);
|
||||
byteArray = Encoding.AtariEncoding.GetBytes(Decks);
|
||||
Assert.AreEqual(DecksBytes, byteArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright (c) 2016 © Claunia.com
|
||||
// Copyright © 2016-2019 Natalia Portillo
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -25,7 +25,6 @@
|
||||
// THE SOFTWARE.
|
||||
|
||||
using NUnit.Framework;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Claunia.Encoding.Tests
|
||||
{
|
||||
@@ -33,44 +32,157 @@ namespace Claunia.Encoding.Tests
|
||||
public class AtariST
|
||||
{
|
||||
const string Punctuations = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
|
||||
readonly byte[] PunctuationsBytes = { 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E,
|
||||
0x3F, 0x40, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x7B, 0x7C, 0x7D, 0x7E };
|
||||
const string Digits = "0123456789";
|
||||
readonly byte[] DigitsBytes = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39 };
|
||||
const string UpperLatin = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
readonly byte[] UpperLatinBytes = { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54,
|
||||
0x55, 0x56, 0x57, 0x58, 0x59, 0x5A };
|
||||
readonly byte[] PunctuationsBytes =
|
||||
{
|
||||
0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x3A, 0x3B,
|
||||
0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x7B, 0x7C, 0x7D, 0x7E
|
||||
};
|
||||
const string Digits = "0123456789";
|
||||
readonly byte[] DigitsBytes = {0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39};
|
||||
const string UpperLatin = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
readonly byte[] UpperLatinBytes =
|
||||
{
|
||||
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51,
|
||||
0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A
|
||||
};
|
||||
const string LowerLatin = "abcdefghijklmnopqrstuvwxyz";
|
||||
readonly byte[] LowerLatinBytes = { 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74,
|
||||
0x75, 0x76, 0x77, 0x78, 0x79, 0x7A };
|
||||
readonly byte[] LowerLatinBytes =
|
||||
{
|
||||
0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71,
|
||||
0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A
|
||||
};
|
||||
|
||||
const string Spanish = "¡¿áéíóúüñÉÜÑ";
|
||||
readonly byte[] SpanishBytes = { 0xAD, 0xA8, 0xA0, 0x82, 0xA1, 0xA2, 0xA3, 0x81, 0xA4, 0x90, 0x9A, 0xA5 };
|
||||
const string French = "éÉàèùÀâêîôûëïüÿçÇœŒæÆ";
|
||||
readonly byte[] FrenchBytes = { 0x82, 0x90, 0x85, 0x8A, 0x97, 0xB6, 0x83, 0x88, 0x8C, 0x93, 0x96, 0x89, 0x8B, 0x81, 0x98, 0x87, 0x80, 0xB4, 0xB5, 0x91, 0x92 };
|
||||
const string German = "äöüßÄÖÜ";
|
||||
readonly byte[] GermanBytes = { 0x84, 0x94, 0x81, 0x9E, 0x8E, 0x99, 0x9A };
|
||||
const string Norwegian = "æøåÆØÅ";
|
||||
readonly byte[] NorwegianBytes = { 0x91, 0xB3, 0x86, 0x92, 0xB2, 0x8F };
|
||||
const string Portuguese = "áéíóúÉâêôãõÃÕçÇ";
|
||||
readonly byte[] PortugueseBytes = { 0xA0, 0x82, 0xA1, 0xA2, 0xA3, 0x90, 0x83, 0x88, 0x93, 0xB0, 0xB1, 0xB7, 0xB8, 0x87, 0x80 };
|
||||
const string Dutch = "ijIJ";
|
||||
readonly byte[] DutchBytes = { 0xC0, 0xC1 };
|
||||
const string Hebrew = "אבגדהוזחטיכלמנסעפצקרשתןךםףץ";
|
||||
readonly byte[] HebrewBytes = { 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6,
|
||||
0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC};
|
||||
const string Greek = "αβΓπΣσµτΦΘΩδ¯";
|
||||
readonly byte[] GreekBytes = { 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xFF };
|
||||
const string Spanish = "¡¿áéíóúüñÉÜÑ";
|
||||
readonly byte[] SpanishBytes = {0xAD, 0xA8, 0xA0, 0x82, 0xA1, 0xA2, 0xA3, 0x81, 0xA4, 0x90, 0x9A, 0xA5};
|
||||
const string French = "éÉàèùÀâêîôûëïüÿçÇœŒæÆ";
|
||||
readonly byte[] FrenchBytes =
|
||||
{
|
||||
0x82, 0x90, 0x85, 0x8A, 0x97, 0xB6, 0x83, 0x88, 0x8C, 0x93, 0x96, 0x89, 0x8B, 0x81, 0x98, 0x87, 0x80,
|
||||
0xB4, 0xB5, 0x91, 0x92
|
||||
};
|
||||
const string German = "äöüßÄÖÜ";
|
||||
readonly byte[] GermanBytes = {0x84, 0x94, 0x81, 0x9E, 0x8E, 0x99, 0x9A};
|
||||
const string Norwegian = "æøåÆØÅ";
|
||||
readonly byte[] NorwegianBytes = {0x91, 0xB3, 0x86, 0x92, 0xB2, 0x8F};
|
||||
const string Portuguese = "áéíóúÉâêôãõÃÕçÇ";
|
||||
readonly byte[] PortugueseBytes =
|
||||
{
|
||||
0xA0, 0x82, 0xA1, 0xA2, 0xA3, 0x90, 0x83, 0x88, 0x93, 0xB0, 0xB1, 0xB7, 0xB8, 0x87, 0x80
|
||||
};
|
||||
const string Dutch = "ijIJ";
|
||||
readonly byte[] DutchBytes = {0xC0, 0xC1};
|
||||
const string Hebrew = "אבגדהוזחטיכלמנסעפצקרשתןךםףץ";
|
||||
readonly byte[] HebrewBytes =
|
||||
{
|
||||
0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2,
|
||||
0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC
|
||||
};
|
||||
const string Greek = "αβΓπΣσµτΦΘΩδ¯";
|
||||
readonly byte[] GreekBytes = {0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xFF};
|
||||
|
||||
const string Typographic = "ªº«»¨´†¶©®™§°∙·";
|
||||
readonly byte[] TypographicBytes = { 0xA6, 0xA7, 0xAE, 0xAF, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, 0xDD, 0xF8, 0xF9, 0xFA };
|
||||
const string Currency = "¢£¥ƒ";
|
||||
readonly byte[] CurrencyBytes = { 0x9B, 0x9C, 0x9D, 0x9F };
|
||||
const string Mathematics = "⌐¬½¼∧∞∮ϕ∈∩≡±≥≤⌠⌡÷≈√ⁿ²³";
|
||||
readonly byte[] MathematicsBytes = { 0xA9, 0xAA, 0xAB, 0xAC, 0xDE, 0xDF, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xFB, 0xFC,
|
||||
0xFD, 0xFE};
|
||||
const string Symbols = "⇧⇩⇨⇦❎✓♪ə";
|
||||
readonly byte[] SymbolsBytes = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x08, 0x0B, 0x1A };
|
||||
readonly byte[] TypographicBytes =
|
||||
{
|
||||
0xA6, 0xA7, 0xAE, 0xAF, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, 0xDD, 0xF8, 0xF9, 0xFA
|
||||
};
|
||||
const string Currency = "¢£¥ƒ";
|
||||
readonly byte[] CurrencyBytes = {0x9B, 0x9C, 0x9D, 0x9F};
|
||||
const string Mathematics = "⌐¬½¼∧∞∮ϕ∈∩≡±≥≤⌠⌡÷≈√ⁿ²³";
|
||||
readonly byte[] MathematicsBytes =
|
||||
{
|
||||
0xA9, 0xAA, 0xAB, 0xAC, 0xDE, 0xDF, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6,
|
||||
0xF7, 0xFB, 0xFC, 0xFD, 0xFE
|
||||
};
|
||||
const string Symbols = "⇧⇩⇨⇦❎✓♪ə";
|
||||
readonly byte[] SymbolsBytes = {0x01, 0x02, 0x03, 0x04, 0x05, 0x08, 0x0B, 0x1A};
|
||||
|
||||
[Test]
|
||||
public void AtariSTPangrams()
|
||||
{
|
||||
byte[] byteArray;
|
||||
string testString;
|
||||
|
||||
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Basque);
|
||||
testString = Encoding.AtariSTEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Basque, testString);
|
||||
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Danish);
|
||||
testString = Encoding.AtariSTEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Danish, testString);
|
||||
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.English);
|
||||
testString = Encoding.AtariSTEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.English, testString);
|
||||
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Finnish);
|
||||
testString = Encoding.AtariSTEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Finnish, testString);
|
||||
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.French);
|
||||
testString = Encoding.AtariSTEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.French, testString);
|
||||
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Galician);
|
||||
testString = Encoding.AtariSTEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Galician, testString);
|
||||
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.German);
|
||||
testString = Encoding.AtariSTEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.German, testString);
|
||||
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Hebrew);
|
||||
testString = Encoding.AtariSTEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Hebrew, testString);
|
||||
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Norwegian);
|
||||
testString = Encoding.AtariSTEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Norwegian, testString);
|
||||
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Portuguese);
|
||||
testString = Encoding.AtariSTEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Portuguese, testString);
|
||||
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Spanish);
|
||||
testString = Encoding.AtariSTEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Spanish, testString);
|
||||
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Swedish);
|
||||
testString = Encoding.AtariSTEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Swedish, testString);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AtariSTToUnicode()
|
||||
{
|
||||
string testString;
|
||||
|
||||
testString = Encoding.AtariSTEncoding.GetString(PunctuationsBytes);
|
||||
Assert.AreEqual(Punctuations, testString);
|
||||
testString = Encoding.AtariSTEncoding.GetString(DigitsBytes);
|
||||
Assert.AreEqual(Digits, testString);
|
||||
testString = Encoding.AtariSTEncoding.GetString(UpperLatinBytes);
|
||||
Assert.AreEqual(UpperLatin, testString);
|
||||
testString = Encoding.AtariSTEncoding.GetString(LowerLatinBytes);
|
||||
Assert.AreEqual(LowerLatin, testString);
|
||||
|
||||
testString = Encoding.AtariSTEncoding.GetString(SpanishBytes);
|
||||
Assert.AreEqual(Spanish, testString);
|
||||
testString = Encoding.AtariSTEncoding.GetString(FrenchBytes);
|
||||
Assert.AreEqual(French, testString);
|
||||
testString = Encoding.AtariSTEncoding.GetString(GermanBytes);
|
||||
Assert.AreEqual(German, testString);
|
||||
testString = Encoding.AtariSTEncoding.GetString(NorwegianBytes);
|
||||
Assert.AreEqual(Norwegian, testString);
|
||||
testString = Encoding.AtariSTEncoding.GetString(PortugueseBytes);
|
||||
Assert.AreEqual(Portuguese, testString);
|
||||
testString = Encoding.AtariSTEncoding.GetString(DutchBytes);
|
||||
Assert.AreEqual(Dutch, testString);
|
||||
testString = Encoding.AtariSTEncoding.GetString(HebrewBytes);
|
||||
Assert.AreEqual(Hebrew, testString);
|
||||
testString = Encoding.AtariSTEncoding.GetString(GreekBytes);
|
||||
Assert.AreEqual(Greek, testString);
|
||||
|
||||
testString = Encoding.AtariSTEncoding.GetString(TypographicBytes);
|
||||
Assert.AreEqual(Typographic, testString);
|
||||
testString = Encoding.AtariSTEncoding.GetString(CurrencyBytes);
|
||||
Assert.AreEqual(Currency, testString);
|
||||
testString = Encoding.AtariSTEncoding.GetString(MathematicsBytes);
|
||||
Assert.AreEqual(Mathematics, testString);
|
||||
testString = Encoding.AtariSTEncoding.GetString(SymbolsBytes);
|
||||
Assert.AreEqual(Symbols, testString);
|
||||
// TODO: 0x09 => U+1F552, 0x0A => U+1F514
|
||||
/*testString = Encoding.AtariSTEncoding.GetString(SymbolsUnicode32Bytes);
|
||||
Assert.AreEqual(SymbolsUnicode32, testString);*/
|
||||
}
|
||||
// TODO: 0x09 => U+1F552, 0x0A => U+1F514
|
||||
/*const string SymbolsUnicode32 = "\ud83d\udd52\ud83d\udd14";
|
||||
readonly byte[] SymbolsUnicode32Bytes = { 0x09, 0x0A };*/
|
||||
@@ -118,93 +230,5 @@ namespace Claunia.Encoding.Tests
|
||||
/*byteArray = Encoding.AtariSTEncoding.GetBytes(SymbolsUnicode32);
|
||||
Assert.AreEqual(SymbolsUnicode32Bytes, byteArray);*/
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AtariSTToUnicode()
|
||||
{
|
||||
string testString;
|
||||
|
||||
testString = Encoding.AtariSTEncoding.GetString(PunctuationsBytes);
|
||||
Assert.AreEqual(Punctuations, testString);
|
||||
testString = Encoding.AtariSTEncoding.GetString(DigitsBytes);
|
||||
Assert.AreEqual(Digits, testString);
|
||||
testString = Encoding.AtariSTEncoding.GetString(UpperLatinBytes);
|
||||
Assert.AreEqual(UpperLatin, testString);
|
||||
testString = Encoding.AtariSTEncoding.GetString(LowerLatinBytes);
|
||||
Assert.AreEqual(LowerLatin, testString);
|
||||
|
||||
testString = Encoding.AtariSTEncoding.GetString(SpanishBytes);
|
||||
Assert.AreEqual(Spanish, testString);
|
||||
testString = Encoding.AtariSTEncoding.GetString(FrenchBytes);
|
||||
Assert.AreEqual(French, testString);
|
||||
testString = Encoding.AtariSTEncoding.GetString(GermanBytes);
|
||||
Assert.AreEqual(German, testString);
|
||||
testString = Encoding.AtariSTEncoding.GetString(NorwegianBytes);
|
||||
Assert.AreEqual(Norwegian, testString);
|
||||
testString = Encoding.AtariSTEncoding.GetString(PortugueseBytes);
|
||||
Assert.AreEqual(Portuguese, testString);
|
||||
testString = Encoding.AtariSTEncoding.GetString(DutchBytes);
|
||||
Assert.AreEqual(Dutch, testString);
|
||||
testString = Encoding.AtariSTEncoding.GetString(HebrewBytes);
|
||||
Assert.AreEqual(Hebrew, testString);
|
||||
testString = Encoding.AtariSTEncoding.GetString(GreekBytes);
|
||||
Assert.AreEqual(Greek, testString);
|
||||
|
||||
testString = Encoding.AtariSTEncoding.GetString(TypographicBytes);
|
||||
Assert.AreEqual(Typographic, testString);
|
||||
testString = Encoding.AtariSTEncoding.GetString(CurrencyBytes);
|
||||
Assert.AreEqual(Currency, testString);
|
||||
testString = Encoding.AtariSTEncoding.GetString(MathematicsBytes);
|
||||
Assert.AreEqual(Mathematics, testString);
|
||||
testString = Encoding.AtariSTEncoding.GetString(SymbolsBytes);
|
||||
Assert.AreEqual(Symbols, testString);
|
||||
// TODO: 0x09 => U+1F552, 0x0A => U+1F514
|
||||
/*testString = Encoding.AtariSTEncoding.GetString(SymbolsUnicode32Bytes);
|
||||
Assert.AreEqual(SymbolsUnicode32, testString);*/
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AtariSTPangrams()
|
||||
{
|
||||
byte[] byteArray;
|
||||
string testString;
|
||||
|
||||
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Basque);
|
||||
testString = Encoding.AtariSTEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Basque, testString);
|
||||
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Danish);
|
||||
testString = Encoding.AtariSTEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Danish, testString);
|
||||
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.English);
|
||||
testString = Encoding.AtariSTEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.English, testString);
|
||||
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Finnish);
|
||||
testString = Encoding.AtariSTEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Finnish, testString);
|
||||
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.French);
|
||||
testString = Encoding.AtariSTEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.French, testString);
|
||||
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Galician);
|
||||
testString = Encoding.AtariSTEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Galician, testString);
|
||||
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.German);
|
||||
testString = Encoding.AtariSTEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.German, testString);
|
||||
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Hebrew);
|
||||
testString = Encoding.AtariSTEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Hebrew, testString);
|
||||
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Norwegian);
|
||||
testString = Encoding.AtariSTEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Norwegian, testString);
|
||||
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Portuguese);
|
||||
testString = Encoding.AtariSTEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Portuguese, testString);
|
||||
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Spanish);
|
||||
testString = Encoding.AtariSTEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Spanish, testString);
|
||||
byteArray = Encoding.AtariSTEncoding.GetBytes(Pangrams.Swedish);
|
||||
testString = Encoding.AtariSTEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Swedish, testString);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +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">
|
||||
<Import Project="..\packages\NUnit.3.11.0\build\NUnit.props" Condition="Exists('..\packages\NUnit.3.11.0\build\NUnit.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
@@ -7,7 +8,8 @@
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>Claunia.Encoding.Tests</RootNamespace>
|
||||
<AssemblyName>Claunia.Encoding.Tests</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<ReleaseVersion>1.7</ReleaseVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -27,18 +29,18 @@
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="nunit.framework">
|
||||
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
|
||||
<Reference Include="nunit.framework, Version=3.11.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb">
|
||||
<HintPath>..\packages\NUnit.3.11.0\lib\net45\nunit.framework.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="LisaRoman.cs" />
|
||||
<Compile Include="ATASCII.cs" />
|
||||
<Compile Include="AtariST.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
<Compile Include="GetEncs.cs" />
|
||||
<Compile Include="Radix50.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Claunia.Encoding\Claunia.Encoding.csproj">
|
||||
@@ -46,5 +48,14 @@
|
||||
<Name>Claunia.Encoding</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\NUnit.3.11.0\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit.3.11.0\build\NUnit.props'))" />
|
||||
</Target>
|
||||
</Project>
|
||||
71
Claunia.Encoding.Tests/GetEncs.cs
Normal file
71
Claunia.Encoding.Tests/GetEncs.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
//
|
||||
// GetEncs.cs
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright © 2017-2019 Natalia Portillo
|
||||
//
|
||||
// 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;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Claunia.Encoding.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
public class GetEncs
|
||||
{
|
||||
[Test]
|
||||
// Well basically this is taken from MSDN's documentation :p
|
||||
public void GetAllEncs()
|
||||
{
|
||||
// Print the header.
|
||||
Console.Write("CodePage identifier and name ");
|
||||
Console.Write("BrDisp BrSave ");
|
||||
Console.Write("MNDisp MNSave ");
|
||||
Console.WriteLine("1-Byte ReadOnly ");
|
||||
|
||||
// For every encoding, get the property values.
|
||||
foreach(EncodingInfo ei in Encoding.GetEncodings())
|
||||
{
|
||||
Encoding e = ei.GetEncoding();
|
||||
|
||||
Console.Write("{0,-6} {1,-25} ", ei.CodePage, ei.Name);
|
||||
Console.Write("{0,-8} {1,-8} ", e.IsBrowserDisplay, e.IsBrowserSave);
|
||||
Console.Write("{0,-8} {1,-8} ", e.IsMailNewsDisplay, e.IsMailNewsSave);
|
||||
Console.WriteLine("{0,-8} {1,-8} ", e.IsSingleByte, e.IsReadOnly);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
// Well basically this is taken from MSDN's documentation :p
|
||||
public void GetExternalEncoding()
|
||||
{
|
||||
System.Text.Encoding e = Encoding.GetEncoding("shift_jis");
|
||||
}
|
||||
|
||||
[Test]
|
||||
// Well basically this is taken from MSDN's documentation :p
|
||||
public void GetInternalEncoding()
|
||||
{
|
||||
System.Text.Encoding e = Encoding.GetEncoding("lisa");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright (c) 2016 © Claunia.com
|
||||
// Copyright © 2016-2019 Natalia Portillo
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -32,66 +32,104 @@ namespace Claunia.Encoding.Tests
|
||||
public class LisaRoman
|
||||
{
|
||||
const string Punctuations = "!\"#$%&()*+,-./:;<=>?@[\\]^_{|}~";
|
||||
readonly byte[] PunctuationsBytes = { 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E,
|
||||
0x3F, 0x40, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x7B, 0x7C, 0x7D, 0x7E };
|
||||
const string Digits = "0123456789";
|
||||
readonly byte[] DigitsBytes = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39 };
|
||||
const string UpperLatin = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
readonly byte[] UpperLatinBytes = { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54,
|
||||
0x55, 0x56, 0x57, 0x58, 0x59, 0x5A };
|
||||
readonly byte[] PunctuationsBytes =
|
||||
{
|
||||
0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x3A, 0x3B, 0x3C,
|
||||
0x3D, 0x3E, 0x3F, 0x40, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x7B, 0x7C, 0x7D, 0x7E
|
||||
};
|
||||
const string Digits = "0123456789";
|
||||
readonly byte[] DigitsBytes = {0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39};
|
||||
const string UpperLatin = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
readonly byte[] UpperLatinBytes =
|
||||
{
|
||||
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51,
|
||||
0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A
|
||||
};
|
||||
const string LowerLatin = "abcdefghijklmnopqrstuvwxyz";
|
||||
readonly byte[] LowerLatinBytes = { 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74,
|
||||
0x75, 0x76, 0x77, 0x78, 0x79, 0x7A };
|
||||
readonly byte[] LowerLatinBytes =
|
||||
{
|
||||
0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71,
|
||||
0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A
|
||||
};
|
||||
|
||||
const string Spanish = "¡¿áéíóúüñÉÜÑ";
|
||||
readonly byte[] SpanishBytes = { 0xC1, 0xC0, 0x87, 0x8E, 0x92, 0x97, 0x9C, 0x9F, 0x96, 0x83, 0x86, 0x84 };
|
||||
const string French = "éÉàèùÀâêîôûëïüÿçÇœŒæÆ";
|
||||
readonly byte[] FrenchBytes = { 0x8E, 0x83, 0x88, 0x8F, 0x9D, 0xCB, 0x89, 0x90, 0x94, 0x99, 0x9E, 0x91, 0x95, 0x9F, 0xD8, 0x8D, 0x82, 0xCF, 0xCE, 0xBE, 0xAE };
|
||||
const string German = "äöüßÄÖÜ";
|
||||
readonly byte[] GermanBytes = { 0x8A, 0x9A, 0x9F, 0xA7, 0x80, 0x85, 0x86 };
|
||||
const string Norwegian = "æøåÆØÅ";
|
||||
readonly byte[] NorwegianBytes = { 0xBE, 0xBF, 0x8C, 0xAE, 0xAF, 0x81 };
|
||||
const string Portuguese = "áéíóúÉâêôãõÃÕçÇ";
|
||||
readonly byte[] PortugueseBytes = { 0x87, 0x8E, 0x92, 0x97, 0x9C, 0x83, 0x89, 0x90, 0x99, 0x8B, 0x9B, 0xCC, 0xCD, 0x8D, 0x82 };
|
||||
const string Spanish = "¡¿áéíóúüñÉÜÑ";
|
||||
readonly byte[] SpanishBytes = {0xC1, 0xC0, 0x87, 0x8E, 0x92, 0x97, 0x9C, 0x9F, 0x96, 0x83, 0x86, 0x84};
|
||||
const string French = "éÉàèùÀâêîôûëïüÿçÇœŒæÆ";
|
||||
readonly byte[] FrenchBytes =
|
||||
{
|
||||
0x8E, 0x83, 0x88, 0x8F, 0x9D, 0xCB, 0x89, 0x90, 0x94, 0x99, 0x9E, 0x91, 0x95, 0x9F, 0xD8, 0x8D, 0x82,
|
||||
0xCF, 0xCE, 0xBE, 0xAE
|
||||
};
|
||||
const string German = "äöüßÄÖÜ";
|
||||
readonly byte[] GermanBytes = {0x8A, 0x9A, 0x9F, 0xA7, 0x80, 0x85, 0x86};
|
||||
const string Norwegian = "æøåÆØÅ";
|
||||
readonly byte[] NorwegianBytes = {0xBE, 0xBF, 0x8C, 0xAE, 0xAF, 0x81};
|
||||
const string Portuguese = "áéíóúÉâêôãõÃÕçÇ";
|
||||
readonly byte[] PortugueseBytes =
|
||||
{
|
||||
0x87, 0x8E, 0x92, 0x97, 0x9C, 0x83, 0x89, 0x90, 0x99, 0x8B, 0x9B, 0xCC, 0xCD, 0x8D, 0x82
|
||||
};
|
||||
|
||||
const string Typographic = "†°•¶®©™´¨ªº«»…–—“”‘’§";
|
||||
readonly byte[] TypographicBytes = { 0xA0, 0xA1, 0xA5, 0xA6, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xBB, 0xBC, 0xC7, 0xC8, 0xC9, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xA4};
|
||||
const string Currency = "¢£¥";
|
||||
readonly byte[] CurrencyBytes = { 0xA2, 0xA3, 0xB4 };
|
||||
const string Mathematics = "≠∞±≤≥µ∂∑∏π∫Ω¬√ƒ≈∆÷◊";
|
||||
readonly byte[] MathematicsBytes = { 0xAD, 0xB0, 0xB1, 0xB2, 0xB3, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBD, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xD6, 0xD7 };
|
||||
readonly byte[] TypographicBytes =
|
||||
{
|
||||
0xA0, 0xA1, 0xA5, 0xA6, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xBB, 0xBC, 0xC7, 0xC8, 0xC9, 0xD0, 0xD1, 0xD2,
|
||||
0xD3, 0xD4, 0xD5, 0xA4
|
||||
};
|
||||
const string Currency = "¢£¥";
|
||||
readonly byte[] CurrencyBytes = {0xA2, 0xA3, 0xB4};
|
||||
const string Mathematics = "≠∞±≤≥µ∂∑∏π∫Ω¬√ƒ≈∆÷◊";
|
||||
readonly byte[] MathematicsBytes =
|
||||
{
|
||||
0xAD, 0xB0, 0xB1, 0xB2, 0xB3, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBD, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6,
|
||||
0xD6, 0xD7
|
||||
};
|
||||
|
||||
[Test]
|
||||
public void UnicodeToLisa()
|
||||
public void LisaPangrams()
|
||||
{
|
||||
byte[] byteArray;
|
||||
string testString;
|
||||
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Punctuations);
|
||||
Assert.AreEqual(PunctuationsBytes, byteArray);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Digits);
|
||||
Assert.AreEqual(DigitsBytes, byteArray);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(UpperLatin);
|
||||
Assert.AreEqual(UpperLatinBytes, byteArray);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(LowerLatin);
|
||||
Assert.AreEqual(LowerLatinBytes, byteArray);
|
||||
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Spanish);
|
||||
Assert.AreEqual(SpanishBytes, byteArray);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(French);
|
||||
Assert.AreEqual(FrenchBytes, byteArray);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(German);
|
||||
Assert.AreEqual(GermanBytes, byteArray);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Norwegian);
|
||||
Assert.AreEqual(NorwegianBytes, byteArray);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Portuguese);
|
||||
Assert.AreEqual(PortugueseBytes, byteArray);
|
||||
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Typographic);
|
||||
Assert.AreEqual(TypographicBytes, byteArray);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Currency);
|
||||
Assert.AreEqual(CurrencyBytes, byteArray);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Mathematics);
|
||||
Assert.AreEqual(MathematicsBytes, byteArray);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Pangrams.Basque);
|
||||
testString = Encoding.LisaEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Basque, testString);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Pangrams.Breton);
|
||||
testString = Encoding.LisaEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Breton, testString);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Pangrams.Danish);
|
||||
testString = Encoding.LisaEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Danish, testString);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Pangrams.Dutch);
|
||||
testString = Encoding.LisaEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Dutch, testString);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Pangrams.English);
|
||||
testString = Encoding.LisaEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.English, testString);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Pangrams.Finnish);
|
||||
testString = Encoding.LisaEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Finnish, testString);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Pangrams.French);
|
||||
testString = Encoding.LisaEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.French, testString);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Pangrams.Galician);
|
||||
testString = Encoding.LisaEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Galician, testString);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Pangrams.German);
|
||||
testString = Encoding.LisaEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.German, testString);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Pangrams.Norwegian);
|
||||
testString = Encoding.LisaEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Norwegian, testString);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Pangrams.Portuguese);
|
||||
testString = Encoding.LisaEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Portuguese, testString);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Pangrams.Spanish);
|
||||
testString = Encoding.LisaEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Spanish, testString);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Pangrams.Swedish);
|
||||
testString = Encoding.LisaEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Swedish, testString);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -128,50 +166,36 @@ namespace Claunia.Encoding.Tests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LisaPangrams()
|
||||
public void UnicodeToLisa()
|
||||
{
|
||||
byte[] byteArray;
|
||||
string testString;
|
||||
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Pangrams.Basque);
|
||||
testString = Encoding.LisaEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Basque, testString);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Pangrams.Breton);
|
||||
testString = Encoding.LisaEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Breton, testString);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Pangrams.Danish);
|
||||
testString = Encoding.LisaEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Danish, testString);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Pangrams.Dutch);
|
||||
testString = Encoding.LisaEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Dutch, testString);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Pangrams.English);
|
||||
testString = Encoding.LisaEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.English, testString);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Pangrams.Finnish);
|
||||
testString = Encoding.LisaEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Finnish, testString);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Pangrams.French);
|
||||
testString = Encoding.LisaEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.French, testString);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Pangrams.Galician);
|
||||
testString = Encoding.LisaEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Galician, testString);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Pangrams.German);
|
||||
testString = Encoding.LisaEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.German, testString);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Pangrams.Norwegian);
|
||||
testString = Encoding.LisaEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Norwegian, testString);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Pangrams.Portuguese);
|
||||
testString = Encoding.LisaEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Portuguese, testString);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Pangrams.Spanish);
|
||||
testString = Encoding.LisaEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Spanish, testString);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Pangrams.Swedish);
|
||||
testString = Encoding.LisaEncoding.GetString(byteArray);
|
||||
Assert.AreEqual(Pangrams.Swedish, testString);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Punctuations);
|
||||
Assert.AreEqual(PunctuationsBytes, byteArray);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Digits);
|
||||
Assert.AreEqual(DigitsBytes, byteArray);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(UpperLatin);
|
||||
Assert.AreEqual(UpperLatinBytes, byteArray);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(LowerLatin);
|
||||
Assert.AreEqual(LowerLatinBytes, byteArray);
|
||||
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Spanish);
|
||||
Assert.AreEqual(SpanishBytes, byteArray);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(French);
|
||||
Assert.AreEqual(FrenchBytes, byteArray);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(German);
|
||||
Assert.AreEqual(GermanBytes, byteArray);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Norwegian);
|
||||
Assert.AreEqual(NorwegianBytes, byteArray);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Portuguese);
|
||||
Assert.AreEqual(PortugueseBytes, byteArray);
|
||||
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Typographic);
|
||||
Assert.AreEqual(TypographicBytes, byteArray);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Currency);
|
||||
Assert.AreEqual(CurrencyBytes, byteArray);
|
||||
byteArray = Encoding.LisaEncoding.GetBytes(Mathematics);
|
||||
Assert.AreEqual(MathematicsBytes, byteArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
86
Claunia.Encoding.Tests/Radix50.cs
Normal file
86
Claunia.Encoding.Tests/Radix50.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
//
|
||||
// LisaRoman.cs
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright © 2016-2019 Natalia Portillo
|
||||
//
|
||||
// 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 NUnit.Framework;
|
||||
|
||||
namespace Claunia.Encoding.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
public class Radix50
|
||||
{
|
||||
const string Punctuations = " .$%";
|
||||
readonly byte[] PunctuationsBytes = {0b00000001, 0b11000110, 0b11011101};
|
||||
const string Digits = "0123456789";
|
||||
readonly byte[] DigitsBytes =
|
||||
{
|
||||
0b01111001, 0b11111000, 0b00100001, 0b10001010, 0b00111001, 0b00100101, 0b10011010, 0b01110000
|
||||
};
|
||||
const string UpperLatin = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
readonly byte[] UpperLatinBytes =
|
||||
{
|
||||
0b00000100, 0b00100000, 0b11000100, 0b00010100, 0b01100001, 0b11001000, 0b00100100, 0b10100010,
|
||||
0b11001100, 0b00110100, 0b11100011, 0b11010000, 0b01000101, 0b00100100, 0b11010100, 0b01010101,
|
||||
0b01100101, 0b11011000, 0b01100101, 0b10100000
|
||||
};
|
||||
const string Sentence = "THIS IS A TEST$";
|
||||
const string SentencePadded = "THIS IS A TEST$ "; // It gets space padded when decoding is not multiple
|
||||
readonly byte[] SentenceBytes =
|
||||
{
|
||||
0b01010000, 0b10000010, 0b01010011, 0b00000000, 0b10010100, 0b11000000, 0b00000100, 0b00000101,
|
||||
0b00000101, 0b01001101, 0b01000110, 0b11000000
|
||||
};
|
||||
|
||||
[Test]
|
||||
public void RadixToUnicode()
|
||||
{
|
||||
string testString;
|
||||
|
||||
testString = Encoding.Radix50Encoding.GetString(PunctuationsBytes);
|
||||
Assert.AreEqual(Punctuations, testString);
|
||||
testString = Encoding.Radix50Encoding.GetString(DigitsBytes);
|
||||
Assert.AreEqual(Digits, testString);
|
||||
testString = Encoding.Radix50Encoding.GetString(UpperLatinBytes);
|
||||
Assert.AreEqual(UpperLatin, testString);
|
||||
testString = Encoding.Radix50Encoding.GetString(SentenceBytes);
|
||||
Assert.AreEqual(SentencePadded, testString);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UnicodeToRadix()
|
||||
{
|
||||
byte[] byteArray;
|
||||
|
||||
byteArray = Encoding.Radix50Encoding.GetBytes(Punctuations);
|
||||
Assert.AreEqual(PunctuationsBytes, byteArray);
|
||||
byteArray = Encoding.Radix50Encoding.GetBytes(Digits);
|
||||
Assert.AreEqual(DigitsBytes, byteArray);
|
||||
byteArray = Encoding.Radix50Encoding.GetBytes(UpperLatin);
|
||||
Assert.AreEqual(UpperLatinBytes, byteArray);
|
||||
byteArray = Encoding.Radix50Encoding.GetBytes(Sentence);
|
||||
Assert.AreEqual(SentenceBytes, byteArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="NUnit" version="2.6.4" targetFramework="net45" />
|
||||
<package id="NUnit" version="3.11.0" targetFramework="net45" />
|
||||
</packages>
|
||||
@@ -24,35 +24,11 @@ Global
|
||||
Policies = $0
|
||||
$0.StandardHeader = $1
|
||||
$1.Text = @\n${FileName}\n \nAuthor:\n ${AuthorName} <${AuthorEmail}>\n\nCopyright (c) ${Year} ${CopyrightHolder}\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the "Software"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.
|
||||
$1.IncludeInNewFiles = True
|
||||
$0.TextStylePolicy = $2
|
||||
$2.FileWidth = 120
|
||||
$2.inheritsSet = VisualStudio
|
||||
$2.inheritsScope = text/plain
|
||||
$2.scope = text/plain
|
||||
$2.TabsToSpaces = True
|
||||
$0.CSharpFormattingPolicy = $3
|
||||
$3.IndentSwitchSection = True
|
||||
$3.inheritsSet = Mono
|
||||
$3.inheritsScope = text/x-csharp
|
||||
$3.scope = text/x-csharp
|
||||
$3.NewLinesForBracesInProperties = True
|
||||
$3.NewLinesForBracesInAccessors = True
|
||||
$3.NewLinesForBracesInAnonymousMethods = True
|
||||
$3.NewLinesForBracesInControlBlocks = True
|
||||
$3.NewLinesForBracesInAnonymousTypes = True
|
||||
$3.NewLinesForBracesInObjectCollectionArrayInitializers = True
|
||||
$3.NewLinesForBracesInLambdaExpressionBody = True
|
||||
$3.NewLineForElse = True
|
||||
$3.NewLineForCatch = True
|
||||
$3.NewLineForFinally = True
|
||||
$3.NewLineForMembersInObjectInit = True
|
||||
$3.NewLineForMembersInAnonymousTypes = True
|
||||
$3.NewLineForClausesInQuery = True
|
||||
$3.SpacingAfterMethodDeclarationName = False
|
||||
$3.SpaceAfterMethodCallName = False
|
||||
$3.SpaceAfterControlFlowStatementKeyword = False
|
||||
$3.SpaceBeforeOpenSquareBracket = False
|
||||
$3.WrappingPreserveSingleLine = False
|
||||
$3.WrappingKeepStatementsOnSingleLine = False
|
||||
version = 1.6
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
542
Claunia.Encoding/Apple2.cs
Normal file
542
Claunia.Encoding/Apple2.cs
Normal file
@@ -0,0 +1,542 @@
|
||||
//
|
||||
// Apple II.cs
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright © 2016-2019 Natalia Portillo
|
||||
//
|
||||
// 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 = "apple2";
|
||||
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>
|
||||
/// 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>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for displaying content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserDisplay => browserDisplay;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for saving content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserSave => 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 => 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 => mailNewsSave;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding is read-only.
|
||||
/// </summary>
|
||||
/// <value>The is single byte.</value>
|
||||
public override bool IsReadOnly => readOnly;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding uses single-byte code points.
|
||||
/// </summary>
|
||||
public override bool IsSingleByte => singleByte;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the code page identifier of the current Encoding.
|
||||
/// </summary>
|
||||
public override int CodePage => _codepage;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent body tags
|
||||
/// </summary>
|
||||
public override string BodyName => _bodyname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent header tags
|
||||
/// </summary>
|
||||
public override string HeaderName => _headername;
|
||||
|
||||
/// <summary>
|
||||
/// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.
|
||||
/// </summary>
|
||||
public override string WebName => _webname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the human-readable description of the current encoding.
|
||||
/// </summary>
|
||||
public override string EncodingName => _encodingname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Windows operating system code page that most closely corresponds to the current encoding.
|
||||
/// </summary>
|
||||
public override int WindowsCodePage => _windowsCodepage;
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string" />.
|
||||
/// </summary>
|
||||
/// <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) =>
|
||||
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) => 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) => 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) => 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() => 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 override string GetString(byte[] bytes) => 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) =>
|
||||
new string(GetChars(bytes, index, count));
|
||||
|
||||
/// <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) => 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
617
Claunia.Encoding/Apple2c.cs
Normal file
617
Claunia.Encoding/Apple2c.cs
Normal file
@@ -0,0 +1,617 @@
|
||||
//
|
||||
// Apple IIc.cs
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright © 2016-2019 Natalia Portillo
|
||||
//
|
||||
// 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>
|
||||
/// 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>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for displaying content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserDisplay => browserDisplay;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for saving content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserSave => 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 => 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 => mailNewsSave;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding is read-only.
|
||||
/// </summary>
|
||||
/// <value>The is single byte.</value>
|
||||
public override bool IsReadOnly => readOnly;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding uses single-byte code points.
|
||||
/// </summary>
|
||||
public override bool IsSingleByte => singleByte;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the code page identifier of the current Encoding.
|
||||
/// </summary>
|
||||
public override int CodePage => _codepage;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent body tags
|
||||
/// </summary>
|
||||
public override string BodyName => _bodyname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent header tags
|
||||
/// </summary>
|
||||
public override string HeaderName => _headername;
|
||||
|
||||
/// <summary>
|
||||
/// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.
|
||||
/// </summary>
|
||||
public override string WebName => _webname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the human-readable description of the current encoding.
|
||||
/// </summary>
|
||||
public override string EncodingName => _encodingname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Windows operating system code page that most closely corresponds to the current encoding.
|
||||
/// </summary>
|
||||
public override int WindowsCodePage => _windowsCodepage;
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string" />.
|
||||
/// </summary>
|
||||
/// <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) =>
|
||||
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) => 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) => 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) => 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() => 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 override string GetString(byte[] bytes) => 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) =>
|
||||
new string(GetChars(bytes, index, count));
|
||||
|
||||
/// <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) => 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
603
Claunia.Encoding/Apple2e.cs
Normal file
603
Claunia.Encoding/Apple2e.cs
Normal file
@@ -0,0 +1,603 @@
|
||||
//
|
||||
// Apple IIe.cs
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright © 2016-2019 Natalia Portillo
|
||||
//
|
||||
// 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>
|
||||
/// 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>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for displaying content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserDisplay => browserDisplay;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for saving content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserSave => 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 => 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 => mailNewsSave;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding is read-only.
|
||||
/// </summary>
|
||||
/// <value>The is single byte.</value>
|
||||
public override bool IsReadOnly => readOnly;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding uses single-byte code points.
|
||||
/// </summary>
|
||||
public override bool IsSingleByte => singleByte;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the code page identifier of the current Encoding.
|
||||
/// </summary>
|
||||
public override int CodePage => _codepage;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent body tags
|
||||
/// </summary>
|
||||
public override string BodyName => _bodyname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent header tags
|
||||
/// </summary>
|
||||
public override string HeaderName => _headername;
|
||||
|
||||
/// <summary>
|
||||
/// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.
|
||||
/// </summary>
|
||||
public override string WebName => _webname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the human-readable description of the current encoding.
|
||||
/// </summary>
|
||||
public override string EncodingName => _encodingname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Windows operating system code page that most closely corresponds to the current encoding.
|
||||
/// </summary>
|
||||
public override int WindowsCodePage => _windowsCodepage;
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string" />.
|
||||
/// </summary>
|
||||
/// <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) =>
|
||||
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) => 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) => 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) => 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() => 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 override string GetString(byte[] bytes) => 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) =>
|
||||
new string(GetChars(bytes, index, count));
|
||||
|
||||
/// <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) => 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
584
Claunia.Encoding/Apple2gs.cs
Normal file
584
Claunia.Encoding/Apple2gs.cs
Normal file
@@ -0,0 +1,584 @@
|
||||
//
|
||||
// Apple IIgs.cs
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright © 2016-2019 Natalia Portillo
|
||||
//
|
||||
// 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>
|
||||
/// 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>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for displaying content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserDisplay => browserDisplay;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for saving content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserSave => 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 => 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 => mailNewsSave;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding is read-only.
|
||||
/// </summary>
|
||||
/// <value>The is single byte.</value>
|
||||
public override bool IsReadOnly => readOnly;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding uses single-byte code points.
|
||||
/// </summary>
|
||||
public override bool IsSingleByte => singleByte;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the code page identifier of the current Encoding.
|
||||
/// </summary>
|
||||
public override int CodePage => _codepage;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent body tags
|
||||
/// </summary>
|
||||
public override string BodyName => _bodyname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent header tags
|
||||
/// </summary>
|
||||
public override string HeaderName => _headername;
|
||||
|
||||
/// <summary>
|
||||
/// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.
|
||||
/// </summary>
|
||||
public override string WebName => _webname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the human-readable description of the current encoding.
|
||||
/// </summary>
|
||||
public override string EncodingName => _encodingname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Windows operating system code page that most closely corresponds to the current encoding.
|
||||
/// </summary>
|
||||
public override int WindowsCodePage => _windowsCodepage;
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string" />.
|
||||
/// </summary>
|
||||
/// <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) =>
|
||||
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) => 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) => 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) => 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() => 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 override string GetString(byte[] bytes) => 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) =>
|
||||
new string(GetChars(bytes, index, count));
|
||||
|
||||
/// <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) => 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,60 +1,51 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\packages\NuGet.Build.Packaging.0.1.248\build\NuGet.Build.Packaging.props" Condition="Exists('..\packages\NuGet.Build.Packaging.0.1.248\build\NuGet.Build.Packaging.props')" />
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{85DA90BC-9F49-4579-B4D1-4FF2D5925D7F}</ProjectGuid>
|
||||
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<UseMSBuildEngine>true</UseMSBuildEngine>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>Claunia.Encoding</RootNamespace>
|
||||
<AssemblyName>Claunia.Encoding</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile>Profile78</TargetFrameworkProfile>
|
||||
<PackOnBuild>true</PackOnBuild>
|
||||
<PackageId>Claunia.Encoding</PackageId>
|
||||
<PackageVersion>1.0</PackageVersion>
|
||||
<PackageVersion>1.7</PackageVersion>
|
||||
<Authors>Natalia Portillo</Authors>
|
||||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
|
||||
<Owners>Natalia Portillo</Owners>
|
||||
<PackageProjectUrl>https://github.com/claunia/Claunia.Encoding</PackageProjectUrl>
|
||||
<Summary>Library to provide codepage conversion to and from archaic and old computer systems and Unicode.</Summary>
|
||||
<Title>Claunia.Encoding</Title>
|
||||
<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>
|
||||
<ReleaseVersion>1.7</ReleaseVersion>
|
||||
<PackageReleaseNotes>Support .NET Core and .NET Framework 4.0.</PackageReleaseNotes>
|
||||
<TargetFrameworks>net40;netstandard2.0</TargetFrameworks>
|
||||
<VersionPrefix>1.7</VersionPrefix>
|
||||
<Company>Claunia.com</Company>
|
||||
<Copyright>© 2016-2019 Natalia Portillo</Copyright>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<PackageProjectUrl>https://www.github.com/claunia/Claunia.Encoding</PackageProjectUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<NeutralLanguage>en-US</NeutralLanguage>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<PublishRepositoryUrl>true</PublishRepositoryUrl>
|
||||
<EmbedUntrackedSources>true</EmbedUntrackedSources>
|
||||
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DocumentationFile>bin\Debug\Claunia.Encoding.xml</DocumentationFile>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
<DefineConstants>TRACE;RELEASE</DefineConstants>
|
||||
<DocumentationFile>bin\Release\Claunia.Encoding.xml</DocumentationFile>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="PETSCII.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="LisaRoman.cs" />
|
||||
<Compile Include="Encoding.cs" />
|
||||
<Compile Include="Pangrams.cs" />
|
||||
<Compile Include="ATASCII.cs" />
|
||||
<Compile Include="AtariST.cs" />
|
||||
<Compile Include="ZX80.cs" />
|
||||
<Compile Include="ZX81.cs" />
|
||||
<Compile Include="ZXSpectrum.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<DefineConstants>TRACE;DEBUG</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="$(TargetFramework.StartsWith('netcoreapp')) Or $(TargetFramework.StartsWith('netstandard'))">
|
||||
<DefineConstants>$(DefineConstants);NETCORE</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="..\LICENSE.MIT">
|
||||
<Link>LICENSE.MIT</Link>
|
||||
@@ -65,25 +56,4 @@
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
|
||||
<ProjectExtensions>
|
||||
<MonoDevelop>
|
||||
<Properties>
|
||||
<Policies>
|
||||
<TextStylePolicy FileWidth="120" TabWidth="4" IndentWidth="4" RemoveTrailingWhitespace="True" NoTabsAfterNonTabs="False" EolMarker="Native" TabsToSpaces="True" scope="text/x-csharp">
|
||||
<inheritsSet />
|
||||
<inheritsScope />
|
||||
</TextStylePolicy>
|
||||
<CSharpFormattingPolicy IndentBlock="True" IndentBraces="False" IndentSwitchSection="True" IndentSwitchCaseSection="True" LabelPositioning="OneLess" NewLinesForBracesInTypes="True" NewLinesForBracesInMethods="True" NewLineForMembersInObjectInit="False" NewLineForMembersInAnonymousTypes="False" NewLineForClausesInQuery="False" SpacingAfterMethodDeclarationName="False" SpaceWithinMethodDeclarationParenthesis="False" SpaceBetweenEmptyMethodDeclarationParentheses="False" SpaceAfterMethodCallName="False" SpaceWithinMethodCallParentheses="False" SpaceBetweenEmptyMethodCallParentheses="False" SpaceAfterControlFlowStatementKeyword="False" SpaceWithinExpressionParentheses="False" SpaceWithinCastParentheses="False" SpaceWithinOtherParentheses="False" SpaceAfterCast="False" SpacesIgnoreAroundVariableDeclaration="False" SpaceBeforeOpenSquareBracket="False" SpaceBetweenEmptySquareBrackets="False" SpaceWithinSquareBrackets="False" SpaceAfterColonInBaseTypeDeclaration="True" SpaceAfterComma="True" SpaceAfterDot="False" SpaceAfterSemicolonsInForStatement="True" SpaceBeforeColonInBaseTypeDeclaration="True" SpaceBeforeComma="False" SpaceBeforeDot="False" SpaceBeforeSemicolonsInForStatement="False" SpacingAroundBinaryOperator="Single" WrappingPreserveSingleLine="True" WrappingKeepStatementsOnSingleLine="True" PlaceSystemDirectiveFirst="True" NewLinesForBracesInProperties="False" NewLinesForBracesInAccessors="False" NewLinesForBracesInAnonymousMethods="False" NewLinesForBracesInControlBlocks="False" NewLinesForBracesInAnonymousTypes="False" NewLinesForBracesInObjectCollectionArrayInitializers="False" NewLinesForBracesInLambdaExpressionBody="False" NewLineForElse="False" NewLineForCatch="False" NewLineForFinally="False" scope="text/x-csharp">
|
||||
<inheritsSet />
|
||||
<inheritsScope />
|
||||
</CSharpFormattingPolicy>
|
||||
</Policies>
|
||||
</Properties>
|
||||
</MonoDevelop>
|
||||
</ProjectExtensions>
|
||||
<Import Project="..\packages\NuGet.Build.Packaging.0.1.248\build\NuGet.Build.Packaging.targets" Condition="Exists('..\packages\NuGet.Build.Packaging.0.1.248\build\NuGet.Build.Packaging.targets')" />
|
||||
</Project>
|
||||
@@ -4,7 +4,7 @@
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright (c) 2016 © Claunia.com
|
||||
// Copyright © 2016-2019 Natalia Portillo
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -24,29 +24,137 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Claunia.Encoding
|
||||
{
|
||||
/// <summary>
|
||||
/// This class contains static instances of the supported encodings.
|
||||
/// This class contains static instances of the supported encodings.
|
||||
/// </summary>
|
||||
public static class Encoding
|
||||
public abstract class Encoding : System.Text.Encoding
|
||||
{
|
||||
/// <summary>
|
||||
/// Static instance for the LisaRoman encoding
|
||||
/// Static instance for the LisaRoman encoding
|
||||
/// </summary>
|
||||
public static System.Text.Encoding LisaEncoding = new LisaRoman();
|
||||
/// <summary>
|
||||
/// Static instance for the ATASCII encoding
|
||||
/// Static instance for the ATASCII encoding
|
||||
/// </summary>
|
||||
public static System.Text.Encoding AtariEncoding = new ATASCII();
|
||||
/// <summary>
|
||||
/// Static instance for the Atari ST encoding
|
||||
/// Static instance for the Atari ST encoding
|
||||
/// </summary>
|
||||
public static System.Text.Encoding AtariSTEncoding = new AtariST();
|
||||
/// <summary>
|
||||
/// Static instance for the PETSCII encoding
|
||||
/// Static instance for the PETSCII encoding
|
||||
/// </summary>
|
||||
public static System.Text.Encoding PETEncoding = new PETSCII();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Static instance for the DEC Radix-50 encoding
|
||||
/// </summary>
|
||||
public static System.Text.Encoding Radix50Encoding = new Radix50();
|
||||
/// <summary>
|
||||
/// Static instance for the GEM encoding
|
||||
/// </summary>
|
||||
public static System.Text.Encoding GemEncoding = new Gem();
|
||||
/// <summary>
|
||||
/// Static instance for the GEM encoding
|
||||
/// </summary>
|
||||
public static System.Text.Encoding GeosEncoding = new Geos();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for displaying content.
|
||||
/// </summary>
|
||||
public abstract override bool IsBrowserDisplay { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for saving content.
|
||||
/// </summary>
|
||||
public abstract override bool IsBrowserSave { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content.
|
||||
/// </summary>
|
||||
public abstract override bool IsMailNewsDisplay { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content.
|
||||
/// </summary>
|
||||
public abstract override bool IsMailNewsSave { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding is read-only.
|
||||
/// </summary>
|
||||
/// <value>The is single byte.</value>
|
||||
public new abstract bool IsReadOnly { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding uses single-byte code points.
|
||||
/// </summary>
|
||||
public abstract override bool IsSingleByte { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the code page identifier of the current Encoding.
|
||||
/// </summary>
|
||||
public abstract override int CodePage { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent body tags
|
||||
/// </summary>
|
||||
public abstract override string BodyName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent header tags
|
||||
/// </summary>
|
||||
public abstract override string HeaderName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.
|
||||
/// </summary>
|
||||
public abstract override string WebName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the human-readable description of the current encoding.
|
||||
/// </summary>
|
||||
public abstract override string EncodingName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Windows operating system code page that most closely corresponds to the current encoding.
|
||||
/// </summary>
|
||||
public abstract override int WindowsCodePage { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns an array that contains all encodings.
|
||||
/// </summary>
|
||||
/// <returns>An array that contains all encodings.</returns>
|
||||
public new static IEnumerable<EncodingInfo> GetEncodings() =>
|
||||
(from type in Assembly.GetExecutingAssembly().GetTypes()
|
||||
where type.IsSubclassOf(typeof(Encoding))
|
||||
let encoding = (Encoding)type.GetConstructor(new Type[] { }).Invoke(new object[] { })
|
||||
select new EncodingInfo(encoding.CodePage, encoding.BodyName, encoding.EncodingName, false, type))
|
||||
.ToArray();
|
||||
|
||||
/// <summary>
|
||||
/// Returns the encoding associated with the specified code page name.
|
||||
/// </summary>
|
||||
/// <returns>The encoding associated with the specified code page.</returns>
|
||||
/// <param name="name">
|
||||
/// The code page name of the preferred encoding. Any value returned by the WebName property is valid.
|
||||
/// Possible values are listed in the Name column of the table that appears in the Encoding class topic.
|
||||
/// </param>
|
||||
public new static System.Text.Encoding GetEncoding(string name)
|
||||
{
|
||||
foreach(Type type in Assembly.GetExecutingAssembly().GetTypes())
|
||||
if(type.IsSubclassOf(typeof(Encoding)))
|
||||
{
|
||||
Encoding encoding = (Encoding)type.GetConstructor(new Type[] { }).Invoke(new object[] { });
|
||||
if(encoding.BodyName == name.ToLowerInvariant()) return encoding;
|
||||
}
|
||||
|
||||
return System.Text.Encoding.GetEncoding(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
70
Claunia.Encoding/EncodingInfo.cs
Normal file
70
Claunia.Encoding/EncodingInfo.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
|
||||
namespace Claunia.Encoding
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides basic information about an encoding.
|
||||
/// </summary>
|
||||
public sealed class EncodingInfo
|
||||
{
|
||||
bool isSystem;
|
||||
readonly Type thisType;
|
||||
|
||||
internal EncodingInfo(int codePage, string name, string displayName, bool system = true,
|
||||
Type internalType = null)
|
||||
{
|
||||
CodePage = codePage;
|
||||
Name = name;
|
||||
DisplayName = displayName;
|
||||
isSystem = system;
|
||||
thisType = internalType;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the code page identifier of the encoding.
|
||||
/// </summary>
|
||||
/// <value>The code page identifier of the encoding.</value>
|
||||
public int CodePage { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name registered with the Internet Assigned Numbers Authority (IANA) for the encoding.
|
||||
/// </summary>
|
||||
/// <value>The IANA name for the encoding. For more information about the IANA, see www.iana.org.</value>
|
||||
public string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the human-readable description of the encoding.
|
||||
/// </summary>
|
||||
/// <value>The human-readable description of the encoding.</value>
|
||||
public string DisplayName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns a Encoding object that corresponds to the current EncodingInfo object.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A <see cref="T:Claunia.Encoding.Encoding" /> object that corresponds to the current
|
||||
/// <see cref="T:Claunia.Encoding.EncodingInfo" /> object.
|
||||
/// </returns>
|
||||
public Encoding GetEncoding() => (Encoding)thisType.GetConstructor(new Type[] { }).Invoke(new object[] { });
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the specified object is equal to the current EncodingInfo object.
|
||||
/// </summary>
|
||||
/// <param name="value">An object to compare to the current <see cref="T:Claunia.Encoding.EncodingInfo" /> object.</param>
|
||||
/// <returns>
|
||||
/// <c>true</c> if value is a <see cref="T:Claunia.Encoding.EncodingInfo" /> and is equal to the current
|
||||
/// <see cref="T:Claunia.Encoding.EncodingInfo" />; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public override bool Equals(object value) => value is EncodingInfo that && CodePage == that.CodePage;
|
||||
|
||||
/// <summary>
|
||||
/// Returns the hash code for the current EncodingInfo object.
|
||||
/// </summary>
|
||||
/// <returns>A 32-bit signed integer hash code.</returns>
|
||||
public override int GetHashCode() => CodePage;
|
||||
}
|
||||
}
|
||||
724
Claunia.Encoding/Gem.cs
Normal file
724
Claunia.Encoding/Gem.cs
Normal file
@@ -0,0 +1,724 @@
|
||||
//
|
||||
// Gem.cs
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright © 2016-2019 Natalia Portillo
|
||||
//
|
||||
// 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 a GEM character encoding of Unicode characters.
|
||||
/// </summary>
|
||||
public class Gem : Encoding
|
||||
{
|
||||
const string _bodyname = "gem";
|
||||
const int _codepage = 0;
|
||||
const string _encodingname = "Western European (GEM)";
|
||||
const string _headername = "gem";
|
||||
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>
|
||||
/// The GEM to Unicode character map.
|
||||
/// Pending: 0x09 => 0x0001F552, 0x0A => 0x0001F514
|
||||
/// </summary>
|
||||
static readonly char[] GemTable =
|
||||
{
|
||||
// 0x00
|
||||
'\u0000', '\u21E7', '\u21E9', '\u21E8', '\u21E6', '\u25FC', '\uFFFD', '\u25C6',
|
||||
// 0x08
|
||||
'\u2713', '\uFFFD', '\uFFFD', '\u266A', '\u25B4', '\u25BE', '\u25B8', '\u25C2',
|
||||
// 0x10
|
||||
'\u25BA', '\u25C4', '\u29D3', '\u2582', '\u00B6', '\u00A7', '\u2195', '\u21A8',
|
||||
// 0x18
|
||||
'\u2191', '\u2193', '\u2192', '\u2190', '\u221F', '\u2194', '\u25B2', '\u25BC',
|
||||
// 0x20
|
||||
'\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027',
|
||||
// 0x28
|
||||
'\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F',
|
||||
// 0x30
|
||||
'\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037',
|
||||
// 0x38
|
||||
'\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F',
|
||||
// 0x40
|
||||
'\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047',
|
||||
// 0x48
|
||||
'\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F',
|
||||
// 0x50
|
||||
'\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057',
|
||||
// 0x58
|
||||
'\u0058', '\u0059', '\u005A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F',
|
||||
// 0x60
|
||||
'\u0060', '\u0061', '\u0062', '\u0063', '\u0064', '\u0065', '\u0066', '\u0067',
|
||||
// 0x68
|
||||
'\u0068', '\u0069', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F',
|
||||
// 0x70
|
||||
'\u0070', '\u0071', '\u0072', '\u0073', '\u0074', '\u0075', '\u0076', '\u0077',
|
||||
// 0x78
|
||||
'\u0078', '\u0079', '\u007A', '\u007B', '\u007C', '\u007D', '\u007E', '\u2302',
|
||||
// 0x80
|
||||
'\u00C7', '\u00FC', '\u00E9', '\u00E2', '\u00E4', '\u00E0', '\u00E5', '\u00E7',
|
||||
// 0x88
|
||||
'\u00EA', '\u00EB', '\u00E8', '\u00EF', '\u00EE', '\u00EC', '\u00C4', '\u00C5',
|
||||
// 0x90
|
||||
'\u00C9', '\u00E6', '\u00C6', '\u00F4', '\u00F6', '\u00F2', '\u00FB', '\u00F9',
|
||||
// 0x98
|
||||
'\u00FF', '\u00D6', '\u00DC', '\u00FB', '\u00A3', '\u00D8', '\u00A4', '\u0192',
|
||||
// 0xA0
|
||||
'\u00E1', '\u00ED', '\u00F3', '\u00FA', '\u00F1', '\u00D1', '\u00AA', '\u00BA',
|
||||
// 0xA8
|
||||
'\u00BF', '\u201C', '\u201D', '\u2039', '\u203A', '\u00A1', '\u00AB', '\u00BB',
|
||||
// 0xB0
|
||||
'\u00E3', '\u00F5', '\u00A5', '\u00A2', '\u0153', '\u0152', '\u00C0', '\u00C3',
|
||||
// 0xB8
|
||||
'\u00D5', '\u00A7', '\u2021', '\u2020', '\u00B6', '\u00A9', '\u00AE', '\u2122',
|
||||
// 0xC0
|
||||
'\u201E', '\u2026', '\u2030', '\u2022', '\u2013', '\u2014', '\u2070', '\u00C1',
|
||||
// 0xC8
|
||||
'\u00C2', '\u00C8', '\u00CA', '\u00CB', '\u00CC', '\u00CD', '\u00CE', '\u00CF',
|
||||
// 0xD0
|
||||
'\u00D2', '\u00D3', '\u00D4', '\u0160', '\u0161', '\u00D9', '\u00DA', '\u00DB',
|
||||
// 0xD8
|
||||
'\u0178', '\u00DF', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD',
|
||||
// 0xE0
|
||||
'\u03B1', '\u03B2', '\u0393', '\u03C0', '\u03A3', '\u03C3', '\u00B5', '\u03C4',
|
||||
// 0xE8
|
||||
'\u03A6', '\u0398', '\u03A9', '\u03B4', '\u222E', '\u0278', '\u2208', '\u2229',
|
||||
// 0xF0
|
||||
'\u2261', '\u00B1', '\u2265', '\u2264', '\u2320', '\u2321', '\u00F7', '\u2248',
|
||||
// 0xF8
|
||||
'\u00B0', '\u2219', '\u00B7', '\u221A', '\u207F', '\u00B2', '\u25A0', '\u2205'
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for displaying content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserDisplay => browserDisplay;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for saving content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserSave => 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 => 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 => mailNewsSave;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding is read-only.
|
||||
/// </summary>
|
||||
/// <value>The is single byte.</value>
|
||||
public override bool IsReadOnly => readOnly;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding uses single-byte code points.
|
||||
/// </summary>
|
||||
public override bool IsSingleByte => singleByte;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the code page identifier of the current Encoding.
|
||||
/// </summary>
|
||||
public override int CodePage => _codepage;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent body tags
|
||||
/// </summary>
|
||||
public override string BodyName => _bodyname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent header tags
|
||||
/// </summary>
|
||||
public override string HeaderName => _headername;
|
||||
|
||||
/// <summary>
|
||||
/// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.
|
||||
/// </summary>
|
||||
public override string WebName => _webname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the human-readable description of the current encoding.
|
||||
/// </summary>
|
||||
public override string EncodingName => _encodingname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Windows operating system code page that most closely corresponds to the current encoding.
|
||||
/// </summary>
|
||||
public override int WindowsCodePage => _windowsCodepage;
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string" />.
|
||||
/// </summary>
|
||||
/// <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) =>
|
||||
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) => 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) => 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) => 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() => 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 override string GetString(byte[] bytes) => 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) =>
|
||||
new string(GetChars(bytes, index, count));
|
||||
|
||||
/// <summary>
|
||||
/// Converts a GEM character to an Unicode character
|
||||
/// </summary>
|
||||
/// <returns>Unicode character.</returns>
|
||||
/// <param name="character">GEM character.</param>
|
||||
static char GetChar(byte character) => GemTable[character];
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Unicode character to an GEM character
|
||||
/// </summary>
|
||||
/// <returns>GEM character.</returns>
|
||||
/// <param name="character">Unicode character.</param>
|
||||
static byte GetByte(char character)
|
||||
{
|
||||
switch(character)
|
||||
{
|
||||
case '\u0000': return 0x00;
|
||||
case '\u21E7': return 0x01;
|
||||
case '\u21E9': return 0x02;
|
||||
case '\u21E8': return 0x03;
|
||||
case '\u21E6': return 0x04;
|
||||
case '\u25FC': return 0x05;
|
||||
case '\u25C6': return 0x07;
|
||||
case '\u2713': return 0x08;
|
||||
case '\u266A': return 0x0B;
|
||||
case '\u25B4': return 0x0C;
|
||||
case '\u25BE': return 0x0D;
|
||||
case '\u25B8': return 0x0E;
|
||||
case '\u25C2': return 0x0F;
|
||||
case '\u25BA': return 0x10;
|
||||
case '\u25C4': return 0x11;
|
||||
case '\u29D3': return 0x12;
|
||||
case '\u2582': return 0x13;
|
||||
case '\u2195': return 0x16;
|
||||
case '\u21A8': return 0x17;
|
||||
case '\u2191': return 0x18;
|
||||
case '\u2193': return 0x19;
|
||||
case '\u2192': return 0x1A;
|
||||
case '\u2190': return 0x1B;
|
||||
case '\u221F': return 0x1C;
|
||||
case '\u2194': return 0x1D;
|
||||
case '\u25B2': return 0x1E;
|
||||
case '\u25BC': return 0x1F;
|
||||
case '\u0020': return 0x20;
|
||||
case '\u0021': return 0x21;
|
||||
case '\u0022': return 0x22;
|
||||
case '\u0023': return 0x23;
|
||||
case '\u0024': return 0x24;
|
||||
case '\u0025': return 0x25;
|
||||
case '\u0026': return 0x26;
|
||||
case '\u0027': return 0x27;
|
||||
case '\u0028': return 0x28;
|
||||
case '\u0029': return 0x29;
|
||||
case '\u002A': return 0x2A;
|
||||
case '\u002B': return 0x2B;
|
||||
case '\u002C': return 0x2C;
|
||||
case '\u002D': return 0x2D;
|
||||
case '\u002E': return 0x2E;
|
||||
case '\u002F': return 0x2F;
|
||||
case '\u0030': return 0x30;
|
||||
case '\u0031': return 0x31;
|
||||
case '\u0032': return 0x32;
|
||||
case '\u0033': return 0x33;
|
||||
case '\u0034': return 0x34;
|
||||
case '\u0035': return 0x35;
|
||||
case '\u0036': return 0x36;
|
||||
case '\u0037': return 0x37;
|
||||
case '\u0038': return 0x38;
|
||||
case '\u0039': return 0x39;
|
||||
case '\u003A': return 0x3A;
|
||||
case '\u003B': return 0x3B;
|
||||
case '\u003C': return 0x3C;
|
||||
case '\u003D': return 0x3D;
|
||||
case '\u003E': return 0x3E;
|
||||
case '\u003F': return 0x3F;
|
||||
case '\u0040': return 0x40;
|
||||
case '\u0041': return 0x41;
|
||||
case '\u0042': return 0x42;
|
||||
case '\u0043': return 0x43;
|
||||
case '\u0044': return 0x44;
|
||||
case '\u0045': return 0x45;
|
||||
case '\u0046': return 0x46;
|
||||
case '\u0047': return 0x47;
|
||||
case '\u0048': return 0x48;
|
||||
case '\u0049': return 0x49;
|
||||
case '\u004A': return 0x4A;
|
||||
case '\u004B': return 0x4B;
|
||||
case '\u004C': return 0x4C;
|
||||
case '\u004D': return 0x4D;
|
||||
case '\u004E': return 0x4E;
|
||||
case '\u004F': return 0x4F;
|
||||
case '\u0050': return 0x50;
|
||||
case '\u0051': return 0x51;
|
||||
case '\u0052': return 0x52;
|
||||
case '\u0053': return 0x53;
|
||||
case '\u0054': return 0x54;
|
||||
case '\u0055': return 0x55;
|
||||
case '\u0056': return 0x56;
|
||||
case '\u0057': return 0x57;
|
||||
case '\u0058': return 0x58;
|
||||
case '\u0059': return 0x59;
|
||||
case '\u005A': return 0x5A;
|
||||
case '\u005B': return 0x5B;
|
||||
case '\u005C': return 0x5C;
|
||||
case '\u005D': return 0x5D;
|
||||
case '\u005E': return 0x5E;
|
||||
case '\u005F': return 0x5F;
|
||||
case '\u0060': return 0x60;
|
||||
case '\u0061': return 0x61;
|
||||
case '\u0062': return 0x62;
|
||||
case '\u0063': return 0x63;
|
||||
case '\u0064': return 0x64;
|
||||
case '\u0065': return 0x65;
|
||||
case '\u0066': return 0x66;
|
||||
case '\u0067': return 0x67;
|
||||
case '\u0068': return 0x68;
|
||||
case '\u0069': return 0x69;
|
||||
case '\u006A': return 0x6A;
|
||||
case '\u006B': return 0x6B;
|
||||
case '\u006C': return 0x6C;
|
||||
case '\u006D': return 0x6D;
|
||||
case '\u006E': return 0x6E;
|
||||
case '\u006F': return 0x6F;
|
||||
case '\u0070': return 0x70;
|
||||
case '\u0071': return 0x71;
|
||||
case '\u0072': return 0x72;
|
||||
case '\u0073': return 0x73;
|
||||
case '\u0074': return 0x74;
|
||||
case '\u0075': return 0x75;
|
||||
case '\u0076': return 0x76;
|
||||
case '\u0077': return 0x77;
|
||||
case '\u0078': return 0x78;
|
||||
case '\u0079': return 0x79;
|
||||
case '\u007A': return 0x7A;
|
||||
case '\u007B': return 0x7B;
|
||||
case '\u007C': return 0x7C;
|
||||
case '\u007D': return 0x7D;
|
||||
case '\u007E': return 0x7E;
|
||||
case '\u2302': return 0x7F;
|
||||
case '\u00C7': return 0x80;
|
||||
case '\u00FC': return 0x81;
|
||||
case '\u00E9': return 0x82;
|
||||
case '\u00E2': return 0x83;
|
||||
case '\u00E4': return 0x84;
|
||||
case '\u00E0': return 0x85;
|
||||
case '\u00E5': return 0x86;
|
||||
case '\u00E7': return 0x87;
|
||||
case '\u00EA': return 0x88;
|
||||
case '\u00EB': return 0x89;
|
||||
case '\u00E8': return 0x8A;
|
||||
case '\u00EF': return 0x8B;
|
||||
case '\u00EE': return 0x8C;
|
||||
case '\u00EC': return 0x8D;
|
||||
case '\u00C4': return 0x8E;
|
||||
case '\u00C5': return 0x8F;
|
||||
case '\u00C9': return 0x90;
|
||||
case '\u00E6': return 0x91;
|
||||
case '\u00C6': return 0x92;
|
||||
case '\u00F4': return 0x93;
|
||||
case '\u00F6': return 0x94;
|
||||
case '\u00F2': return 0x95;
|
||||
case '\u00FB': return 0x96;
|
||||
case '\u00F9': return 0x97;
|
||||
case '\u00FF': return 0x98;
|
||||
case '\u00D6': return 0x99;
|
||||
case '\u00DC': return 0x9A;
|
||||
case '\u00F8': return 0x9B;
|
||||
case '\u00A3': return 0x9C;
|
||||
case '\u00D8': return 0x9D;
|
||||
case '\u00A4': return 0x9E;
|
||||
case '\u0192': return 0x9F;
|
||||
case '\u00E1': return 0xA0;
|
||||
case '\u00ED': return 0xA1;
|
||||
case '\u00F3': return 0xA2;
|
||||
case '\u00FA': return 0xA3;
|
||||
case '\u00F1': return 0xA4;
|
||||
case '\u00D1': return 0xA5;
|
||||
case '\u00AA': return 0xA6;
|
||||
case '\u00BA': return 0xA7;
|
||||
case '\u00BF': return 0xA8;
|
||||
case '\u201C': return 0xA9;
|
||||
case '\u201D': return 0xAA;
|
||||
case '\u2039': return 0xAB;
|
||||
case '\u203A': return 0xAC;
|
||||
case '\u00A1': return 0xAD;
|
||||
case '\u00AB': return 0xAE;
|
||||
case '\u00BB': return 0xAF;
|
||||
case '\u00E3': return 0xB0;
|
||||
case '\u00F5': return 0xB1;
|
||||
case '\u00A5': return 0xB2;
|
||||
case '\u00A2': return 0xB3;
|
||||
case '\u0153': return 0xB4;
|
||||
case '\u0152': return 0xB5;
|
||||
case '\u00C0': return 0xB6;
|
||||
case '\u00C3': return 0xB7;
|
||||
case '\u00D5': return 0xB8;
|
||||
case '\u00A7': return 0xB9;
|
||||
case '\u2821': return 0xBA;
|
||||
case '\u2020': return 0xBB;
|
||||
case '\u00B6': return 0xBC;
|
||||
case '\u00A9': return 0xBD;
|
||||
case '\u00AE': return 0xBE;
|
||||
case '\u2122': return 0xBF;
|
||||
case '\u201E': return 0xC0;
|
||||
case '\u2026': return 0xC1;
|
||||
case '\u2030': return 0xC2;
|
||||
case '\u2022': return 0xC3;
|
||||
case '\u2013': return 0xC4;
|
||||
case '\u2014': return 0xC5;
|
||||
case '\u2070': return 0xC6;
|
||||
case '\u00C1': return 0xC7;
|
||||
case '\u00C2': return 0xC8;
|
||||
case '\u00C8': return 0xC9;
|
||||
case '\u00CA': return 0xCA;
|
||||
case '\u00CB': return 0xCB;
|
||||
case '\u00CC': return 0xCC;
|
||||
case '\u00CD': return 0xCD;
|
||||
case '\u00CE': return 0xCE;
|
||||
case '\u00CF': return 0xCF;
|
||||
case '\u00D2': return 0xD0;
|
||||
case '\u00D3': return 0xD1;
|
||||
case '\u00D4': return 0xD2;
|
||||
case '\u0160': return 0xD3;
|
||||
case '\u0161': return 0xD4;
|
||||
case '\u00D9': return 0xD5;
|
||||
case '\u00DA': return 0xD6;
|
||||
case '\u00DB': return 0xD7;
|
||||
case '\u0178': return 0xD8;
|
||||
case '\u00DF': return 0xD9;
|
||||
case '\u03B1': return 0xE0;
|
||||
case '\u03B2': return 0xE1;
|
||||
case '\u0393': return 0xE2;
|
||||
case '\u03C0': return 0xE3;
|
||||
case '\u03A3': return 0xE4;
|
||||
case '\u03C3': return 0xE5;
|
||||
case '\u00B5': return 0xE6;
|
||||
case '\u03C4': return 0xE7;
|
||||
case '\u03A6': return 0xE8;
|
||||
case '\u0398': return 0xE9;
|
||||
case '\u03A9': return 0xEA;
|
||||
case '\u03B4': return 0xEB;
|
||||
case '\u222E': return 0xEC;
|
||||
case '\u0278': return 0xED;
|
||||
case '\u2208': return 0xEE;
|
||||
case '\u2229': return 0xEF;
|
||||
case '\u2261': return 0xF0;
|
||||
case '\u00B1': return 0xF1;
|
||||
case '\u2265': return 0xF2;
|
||||
case '\u2264': return 0xF3;
|
||||
case '\u2320': return 0xF4;
|
||||
case '\u2321': return 0xF5;
|
||||
case '\u00F7': return 0xF6;
|
||||
case '\u2248': return 0xF7;
|
||||
case '\u00B0': return 0xF8;
|
||||
case '\u2219': return 0xF9;
|
||||
case '\u00B7': return 0xFA;
|
||||
case '\u221A': return 0xFB;
|
||||
case '\u207F': return 0xFC;
|
||||
case '\u00B2': return 0xFD;
|
||||
case '\u25A0': return 0xFE;
|
||||
case '\u2205': return 0xFF;
|
||||
default:
|
||||
// Fallback to '?'
|
||||
return 0x3F;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
720
Claunia.Encoding/Geos.cs
Normal file
720
Claunia.Encoding/Geos.cs
Normal file
@@ -0,0 +1,720 @@
|
||||
//
|
||||
// Geos.cs
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright © 2016-2019 Natalia Portillo
|
||||
//
|
||||
// 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 GEOS character encoding of Unicode characters.
|
||||
/// </summary>
|
||||
public class Geos : Encoding
|
||||
{
|
||||
const string _bodyname = "geos";
|
||||
const int _codepage = 0;
|
||||
const string _encodingname = "Western European (GEOS)";
|
||||
const string _headername = "geos";
|
||||
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>
|
||||
/// The GEOS to Unicode character map.
|
||||
/// In the GEOS character map application lots of positions appears as '\u002E' ('.' period) in normal (non-symbol)
|
||||
/// fonts.
|
||||
/// </summary>
|
||||
static readonly char[] GeosTable =
|
||||
{
|
||||
// 0x00
|
||||
'\u0000', '\u0001', '\u0002', '\u0003', '\u0004', '\u0005', '\u0006', '\u0007',
|
||||
// 0x08
|
||||
'\u0008', '\u0009', '\u000A', '\u000B', '\u000C', '\u000D', '\u000E', '\u000F',
|
||||
// 0x10
|
||||
'\u0010', '\u0011', '\u0012', '\u0013', '\u0014', '\u0015', '\u0016', '\u0017',
|
||||
// 0x18
|
||||
'\u0018', '\u0019', '\u001A', '\u001B', '\u001C', '\u001D', '\u001E', '\u001F',
|
||||
// 0x20
|
||||
'\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027',
|
||||
// 0x28
|
||||
'\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F',
|
||||
// 0x30
|
||||
'\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037',
|
||||
// 0x38
|
||||
'\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F',
|
||||
// 0x40
|
||||
'\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047',
|
||||
// 0x48
|
||||
'\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F',
|
||||
// 0x50
|
||||
'\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057',
|
||||
// 0x58
|
||||
'\u0058', '\u0059', '\u005A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F',
|
||||
// 0x60
|
||||
'\u0060', '\u0061', '\u0062', '\u0063', '\u0064', '\u0065', '\u0066', '\u0067',
|
||||
// 0x68
|
||||
'\u0068', '\u0069', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F',
|
||||
// 0x70
|
||||
'\u0070', '\u0071', '\u0072', '\u0073', '\u0074', '\u0075', '\u0076', '\u0077',
|
||||
// 0x78
|
||||
'\u0078', '\u0079', '\u007A', '\u007B', '\u007C', '\u007D', '\u007E', '\u007F',
|
||||
// 0x80
|
||||
'\u00C4', '\u00C5', '\u00C7', '\u00C9', '\u00D1', '\u00D6', '\u00DC', '\u00E1',
|
||||
// 0x88
|
||||
'\u00E0', '\u00E2', '\u00E4', '\u00E3', '\u00E5', '\u00E7', '\u00E9', '\u00E8',
|
||||
// 0x90
|
||||
'\u00EA', '\u00EB', '\u00ED', '\u00EC', '\u00EE', '\u00EF', '\u00F1', '\u00F3',
|
||||
// 0x98
|
||||
'\u00F2', '\u00F4', '\u00F5', '\u00FA', '\u00F9', '\u00FB', '\u00FC', '\u2020',
|
||||
// 0xA0
|
||||
'\u00B0', '\u00A2', '\u00A3', '\u00A7', '\u00B7', '\u00B6', '\u00DF', '\u00AE',
|
||||
// 0xA8
|
||||
'\u00A9', '\u2122', '\u0022', '\u0027', '\u002E', '\u00C6', '\u00D8', '\u221E',
|
||||
// 0xB0
|
||||
'\u00B1', '\u2264', '\u2265', '\u00A5', '\u00B5', '\u002E', '\u002E', '\u002E',
|
||||
// 0xB8
|
||||
'\u03C0', '\u002E', '\u00AA', '\u00BA', '\u03A9', '\u00E6', '\u00F8', '\u00BF',
|
||||
// 0xC0
|
||||
'\u00A1', '\u00AC', '\u221A', '\u0192', '\u2248', '\u002E', '\u00AB', '\u00BB',
|
||||
// 0xC8
|
||||
'\u2026', '\u00A0', '\u00C0', '\u00C3', '\u00D5', '\u0152', '\u0153', '\u2013',
|
||||
// 0xD0
|
||||
'\u2014', '\u201C', '\u201D', '\u2018', '\u2019', '\u00F7', '\u002E', '\u00FF',
|
||||
// 0xD8
|
||||
'\u0178', '\u002E', '\u00A4', '\u2039', '\u203A', '\u00FD', '\u00DD', '\u2021',
|
||||
// 0xE0
|
||||
'\u002E', '\u201A', '\u201E', '\u2030', '\u00C2', '\u00CA', '\u00C1', '\u00CB',
|
||||
// 0xE8
|
||||
'\u00C8', '\u00CD', '\u00CE', '\u00CF', '\u00CC', '\u00D3', '\u00D4', '\u002E',
|
||||
// 0xF0
|
||||
'\u00D2', '\u00DA', '\u00D9', '\u00B9', '\u20C6', '\u20DC', '\u00AF', '\u02C7',
|
||||
// 0xF8
|
||||
'\u00B7', '\u00B0', '\u00B8', '\u2032', '\u02DB', '\u02D8', '\u00A0', '\u002E'
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for displaying content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserDisplay => browserDisplay;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for saving content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserSave => 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 => 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 => mailNewsSave;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding is read-only.
|
||||
/// </summary>
|
||||
/// <value>The is single byte.</value>
|
||||
public override bool IsReadOnly => readOnly;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding uses single-byte code points.
|
||||
/// </summary>
|
||||
public override bool IsSingleByte => singleByte;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the code page identifier of the current Encoding.
|
||||
/// </summary>
|
||||
public override int CodePage => _codepage;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent body tags
|
||||
/// </summary>
|
||||
public override string BodyName => _bodyname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent header tags
|
||||
/// </summary>
|
||||
public override string HeaderName => _headername;
|
||||
|
||||
/// <summary>
|
||||
/// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.
|
||||
/// </summary>
|
||||
public override string WebName => _webname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the human-readable description of the current encoding.
|
||||
/// </summary>
|
||||
public override string EncodingName => _encodingname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Windows operating system code page that most closely corresponds to the current encoding.
|
||||
/// </summary>
|
||||
public override int WindowsCodePage => _windowsCodepage;
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string" />.
|
||||
/// </summary>
|
||||
/// <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) =>
|
||||
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) => 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) => 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) => 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() => 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 override string GetString(byte[] bytes) => 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) =>
|
||||
new string(GetChars(bytes, index, count));
|
||||
|
||||
/// <summary>
|
||||
/// Converts a GEOS character to an Unicode character
|
||||
/// </summary>
|
||||
/// <returns>Unicode character.</returns>
|
||||
/// <param name="character">GEOS character.</param>
|
||||
static char GetChar(byte character) => GeosTable[character];
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Unicode character to an GEOS character
|
||||
/// </summary>
|
||||
/// <returns>GEOS 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 '\u005C': return 0x5C;
|
||||
case '\u005D': return 0x5D;
|
||||
case '\u005E': return 0x5E;
|
||||
case '\u005F': return 0x5F;
|
||||
case '\u0060': return 0x60;
|
||||
case '\u0061': return 0x61;
|
||||
case '\u0062': return 0x62;
|
||||
case '\u0063': return 0x63;
|
||||
case '\u0064': return 0x64;
|
||||
case '\u0065': return 0x65;
|
||||
case '\u0066': return 0x66;
|
||||
case '\u0067': return 0x67;
|
||||
case '\u0068': return 0x68;
|
||||
case '\u0069': return 0x69;
|
||||
case '\u006A': return 0x6A;
|
||||
case '\u006B': return 0x6B;
|
||||
case '\u006C': return 0x6C;
|
||||
case '\u006D': return 0x6D;
|
||||
case '\u006E': return 0x6E;
|
||||
case '\u006F': return 0x6F;
|
||||
case '\u0070': return 0x70;
|
||||
case '\u0071': return 0x71;
|
||||
case '\u0072': return 0x72;
|
||||
case '\u0073': return 0x73;
|
||||
case '\u0074': return 0x74;
|
||||
case '\u0075': return 0x75;
|
||||
case '\u0076': return 0x76;
|
||||
case '\u0077': return 0x77;
|
||||
case '\u0078': return 0x78;
|
||||
case '\u0079': return 0x79;
|
||||
case '\u007A': return 0x7A;
|
||||
case '\u007B': return 0x7B;
|
||||
case '\u007C': return 0x7C;
|
||||
case '\u007D': return 0x7D;
|
||||
case '\u007E': return 0x7E;
|
||||
case '\u007F': return 0x7F;
|
||||
case '\u00C4': return 0x80;
|
||||
case '\u00C5': return 0x81;
|
||||
case '\u00C7': return 0x82;
|
||||
case '\u00C9': return 0x83;
|
||||
case '\u00D1': return 0x84;
|
||||
case '\u00D6': return 0x85;
|
||||
case '\u00DC': return 0x86;
|
||||
case '\u00E1': return 0x87;
|
||||
case '\u00E0': return 0x88;
|
||||
case '\u00E2': return 0x89;
|
||||
case '\u00E4': return 0x8A;
|
||||
case '\u00E3': return 0x8B;
|
||||
case '\u00E5': return 0x8C;
|
||||
case '\u00E7': return 0x8D;
|
||||
case '\u00E9': return 0x8E;
|
||||
case '\u00E8': return 0x8F;
|
||||
case '\u00EA': return 0x90;
|
||||
case '\u00EB': return 0x91;
|
||||
case '\u00ED': return 0x92;
|
||||
case '\u00EC': return 0x93;
|
||||
case '\u00EE': return 0x94;
|
||||
case '\u00EF': return 0x95;
|
||||
case '\u00F1': return 0x96;
|
||||
case '\u00F3': return 0x97;
|
||||
case '\u00F2': return 0x98;
|
||||
case '\u00F4': return 0x99;
|
||||
case '\u00F5': return 0x9A;
|
||||
case '\u00FA': return 0x9B;
|
||||
case '\u00F9': return 0x9C;
|
||||
case '\u00FB': return 0x9D;
|
||||
case '\u00FC': return 0x9E;
|
||||
case '\u2020': return 0x9F;
|
||||
case '\u00B0': return 0xA0;
|
||||
case '\u00A2': return 0xA1;
|
||||
case '\u00A3': return 0xA2;
|
||||
case '\u00A7': return 0xA3;
|
||||
case '\u00B7': return 0xA4;
|
||||
case '\u00B6': return 0xA5;
|
||||
case '\u00DF': return 0xA6;
|
||||
case '\u00AE': return 0xA7;
|
||||
case '\u00A9': return 0xA8;
|
||||
case '\u2122': return 0xA9;
|
||||
case '\u00C6': return 0xAD;
|
||||
case '\u00D8': return 0xAE;
|
||||
case '\u221E': return 0xAF;
|
||||
case '\u00B1': return 0xB0;
|
||||
case '\u2264': return 0xB1;
|
||||
case '\u2265': return 0xB2;
|
||||
case '\u00A5': return 0xB3;
|
||||
case '\u00B5': return 0xB4;
|
||||
case '\u03C0': return 0xB8;
|
||||
case '\u00AA': return 0xBA;
|
||||
case '\u00BA': return 0xBB;
|
||||
case '\u03A9': return 0xBC;
|
||||
case '\u00E6': return 0xBD;
|
||||
case '\u00F8': return 0xBE;
|
||||
case '\u00BF': return 0xBF;
|
||||
case '\u00A1': return 0xC0;
|
||||
case '\u00AC': return 0xC1;
|
||||
case '\u221A': return 0xC2;
|
||||
case '\u0192': return 0xC3;
|
||||
case '\u2248': return 0xC4;
|
||||
case '\u00AB': return 0xC6;
|
||||
case '\u00BB': return 0xC7;
|
||||
case '\u2026': return 0xC8;
|
||||
case '\u00A0': return 0xC9;
|
||||
case '\u00C0': return 0xCA;
|
||||
case '\u00C3': return 0xCB;
|
||||
case '\u00D5': return 0xCC;
|
||||
case '\u0152': return 0xCD;
|
||||
case '\u0153': return 0xCE;
|
||||
case '\u2013': return 0xCF;
|
||||
case '\u2014': return 0xD0;
|
||||
case '\u201C': return 0xD1;
|
||||
case '\u201D': return 0xD2;
|
||||
case '\u2018': return 0xD3;
|
||||
case '\u2019': return 0xD4;
|
||||
case '\u00F7': return 0xD5;
|
||||
case '\u00FF': return 0xD7;
|
||||
case '\u0178': return 0xD8;
|
||||
case '\u05A4': return 0xDA;
|
||||
case '\u2039': return 0xDB;
|
||||
case '\u203A': return 0xDC;
|
||||
case '\u00FD': return 0xDD;
|
||||
case '\u00DD': return 0xDE;
|
||||
case '\u2021': return 0xDF;
|
||||
case '\u201A': return 0xE1;
|
||||
case '\u201E': return 0xE2;
|
||||
case '\u2030': return 0xE3;
|
||||
case '\u00C2': return 0xE4;
|
||||
case '\u00CA': return 0xE5;
|
||||
case '\u00C1': return 0xE6;
|
||||
case '\u00CB': return 0xE7;
|
||||
case '\u00C8': return 0xE8;
|
||||
case '\u00CD': return 0xE9;
|
||||
case '\u00CE': return 0xEA;
|
||||
case '\u00CF': return 0xEB;
|
||||
case '\u00CC': return 0xEC;
|
||||
case '\u00D3': return 0xED;
|
||||
case '\u00D4': return 0xEE;
|
||||
case '\u00D2': return 0xF0;
|
||||
case '\u00DA': return 0xF1;
|
||||
case '\u00D9': return 0xF2;
|
||||
case '\u00B9': return 0xF3;
|
||||
case '\u20C6': return 0xF4;
|
||||
case '\u20DC': return 0xF5;
|
||||
case '\u00AF': return 0xF6;
|
||||
case '\u02C7': return 0xF7;
|
||||
case '\u00B8': return 0xFA;
|
||||
case '\u2032': return 0xFB;
|
||||
case '\u02DB': return 0xFC;
|
||||
case '\u02D8': return 0xFD;
|
||||
default:
|
||||
// Fallback to '?'
|
||||
return 0x3F;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
708
Claunia.Encoding/MacArabic.cs
Normal file
708
Claunia.Encoding/MacArabic.cs
Normal file
@@ -0,0 +1,708 @@
|
||||
//
|
||||
// AtariST.cs
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright © 2016-2019 Natalia Portillo
|
||||
//
|
||||
// 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 Mac Arabic character encoding of Unicode characters.
|
||||
/// </summary>
|
||||
public class MacArabic : Encoding
|
||||
{
|
||||
const string _bodyname = "x-mac-arabic";
|
||||
const int _codepage = 10004;
|
||||
const string _encodingname = "Arabic (Mac)";
|
||||
const string _headername = "x-mac-arabic";
|
||||
const string _webname = "x-mac-arabic";
|
||||
const int _windowsCodepage = 10004;
|
||||
|
||||
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>
|
||||
/// The Macintosh Arabic to Unicode character map.
|
||||
/// </summary>
|
||||
static readonly char[] MacArabicTable =
|
||||
{
|
||||
// 0x00
|
||||
'\u0000', '\u0001', '\u0002', '\u0003', '\u0004', '\u0005', '\u0006', '\u0007',
|
||||
// 0x08
|
||||
'\u0008', '\u0009', '\u000A', '\u000B', '\u000C', '\u000D', '\u000E', '\u000F',
|
||||
// 0x10
|
||||
'\u0010', '\u0011', '\u0012', '\u0013', '\u0014', '\u0015', '\u0016', '\u0017',
|
||||
// 0x18
|
||||
'\u0018', '\u0019', '\u001A', '\u001B', '\u001C', '\u001D', '\u001E', '\u001F',
|
||||
// 0x20
|
||||
'\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027',
|
||||
// 0x28
|
||||
'\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F',
|
||||
// 0x30
|
||||
'\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037',
|
||||
// 0x38
|
||||
'\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F',
|
||||
// 0x40
|
||||
'\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047',
|
||||
// 0x48
|
||||
'\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F',
|
||||
// 0x50
|
||||
'\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057',
|
||||
// 0x58
|
||||
'\u0058', '\u0059', '\u005A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F',
|
||||
// 0x60
|
||||
'\u0060', '\u0061', '\u0062', '\u0063', '\u0064', '\u0065', '\u0066', '\u0067',
|
||||
// 0x68
|
||||
'\u0068', '\u0069', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F',
|
||||
// 0x70
|
||||
'\u0070', '\u0071', '\u0072', '\u0073', '\u0074', '\u0075', '\u0076', '\u0077',
|
||||
// 0x78
|
||||
'\u0078', '\u0079', '\u007A', '\u007B', '\u007C', '\u007D', '\u007E', '\u007F',
|
||||
// 0x80
|
||||
'\u00C4', '\u00A0', '\u00C7', '\u00C9', '\u00D1', '\u00D6', '\u00DC', '\u00E1',
|
||||
// 0x88
|
||||
'\u00E0', '\u00E2', '\u00E4', '\u06BA', '\u00AB', '\u00E7', '\u00E9', '\u00E8',
|
||||
// 0x90
|
||||
'\u00EA', '\u00EB', '\u00ED', '\u2026', '\u00EE', '\u00EF', '\u00F1', '\u00F3',
|
||||
// 0x98
|
||||
'\u00BB', '\u00F4', '\u00F6', '\u00F7', '\u00FA', '\u00F9', '\u00FB', '\u00FC',
|
||||
// 0xA0
|
||||
'\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u066A', '\u0026', '\u0027',
|
||||
// 0xA8
|
||||
'\u0028', '\u0029', '\u002A', '\u002B', '\u060C', '\u002D', '\u002E', '\u002F',
|
||||
// 0xB0
|
||||
'\u0660', '\u0661', '\u0662', '\u0663', '\u0664', '\u0665', '\u0666', '\u0667',
|
||||
// 0xB8
|
||||
'\u0668', '\u0669', '\u003A', '\u061B', '\u003C', '\u003D', '\u003E', '\u061F',
|
||||
// 0xC0
|
||||
'\u274A', '\u0621', '\u0622', '\u0623', '\u0624', '\u0625', '\u0626', '\u0627',
|
||||
// 0xC8
|
||||
'\u0628', '\u0629', '\u062A', '\u062B', '\u062C', '\u062D', '\u062E', '\u062F',
|
||||
// 0xD0
|
||||
'\u0630', '\u0631', '\u0632', '\u0633', '\u0634', '\u0635', '\u0636', '\u0637',
|
||||
// 0xD8
|
||||
'\u0638', '\u0639', '\u063A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F',
|
||||
// 0xE0
|
||||
'\u0640', '\u0641', '\u0642', '\u0643', '\u0644', '\u0645', '\u0646', '\u0647',
|
||||
// 0xE8
|
||||
'\u0648', '\u0649', '\u064A', '\u064B', '\u064C', '\u064D', '\u064E', '\u064F',
|
||||
// 0xF0
|
||||
'\u0650', '\u0651', '\u0652', '\u067E', '\u0679', '\u0686', '\u06D5', '\u06A4',
|
||||
// 0xF8
|
||||
'\u06AF', '\u0688', '\u0691', '\u007B', '\u007C', '\u007D', '\u0698', '\u06D2'
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for displaying content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserDisplay => browserDisplay;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for saving content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserSave => 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 => 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 => mailNewsSave;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding is read-only.
|
||||
/// </summary>
|
||||
/// <value>The is single byte.</value>
|
||||
public override bool IsReadOnly => readOnly;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding uses single-byte code points.
|
||||
/// </summary>
|
||||
public override bool IsSingleByte => singleByte;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the code page identifier of the current Encoding.
|
||||
/// </summary>
|
||||
public override int CodePage => _codepage;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent body tags
|
||||
/// </summary>
|
||||
public override string BodyName => _bodyname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent header tags
|
||||
/// </summary>
|
||||
public override string HeaderName => _headername;
|
||||
|
||||
/// <summary>
|
||||
/// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.
|
||||
/// </summary>
|
||||
public override string WebName => _webname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the human-readable description of the current encoding.
|
||||
/// </summary>
|
||||
public override string EncodingName => _encodingname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Windows operating system code page that most closely corresponds to the current encoding.
|
||||
/// </summary>
|
||||
public override int WindowsCodePage => _windowsCodepage;
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string" />.
|
||||
/// </summary>
|
||||
/// <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) =>
|
||||
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) => 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) => 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) => 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() => 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 override string GetString(byte[] bytes) => 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) =>
|
||||
new string(GetChars(bytes, index, count));
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Mac Arabic character to an Unicode character
|
||||
/// </summary>
|
||||
/// <returns>Unicode character.</returns>
|
||||
/// <param name="character">Mac Arabic character.</param>
|
||||
static char GetChar(byte character) => MacArabicTable[character];
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Unicode character to an Mac Arabic character
|
||||
/// </summary>
|
||||
/// <returns>Mac Arabic 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 '\u005C': return 0x5C;
|
||||
case '\u005D': return 0x5D;
|
||||
case '\u005E': return 0x5E;
|
||||
case '\u005F': return 0x5F;
|
||||
case '\u0060': return 0x60;
|
||||
case '\u0061': return 0x61;
|
||||
case '\u0062': return 0x62;
|
||||
case '\u0063': return 0x63;
|
||||
case '\u0064': return 0x64;
|
||||
case '\u0065': return 0x65;
|
||||
case '\u0066': return 0x66;
|
||||
case '\u0067': return 0x67;
|
||||
case '\u0068': return 0x68;
|
||||
case '\u0069': return 0x69;
|
||||
case '\u006A': return 0x6A;
|
||||
case '\u006B': return 0x6B;
|
||||
case '\u006C': return 0x6C;
|
||||
case '\u006D': return 0x6D;
|
||||
case '\u006E': return 0x6E;
|
||||
case '\u006F': return 0x6F;
|
||||
case '\u0070': return 0x70;
|
||||
case '\u0071': return 0x71;
|
||||
case '\u0072': return 0x72;
|
||||
case '\u0073': return 0x73;
|
||||
case '\u0074': return 0x74;
|
||||
case '\u0075': return 0x75;
|
||||
case '\u0076': return 0x76;
|
||||
case '\u0077': return 0x77;
|
||||
case '\u0078': return 0x78;
|
||||
case '\u0079': return 0x79;
|
||||
case '\u007A': return 0x7A;
|
||||
case '\u007B': return 0x7B;
|
||||
case '\u007C': return 0x7C;
|
||||
case '\u007D': return 0x7D;
|
||||
case '\u007E': return 0x7E;
|
||||
case '\u007F': return 0x7F;
|
||||
case '\u00C4': return 0x80;
|
||||
case '\u00A0': return 0x81;
|
||||
case '\u00C7': return 0x82;
|
||||
case '\u00C9': return 0x83;
|
||||
case '\u00D1': return 0x84;
|
||||
case '\u00D6': return 0x85;
|
||||
case '\u00DC': return 0x86;
|
||||
case '\u00E1': return 0x87;
|
||||
case '\u00E0': return 0x88;
|
||||
case '\u00E2': return 0x89;
|
||||
case '\u00E4': return 0x8A;
|
||||
case '\u06BA': return 0x8B;
|
||||
case '\u00AB': return 0x8C;
|
||||
case '\u00E7': return 0x8D;
|
||||
case '\u00E9': return 0x8E;
|
||||
case '\u00E8': return 0x8F;
|
||||
case '\u00EA': return 0x90;
|
||||
case '\u00EB': return 0x91;
|
||||
case '\u00ED': return 0x92;
|
||||
case '\u2026': return 0x93;
|
||||
case '\u00EE': return 0x94;
|
||||
case '\u00EF': return 0x95;
|
||||
case '\u00F1': return 0x96;
|
||||
case '\u00F3': return 0x97;
|
||||
case '\u00BB': return 0x98;
|
||||
case '\u00F4': return 0x99;
|
||||
case '\u00F6': return 0x9A;
|
||||
case '\u00F7': return 0x9B;
|
||||
case '\u00FA': return 0x9C;
|
||||
case '\u00F9': return 0x9D;
|
||||
case '\u00FB': return 0x9E;
|
||||
case '\u00FC': return 0x9F;
|
||||
case '\u066A': return 0xA5;
|
||||
case '\u060C': return 0xAC;
|
||||
case '\u0660': return 0xB0;
|
||||
case '\u0661': return 0xB1;
|
||||
case '\u0662': return 0xB2;
|
||||
case '\u0663': return 0xB3;
|
||||
case '\u0664': return 0xB4;
|
||||
case '\u0665': return 0xB5;
|
||||
case '\u0666': return 0xB6;
|
||||
case '\u0667': return 0xB7;
|
||||
case '\u0668': return 0xB8;
|
||||
case '\u0669': return 0xB9;
|
||||
case '\u061B': return 0xBB;
|
||||
case '\u061F': return 0xBF;
|
||||
case '\u274A': return 0xC0;
|
||||
case '\u0621': return 0xC1;
|
||||
case '\u0622': return 0xC2;
|
||||
case '\u0623': return 0xC3;
|
||||
case '\u0624': return 0xC4;
|
||||
case '\u0625': return 0xC5;
|
||||
case '\u0626': return 0xC6;
|
||||
case '\u0627': return 0xC7;
|
||||
case '\u0628': return 0xC8;
|
||||
case '\u0629': return 0xC9;
|
||||
case '\u062A': return 0xCA;
|
||||
case '\u062B': return 0xCB;
|
||||
case '\u062C': return 0xCC;
|
||||
case '\u062D': return 0xCD;
|
||||
case '\u062E': return 0xCE;
|
||||
case '\u062F': return 0xCF;
|
||||
case '\u0630': return 0xD0;
|
||||
case '\u0631': return 0xD1;
|
||||
case '\u0632': return 0xD2;
|
||||
case '\u0633': return 0xD3;
|
||||
case '\u0634': return 0xD4;
|
||||
case '\u0635': return 0xD5;
|
||||
case '\u0636': return 0xD6;
|
||||
case '\u0637': return 0xD7;
|
||||
case '\u0638': return 0xD8;
|
||||
case '\u0639': return 0xD9;
|
||||
case '\u063A': return 0xDA;
|
||||
case '\u0640': return 0xE0;
|
||||
case '\u0641': return 0xE1;
|
||||
case '\u0642': return 0xE2;
|
||||
case '\u0643': return 0xE3;
|
||||
case '\u0644': return 0xE4;
|
||||
case '\u0645': return 0xE5;
|
||||
case '\u0646': return 0xE6;
|
||||
case '\u0647': return 0xE7;
|
||||
case '\u0648': return 0xE8;
|
||||
case '\u0649': return 0xE9;
|
||||
case '\u064A': return 0xEA;
|
||||
case '\u064B': return 0xEB;
|
||||
case '\u064C': return 0xEC;
|
||||
case '\u064D': return 0xED;
|
||||
case '\u064E': return 0xEE;
|
||||
case '\u064F': return 0xEF;
|
||||
case '\u0650': return 0xF0;
|
||||
case '\u0651': return 0xF1;
|
||||
case '\u0652': return 0xF2;
|
||||
case '\u067E': return 0xF3;
|
||||
case '\u0679': return 0xF4;
|
||||
case '\u0686': return 0xF5;
|
||||
case '\u06D5': return 0xF6;
|
||||
case '\u06A4': return 0xF7;
|
||||
case '\u06AF': return 0xF8;
|
||||
case '\u0688': return 0xF9;
|
||||
case '\u0691': return 0xFA;
|
||||
case '\u0698': return 0xFE;
|
||||
case '\u06D2': return 0xFF;
|
||||
default:
|
||||
// Fallback to '?'
|
||||
return 0x3F;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
734
Claunia.Encoding/MacCentralEuropean.cs
Normal file
734
Claunia.Encoding/MacCentralEuropean.cs
Normal file
@@ -0,0 +1,734 @@
|
||||
//
|
||||
// AtariST.cs
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright © 2016-2019 Natalia Portillo
|
||||
//
|
||||
// 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 Mac CentralEuropean character encoding of Unicode characters.
|
||||
/// </summary>
|
||||
public class MacCentralEuropean : Encoding
|
||||
{
|
||||
const string _bodyname = "x-mac-ce";
|
||||
const int _codepage = 10029;
|
||||
const string _encodingname = "Central European (Mac)";
|
||||
const string _headername = "x-mac-ce";
|
||||
const string _webname = "x-mac-ce";
|
||||
const int _windowsCodepage = 10029;
|
||||
|
||||
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>
|
||||
/// The Macintosh CentralEuropean to Unicode character map.
|
||||
/// </summary>
|
||||
static readonly char[] MacCentralEuropeanTable =
|
||||
{
|
||||
// 0x00
|
||||
'\u0000', '\u0001', '\u0002', '\u0003', '\u0004', '\u0005', '\u0006', '\u0007',
|
||||
// 0x08
|
||||
'\u0008', '\u0009', '\u000A', '\u000B', '\u000C', '\u000D', '\u000E', '\u000F',
|
||||
// 0x10
|
||||
'\u0010', '\u0011', '\u0012', '\u0013', '\u0014', '\u0015', '\u0016', '\u0017',
|
||||
// 0x18
|
||||
'\u0018', '\u0019', '\u001A', '\u001B', '\u001C', '\u001D', '\u001E', '\u001F',
|
||||
// 0x20
|
||||
'\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027',
|
||||
// 0x28
|
||||
'\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F',
|
||||
// 0x30
|
||||
'\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037',
|
||||
// 0x38
|
||||
'\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F',
|
||||
// 0x40
|
||||
'\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047',
|
||||
// 0x48
|
||||
'\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F',
|
||||
// 0x50
|
||||
'\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057',
|
||||
// 0x58
|
||||
'\u0058', '\u0059', '\u005A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F',
|
||||
// 0x60
|
||||
'\u0060', '\u0061', '\u0062', '\u0063', '\u0064', '\u0065', '\u0066', '\u0067',
|
||||
// 0x68
|
||||
'\u0068', '\u0069', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F',
|
||||
// 0x70
|
||||
'\u0070', '\u0071', '\u0072', '\u0073', '\u0074', '\u0075', '\u0076', '\u0077',
|
||||
// 0x78
|
||||
'\u0078', '\u0079', '\u007A', '\u007B', '\u007C', '\u007D', '\u007E', '\u007F',
|
||||
// 0x80
|
||||
'\u00C4', '\u0100', '\u0101', '\u00C9', '\u0104', '\u00D6', '\u00DC', '\u00E1',
|
||||
// 0x88
|
||||
'\u0105', '\u010C', '\u00E4', '\u010D', '\u0106', '\u0107', '\u00E9', '\u0179',
|
||||
// 0x90
|
||||
'\u017A', '\u010E', '\u00ED', '\u010F', '\u0112', '\u0113', '\u0116', '\u00F3',
|
||||
// 0x98
|
||||
'\u0117', '\u00F4', '\u00F6', '\u00F5', '\u00FA', '\u011A', '\u011B', '\u00FC',
|
||||
// 0xA0
|
||||
'\u2020', '\u00B0', '\u0118', '\u00A3', '\u00A7', '\u2022', '\u00B6', '\u00DF',
|
||||
// 0xA8
|
||||
'\u00AE', '\u00A9', '\u2122', '\u0119', '\u00A8', '\u2260', '\u0123', '\u012E',
|
||||
// 0xB0
|
||||
'\u012F', '\u012A', '\u2264', '\u2265', '\u012B', '\u0136', '\u2202', '\u2211',
|
||||
// 0xB8
|
||||
'\u0142', '\u013B', '\u013C', '\u013D', '\u013E', '\u0139', '\u013A', '\u0145',
|
||||
// 0xC0
|
||||
'\u0146', '\u0143', '\u00AC', '\u221A', '\u0144', '\u0147', '\u2206', '\u00AB',
|
||||
// 0xC8
|
||||
'\u00BB', '\u2026', '\u00A0', '\u0148', '\u0150', '\u00D5', '\u0151', '\u014C',
|
||||
// 0xD0
|
||||
'\u2013', '\u2014', '\u201C', '\u201D', '\u2018', '\u2019', '\u00F7', '\u25CA',
|
||||
// 0xD8
|
||||
'\u014D', '\u0154', '\u0155', '\u0158', '\u2039', '\u203A', '\u0159', '\u0156',
|
||||
// 0xE0
|
||||
'\u0157', '\u0160', '\u201A', '\u201E', '\u0161', '\u015A', '\u015B', '\u00C1',
|
||||
// 0xE8
|
||||
'\u0164', '\u0165', '\u00CD', '\u017D', '\u017E', '\u016A', '\u00D3', '\u00D4',
|
||||
// 0xF0
|
||||
'\u016B', '\u016E', '\u00DA', '\u016F', '\u0170', '\u0171', '\u0172', '\u0173',
|
||||
// 0xF8
|
||||
'\u00DD', '\u00FD', '\u0137', '\u017B', '\u0141', '\u017C', '\u0122', '\u02C7'
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for displaying content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserDisplay => browserDisplay;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for saving content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserSave => 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 => 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 => mailNewsSave;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding is read-only.
|
||||
/// </summary>
|
||||
/// <value>The is single byte.</value>
|
||||
public override bool IsReadOnly => readOnly;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding uses single-byte code points.
|
||||
/// </summary>
|
||||
public override bool IsSingleByte => singleByte;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the code page identifier of the current Encoding.
|
||||
/// </summary>
|
||||
public override int CodePage => _codepage;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent body tags
|
||||
/// </summary>
|
||||
public override string BodyName => _bodyname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent header tags
|
||||
/// </summary>
|
||||
public override string HeaderName => _headername;
|
||||
|
||||
/// <summary>
|
||||
/// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.
|
||||
/// </summary>
|
||||
public override string WebName => _webname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the human-readable description of the current encoding.
|
||||
/// </summary>
|
||||
public override string EncodingName => _encodingname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Windows operating system code page that most closely corresponds to the current encoding.
|
||||
/// </summary>
|
||||
public override int WindowsCodePage => _windowsCodepage;
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string" />.
|
||||
/// </summary>
|
||||
/// <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) =>
|
||||
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) => 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) => 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) => 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() => 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 override string GetString(byte[] bytes) => 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) =>
|
||||
new string(GetChars(bytes, index, count));
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Mac CentralEuropean character to an Unicode character
|
||||
/// </summary>
|
||||
/// <returns>Unicode character.</returns>
|
||||
/// <param name="character">Mac CentralEuropean character.</param>
|
||||
static char GetChar(byte character) => MacCentralEuropeanTable[character];
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Unicode character to an Mac CentralEuropean character
|
||||
/// </summary>
|
||||
/// <returns>Mac CentralEuropean 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 '\u005C': return 0x5C;
|
||||
case '\u005D': return 0x5D;
|
||||
case '\u005E': return 0x5E;
|
||||
case '\u005F': return 0x5F;
|
||||
case '\u0060': return 0x60;
|
||||
case '\u0061': return 0x61;
|
||||
case '\u0062': return 0x62;
|
||||
case '\u0063': return 0x63;
|
||||
case '\u0064': return 0x64;
|
||||
case '\u0065': return 0x65;
|
||||
case '\u0066': return 0x66;
|
||||
case '\u0067': return 0x67;
|
||||
case '\u0068': return 0x68;
|
||||
case '\u0069': return 0x69;
|
||||
case '\u006A': return 0x6A;
|
||||
case '\u006B': return 0x6B;
|
||||
case '\u006C': return 0x6C;
|
||||
case '\u006D': return 0x6D;
|
||||
case '\u006E': return 0x6E;
|
||||
case '\u006F': return 0x6F;
|
||||
case '\u0070': return 0x70;
|
||||
case '\u0071': return 0x71;
|
||||
case '\u0072': return 0x72;
|
||||
case '\u0073': return 0x73;
|
||||
case '\u0074': return 0x74;
|
||||
case '\u0075': return 0x75;
|
||||
case '\u0076': return 0x76;
|
||||
case '\u0077': return 0x77;
|
||||
case '\u0078': return 0x78;
|
||||
case '\u0079': return 0x79;
|
||||
case '\u007A': return 0x7A;
|
||||
case '\u007B': return 0x7B;
|
||||
case '\u007C': return 0x7C;
|
||||
case '\u007D': return 0x7D;
|
||||
case '\u007E': return 0x7E;
|
||||
case '\u007F': return 0x7F;
|
||||
case '\u00C4': return 0x80;
|
||||
case '\u0100': return 0x81;
|
||||
case '\u0101': return 0x82;
|
||||
case '\u00C9': return 0x83;
|
||||
case '\u0104': return 0x84;
|
||||
case '\u00D6': return 0x85;
|
||||
case '\u00DC': return 0x86;
|
||||
case '\u00E1': return 0x87;
|
||||
case '\u0105': return 0x88;
|
||||
case '\u010C': return 0x89;
|
||||
case '\u00E4': return 0x8A;
|
||||
case '\u010D': return 0x8B;
|
||||
case '\u0106': return 0x8C;
|
||||
case '\u0107': return 0x8D;
|
||||
case '\u00E9': return 0x8E;
|
||||
case '\u0179': return 0x8F;
|
||||
case '\u017A': return 0x90;
|
||||
case '\u010E': return 0x91;
|
||||
case '\u00ED': return 0x92;
|
||||
case '\u010F': return 0x93;
|
||||
case '\u0112': return 0x94;
|
||||
case '\u0113': return 0x95;
|
||||
case '\u0116': return 0x96;
|
||||
case '\u00F3': return 0x97;
|
||||
case '\u0117': return 0x98;
|
||||
case '\u00F4': return 0x99;
|
||||
case '\u00F6': return 0x9A;
|
||||
case '\u00F5': return 0x9B;
|
||||
case '\u00FA': return 0x9C;
|
||||
case '\u011A': return 0x9D;
|
||||
case '\u011B': return 0x9E;
|
||||
case '\u00FC': return 0x9F;
|
||||
case '\u2020': return 0xA0;
|
||||
case '\u00B0': return 0xA1;
|
||||
case '\u0118': return 0xA2;
|
||||
case '\u00A3': return 0xA3;
|
||||
case '\u00A7': return 0xA4;
|
||||
case '\u2022': return 0xA5;
|
||||
case '\u00B6': return 0xA6;
|
||||
case '\u00DF': return 0xA7;
|
||||
case '\u00AE': return 0xA8;
|
||||
case '\u00A9': return 0xA9;
|
||||
case '\u2122': return 0xAA;
|
||||
case '\u0119': return 0xAB;
|
||||
case '\u00A8': return 0xAC;
|
||||
case '\u2260': return 0xAD;
|
||||
case '\u0123': return 0xAE;
|
||||
case '\u012E': return 0xAF;
|
||||
case '\u012F': return 0xB0;
|
||||
case '\u012A': return 0xB1;
|
||||
case '\u2264': return 0xB2;
|
||||
case '\u2265': return 0xB3;
|
||||
case '\u012B': return 0xB4;
|
||||
case '\u0136': return 0xB5;
|
||||
case '\u2202': return 0xB6;
|
||||
case '\u2211': return 0xB7;
|
||||
case '\u0142': return 0xB8;
|
||||
case '\u013B': return 0xB9;
|
||||
case '\u013C': return 0xBA;
|
||||
case '\u013D': return 0xBB;
|
||||
case '\u013E': return 0xBC;
|
||||
case '\u0139': return 0xBD;
|
||||
case '\u013A': return 0xBE;
|
||||
case '\u0145': return 0xBF;
|
||||
case '\u0146': return 0xC0;
|
||||
case '\u0143': return 0xC1;
|
||||
case '\u00AC': return 0xC2;
|
||||
case '\u221A': return 0xC3;
|
||||
case '\u0144': return 0xC4;
|
||||
case '\u0147': return 0xC5;
|
||||
case '\u2206': return 0xC6;
|
||||
case '\u00AB': return 0xC7;
|
||||
case '\u00BB': return 0xC8;
|
||||
case '\u2026': return 0xC9;
|
||||
case '\u00A0': return 0xCA;
|
||||
case '\u0148': return 0xCB;
|
||||
case '\u0150': return 0xCC;
|
||||
case '\u00D5': return 0xCD;
|
||||
case '\u0151': return 0xCE;
|
||||
case '\u014C': return 0xCF;
|
||||
case '\u2013': return 0xD0;
|
||||
case '\u2014': return 0xD1;
|
||||
case '\u201C': return 0xD2;
|
||||
case '\u201D': return 0xD3;
|
||||
case '\u2018': return 0xD4;
|
||||
case '\u2019': return 0xD5;
|
||||
case '\u00F7': return 0xD6;
|
||||
case '\u05CA': return 0xD7;
|
||||
case '\u014D': return 0xD8;
|
||||
case '\u0154': return 0xD9;
|
||||
case '\u0155': return 0xDA;
|
||||
case '\u0158': return 0xDB;
|
||||
case '\u2039': return 0xDC;
|
||||
case '\u203A': return 0xDD;
|
||||
case '\u0159': return 0xDE;
|
||||
case '\u0156': return 0xDF;
|
||||
case '\u0157': return 0xE0;
|
||||
case '\u0160': return 0xE1;
|
||||
case '\u201A': return 0xE2;
|
||||
case '\u201E': return 0xE3;
|
||||
case '\u0161': return 0xE4;
|
||||
case '\u015A': return 0xE5;
|
||||
case '\u015B': return 0xE6;
|
||||
case '\u00C1': return 0xE7;
|
||||
case '\u0164': return 0xE8;
|
||||
case '\u0165': return 0xE9;
|
||||
case '\u00CD': return 0xEA;
|
||||
case '\u017D': return 0xEB;
|
||||
case '\u017E': return 0xEC;
|
||||
case '\u016A': return 0xED;
|
||||
case '\u00D3': return 0xEE;
|
||||
case '\u00D4': return 0xEF;
|
||||
case '\u016B': return 0xF0;
|
||||
case '\u016E': return 0xF1;
|
||||
case '\u00DA': return 0xF2;
|
||||
case '\u016F': return 0xF3;
|
||||
case '\u0170': return 0xF4;
|
||||
case '\u0171': return 0xF5;
|
||||
case '\u0172': return 0xF6;
|
||||
case '\u0173': return 0xF7;
|
||||
case '\u00DD': return 0xF8;
|
||||
case '\u00FD': return 0xF9;
|
||||
case '\u0137': return 0xFA;
|
||||
case '\u017B': return 0xFB;
|
||||
case '\u0141': return 0xFC;
|
||||
case '\u017C': return 0xFD;
|
||||
case '\u0122': return 0xFE;
|
||||
case '\u02C7': return 0xFF;
|
||||
default:
|
||||
// Fallback to '?'
|
||||
return 0x3F;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
734
Claunia.Encoding/MacCroatian.cs
Normal file
734
Claunia.Encoding/MacCroatian.cs
Normal file
@@ -0,0 +1,734 @@
|
||||
//
|
||||
// AtariST.cs
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright © 2016-2019 Natalia Portillo
|
||||
//
|
||||
// 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 Mac Croatian character encoding of Unicode characters.
|
||||
/// </summary>
|
||||
public class MacCroatian : Encoding
|
||||
{
|
||||
const string _bodyname = "x-mac-croatian";
|
||||
const int _codepage = 10082;
|
||||
const string _encodingname = "Croatian (Mac)";
|
||||
const string _headername = "x-mac-croatian";
|
||||
const string _webname = "x-mac-croatian";
|
||||
const int _windowsCodepage = 10082;
|
||||
|
||||
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>
|
||||
/// The Macintosh Croatian to Unicode character map.
|
||||
/// </summary>
|
||||
static readonly char[] MacCroatianTable =
|
||||
{
|
||||
// 0x00
|
||||
'\u0000', '\u0001', '\u0002', '\u0003', '\u0004', '\u0005', '\u0006', '\u0007',
|
||||
// 0x08
|
||||
'\u0008', '\u0009', '\u000A', '\u000B', '\u000C', '\u000D', '\u000E', '\u000F',
|
||||
// 0x10
|
||||
'\u0010', '\u0011', '\u0012', '\u0013', '\u0014', '\u0015', '\u0016', '\u0017',
|
||||
// 0x18
|
||||
'\u0018', '\u0019', '\u001A', '\u001B', '\u001C', '\u001D', '\u001E', '\u001F',
|
||||
// 0x20
|
||||
'\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027',
|
||||
// 0x28
|
||||
'\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F',
|
||||
// 0x30
|
||||
'\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037',
|
||||
// 0x38
|
||||
'\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F',
|
||||
// 0x40
|
||||
'\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047',
|
||||
// 0x48
|
||||
'\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F',
|
||||
// 0x50
|
||||
'\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057',
|
||||
// 0x58
|
||||
'\u0058', '\u0059', '\u005A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F',
|
||||
// 0x60
|
||||
'\u0060', '\u0061', '\u0062', '\u0063', '\u0064', '\u0065', '\u0066', '\u0067',
|
||||
// 0x68
|
||||
'\u0068', '\u0069', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F',
|
||||
// 0x70
|
||||
'\u0070', '\u0071', '\u0072', '\u0073', '\u0074', '\u0075', '\u0076', '\u0077',
|
||||
// 0x78
|
||||
'\u0078', '\u0079', '\u007A', '\u007B', '\u007C', '\u007D', '\u007E', '\u007F',
|
||||
// 0x80
|
||||
'\u00C4', '\u00C5', '\u00C7', '\u00C9', '\u00D1', '\u00D6', '\u00DC', '\u00E1',
|
||||
// 0x88
|
||||
'\u00E0', '\u00E2', '\u00E4', '\u00E3', '\u00E5', '\u00E7', '\u00E9', '\u00E8',
|
||||
// 0x90
|
||||
'\u00EA', '\u00EB', '\u00ED', '\u00EC', '\u00EE', '\u00EF', '\u00F1', '\u00F3',
|
||||
// 0x98
|
||||
'\u00F2', '\u00F4', '\u00F6', '\u00F5', '\u00FA', '\u00F9', '\u00FB', '\u00FC',
|
||||
// 0xA0
|
||||
'\u2020', '\u00B0', '\u00A2', '\u00A3', '\u00A7', '\u2022', '\u00B6', '\u00DF',
|
||||
// 0xA8
|
||||
'\u00AE', '\u0160', '\u2122', '\u00B4', '\u00A8', '\u2260', '\u017D', '\u00D8',
|
||||
// 0xB0
|
||||
'\u221E', '\u00B1', '\u2264', '\u2265', '\u2206', '\u00B5', '\u2202', '\u2211',
|
||||
// 0xB8
|
||||
'\u220F', '\u0161', '\u222B', '\u00AA', '\u00BA', '\u03A9', '\u017E', '\u00F8',
|
||||
// 0xC0
|
||||
'\u00BF', '\u00A1', '\u00AC', '\u221A', '\u0192', '\u2248', '\u0106', '\u00AB',
|
||||
// 0xC8
|
||||
'\u010C', '\u2026', '\u00A0', '\u00C0', '\u00C3', '\u00D5', '\u0152', '\u0153',
|
||||
// 0xD0
|
||||
'\u0110', '\u2014', '\u201C', '\u201D', '\u2018', '\u2019', '\u00F7', '\u25CA',
|
||||
// 0xD8
|
||||
'\uF8FF', '\u00A9', '\u2044', '\u20AC', '\u2039', '\u203A', '\u00C6', '\u00BB',
|
||||
// 0xE0
|
||||
'\u2013', '\u00B7', '\u201A', '\u201E', '\u2030', '\u00C2', '\u0107', '\u00C1',
|
||||
// 0xE8
|
||||
'\u010D', '\u00C8', '\u00CD', '\u00CE', '\u00CF', '\u00CC', '\u00D3', '\u00D4',
|
||||
// 0xF0
|
||||
'\u0111', '\u00D2', '\u00DA', '\u00D8', '\u00D9', '\u0131', '\u02C6', '\u02DC',
|
||||
// 0xF8
|
||||
'\u00AF', '\u03C0', '\u00CB', '\u02DA', '\u00B8', '\u00CA', '\u00E6', '\u02C7'
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for displaying content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserDisplay => browserDisplay;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for saving content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserSave => 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 => 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 => mailNewsSave;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding is read-only.
|
||||
/// </summary>
|
||||
/// <value>The is single byte.</value>
|
||||
public override bool IsReadOnly => readOnly;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding uses single-byte code points.
|
||||
/// </summary>
|
||||
public override bool IsSingleByte => singleByte;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the code page identifier of the current Encoding.
|
||||
/// </summary>
|
||||
public override int CodePage => _codepage;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent body tags
|
||||
/// </summary>
|
||||
public override string BodyName => _bodyname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent header tags
|
||||
/// </summary>
|
||||
public override string HeaderName => _headername;
|
||||
|
||||
/// <summary>
|
||||
/// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.
|
||||
/// </summary>
|
||||
public override string WebName => _webname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the human-readable description of the current encoding.
|
||||
/// </summary>
|
||||
public override string EncodingName => _encodingname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Windows operating system code page that most closely corresponds to the current encoding.
|
||||
/// </summary>
|
||||
public override int WindowsCodePage => _windowsCodepage;
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string" />.
|
||||
/// </summary>
|
||||
/// <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) =>
|
||||
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) => 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) => 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) => 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() => 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 override string GetString(byte[] bytes) => 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) =>
|
||||
new string(GetChars(bytes, index, count));
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Mac Croatian character to an Unicode character
|
||||
/// </summary>
|
||||
/// <returns>Unicode character.</returns>
|
||||
/// <param name="character">Mac Croatian character.</param>
|
||||
static char GetChar(byte character) => MacCroatianTable[character];
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Unicode character to an Mac Croatian character
|
||||
/// </summary>
|
||||
/// <returns>Mac Croatian 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 '\u005C': return 0x5C;
|
||||
case '\u005D': return 0x5D;
|
||||
case '\u005E': return 0x5E;
|
||||
case '\u005F': return 0x5F;
|
||||
case '\u0060': return 0x60;
|
||||
case '\u0061': return 0x61;
|
||||
case '\u0062': return 0x62;
|
||||
case '\u0063': return 0x63;
|
||||
case '\u0064': return 0x64;
|
||||
case '\u0065': return 0x65;
|
||||
case '\u0066': return 0x66;
|
||||
case '\u0067': return 0x67;
|
||||
case '\u0068': return 0x68;
|
||||
case '\u0069': return 0x69;
|
||||
case '\u006A': return 0x6A;
|
||||
case '\u006B': return 0x6B;
|
||||
case '\u006C': return 0x6C;
|
||||
case '\u006D': return 0x6D;
|
||||
case '\u006E': return 0x6E;
|
||||
case '\u006F': return 0x6F;
|
||||
case '\u0070': return 0x70;
|
||||
case '\u0071': return 0x71;
|
||||
case '\u0072': return 0x72;
|
||||
case '\u0073': return 0x73;
|
||||
case '\u0074': return 0x74;
|
||||
case '\u0075': return 0x75;
|
||||
case '\u0076': return 0x76;
|
||||
case '\u0077': return 0x77;
|
||||
case '\u0078': return 0x78;
|
||||
case '\u0079': return 0x79;
|
||||
case '\u007A': return 0x7A;
|
||||
case '\u007B': return 0x7B;
|
||||
case '\u007C': return 0x7C;
|
||||
case '\u007D': return 0x7D;
|
||||
case '\u007E': return 0x7E;
|
||||
case '\u007F': return 0x7F;
|
||||
case '\u00C4': return 0x80;
|
||||
case '\u00C5': return 0x81;
|
||||
case '\u00C7': return 0x82;
|
||||
case '\u00C9': return 0x83;
|
||||
case '\u00D1': return 0x84;
|
||||
case '\u00D6': return 0x85;
|
||||
case '\u00DC': return 0x86;
|
||||
case '\u00E1': return 0x87;
|
||||
case '\u00E0': return 0x88;
|
||||
case '\u00E2': return 0x89;
|
||||
case '\u00E4': return 0x8A;
|
||||
case '\u00E3': return 0x8B;
|
||||
case '\u00E5': return 0x8C;
|
||||
case '\u00E7': return 0x8D;
|
||||
case '\u00E9': return 0x8E;
|
||||
case '\u00E8': return 0x8F;
|
||||
case '\u00EA': return 0x90;
|
||||
case '\u00EB': return 0x91;
|
||||
case '\u00ED': return 0x92;
|
||||
case '\u00EC': return 0x93;
|
||||
case '\u00EE': return 0x94;
|
||||
case '\u00EF': return 0x95;
|
||||
case '\u00F1': return 0x96;
|
||||
case '\u00F3': return 0x97;
|
||||
case '\u00F2': return 0x98;
|
||||
case '\u00F4': return 0x99;
|
||||
case '\u00F6': return 0x9A;
|
||||
case '\u00F5': return 0x9B;
|
||||
case '\u00FA': return 0x9C;
|
||||
case '\u00F9': return 0x9D;
|
||||
case '\u00FB': return 0x9E;
|
||||
case '\u00FC': return 0x9F;
|
||||
case '\u2020': return 0xA0;
|
||||
case '\u00B0': return 0xA1;
|
||||
case '\u00A2': return 0xA2;
|
||||
case '\u00A3': return 0xA3;
|
||||
case '\u00A7': return 0xA4;
|
||||
case '\u2022': return 0xA5;
|
||||
case '\u00B6': return 0xA6;
|
||||
case '\u00DF': return 0xA7;
|
||||
case '\u00AE': return 0xA8;
|
||||
case '\u0160': return 0xA9;
|
||||
case '\u2122': return 0xAA;
|
||||
case '\u00B4': return 0xAB;
|
||||
case '\u00A8': return 0xAC;
|
||||
case '\u2260': return 0xAD;
|
||||
case '\u017D': return 0xAE;
|
||||
case '\u00D8': return 0xAF;
|
||||
case '\u221E': return 0xB0;
|
||||
case '\u00B1': return 0xB1;
|
||||
case '\u2264': return 0xB2;
|
||||
case '\u2265': return 0xB3;
|
||||
case '\u2206': return 0xB4;
|
||||
case '\u00B5': return 0xB5;
|
||||
case '\u2202': return 0xB6;
|
||||
case '\u2211': return 0xB7;
|
||||
case '\u220F': return 0xB8;
|
||||
case '\u0161': return 0xB9;
|
||||
case '\u222B': return 0xBA;
|
||||
case '\u00AA': return 0xBB;
|
||||
case '\u00BA': return 0xBC;
|
||||
case '\u03A9': return 0xBD;
|
||||
case '\u017E': return 0xBE;
|
||||
case '\u00F8': return 0xBF;
|
||||
case '\u00BF': return 0xC0;
|
||||
case '\u00A1': return 0xC1;
|
||||
case '\u00AC': return 0xC2;
|
||||
case '\u221A': return 0xC3;
|
||||
case '\u0192': return 0xC4;
|
||||
case '\u2248': return 0xC5;
|
||||
case '\u0106': return 0xC6;
|
||||
case '\u00AB': return 0xC7;
|
||||
case '\u010C': return 0xC8;
|
||||
case '\u2026': return 0xC9;
|
||||
case '\u00A0': return 0xCA;
|
||||
case '\u00C0': return 0xCB;
|
||||
case '\u00C3': return 0xCC;
|
||||
case '\u00D5': return 0xCD;
|
||||
case '\u0152': return 0xCE;
|
||||
case '\u0153': return 0xCF;
|
||||
case '\u0110': return 0xD0;
|
||||
case '\u2014': return 0xD1;
|
||||
case '\u201C': return 0xD2;
|
||||
case '\u201D': return 0xD3;
|
||||
case '\u2018': return 0xD4;
|
||||
case '\u2019': return 0xD5;
|
||||
case '\u00F7': return 0xD6;
|
||||
case '\u25CA': return 0xD7;
|
||||
case '\uF8FF': return 0xD8;
|
||||
case '\u00A9': return 0xD9;
|
||||
case '\u2044': return 0xDA;
|
||||
case '\u20AC': return 0xDB;
|
||||
case '\u2039': return 0xDC;
|
||||
case '\u203A': return 0xDD;
|
||||
case '\u00C6': return 0xDE;
|
||||
case '\u00BB': return 0xDF;
|
||||
case '\u2013': return 0xE0;
|
||||
case '\u00B7': return 0xE1;
|
||||
case '\u201A': return 0xE2;
|
||||
case '\u201E': return 0xE3;
|
||||
case '\u2030': return 0xE4;
|
||||
case '\u00C2': return 0xE5;
|
||||
case '\u0107': return 0xE6;
|
||||
case '\u00C1': return 0xE7;
|
||||
case '\u010D': return 0xE8;
|
||||
case '\u00C8': return 0xE9;
|
||||
case '\u00CD': return 0xEA;
|
||||
case '\u00CE': return 0xEB;
|
||||
case '\u00CF': return 0xEC;
|
||||
case '\u00CC': return 0xED;
|
||||
case '\u00D3': return 0xEE;
|
||||
case '\u00D4': return 0xEF;
|
||||
case '\u0111': return 0xF0;
|
||||
case '\u00D2': return 0xF1;
|
||||
case '\u00DA': return 0xF2;
|
||||
case '\u00DB': return 0xF3;
|
||||
case '\u00D9': return 0xF4;
|
||||
case '\u0131': return 0xF5;
|
||||
case '\u02C6': return 0xF6;
|
||||
case '\u02DC': return 0xF7;
|
||||
case '\u00AF': return 0xF8;
|
||||
case '\u03C0': return 0xF9;
|
||||
case '\u00CB': return 0xFA;
|
||||
case '\u02DA': return 0xFB;
|
||||
case '\u00B8': return 0xFC;
|
||||
case '\u00CA': return 0xFD;
|
||||
case '\u00E6': return 0xFE;
|
||||
case '\u02C7': return 0xFF;
|
||||
default:
|
||||
// Fallback to '?'
|
||||
return 0x3F;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
734
Claunia.Encoding/MacCyrillic.cs
Normal file
734
Claunia.Encoding/MacCyrillic.cs
Normal file
@@ -0,0 +1,734 @@
|
||||
//
|
||||
// AtariST.cs
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright © 2016-2019 Natalia Portillo
|
||||
//
|
||||
// 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 Mac Cyrillic character encoding of Unicode characters.
|
||||
/// </summary>
|
||||
public class MacCyrillic : Encoding
|
||||
{
|
||||
const string _bodyname = "x-mac-cyrillic";
|
||||
const int _codepage = 10007;
|
||||
const string _encodingname = "Cyrillic (Mac)";
|
||||
const string _headername = "x-mac-cyrillic";
|
||||
const string _webname = "x-mac-cyrillic";
|
||||
const int _windowsCodepage = 10007;
|
||||
|
||||
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>
|
||||
/// The Macintosh Cyrillic to Unicode character map.
|
||||
/// </summary>
|
||||
static readonly char[] MacCyrillicTable =
|
||||
{
|
||||
// 0x00
|
||||
'\u0000', '\u0001', '\u0002', '\u0003', '\u0004', '\u0005', '\u0006', '\u0007',
|
||||
// 0x08
|
||||
'\u0008', '\u0009', '\u000A', '\u000B', '\u000C', '\u000D', '\u000E', '\u000F',
|
||||
// 0x10
|
||||
'\u0010', '\u0011', '\u0012', '\u0013', '\u0014', '\u0015', '\u0016', '\u0017',
|
||||
// 0x18
|
||||
'\u0018', '\u0019', '\u001A', '\u001B', '\u001C', '\u001D', '\u001E', '\u001F',
|
||||
// 0x20
|
||||
'\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027',
|
||||
// 0x28
|
||||
'\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F',
|
||||
// 0x30
|
||||
'\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037',
|
||||
// 0x38
|
||||
'\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F',
|
||||
// 0x40
|
||||
'\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047',
|
||||
// 0x48
|
||||
'\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F',
|
||||
// 0x50
|
||||
'\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057',
|
||||
// 0x58
|
||||
'\u0058', '\u0059', '\u005A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F',
|
||||
// 0x60
|
||||
'\u0060', '\u0061', '\u0062', '\u0063', '\u0064', '\u0065', '\u0066', '\u0067',
|
||||
// 0x68
|
||||
'\u0068', '\u0069', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F',
|
||||
// 0x70
|
||||
'\u0070', '\u0071', '\u0072', '\u0073', '\u0074', '\u0075', '\u0076', '\u0077',
|
||||
// 0x78
|
||||
'\u0078', '\u0079', '\u007A', '\u007B', '\u007C', '\u007D', '\u007E', '\u007F',
|
||||
// 0x80
|
||||
'\u0410', '\u0411', '\u0412', '\u0413', '\u0414', '\u0415', '\u0416', '\u0417',
|
||||
// 0x88
|
||||
'\u0418', '\u0419', '\u041A', '\u041B', '\u041C', '\u041D', '\u041E', '\u041F',
|
||||
// 0x90
|
||||
'\u0420', '\u0421', '\u0422', '\u0423', '\u0424', '\u0425', '\u0426', '\u0427',
|
||||
// 0x98
|
||||
'\u0428', '\u0429', '\u042A', '\u042B', '\u042C', '\u042D', '\u042E', '\u042F',
|
||||
// 0xA0
|
||||
'\u2020', '\u00B0', '\u00A2', '\u00A3', '\u00A7', '\u2022', '\u00B6', '\u0406',
|
||||
// 0xA8
|
||||
'\u00AE', '\u00A9', '\u2122', '\u0402', '\u0452', '\u2260', '\u0403', '\u0453',
|
||||
// 0xB0
|
||||
'\u221E', '\u00B1', '\u2264', '\u2265', '\u0456', '\u00B5', '\u2202', '\u0408',
|
||||
// 0xB8
|
||||
'\u0404', '\u0454', '\u0407', '\u0457', '\u0409', '\u0459', '\u040A', '\u045A',
|
||||
// 0xC0
|
||||
'\u0458', '\u0405', '\u00AC', '\u221A', '\u0192', '\u2248', '\u2206', '\u00AB',
|
||||
// 0xC8
|
||||
'\u00BB', '\u2026', '\u00A0', '\u040B', '\u045B', '\u040C', '\u045C', '\u0455',
|
||||
// 0xD0
|
||||
'\u2013', '\u2014', '\u201C', '\u201D', '\u2018', '\u2019', '\u00F7', '\u201E',
|
||||
// 0xD8
|
||||
'\u040E', '\u045E', '\u040F', '\u045F', '\u2116', '\u0401', '\u0451', '\u044F',
|
||||
// 0xE0
|
||||
'\u0430', '\u0431', '\u0432', '\u0433', '\u0434', '\u0435', '\u0436', '\u0437',
|
||||
// 0xE8
|
||||
'\u0438', '\u0439', '\u043A', '\u043B', '\u043C', '\u043D', '\u043E', '\u043F',
|
||||
// 0xF0
|
||||
'\u0440', '\u0441', '\u0442', '\u0443', '\u0444', '\u0445', '\u0446', '\u0447',
|
||||
// 0xF8
|
||||
'\u0448', '\u0449', '\u044A', '\u044B', '\u044C', '\u044D', '\u044E', '\u20AC'
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for displaying content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserDisplay => browserDisplay;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for saving content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserSave => 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 => 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 => mailNewsSave;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding is read-only.
|
||||
/// </summary>
|
||||
/// <value>The is single byte.</value>
|
||||
public override bool IsReadOnly => readOnly;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding uses single-byte code points.
|
||||
/// </summary>
|
||||
public override bool IsSingleByte => singleByte;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the code page identifier of the current Encoding.
|
||||
/// </summary>
|
||||
public override int CodePage => _codepage;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent body tags
|
||||
/// </summary>
|
||||
public override string BodyName => _bodyname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent header tags
|
||||
/// </summary>
|
||||
public override string HeaderName => _headername;
|
||||
|
||||
/// <summary>
|
||||
/// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.
|
||||
/// </summary>
|
||||
public override string WebName => _webname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the human-readable description of the current encoding.
|
||||
/// </summary>
|
||||
public override string EncodingName => _encodingname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Windows operating system code page that most closely corresponds to the current encoding.
|
||||
/// </summary>
|
||||
public override int WindowsCodePage => _windowsCodepage;
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string" />.
|
||||
/// </summary>
|
||||
/// <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) =>
|
||||
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) => 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) => 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) => 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() => 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 override string GetString(byte[] bytes) => 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) =>
|
||||
new string(GetChars(bytes, index, count));
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Mac Cyrillic character to an Unicode character
|
||||
/// </summary>
|
||||
/// <returns>Unicode character.</returns>
|
||||
/// <param name="character">Mac Cyrillic character.</param>
|
||||
static char GetChar(byte character) => MacCyrillicTable[character];
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Unicode character to an Mac Cyrillic character
|
||||
/// </summary>
|
||||
/// <returns>Mac Cyrillic 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 '\u005C': return 0x5C;
|
||||
case '\u005D': return 0x5D;
|
||||
case '\u005E': return 0x5E;
|
||||
case '\u005F': return 0x5F;
|
||||
case '\u0060': return 0x60;
|
||||
case '\u0061': return 0x61;
|
||||
case '\u0062': return 0x62;
|
||||
case '\u0063': return 0x63;
|
||||
case '\u0064': return 0x64;
|
||||
case '\u0065': return 0x65;
|
||||
case '\u0066': return 0x66;
|
||||
case '\u0067': return 0x67;
|
||||
case '\u0068': return 0x68;
|
||||
case '\u0069': return 0x69;
|
||||
case '\u006A': return 0x6A;
|
||||
case '\u006B': return 0x6B;
|
||||
case '\u006C': return 0x6C;
|
||||
case '\u006D': return 0x6D;
|
||||
case '\u006E': return 0x6E;
|
||||
case '\u006F': return 0x6F;
|
||||
case '\u0070': return 0x70;
|
||||
case '\u0071': return 0x71;
|
||||
case '\u0072': return 0x72;
|
||||
case '\u0073': return 0x73;
|
||||
case '\u0074': return 0x74;
|
||||
case '\u0075': return 0x75;
|
||||
case '\u0076': return 0x76;
|
||||
case '\u0077': return 0x77;
|
||||
case '\u0078': return 0x78;
|
||||
case '\u0079': return 0x79;
|
||||
case '\u007A': return 0x7A;
|
||||
case '\u007B': return 0x7B;
|
||||
case '\u007C': return 0x7C;
|
||||
case '\u007D': return 0x7D;
|
||||
case '\u007E': return 0x7E;
|
||||
case '\u007F': return 0x7F;
|
||||
case '\u0410': return 0x80;
|
||||
case '\u0411': return 0x81;
|
||||
case '\u0412': return 0x82;
|
||||
case '\u0413': return 0x83;
|
||||
case '\u0414': return 0x84;
|
||||
case '\u0415': return 0x85;
|
||||
case '\u0416': return 0x86;
|
||||
case '\u0417': return 0x87;
|
||||
case '\u0418': return 0x88;
|
||||
case '\u0419': return 0x89;
|
||||
case '\u041A': return 0x8A;
|
||||
case '\u041B': return 0x8B;
|
||||
case '\u041C': return 0x8C;
|
||||
case '\u041D': return 0x8D;
|
||||
case '\u041E': return 0x8E;
|
||||
case '\u041F': return 0x8F;
|
||||
case '\u0420': return 0x90;
|
||||
case '\u0421': return 0x91;
|
||||
case '\u0422': return 0x92;
|
||||
case '\u0423': return 0x93;
|
||||
case '\u0424': return 0x94;
|
||||
case '\u0425': return 0x95;
|
||||
case '\u0426': return 0x96;
|
||||
case '\u0427': return 0x97;
|
||||
case '\u0428': return 0x98;
|
||||
case '\u0429': return 0x99;
|
||||
case '\u042A': return 0x9A;
|
||||
case '\u042B': return 0x9B;
|
||||
case '\u042C': return 0x9C;
|
||||
case '\u042D': return 0x9D;
|
||||
case '\u042E': return 0x9E;
|
||||
case '\u042F': return 0x9F;
|
||||
case '\u2020': return 0xA0;
|
||||
case '\u00B0': return 0xA1;
|
||||
case '\u0490': return 0xA2;
|
||||
case '\u00A3': return 0xA3;
|
||||
case '\u00A7': return 0xA4;
|
||||
case '\u2022': return 0xA5;
|
||||
case '\u00B6': return 0xA6;
|
||||
case '\u0406': return 0xA7;
|
||||
case '\u00AE': return 0xA8;
|
||||
case '\u00A9': return 0xA9;
|
||||
case '\u2122': return 0xAA;
|
||||
case '\u0402': return 0xAB;
|
||||
case '\u0452': return 0xAC;
|
||||
case '\u2260': return 0xAD;
|
||||
case '\u0403': return 0xAE;
|
||||
case '\u0453': return 0xAF;
|
||||
case '\u221E': return 0xB0;
|
||||
case '\u00B1': return 0xB1;
|
||||
case '\u2264': return 0xB2;
|
||||
case '\u2265': return 0xB3;
|
||||
case '\u0456': return 0xB4;
|
||||
case '\u00B5': return 0xB5;
|
||||
case '\u0491': return 0xB6;
|
||||
case '\u0408': return 0xB7;
|
||||
case '\u0404': return 0xB8;
|
||||
case '\u0454': return 0xB9;
|
||||
case '\u0407': return 0xBA;
|
||||
case '\u0457': return 0xBB;
|
||||
case '\u0409': return 0xBC;
|
||||
case '\u0459': return 0xBD;
|
||||
case '\u040A': return 0xBE;
|
||||
case '\u045A': return 0xBF;
|
||||
case '\u0458': return 0xC0;
|
||||
case '\u0405': return 0xC1;
|
||||
case '\u00AC': return 0xC2;
|
||||
case '\u221A': return 0xC3;
|
||||
case '\u0192': return 0xC4;
|
||||
case '\u2248': return 0xC5;
|
||||
case '\u2206': return 0xC6;
|
||||
case '\u00AB': return 0xC7;
|
||||
case '\u00BB': return 0xC8;
|
||||
case '\u2026': return 0xC9;
|
||||
case '\u00A0': return 0xCA;
|
||||
case '\u040B': return 0xCB;
|
||||
case '\u045B': return 0xCC;
|
||||
case '\u040C': return 0xCD;
|
||||
case '\u045C': return 0xCE;
|
||||
case '\u0455': return 0xCF;
|
||||
case '\u2013': return 0xD0;
|
||||
case '\u2014': return 0xD1;
|
||||
case '\u201C': return 0xD2;
|
||||
case '\u201D': return 0xD3;
|
||||
case '\u2018': return 0xD4;
|
||||
case '\u2019': return 0xD5;
|
||||
case '\u00F7': return 0xD6;
|
||||
case '\u201E': return 0xD7;
|
||||
case '\u040E': return 0xD8;
|
||||
case '\u045E': return 0xD9;
|
||||
case '\u040F': return 0xDA;
|
||||
case '\u045F': return 0xDB;
|
||||
case '\u2116': return 0xDC;
|
||||
case '\u0401': return 0xDD;
|
||||
case '\u0451': return 0xDE;
|
||||
case '\u044F': return 0xDF;
|
||||
case '\u0430': return 0xE0;
|
||||
case '\u0431': return 0xE1;
|
||||
case '\u0432': return 0xE2;
|
||||
case '\u0433': return 0xE3;
|
||||
case '\u0434': return 0xE4;
|
||||
case '\u0435': return 0xE5;
|
||||
case '\u0436': return 0xE6;
|
||||
case '\u0437': return 0xE7;
|
||||
case '\u0438': return 0xE8;
|
||||
case '\u0439': return 0xE9;
|
||||
case '\u043A': return 0xEA;
|
||||
case '\u043B': return 0xEB;
|
||||
case '\u043C': return 0xEC;
|
||||
case '\u043D': return 0xED;
|
||||
case '\u043E': return 0xEE;
|
||||
case '\u043F': return 0xEF;
|
||||
case '\u0440': return 0xF0;
|
||||
case '\u0441': return 0xF1;
|
||||
case '\u0442': return 0xF2;
|
||||
case '\u0443': return 0xF3;
|
||||
case '\u0444': return 0xF4;
|
||||
case '\u0445': return 0xF5;
|
||||
case '\u0446': return 0xF6;
|
||||
case '\u0447': return 0xF7;
|
||||
case '\u0448': return 0xF8;
|
||||
case '\u0449': return 0xF9;
|
||||
case '\u044A': return 0xFA;
|
||||
case '\u044B': return 0xFB;
|
||||
case '\u044C': return 0xFC;
|
||||
case '\u044D': return 0xFD;
|
||||
case '\u044E': return 0xFE;
|
||||
case '\u20AC': return 0xFF;
|
||||
default:
|
||||
// Fallback to '?'
|
||||
return 0x3F;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
708
Claunia.Encoding/MacFarsi.cs
Normal file
708
Claunia.Encoding/MacFarsi.cs
Normal file
@@ -0,0 +1,708 @@
|
||||
//
|
||||
// AtariST.cs
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright © 2016-2019 Natalia Portillo
|
||||
//
|
||||
// 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 Mac Farsi character encoding of Unicode characters.
|
||||
/// </summary>
|
||||
public class MacFarsi : Encoding
|
||||
{
|
||||
const string _bodyname = "x-mac-farsi";
|
||||
const int _codepage = 10014;
|
||||
const string _encodingname = "Farsi (Mac)";
|
||||
const string _headername = "x-mac-farsi";
|
||||
const string _webname = "x-mac-farsi";
|
||||
const int _windowsCodepage = 10014;
|
||||
|
||||
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>
|
||||
/// The Macintosh Farsi to Unicode character map.
|
||||
/// </summary>
|
||||
static readonly char[] MacFarsiTable =
|
||||
{
|
||||
// 0x00
|
||||
'\u0000', '\u0001', '\u0002', '\u0003', '\u0004', '\u0005', '\u0006', '\u0007',
|
||||
// 0x08
|
||||
'\u0008', '\u0009', '\u000A', '\u000B', '\u000C', '\u000D', '\u000E', '\u000F',
|
||||
// 0x10
|
||||
'\u0010', '\u0011', '\u0012', '\u0013', '\u0014', '\u0015', '\u0016', '\u0017',
|
||||
// 0x18
|
||||
'\u0018', '\u0019', '\u001A', '\u001B', '\u001C', '\u001D', '\u001E', '\u001F',
|
||||
// 0x20
|
||||
'\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027',
|
||||
// 0x28
|
||||
'\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F',
|
||||
// 0x30
|
||||
'\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037',
|
||||
// 0x38
|
||||
'\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F',
|
||||
// 0x40
|
||||
'\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047',
|
||||
// 0x48
|
||||
'\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F',
|
||||
// 0x50
|
||||
'\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057',
|
||||
// 0x58
|
||||
'\u0058', '\u0059', '\u005A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F',
|
||||
// 0x60
|
||||
'\u0060', '\u0061', '\u0062', '\u0063', '\u0064', '\u0065', '\u0066', '\u0067',
|
||||
// 0x68
|
||||
'\u0068', '\u0069', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F',
|
||||
// 0x70
|
||||
'\u0070', '\u0071', '\u0072', '\u0073', '\u0074', '\u0075', '\u0076', '\u0077',
|
||||
// 0x78
|
||||
'\u0078', '\u0079', '\u007A', '\u007B', '\u007C', '\u007D', '\u007E', '\u007F',
|
||||
// 0x80
|
||||
'\u00C4', '\u00A0', '\u00C7', '\u00C9', '\u00D1', '\u00D6', '\u00DC', '\u00E1',
|
||||
// 0x88
|
||||
'\u00E0', '\u00E2', '\u00E4', '\u06BA', '\u00AB', '\u00E7', '\u00E9', '\u00E8',
|
||||
// 0x90
|
||||
'\u00EA', '\u00EB', '\u00ED', '\u2026', '\u00EE', '\u00EF', '\u00F1', '\u00F3',
|
||||
// 0x98
|
||||
'\u00BB', '\u00F4', '\u00F6', '\u00F7', '\u00FA', '\u00F9', '\u00FB', '\u00FC',
|
||||
// 0xA0
|
||||
'\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u066A', '\u0026', '\u0027',
|
||||
// 0xA8
|
||||
'\u0028', '\u0029', '\u002A', '\u002B', '\u060C', '\u002D', '\u002E', '\u002F',
|
||||
// 0xB0
|
||||
'\u06F0', '\u06F1', '\u06F2', '\u06F3', '\u06F4', '\u06F5', '\u06F6', '\u06F7',
|
||||
// 0xB8
|
||||
'\u06F8', '\u06F9', '\u003A', '\u061B', '\u003C', '\u003D', '\u003E', '\u061F',
|
||||
// 0xC0
|
||||
'\u274A', '\u0621', '\u0622', '\u0623', '\u0624', '\u0625', '\u0626', '\u0627',
|
||||
// 0xC8
|
||||
'\u0628', '\u0629', '\u062A', '\u062B', '\u062C', '\u062D', '\u062E', '\u062F',
|
||||
// 0xD0
|
||||
'\u0630', '\u0631', '\u0632', '\u0633', '\u0634', '\u0635', '\u0636', '\u0637',
|
||||
// 0xD8
|
||||
'\u0638', '\u0639', '\u063A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F',
|
||||
// 0xE0
|
||||
'\u0640', '\u0641', '\u0642', '\u0643', '\u0644', '\u0645', '\u0646', '\u0647',
|
||||
// 0xE8
|
||||
'\u0648', '\u0649', '\u064A', '\u064B', '\u064C', '\u064D', '\u064E', '\u064F',
|
||||
// 0xF0
|
||||
'\u0650', '\u0651', '\u0652', '\u067E', '\u0679', '\u0686', '\u06D5', '\u06A4',
|
||||
// 0xF8
|
||||
'\u06AF', '\u0688', '\u0691', '\u007B', '\u007C', '\u007D', '\u0698', '\u06D2'
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for displaying content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserDisplay => browserDisplay;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for saving content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserSave => 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 => 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 => mailNewsSave;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding is read-only.
|
||||
/// </summary>
|
||||
/// <value>The is single byte.</value>
|
||||
public override bool IsReadOnly => readOnly;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding uses single-byte code points.
|
||||
/// </summary>
|
||||
public override bool IsSingleByte => singleByte;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the code page identifier of the current Encoding.
|
||||
/// </summary>
|
||||
public override int CodePage => _codepage;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent body tags
|
||||
/// </summary>
|
||||
public override string BodyName => _bodyname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent header tags
|
||||
/// </summary>
|
||||
public override string HeaderName => _headername;
|
||||
|
||||
/// <summary>
|
||||
/// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.
|
||||
/// </summary>
|
||||
public override string WebName => _webname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the human-readable description of the current encoding.
|
||||
/// </summary>
|
||||
public override string EncodingName => _encodingname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Windows operating system code page that most closely corresponds to the current encoding.
|
||||
/// </summary>
|
||||
public override int WindowsCodePage => _windowsCodepage;
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string" />.
|
||||
/// </summary>
|
||||
/// <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) =>
|
||||
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) => 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) => 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) => 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() => 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 override string GetString(byte[] bytes) => 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) =>
|
||||
new string(GetChars(bytes, index, count));
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Mac Farsi character to an Unicode character
|
||||
/// </summary>
|
||||
/// <returns>Unicode character.</returns>
|
||||
/// <param name="character">Mac Farsi character.</param>
|
||||
static char GetChar(byte character) => MacFarsiTable[character];
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Unicode character to an Mac Farsi character
|
||||
/// </summary>
|
||||
/// <returns>Mac Farsi 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 '\u005C': return 0x5C;
|
||||
case '\u005D': return 0x5D;
|
||||
case '\u005E': return 0x5E;
|
||||
case '\u005F': return 0x5F;
|
||||
case '\u0060': return 0x60;
|
||||
case '\u0061': return 0x61;
|
||||
case '\u0062': return 0x62;
|
||||
case '\u0063': return 0x63;
|
||||
case '\u0064': return 0x64;
|
||||
case '\u0065': return 0x65;
|
||||
case '\u0066': return 0x66;
|
||||
case '\u0067': return 0x67;
|
||||
case '\u0068': return 0x68;
|
||||
case '\u0069': return 0x69;
|
||||
case '\u006A': return 0x6A;
|
||||
case '\u006B': return 0x6B;
|
||||
case '\u006C': return 0x6C;
|
||||
case '\u006D': return 0x6D;
|
||||
case '\u006E': return 0x6E;
|
||||
case '\u006F': return 0x6F;
|
||||
case '\u0070': return 0x70;
|
||||
case '\u0071': return 0x71;
|
||||
case '\u0072': return 0x72;
|
||||
case '\u0073': return 0x73;
|
||||
case '\u0074': return 0x74;
|
||||
case '\u0075': return 0x75;
|
||||
case '\u0076': return 0x76;
|
||||
case '\u0077': return 0x77;
|
||||
case '\u0078': return 0x78;
|
||||
case '\u0079': return 0x79;
|
||||
case '\u007A': return 0x7A;
|
||||
case '\u007B': return 0x7B;
|
||||
case '\u007C': return 0x7C;
|
||||
case '\u007D': return 0x7D;
|
||||
case '\u007E': return 0x7E;
|
||||
case '\u007F': return 0x7F;
|
||||
case '\u00C4': return 0x80;
|
||||
case '\u00A0': return 0x81;
|
||||
case '\u00C7': return 0x82;
|
||||
case '\u00C9': return 0x83;
|
||||
case '\u00D1': return 0x84;
|
||||
case '\u00D6': return 0x85;
|
||||
case '\u00DC': return 0x86;
|
||||
case '\u00E1': return 0x87;
|
||||
case '\u00E0': return 0x88;
|
||||
case '\u00E2': return 0x89;
|
||||
case '\u00E4': return 0x8A;
|
||||
case '\u06BA': return 0x8B;
|
||||
case '\u00AB': return 0x8C;
|
||||
case '\u00E7': return 0x8D;
|
||||
case '\u00E9': return 0x8E;
|
||||
case '\u00E8': return 0x8F;
|
||||
case '\u00EA': return 0x90;
|
||||
case '\u00EB': return 0x91;
|
||||
case '\u00ED': return 0x92;
|
||||
case '\u2026': return 0x93;
|
||||
case '\u00EE': return 0x94;
|
||||
case '\u00EF': return 0x95;
|
||||
case '\u00F1': return 0x96;
|
||||
case '\u00F3': return 0x97;
|
||||
case '\u00BB': return 0x98;
|
||||
case '\u00F4': return 0x99;
|
||||
case '\u00F6': return 0x9A;
|
||||
case '\u00F7': return 0x9B;
|
||||
case '\u00FA': return 0x9C;
|
||||
case '\u00F9': return 0x9D;
|
||||
case '\u00FB': return 0x9E;
|
||||
case '\u00FC': return 0x9F;
|
||||
case '\u066A': return 0xA5;
|
||||
case '\u060C': return 0xAC;
|
||||
case '\u06F0': return 0xB0;
|
||||
case '\u06F1': return 0xB1;
|
||||
case '\u06F2': return 0xB2;
|
||||
case '\u06F3': return 0xB3;
|
||||
case '\u06F4': return 0xB4;
|
||||
case '\u06F5': return 0xB5;
|
||||
case '\u06F6': return 0xB6;
|
||||
case '\u06F7': return 0xB7;
|
||||
case '\u06F8': return 0xB8;
|
||||
case '\u06F9': return 0xB9;
|
||||
case '\u061B': return 0xBB;
|
||||
case '\u061F': return 0xBF;
|
||||
case '\u274A': return 0xC0;
|
||||
case '\u0621': return 0xC1;
|
||||
case '\u0622': return 0xC2;
|
||||
case '\u0623': return 0xC3;
|
||||
case '\u0624': return 0xC4;
|
||||
case '\u0625': return 0xC5;
|
||||
case '\u0626': return 0xC6;
|
||||
case '\u0627': return 0xC7;
|
||||
case '\u0628': return 0xC8;
|
||||
case '\u0629': return 0xC9;
|
||||
case '\u062A': return 0xCA;
|
||||
case '\u062B': return 0xCB;
|
||||
case '\u062C': return 0xCC;
|
||||
case '\u062D': return 0xCD;
|
||||
case '\u062E': return 0xCE;
|
||||
case '\u062F': return 0xCF;
|
||||
case '\u0630': return 0xD0;
|
||||
case '\u0631': return 0xD1;
|
||||
case '\u0632': return 0xD2;
|
||||
case '\u0633': return 0xD3;
|
||||
case '\u0634': return 0xD4;
|
||||
case '\u0635': return 0xD5;
|
||||
case '\u0636': return 0xD6;
|
||||
case '\u0637': return 0xD7;
|
||||
case '\u0638': return 0xD8;
|
||||
case '\u0639': return 0xD9;
|
||||
case '\u063A': return 0xDA;
|
||||
case '\u0640': return 0xE0;
|
||||
case '\u0641': return 0xE1;
|
||||
case '\u0642': return 0xE2;
|
||||
case '\u0643': return 0xE3;
|
||||
case '\u0644': return 0xE4;
|
||||
case '\u0645': return 0xE5;
|
||||
case '\u0646': return 0xE6;
|
||||
case '\u0647': return 0xE7;
|
||||
case '\u0648': return 0xE8;
|
||||
case '\u0649': return 0xE9;
|
||||
case '\u064A': return 0xEA;
|
||||
case '\u064B': return 0xEB;
|
||||
case '\u064C': return 0xEC;
|
||||
case '\u064D': return 0xED;
|
||||
case '\u064E': return 0xEE;
|
||||
case '\u064F': return 0xEF;
|
||||
case '\u0650': return 0xF0;
|
||||
case '\u0651': return 0xF1;
|
||||
case '\u0652': return 0xF2;
|
||||
case '\u067E': return 0xF3;
|
||||
case '\u0679': return 0xF4;
|
||||
case '\u0686': return 0xF5;
|
||||
case '\u06D5': return 0xF6;
|
||||
case '\u06A4': return 0xF7;
|
||||
case '\u06AF': return 0xF8;
|
||||
case '\u0688': return 0xF9;
|
||||
case '\u0691': return 0xFA;
|
||||
case '\u0698': return 0xFE;
|
||||
case '\u06D2': return 0xFF;
|
||||
default:
|
||||
// Fallback to '?'
|
||||
return 0x3F;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
734
Claunia.Encoding/MacGreek.cs
Normal file
734
Claunia.Encoding/MacGreek.cs
Normal file
@@ -0,0 +1,734 @@
|
||||
//
|
||||
// AtariST.cs
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright © 2016-2019 Natalia Portillo
|
||||
//
|
||||
// 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 Mac Greek character encoding of Unicode characters.
|
||||
/// </summary>
|
||||
public class MacGreek : Encoding
|
||||
{
|
||||
const string _bodyname = "x-mac-greek";
|
||||
const int _codepage = 10006;
|
||||
const string _encodingname = "Greek (Mac)";
|
||||
const string _headername = "x-mac-greek";
|
||||
const string _webname = "x-mac-greek";
|
||||
const int _windowsCodepage = 10006;
|
||||
|
||||
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>
|
||||
/// The Macintosh Greek to Unicode character map.
|
||||
/// </summary>
|
||||
static readonly char[] MacGreekTable =
|
||||
{
|
||||
// 0x00
|
||||
'\u0000', '\u0001', '\u0002', '\u0003', '\u0004', '\u0005', '\u0006', '\u0007',
|
||||
// 0x08
|
||||
'\u0008', '\u0009', '\u000A', '\u000B', '\u000C', '\u000D', '\u000E', '\u000F',
|
||||
// 0x10
|
||||
'\u0010', '\u0011', '\u0012', '\u0013', '\u0014', '\u0015', '\u0016', '\u0017',
|
||||
// 0x18
|
||||
'\u0018', '\u0019', '\u001A', '\u001B', '\u001C', '\u001D', '\u001E', '\u001F',
|
||||
// 0x20
|
||||
'\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027',
|
||||
// 0x28
|
||||
'\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F',
|
||||
// 0x30
|
||||
'\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037',
|
||||
// 0x38
|
||||
'\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F',
|
||||
// 0x40
|
||||
'\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047',
|
||||
// 0x48
|
||||
'\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F',
|
||||
// 0x50
|
||||
'\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057',
|
||||
// 0x58
|
||||
'\u0058', '\u0059', '\u005A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F',
|
||||
// 0x60
|
||||
'\u0060', '\u0061', '\u0062', '\u0063', '\u0064', '\u0065', '\u0066', '\u0067',
|
||||
// 0x68
|
||||
'\u0068', '\u0069', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F',
|
||||
// 0x70
|
||||
'\u0070', '\u0071', '\u0072', '\u0073', '\u0074', '\u0075', '\u0076', '\u0077',
|
||||
// 0x78
|
||||
'\u0078', '\u0079', '\u007A', '\u007B', '\u007C', '\u007D', '\u007E', '\u007F',
|
||||
// 0x80
|
||||
'\u00C4', '\u00B9', '\u00B2', '\u00C9', '\u00B3', '\u00D6', '\u00DC', '\u0385',
|
||||
// 0x88
|
||||
'\u00E0', '\u00E2', '\u00E4', '\u0384', '\u00A8', '\u00E7', '\u00E9', '\u00E8',
|
||||
// 0x90
|
||||
'\u00EA', '\u00EB', '\u00A3', '\u2122', '\u00EE', '\u00EF', '\u2022', '\u00BD',
|
||||
// 0x98
|
||||
'\u2030', '\u00F4', '\u00F6', '\u00A6', '\u20AC', '\u00F9', '\u00FB', '\u00FC',
|
||||
// 0xA0
|
||||
'\u2020', '\u0393', '\u0394', '\u0398', '\u039B', '\u039E', '\u03A0', '\u00DF',
|
||||
// 0xA8
|
||||
'\u00AE', '\u00A9', '\u03A3', '\u03AA', '\u00A7', '\u2260', '\u00B0', '\u00B7',
|
||||
// 0xB0
|
||||
'\u0391', '\u00B1', '\u2264', '\u2265', '\u00A5', '\u0392', '\u0395', '\u0396',
|
||||
// 0xB8
|
||||
'\u0397', '\u0399', '\u039A', '\u039C', '\u03A6', '\u03AB', '\u03A8', '\u03A9',
|
||||
// 0xC0
|
||||
'\u03AC', '\u039D', '\u00AC', '\u039F', '\u03A1', '\u2248', '\u03A4', '\u00AB',
|
||||
// 0xC8
|
||||
'\u00BB', '\u2026', '\u00A0', '\u03A5', '\u03A7', '\u0386', '\u0388', '\u0153',
|
||||
// 0xD0
|
||||
'\u2013', '\u2015', '\u201C', '\u201D', '\u2018', '\u2019', '\u00F7', '\u0389',
|
||||
// 0xD8
|
||||
'\u038A', '\u038C', '\u038E', '\u03AD', '\u03AE', '\u03AF', '\u03CC', '\u038F',
|
||||
// 0xE0
|
||||
'\u03CD', '\u03B1', '\u03B2', '\u03C8', '\u03B4', '\u03B5', '\u03C6', '\u03B3',
|
||||
// 0xE8
|
||||
'\u03B7', '\u03B9', '\u03BE', '\u03BA', '\u03BB', '\u03BC', '\u03BD', '\u03BF',
|
||||
// 0xF0
|
||||
'\u03C0', '\u03CE', '\u03C1', '\u03C3', '\u03C4', '\u03B8', '\u03C9', '\u03C2',
|
||||
// 0xF8
|
||||
'\u03C7', '\u03C5', '\u03B6', '\u03CA', '\u03CB', '\u0390', '\u03B0', '\u00AD'
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for displaying content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserDisplay => browserDisplay;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for saving content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserSave => 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 => 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 => mailNewsSave;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding is read-only.
|
||||
/// </summary>
|
||||
/// <value>The is single byte.</value>
|
||||
public override bool IsReadOnly => readOnly;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding uses single-byte code points.
|
||||
/// </summary>
|
||||
public override bool IsSingleByte => singleByte;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the code page identifier of the current Encoding.
|
||||
/// </summary>
|
||||
public override int CodePage => _codepage;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent body tags
|
||||
/// </summary>
|
||||
public override string BodyName => _bodyname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent header tags
|
||||
/// </summary>
|
||||
public override string HeaderName => _headername;
|
||||
|
||||
/// <summary>
|
||||
/// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.
|
||||
/// </summary>
|
||||
public override string WebName => _webname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the human-readable description of the current encoding.
|
||||
/// </summary>
|
||||
public override string EncodingName => _encodingname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Windows operating system code page that most closely corresponds to the current encoding.
|
||||
/// </summary>
|
||||
public override int WindowsCodePage => _windowsCodepage;
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string" />.
|
||||
/// </summary>
|
||||
/// <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) =>
|
||||
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) => 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) => 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) => 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() => 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 override string GetString(byte[] bytes) => 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) =>
|
||||
new string(GetChars(bytes, index, count));
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Mac Greek character to an Unicode character
|
||||
/// </summary>
|
||||
/// <returns>Unicode character.</returns>
|
||||
/// <param name="character">Mac Greek character.</param>
|
||||
static char GetChar(byte character) => MacGreekTable[character];
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Unicode character to an Mac Greek character
|
||||
/// </summary>
|
||||
/// <returns>Mac Greek 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 '\u005C': return 0x5C;
|
||||
case '\u005D': return 0x5D;
|
||||
case '\u005E': return 0x5E;
|
||||
case '\u005F': return 0x5F;
|
||||
case '\u0060': return 0x60;
|
||||
case '\u0061': return 0x61;
|
||||
case '\u0062': return 0x62;
|
||||
case '\u0063': return 0x63;
|
||||
case '\u0064': return 0x64;
|
||||
case '\u0065': return 0x65;
|
||||
case '\u0066': return 0x66;
|
||||
case '\u0067': return 0x67;
|
||||
case '\u0068': return 0x68;
|
||||
case '\u0069': return 0x69;
|
||||
case '\u006A': return 0x6A;
|
||||
case '\u006B': return 0x6B;
|
||||
case '\u006C': return 0x6C;
|
||||
case '\u006D': return 0x6D;
|
||||
case '\u006E': return 0x6E;
|
||||
case '\u006F': return 0x6F;
|
||||
case '\u0070': return 0x70;
|
||||
case '\u0071': return 0x71;
|
||||
case '\u0072': return 0x72;
|
||||
case '\u0073': return 0x73;
|
||||
case '\u0074': return 0x74;
|
||||
case '\u0075': return 0x75;
|
||||
case '\u0076': return 0x76;
|
||||
case '\u0077': return 0x77;
|
||||
case '\u0078': return 0x78;
|
||||
case '\u0079': return 0x79;
|
||||
case '\u007A': return 0x7A;
|
||||
case '\u007B': return 0x7B;
|
||||
case '\u007C': return 0x7C;
|
||||
case '\u007D': return 0x7D;
|
||||
case '\u007E': return 0x7E;
|
||||
case '\u007F': return 0x7F;
|
||||
case '\u00C4': return 0x80;
|
||||
case '\u00B9': return 0x81;
|
||||
case '\u00B2': return 0x82;
|
||||
case '\u00C9': return 0x83;
|
||||
case '\u00B3': return 0x84;
|
||||
case '\u00D6': return 0x85;
|
||||
case '\u00DC': return 0x86;
|
||||
case '\u0385': return 0x87;
|
||||
case '\u00E0': return 0x88;
|
||||
case '\u00E2': return 0x89;
|
||||
case '\u00E4': return 0x8A;
|
||||
case '\u0384': return 0x8B;
|
||||
case '\u00A8': return 0x8C;
|
||||
case '\u00E7': return 0x8D;
|
||||
case '\u00E9': return 0x8E;
|
||||
case '\u00E8': return 0x8F;
|
||||
case '\u00EA': return 0x90;
|
||||
case '\u00EB': return 0x91;
|
||||
case '\u00A3': return 0x92;
|
||||
case '\u2122': return 0x93;
|
||||
case '\u00EE': return 0x94;
|
||||
case '\u00EF': return 0x95;
|
||||
case '\u2022': return 0x96;
|
||||
case '\u00BD': return 0x97;
|
||||
case '\u2030': return 0x98;
|
||||
case '\u00F4': return 0x99;
|
||||
case '\u00F6': return 0x9A;
|
||||
case '\u00A6': return 0x9B;
|
||||
case '\u20AC': return 0x9C;
|
||||
case '\u00F9': return 0x9D;
|
||||
case '\u00FB': return 0x9E;
|
||||
case '\u00FC': return 0x9F;
|
||||
case '\u2020': return 0xA0;
|
||||
case '\u0393': return 0xA1;
|
||||
case '\u0394': return 0xA2;
|
||||
case '\u0398': return 0xA3;
|
||||
case '\u039B': return 0xA4;
|
||||
case '\u039E': return 0xA5;
|
||||
case '\u03A0': return 0xA6;
|
||||
case '\u00DF': return 0xA7;
|
||||
case '\u00AE': return 0xA8;
|
||||
case '\u00A9': return 0xA9;
|
||||
case '\u03A3': return 0xAA;
|
||||
case '\u03AA': return 0xAB;
|
||||
case '\u00A7': return 0xAC;
|
||||
case '\u2260': return 0xAD;
|
||||
case '\u00B0': return 0xAE;
|
||||
case '\u00B7': return 0xAF;
|
||||
case '\u0391': return 0xB0;
|
||||
case '\u00B1': return 0xB1;
|
||||
case '\u2264': return 0xB2;
|
||||
case '\u2265': return 0xB3;
|
||||
case '\u00A5': return 0xB4;
|
||||
case '\u0392': return 0xB5;
|
||||
case '\u0395': return 0xB6;
|
||||
case '\u0396': return 0xB7;
|
||||
case '\u0397': return 0xB8;
|
||||
case '\u0399': return 0xB9;
|
||||
case '\u039A': return 0xBA;
|
||||
case '\u039C': return 0xBB;
|
||||
case '\u03A6': return 0xBC;
|
||||
case '\u03AB': return 0xBD;
|
||||
case '\u03A8': return 0xBE;
|
||||
case '\u03A9': return 0xBF;
|
||||
case '\u03AC': return 0xC0;
|
||||
case '\u039D': return 0xC1;
|
||||
case '\u00AC': return 0xC2;
|
||||
case '\u039F': return 0xC3;
|
||||
case '\u03A1': return 0xC4;
|
||||
case '\u2248': return 0xC5;
|
||||
case '\u03A4': return 0xC6;
|
||||
case '\u00AB': return 0xC7;
|
||||
case '\u00BB': return 0xC8;
|
||||
case '\u2026': return 0xC9;
|
||||
case '\u00A0': return 0xCA;
|
||||
case '\u03A5': return 0xCB;
|
||||
case '\u03A7': return 0xCC;
|
||||
case '\u0386': return 0xCD;
|
||||
case '\u0388': return 0xCE;
|
||||
case '\u0153': return 0xCF;
|
||||
case '\u2013': return 0xD0;
|
||||
case '\u2015': return 0xD1;
|
||||
case '\u201C': return 0xD2;
|
||||
case '\u201D': return 0xD3;
|
||||
case '\u2018': return 0xD4;
|
||||
case '\u2019': return 0xD5;
|
||||
case '\u00F7': return 0xD6;
|
||||
case '\u0389': return 0xD7;
|
||||
case '\u038A': return 0xD8;
|
||||
case '\u038C': return 0xD9;
|
||||
case '\u038E': return 0xDA;
|
||||
case '\u03AD': return 0xDB;
|
||||
case '\u03AE': return 0xDC;
|
||||
case '\u03AF': return 0xDD;
|
||||
case '\u03CC': return 0xDE;
|
||||
case '\u038F': return 0xDF;
|
||||
case '\u03CD': return 0xE0;
|
||||
case '\u03B1': return 0xE1;
|
||||
case '\u03B2': return 0xE2;
|
||||
case '\u03C8': return 0xE3;
|
||||
case '\u03B4': return 0xE4;
|
||||
case '\u03B5': return 0xE5;
|
||||
case '\u03C6': return 0xE6;
|
||||
case '\u03B3': return 0xE7;
|
||||
case '\u03B7': return 0xE8;
|
||||
case '\u03B9': return 0xE9;
|
||||
case '\u03BE': return 0xEA;
|
||||
case '\u03BA': return 0xEB;
|
||||
case '\u03BB': return 0xEC;
|
||||
case '\u03BC': return 0xED;
|
||||
case '\u03BD': return 0xEE;
|
||||
case '\u03BF': return 0xEF;
|
||||
case '\u03C0': return 0xF0;
|
||||
case '\u03CE': return 0xF1;
|
||||
case '\u03C1': return 0xF2;
|
||||
case '\u03C3': return 0xF3;
|
||||
case '\u03C4': return 0xF4;
|
||||
case '\u03B8': return 0xF5;
|
||||
case '\u03C9': return 0xF6;
|
||||
case '\u03C2': return 0xF7;
|
||||
case '\u03C7': return 0xF8;
|
||||
case '\u03C5': return 0xF9;
|
||||
case '\u03B6': return 0xFA;
|
||||
case '\u03CA': return 0xFB;
|
||||
case '\u03CB': return 0xFC;
|
||||
case '\u0390': return 0xFD;
|
||||
case '\u03B0': return 0xFE;
|
||||
case '\u00AD': return 0xFF;
|
||||
default:
|
||||
// Fallback to '?'
|
||||
return 0x3F;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
698
Claunia.Encoding/MacHebrew.cs
Normal file
698
Claunia.Encoding/MacHebrew.cs
Normal file
@@ -0,0 +1,698 @@
|
||||
//
|
||||
// AtariST.cs
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright © 2016-2019 Natalia Portillo
|
||||
//
|
||||
// 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 Mac Hebrew character encoding of Unicode characters.
|
||||
/// </summary>
|
||||
public class MacHebrew : Encoding
|
||||
{
|
||||
const string _bodyname = "x-mac-hebrew";
|
||||
const int _codepage = 10005;
|
||||
const string _encodingname = "Hebrew (Mac)";
|
||||
const string _headername = "x-mac-hebrew";
|
||||
const string _webname = "x-mac-hebrew";
|
||||
const int _windowsCodepage = 10005;
|
||||
|
||||
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>
|
||||
/// The Macintosh Hebrew to Unicode character map.
|
||||
/// </summary>
|
||||
// TODO: 0x81 => 0x05F2+0x05B7
|
||||
// TODO: 0xC0 => 0xF86A+0x05DC+0x05B9
|
||||
// TODO: 0xDE => 0x05B8+0xF87F
|
||||
static readonly char[] MacHebrewTable =
|
||||
{
|
||||
// 0x00
|
||||
'\u0000', '\u0001', '\u0002', '\u0003', '\u0004', '\u0005', '\u0006', '\u0007',
|
||||
// 0x08
|
||||
'\u0008', '\u0009', '\u000A', '\u000B', '\u000C', '\u000D', '\u000E', '\u000F',
|
||||
// 0x10
|
||||
'\u0010', '\u0011', '\u0012', '\u0013', '\u0014', '\u0015', '\u0016', '\u0017',
|
||||
// 0x18
|
||||
'\u0018', '\u0019', '\u001A', '\u001B', '\u001C', '\u001D', '\u001E', '\u001F',
|
||||
// 0x20
|
||||
'\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027',
|
||||
// 0x28
|
||||
'\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F',
|
||||
// 0x30
|
||||
'\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037',
|
||||
// 0x38
|
||||
'\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F',
|
||||
// 0x40
|
||||
'\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047',
|
||||
// 0x48
|
||||
'\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F',
|
||||
// 0x50
|
||||
'\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057',
|
||||
// 0x58
|
||||
'\u0058', '\u0059', '\u005A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F',
|
||||
// 0x60
|
||||
'\u0060', '\u0061', '\u0062', '\u0063', '\u0064', '\u0065', '\u0066', '\u0067',
|
||||
// 0x68
|
||||
'\u0068', '\u0069', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F',
|
||||
// 0x70
|
||||
'\u0070', '\u0071', '\u0072', '\u0073', '\u0074', '\u0075', '\u0076', '\u0077',
|
||||
// 0x78
|
||||
'\u0078', '\u0079', '\u007A', '\u007B', '\u007C', '\u007D', '\u007E', '\u007F',
|
||||
// 0x80
|
||||
'\u00C4', '\u0081', '\u00C7', '\u00C9', '\u00D1', '\u00D6', '\u00DC', '\u00E1',
|
||||
// 0x88
|
||||
'\u00E0', '\u00E2', '\u00E4', '\u00E3', '\u00E5', '\u00E7', '\u00E9', '\u00E8',
|
||||
// 0x90
|
||||
'\u00EA', '\u00EB', '\u00ED', '\u00EC', '\u00EE', '\u00EF', '\u00F1', '\u00F3',
|
||||
// 0x98
|
||||
'\u00F2', '\u00F4', '\u00F6', '\u00F5', '\u00FA', '\u00F9', '\u00FB', '\u00FC',
|
||||
// 0xA0
|
||||
'\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u20AA', '\u0027',
|
||||
// 0xA8
|
||||
'\u0029', '\u0028', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F',
|
||||
// 0xB0
|
||||
'\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037',
|
||||
// 0xB8
|
||||
'\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F',
|
||||
// 0xC0
|
||||
'\uF86A', '\u201E', '\uF89B', '\uF89C', '\uF89D', '\uF89E', '\u05BC', '\uFB4B',
|
||||
// 0xC8
|
||||
'\uFB35', '\u2026', '\u00A0', '\u05B8', '\u05B7', '\u05B5', '\u05B6', '\u05B4',
|
||||
// 0xD0
|
||||
'\u2013', '\u2014', '\u201C', '\u201D', '\u2018', '\u2019', '\uFB2A', '\uFB2B',
|
||||
// 0xD8
|
||||
'\u05BF', '\u05B0', '\u05B2', '\u05B1', '\u05BB', '\u05B9', '\u05B8', '\u05B3',
|
||||
// 0xE0
|
||||
'\u05D0', '\u05D1', '\u05D2', '\u05D3', '\u05D4', '\u05D5', '\u05D6', '\u05D7',
|
||||
// 0xE8
|
||||
'\u05D8', '\u05D9', '\u05DA', '\u05DB', '\u05DC', '\u05DD', '\u05DE', '\u05DF',
|
||||
// 0xF0
|
||||
'\u05E0', '\u05E1', '\u05E2', '\u05E3', '\u05E4', '\u05E5', '\u05E6', '\u05E7',
|
||||
// 0xF8
|
||||
'\u05E8', '\u05E9', '\u05EA', '\u007D', '\u005D', '\u007B', '\u005B', '\u007C'
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for displaying content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserDisplay => browserDisplay;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for saving content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserSave => 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 => 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 => mailNewsSave;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding is read-only.
|
||||
/// </summary>
|
||||
/// <value>The is single byte.</value>
|
||||
public override bool IsReadOnly => readOnly;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding uses single-byte code points.
|
||||
/// </summary>
|
||||
public override bool IsSingleByte => singleByte;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the code page identifier of the current Encoding.
|
||||
/// </summary>
|
||||
public override int CodePage => _codepage;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent body tags
|
||||
/// </summary>
|
||||
public override string BodyName => _bodyname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent header tags
|
||||
/// </summary>
|
||||
public override string HeaderName => _headername;
|
||||
|
||||
/// <summary>
|
||||
/// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.
|
||||
/// </summary>
|
||||
public override string WebName => _webname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the human-readable description of the current encoding.
|
||||
/// </summary>
|
||||
public override string EncodingName => _encodingname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Windows operating system code page that most closely corresponds to the current encoding.
|
||||
/// </summary>
|
||||
public override int WindowsCodePage => _windowsCodepage;
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string" />.
|
||||
/// </summary>
|
||||
/// <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) =>
|
||||
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) => 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) => 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) => 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() => 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 override string GetString(byte[] bytes) => 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) =>
|
||||
new string(GetChars(bytes, index, count));
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Mac Hebrew character to an Unicode character
|
||||
/// </summary>
|
||||
/// <returns>Unicode character.</returns>
|
||||
/// <param name="character">Mac Hebrew character.</param>
|
||||
static char GetChar(byte character) => MacHebrewTable[character];
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Unicode character to an Mac Hebrew character
|
||||
/// </summary>
|
||||
/// <returns>Mac Hebrew 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 '\u005C': return 0x5C;
|
||||
case '\u005D': return 0x5D;
|
||||
case '\u005E': return 0x5E;
|
||||
case '\u005F': return 0x5F;
|
||||
case '\u0060': return 0x60;
|
||||
case '\u0061': return 0x61;
|
||||
case '\u0062': return 0x62;
|
||||
case '\u0063': return 0x63;
|
||||
case '\u0064': return 0x64;
|
||||
case '\u0065': return 0x65;
|
||||
case '\u0066': return 0x66;
|
||||
case '\u0067': return 0x67;
|
||||
case '\u0068': return 0x68;
|
||||
case '\u0069': return 0x69;
|
||||
case '\u006A': return 0x6A;
|
||||
case '\u006B': return 0x6B;
|
||||
case '\u006C': return 0x6C;
|
||||
case '\u006D': return 0x6D;
|
||||
case '\u006E': return 0x6E;
|
||||
case '\u006F': return 0x6F;
|
||||
case '\u0070': return 0x70;
|
||||
case '\u0071': return 0x71;
|
||||
case '\u0072': return 0x72;
|
||||
case '\u0073': return 0x73;
|
||||
case '\u0074': return 0x74;
|
||||
case '\u0075': return 0x75;
|
||||
case '\u0076': return 0x76;
|
||||
case '\u0077': return 0x77;
|
||||
case '\u0078': return 0x78;
|
||||
case '\u0079': return 0x79;
|
||||
case '\u007A': return 0x7A;
|
||||
case '\u007B': return 0x7B;
|
||||
case '\u007C': return 0x7C;
|
||||
case '\u007D': return 0x7D;
|
||||
case '\u007E': return 0x7E;
|
||||
case '\u007F': return 0x7F;
|
||||
case '\u00C4': return 0x80;
|
||||
case '\u00C7': return 0x82;
|
||||
case '\u00C9': return 0x83;
|
||||
case '\u00D1': return 0x84;
|
||||
case '\u00D6': return 0x85;
|
||||
case '\u00DC': return 0x86;
|
||||
case '\u00E1': return 0x87;
|
||||
case '\u00E0': return 0x88;
|
||||
case '\u00E2': return 0x89;
|
||||
case '\u00E4': return 0x8A;
|
||||
case '\u00E3': return 0x8B;
|
||||
case '\u00E5': return 0x8C;
|
||||
case '\u00E7': return 0x8D;
|
||||
case '\u00E9': return 0x8E;
|
||||
case '\u00E8': return 0x8F;
|
||||
case '\u00EA': return 0x90;
|
||||
case '\u00EB': return 0x91;
|
||||
case '\u00ED': return 0x92;
|
||||
case '\u00EC': return 0x93;
|
||||
case '\u00EE': return 0x94;
|
||||
case '\u00EF': return 0x95;
|
||||
case '\u00F1': return 0x96;
|
||||
case '\u00F3': return 0x97;
|
||||
case '\u00F2': return 0x98;
|
||||
case '\u00F4': return 0x99;
|
||||
case '\u00F6': return 0x9A;
|
||||
case '\u00F5': return 0x9B;
|
||||
case '\u00FA': return 0x9C;
|
||||
case '\u00F9': return 0x9D;
|
||||
case '\u00FB': return 0x9E;
|
||||
case '\u00FC': return 0x9F;
|
||||
case '\u20AA': return 0xA6;
|
||||
case '\u201E': return 0xC1;
|
||||
case '\uF89B': return 0xC2;
|
||||
case '\uF89C': return 0xC3;
|
||||
case '\uF89D': return 0xC4;
|
||||
case '\uF89E': return 0xC5;
|
||||
case '\u05BC': return 0xC6;
|
||||
case '\uFB4B': return 0xC7;
|
||||
case '\uFB35': return 0xC8;
|
||||
case '\u2026': return 0xC9;
|
||||
case '\u00A0': return 0xCA;
|
||||
case '\u05B8': return 0xCB;
|
||||
case '\u05B7': return 0xCC;
|
||||
case '\u05B5': return 0xCD;
|
||||
case '\u05B6': return 0xCE;
|
||||
case '\u05B4': return 0xCF;
|
||||
case '\u2013': return 0xD0;
|
||||
case '\u2014': return 0xD1;
|
||||
case '\u201C': return 0xD2;
|
||||
case '\u201D': return 0xD3;
|
||||
case '\u2018': return 0xD4;
|
||||
case '\u2019': return 0xD5;
|
||||
case '\uFB2A': return 0xD6;
|
||||
case '\uFB2B': return 0xD7;
|
||||
case '\u05BF': return 0xD8;
|
||||
case '\u05B0': return 0xD9;
|
||||
case '\u05B2': return 0xDA;
|
||||
case '\u05B1': return 0xDB;
|
||||
case '\u05BB': return 0xDC;
|
||||
case '\u05B9': return 0xDD;
|
||||
case '\u05B3': return 0xDF;
|
||||
case '\u05D0': return 0xE0;
|
||||
case '\u05D1': return 0xE1;
|
||||
case '\u05D2': return 0xE2;
|
||||
case '\u05D3': return 0xE3;
|
||||
case '\u05D4': return 0xE4;
|
||||
case '\u05D5': return 0xE5;
|
||||
case '\u05D6': return 0xE6;
|
||||
case '\u05D7': return 0xE7;
|
||||
case '\u05D8': return 0xE8;
|
||||
case '\u05D9': return 0xE9;
|
||||
case '\u05DA': return 0xEA;
|
||||
case '\u05DB': return 0xEB;
|
||||
case '\u05DC': return 0xEC;
|
||||
case '\u05DD': return 0xED;
|
||||
case '\u05DE': return 0xEE;
|
||||
case '\u05DF': return 0xEF;
|
||||
case '\u05E0': return 0xF0;
|
||||
case '\u05E1': return 0xF1;
|
||||
case '\u05E2': return 0xF2;
|
||||
case '\u05E3': return 0xF3;
|
||||
case '\u05E4': return 0xF4;
|
||||
case '\u05E5': return 0xF5;
|
||||
case '\u05E6': return 0xF6;
|
||||
case '\u05E7': return 0xF7;
|
||||
case '\u05E8': return 0xF8;
|
||||
case '\u05E9': return 0xF9;
|
||||
case '\u05EA': return 0xFA;
|
||||
default:
|
||||
// Fallback to '?'
|
||||
return 0x3F;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
735
Claunia.Encoding/MacRoman.cs
Normal file
735
Claunia.Encoding/MacRoman.cs
Normal file
@@ -0,0 +1,735 @@
|
||||
//
|
||||
// MacRoman.cs
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright © 2016-2019 Natalia Portillo
|
||||
//
|
||||
// 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 Mac character encoding of Unicode characters.
|
||||
/// </summary>
|
||||
public class MacRoman : Encoding
|
||||
{
|
||||
const string _bodyname = "macintosh";
|
||||
const int _codepage = 10000;
|
||||
const string _encodingname = "Western European (Mac)";
|
||||
const string _headername = "macintosh";
|
||||
const string _webname = "macintosh";
|
||||
const int _windowsCodepage = 10000;
|
||||
|
||||
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>
|
||||
/// The Mac to Unicode character map.
|
||||
/// MacRoman is a superset of LisaRoman.
|
||||
/// </summary>
|
||||
static readonly char[] MacRomanTable =
|
||||
{
|
||||
// 0x00
|
||||
'\u0000', '\u0001', '\u0002', '\u0003', '\u0004', '\u0005', '\u0006', '\u0007',
|
||||
// 0x08
|
||||
'\u0008', '\u0009', '\u000A', '\u000B', '\u000C', '\u000D', '\u000E', '\u000F',
|
||||
// 0x10
|
||||
'\u0010', '\u0011', '\u0012', '\u0013', '\u0014', '\u0015', '\u0016', '\u0017',
|
||||
// 0x18
|
||||
'\u0018', '\u0019', '\u001A', '\u001B', '\u001C', '\u001D', '\u001E', '\u001F',
|
||||
// 0x20
|
||||
'\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027',
|
||||
// 0x28
|
||||
'\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F',
|
||||
// 0x30
|
||||
'\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037',
|
||||
// 0x38
|
||||
'\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F',
|
||||
// 0x40
|
||||
'\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047',
|
||||
// 0x48
|
||||
'\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F',
|
||||
// 0x50
|
||||
'\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057',
|
||||
// 0x58
|
||||
'\u0058', '\u0059', '\u005A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F',
|
||||
// 0x60
|
||||
'\u0060', '\u0061', '\u0062', '\u0063', '\u0064', '\u0065', '\u0066', '\u0067',
|
||||
// 0x68
|
||||
'\u0068', '\u0069', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F',
|
||||
// 0x70
|
||||
'\u0070', '\u0071', '\u0072', '\u0073', '\u0074', '\u0075', '\u0076', '\u0077',
|
||||
// 0x78
|
||||
'\u0078', '\u0079', '\u007A', '\u007B', '\u007C', '\u007D', '\u007E', '\u007F',
|
||||
// 0x80
|
||||
'\u00C4', '\u00C5', '\u00C7', '\u00C9', '\u00D1', '\u00D6', '\u00DC', '\u00E1',
|
||||
// 0x88
|
||||
'\u00E0', '\u00E2', '\u00E4', '\u00E3', '\u00E5', '\u00E7', '\u00E9', '\u00E8',
|
||||
// 0x90
|
||||
'\u00EA', '\u00EB', '\u00ED', '\u00EC', '\u00EE', '\u00EF', '\u00F1', '\u00F3',
|
||||
// 0x98
|
||||
'\u00F2', '\u00F4', '\u00F6', '\u00F5', '\u00FA', '\u00F9', '\u00FB', '\u00FC',
|
||||
// 0xA0
|
||||
'\u2020', '\u00B0', '\u00A2', '\u00A3', '\u00A7', '\u2022', '\u00B6', '\u00DF',
|
||||
// 0xA8
|
||||
'\u00AE', '\u00A9', '\u2122', '\u00B4', '\u00A8', '\u2260', '\u00C6', '\u00D8',
|
||||
// 0xB0
|
||||
'\u221E', '\u00B1', '\u2264', '\u2265', '\u00A5', '\u00B5', '\u2202', '\u2211',
|
||||
// 0xB8
|
||||
'\u220F', '\u03C0', '\u222B', '\u00AA', '\u00BA', '\u03A9', '\u00E6', '\u00F8',
|
||||
// 0xC0
|
||||
'\u00BF', '\u00A1', '\u00AC', '\u221A', '\u0192', '\u2248', '\u2206', '\u00AB',
|
||||
// 0xC8
|
||||
'\u00BB', '\u2026', '\u00A0', '\u00C0', '\u00C3', '\u00D5', '\u0152', '\u0153',
|
||||
// 0xD0
|
||||
'\u2013', '\u2014', '\u201C', '\u201D', '\u2018', '\u2019', '\u00F7', '\u25CA',
|
||||
// 0xD8
|
||||
'\u00FF', '\u0178', '\u2044', '\u20AC', '\u2039', '\u203A', '\uFB01', '\uFB02',
|
||||
// 0xE0
|
||||
'\u2021', '\u00B7', '\u201A', '\u201E', '\u2030', '\u00C2', '\u00CA', '\u00C1',
|
||||
// 0xE8
|
||||
'\u00CB', '\u00C8', '\u00CD', '\u00CE', '\u00CF', '\u00CC', '\u00D3', '\u00D4',
|
||||
// 0xF0
|
||||
'\uF8FF', '\u00D2', '\u00DA', '\u00DB', '\u00D9', '\u0131', '\u02C6', '\u02DC',
|
||||
// 0xF8
|
||||
'\u00AF', '\u02D8', '\u02D9', '\u02DA', '\u00B8', '\u02DD', '\u02DB', '\u02C7'
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for displaying content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserDisplay => browserDisplay;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for saving content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserSave => 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 => 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 => mailNewsSave;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding is read-only.
|
||||
/// </summary>
|
||||
/// <value>The is single byte.</value>
|
||||
public override bool IsReadOnly => readOnly;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding uses single-byte code points.
|
||||
/// </summary>
|
||||
public override bool IsSingleByte => singleByte;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the code page identifier of the current Encoding.
|
||||
/// </summary>
|
||||
public override int CodePage => _codepage;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent body tags
|
||||
/// </summary>
|
||||
public override string BodyName => _bodyname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent header tags
|
||||
/// </summary>
|
||||
public override string HeaderName => _headername;
|
||||
|
||||
/// <summary>
|
||||
/// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.
|
||||
/// </summary>
|
||||
public override string WebName => _webname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the human-readable description of the current encoding.
|
||||
/// </summary>
|
||||
public override string EncodingName => _encodingname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Windows operating system code page that most closely corresponds to the current encoding.
|
||||
/// </summary>
|
||||
public override int WindowsCodePage => _windowsCodepage;
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string" />.
|
||||
/// </summary>
|
||||
/// <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) =>
|
||||
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) => 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) => 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) => 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() => 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 override string GetString(byte[] bytes) => 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) =>
|
||||
new string(GetChars(bytes, index, count));
|
||||
|
||||
/// <summary>
|
||||
/// Converts a MacRoman character to an Unicode character
|
||||
/// </summary>
|
||||
/// <returns>Unicode character.</returns>
|
||||
/// <param name="character">MacRoman character.</param>
|
||||
static char GetChar(byte character) => MacRomanTable[character];
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Unicode character to an MacRoman character
|
||||
/// </summary>
|
||||
/// <returns>MacRoman 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 '\u005C': return 0x5C;
|
||||
case '\u005D': return 0x5D;
|
||||
case '\u005E': return 0x5E;
|
||||
case '\u005F': return 0x5F;
|
||||
case '\u0060': return 0x60;
|
||||
case '\u0061': return 0x61;
|
||||
case '\u0062': return 0x62;
|
||||
case '\u0063': return 0x63;
|
||||
case '\u0064': return 0x64;
|
||||
case '\u0065': return 0x65;
|
||||
case '\u0066': return 0x66;
|
||||
case '\u0067': return 0x67;
|
||||
case '\u0068': return 0x68;
|
||||
case '\u0069': return 0x69;
|
||||
case '\u006A': return 0x6A;
|
||||
case '\u006B': return 0x6B;
|
||||
case '\u006C': return 0x6C;
|
||||
case '\u006D': return 0x6D;
|
||||
case '\u006E': return 0x6E;
|
||||
case '\u006F': return 0x6F;
|
||||
case '\u0070': return 0x70;
|
||||
case '\u0071': return 0x71;
|
||||
case '\u0072': return 0x72;
|
||||
case '\u0073': return 0x73;
|
||||
case '\u0074': return 0x74;
|
||||
case '\u0075': return 0x75;
|
||||
case '\u0076': return 0x76;
|
||||
case '\u0077': return 0x77;
|
||||
case '\u0078': return 0x78;
|
||||
case '\u0079': return 0x79;
|
||||
case '\u007A': return 0x7A;
|
||||
case '\u007B': return 0x7B;
|
||||
case '\u007C': return 0x7C;
|
||||
case '\u007D': return 0x7D;
|
||||
case '\u007E': return 0x7E;
|
||||
case '\u007F': return 0x7F;
|
||||
case '\u00C4': return 0x80;
|
||||
case '\u00C5': return 0x81;
|
||||
case '\u00C7': return 0x82;
|
||||
case '\u00C9': return 0x83;
|
||||
case '\u00D1': return 0x84;
|
||||
case '\u00D6': return 0x85;
|
||||
case '\u00DC': return 0x86;
|
||||
case '\u00E1': return 0x87;
|
||||
case '\u00E0': return 0x88;
|
||||
case '\u00E2': return 0x89;
|
||||
case '\u00E4': return 0x8A;
|
||||
case '\u00E3': return 0x8B;
|
||||
case '\u00E5': return 0x8C;
|
||||
case '\u00E7': return 0x8D;
|
||||
case '\u00E9': return 0x8E;
|
||||
case '\u00E8': return 0x8F;
|
||||
case '\u00EA': return 0x90;
|
||||
case '\u00EB': return 0x91;
|
||||
case '\u00ED': return 0x92;
|
||||
case '\u00EC': return 0x93;
|
||||
case '\u00EE': return 0x94;
|
||||
case '\u00EF': return 0x95;
|
||||
case '\u00F1': return 0x96;
|
||||
case '\u00F3': return 0x97;
|
||||
case '\u00F2': return 0x98;
|
||||
case '\u00F4': return 0x99;
|
||||
case '\u00F6': return 0x9A;
|
||||
case '\u00F5': return 0x9B;
|
||||
case '\u00FA': return 0x9C;
|
||||
case '\u00F9': return 0x9D;
|
||||
case '\u00FB': return 0x9E;
|
||||
case '\u00FC': return 0x9F;
|
||||
case '\u2020': return 0xA0;
|
||||
case '\u00B0': return 0xA1;
|
||||
case '\u00A2': return 0xA2;
|
||||
case '\u00A3': return 0xA3;
|
||||
case '\u00A7': return 0xA4;
|
||||
case '\u2022': return 0xA5;
|
||||
case '\u00B6': return 0xA6;
|
||||
case '\u00DF': return 0xA7;
|
||||
case '\u00AE': return 0xA8;
|
||||
case '\u00A9': return 0xA9;
|
||||
case '\u2122': return 0xAA;
|
||||
case '\u00B4': return 0xAB;
|
||||
case '\u00A8': return 0xAC;
|
||||
case '\u2260': return 0xAD;
|
||||
case '\u00C6': return 0xAE;
|
||||
case '\u00D8': return 0xAF;
|
||||
case '\u221E': return 0xB0;
|
||||
case '\u00B1': return 0xB1;
|
||||
case '\u2264': return 0xB2;
|
||||
case '\u2265': return 0xB3;
|
||||
case '\u00A5': return 0xB4;
|
||||
case '\u00B5': return 0xB5;
|
||||
case '\u2202': return 0xB6;
|
||||
case '\u2211': return 0xB7;
|
||||
case '\u220F': return 0xB8;
|
||||
case '\u03C0': return 0xB9;
|
||||
case '\u222B': return 0xBA;
|
||||
case '\u00AA': return 0xBB;
|
||||
case '\u00BA': return 0xBC;
|
||||
case '\u03A9': return 0xBD;
|
||||
case '\u00E6': return 0xBE;
|
||||
case '\u00F8': return 0xBF;
|
||||
case '\u00BF': return 0xC0;
|
||||
case '\u00A1': return 0xC1;
|
||||
case '\u00AC': return 0xC2;
|
||||
case '\u221A': return 0xC3;
|
||||
case '\u0192': return 0xC4;
|
||||
case '\u2248': return 0xC5;
|
||||
case '\u2206': return 0xC6;
|
||||
case '\u00AB': return 0xC7;
|
||||
case '\u00BB': return 0xC8;
|
||||
case '\u2026': return 0xC9;
|
||||
case '\u00A0': return 0xCA;
|
||||
case '\u00C0': return 0xCB;
|
||||
case '\u00C3': return 0xCC;
|
||||
case '\u00D5': return 0xCD;
|
||||
case '\u0152': return 0xCE;
|
||||
case '\u0153': return 0xCF;
|
||||
case '\u2013': return 0xD0;
|
||||
case '\u2014': return 0xD1;
|
||||
case '\u201C': return 0xD2;
|
||||
case '\u201D': return 0xD3;
|
||||
case '\u2018': return 0xD4;
|
||||
case '\u2019': return 0xD5;
|
||||
case '\u00F7': return 0xD6;
|
||||
case '\u25CA': return 0xD7;
|
||||
case '\u00FF': return 0xD8;
|
||||
case '\u0178': return 0xD9;
|
||||
case '\u2044': return 0xDA;
|
||||
case '\u20AC': return 0xDB;
|
||||
case '\u2039': return 0xDC;
|
||||
case '\u203A': return 0xDD;
|
||||
case '\uFB01': return 0xDE;
|
||||
case '\uFB02': return 0xDF;
|
||||
case '\u2021': return 0xE0;
|
||||
case '\u00B7': return 0xE1;
|
||||
case '\u201A': return 0xE2;
|
||||
case '\u201E': return 0xE3;
|
||||
case '\u2030': return 0xE4;
|
||||
case '\u00C2': return 0xE5;
|
||||
case '\u00CA': return 0xE6;
|
||||
case '\u00C1': return 0xE7;
|
||||
case '\u00CB': return 0xE8;
|
||||
case '\u00C8': return 0xE9;
|
||||
case '\u00CD': return 0xEA;
|
||||
case '\u00CE': return 0xEB;
|
||||
case '\u00CF': return 0xEC;
|
||||
case '\u00CC': return 0xED;
|
||||
case '\u00D3': return 0xEE;
|
||||
case '\u00D4': return 0xEF;
|
||||
case '\uF8FF': return 0xF0;
|
||||
case '\u00D2': return 0xF1;
|
||||
case '\u00DA': return 0xF2;
|
||||
case '\u00DB': return 0xF3;
|
||||
case '\u00D9': return 0xF4;
|
||||
case '\u0131': return 0xF5;
|
||||
case '\u02C6': return 0xF6;
|
||||
case '\u02DC': return 0xF7;
|
||||
case '\u00AF': return 0xF8;
|
||||
case '\u02D8': return 0xF9;
|
||||
case '\u02D9': return 0xFA;
|
||||
case '\u02DA': return 0xFB;
|
||||
case '\u00B8': return 0xFC;
|
||||
case '\u02DD': return 0xFD;
|
||||
case '\u02DB': return 0xFE;
|
||||
case '\u02C7': return 0xFF;
|
||||
default:
|
||||
// Fallback to '?'
|
||||
return 0x3F;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
735
Claunia.Encoding/MacRomanian.cs
Normal file
735
Claunia.Encoding/MacRomanian.cs
Normal file
@@ -0,0 +1,735 @@
|
||||
//
|
||||
// MacRomanian.cs
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright © 2016-2019 Natalia Portillo
|
||||
//
|
||||
// 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 Mac character encoding of Unicode characters.
|
||||
/// </summary>
|
||||
public class MacRomanian : Encoding
|
||||
{
|
||||
const string _bodyname = "x-mac-romanian";
|
||||
const int _codepage = 10010;
|
||||
const string _encodingname = "Romanianian (Mac)";
|
||||
const string _headername = "x-mac-romanian";
|
||||
const string _webname = "x-mac-romanian";
|
||||
const int _windowsCodepage = 10010;
|
||||
|
||||
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>
|
||||
/// The Mac to Unicode character map.
|
||||
/// MacRomanian is a superset of MacRomanian.
|
||||
/// </summary>
|
||||
static readonly char[] MacRomanianTable =
|
||||
{
|
||||
// 0x00
|
||||
'\u0000', '\u0001', '\u0002', '\u0003', '\u0004', '\u0005', '\u0006', '\u0007',
|
||||
// 0x08
|
||||
'\u0008', '\u0009', '\u000A', '\u000B', '\u000C', '\u000D', '\u000E', '\u000F',
|
||||
// 0x10
|
||||
'\u0010', '\u0011', '\u0012', '\u0013', '\u0014', '\u0015', '\u0016', '\u0017',
|
||||
// 0x18
|
||||
'\u0018', '\u0019', '\u001A', '\u001B', '\u001C', '\u001D', '\u001E', '\u001F',
|
||||
// 0x20
|
||||
'\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027',
|
||||
// 0x28
|
||||
'\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F',
|
||||
// 0x30
|
||||
'\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037',
|
||||
// 0x38
|
||||
'\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F',
|
||||
// 0x40
|
||||
'\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047',
|
||||
// 0x48
|
||||
'\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F',
|
||||
// 0x50
|
||||
'\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057',
|
||||
// 0x58
|
||||
'\u0058', '\u0059', '\u005A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F',
|
||||
// 0x60
|
||||
'\u0060', '\u0061', '\u0062', '\u0063', '\u0064', '\u0065', '\u0066', '\u0067',
|
||||
// 0x68
|
||||
'\u0068', '\u0069', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F',
|
||||
// 0x70
|
||||
'\u0070', '\u0071', '\u0072', '\u0073', '\u0074', '\u0075', '\u0076', '\u0077',
|
||||
// 0x78
|
||||
'\u0078', '\u0079', '\u007A', '\u007B', '\u007C', '\u007D', '\u007E', '\u007F',
|
||||
// 0x80
|
||||
'\u00C4', '\u00C5', '\u00C7', '\u00C9', '\u00D1', '\u00D6', '\u00DC', '\u00E1',
|
||||
// 0x88
|
||||
'\u00E0', '\u00E2', '\u00E4', '\u00E3', '\u00E5', '\u00E7', '\u00E9', '\u00E8',
|
||||
// 0x90
|
||||
'\u00EA', '\u00EB', '\u00ED', '\u00EC', '\u00EE', '\u00EF', '\u00F1', '\u00F3',
|
||||
// 0x98
|
||||
'\u00F2', '\u00F4', '\u00F6', '\u00F5', '\u00FA', '\u00F9', '\u00FB', '\u00FC',
|
||||
// 0xA0
|
||||
'\u2020', '\u00B0', '\u00A2', '\u00A3', '\u00A7', '\u2022', '\u00B6', '\u00DF',
|
||||
// 0xA8
|
||||
'\u00AE', '\u00A9', '\u2122', '\u00B4', '\u00A8', '\u2260', '\u0102', '\u0218',
|
||||
// 0xB0
|
||||
'\u221E', '\u00B1', '\u2264', '\u2265', '\u00A5', '\u00B5', '\u2202', '\u2211',
|
||||
// 0xB8
|
||||
'\u220F', '\u03C0', '\u222B', '\u00AA', '\u00BA', '\u03A9', '\u0103', '\u0219',
|
||||
// 0xC0
|
||||
'\u00BF', '\u00A1', '\u00AC', '\u221A', '\u0192', '\u2248', '\u2206', '\u00AB',
|
||||
// 0xC8
|
||||
'\u00BB', '\u2026', '\u00A0', '\u00C0', '\u00C3', '\u00D5', '\u0152', '\u0153',
|
||||
// 0xD0
|
||||
'\u2013', '\u2014', '\u201C', '\u201D', '\u2018', '\u2019', '\u00F7', '\u25CA',
|
||||
// 0xD8
|
||||
'\u00FF', '\u0178', '\u2044', '\u20AC', '\u2039', '\u203A', '\u021A', '\u021B',
|
||||
// 0xE0
|
||||
'\u2021', '\u00B7', '\u201A', '\u201E', '\u2030', '\u00C2', '\u00CA', '\u00C1',
|
||||
// 0xE8
|
||||
'\u00CB', '\u00C8', '\u00CD', '\u00CE', '\u00CF', '\u00CC', '\u00D3', '\u00D4',
|
||||
// 0xF0
|
||||
'\uF8FF', '\u00D2', '\u00DA', '\u00DB', '\u00D9', '\u0131', '\u02C6', '\u02DC',
|
||||
// 0xF8
|
||||
'\u00AF', '\u02D8', '\u02D9', '\u02DA', '\u00B8', '\u02DD', '\u02DB', '\u02C7'
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for displaying content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserDisplay => browserDisplay;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for saving content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserSave => 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 => 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 => mailNewsSave;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding is read-only.
|
||||
/// </summary>
|
||||
/// <value>The is single byte.</value>
|
||||
public override bool IsReadOnly => readOnly;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding uses single-byte code points.
|
||||
/// </summary>
|
||||
public override bool IsSingleByte => singleByte;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the code page identifier of the current Encoding.
|
||||
/// </summary>
|
||||
public override int CodePage => _codepage;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent body tags
|
||||
/// </summary>
|
||||
public override string BodyName => _bodyname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent header tags
|
||||
/// </summary>
|
||||
public override string HeaderName => _headername;
|
||||
|
||||
/// <summary>
|
||||
/// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.
|
||||
/// </summary>
|
||||
public override string WebName => _webname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the human-readable description of the current encoding.
|
||||
/// </summary>
|
||||
public override string EncodingName => _encodingname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Windows operating system code page that most closely corresponds to the current encoding.
|
||||
/// </summary>
|
||||
public override int WindowsCodePage => _windowsCodepage;
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string" />.
|
||||
/// </summary>
|
||||
/// <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) =>
|
||||
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) => 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) => 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) => 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() => 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 override string GetString(byte[] bytes) => 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) =>
|
||||
new string(GetChars(bytes, index, count));
|
||||
|
||||
/// <summary>
|
||||
/// Converts a MacRomanian character to an Unicode character
|
||||
/// </summary>
|
||||
/// <returns>Unicode character.</returns>
|
||||
/// <param name="character">MacRomanian character.</param>
|
||||
static char GetChar(byte character) => MacRomanianTable[character];
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Unicode character to an MacRomanian character
|
||||
/// </summary>
|
||||
/// <returns>MacRomanian 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 '\u005C': return 0x5C;
|
||||
case '\u005D': return 0x5D;
|
||||
case '\u005E': return 0x5E;
|
||||
case '\u005F': return 0x5F;
|
||||
case '\u0060': return 0x60;
|
||||
case '\u0061': return 0x61;
|
||||
case '\u0062': return 0x62;
|
||||
case '\u0063': return 0x63;
|
||||
case '\u0064': return 0x64;
|
||||
case '\u0065': return 0x65;
|
||||
case '\u0066': return 0x66;
|
||||
case '\u0067': return 0x67;
|
||||
case '\u0068': return 0x68;
|
||||
case '\u0069': return 0x69;
|
||||
case '\u006A': return 0x6A;
|
||||
case '\u006B': return 0x6B;
|
||||
case '\u006C': return 0x6C;
|
||||
case '\u006D': return 0x6D;
|
||||
case '\u006E': return 0x6E;
|
||||
case '\u006F': return 0x6F;
|
||||
case '\u0070': return 0x70;
|
||||
case '\u0071': return 0x71;
|
||||
case '\u0072': return 0x72;
|
||||
case '\u0073': return 0x73;
|
||||
case '\u0074': return 0x74;
|
||||
case '\u0075': return 0x75;
|
||||
case '\u0076': return 0x76;
|
||||
case '\u0077': return 0x77;
|
||||
case '\u0078': return 0x78;
|
||||
case '\u0079': return 0x79;
|
||||
case '\u007A': return 0x7A;
|
||||
case '\u007B': return 0x7B;
|
||||
case '\u007C': return 0x7C;
|
||||
case '\u007D': return 0x7D;
|
||||
case '\u007E': return 0x7E;
|
||||
case '\u007F': return 0x7F;
|
||||
case '\u00C4': return 0x80;
|
||||
case '\u00C5': return 0x81;
|
||||
case '\u00C7': return 0x82;
|
||||
case '\u00C9': return 0x83;
|
||||
case '\u00D1': return 0x84;
|
||||
case '\u00D6': return 0x85;
|
||||
case '\u00DC': return 0x86;
|
||||
case '\u00E1': return 0x87;
|
||||
case '\u00E0': return 0x88;
|
||||
case '\u00E2': return 0x89;
|
||||
case '\u00E4': return 0x8A;
|
||||
case '\u00E3': return 0x8B;
|
||||
case '\u00E5': return 0x8C;
|
||||
case '\u00E7': return 0x8D;
|
||||
case '\u00E9': return 0x8E;
|
||||
case '\u00E8': return 0x8F;
|
||||
case '\u00EA': return 0x90;
|
||||
case '\u00EB': return 0x91;
|
||||
case '\u00ED': return 0x92;
|
||||
case '\u00EC': return 0x93;
|
||||
case '\u00EE': return 0x94;
|
||||
case '\u00EF': return 0x95;
|
||||
case '\u00F1': return 0x96;
|
||||
case '\u00F3': return 0x97;
|
||||
case '\u00F2': return 0x98;
|
||||
case '\u00F4': return 0x99;
|
||||
case '\u00F6': return 0x9A;
|
||||
case '\u00F5': return 0x9B;
|
||||
case '\u00FA': return 0x9C;
|
||||
case '\u00F9': return 0x9D;
|
||||
case '\u00FB': return 0x9E;
|
||||
case '\u00FC': return 0x9F;
|
||||
case '\u2020': return 0xA0;
|
||||
case '\u00B0': return 0xA1;
|
||||
case '\u00A2': return 0xA2;
|
||||
case '\u00A3': return 0xA3;
|
||||
case '\u00A7': return 0xA4;
|
||||
case '\u2022': return 0xA5;
|
||||
case '\u00B6': return 0xA6;
|
||||
case '\u00DF': return 0xA7;
|
||||
case '\u00AE': return 0xA8;
|
||||
case '\u00A9': return 0xA9;
|
||||
case '\u2122': return 0xAA;
|
||||
case '\u00B4': return 0xAB;
|
||||
case '\u00A8': return 0xAC;
|
||||
case '\u2260': return 0xAD;
|
||||
case '\u0102': return 0xAE;
|
||||
case '\u0218': return 0xAF;
|
||||
case '\u221E': return 0xB0;
|
||||
case '\u00B1': return 0xB1;
|
||||
case '\u2264': return 0xB2;
|
||||
case '\u2265': return 0xB3;
|
||||
case '\u00A5': return 0xB4;
|
||||
case '\u00B5': return 0xB5;
|
||||
case '\u2202': return 0xB6;
|
||||
case '\u2211': return 0xB7;
|
||||
case '\u220F': return 0xB8;
|
||||
case '\u03C0': return 0xB9;
|
||||
case '\u222B': return 0xBA;
|
||||
case '\u00AA': return 0xBB;
|
||||
case '\u00BA': return 0xBC;
|
||||
case '\u03A9': return 0xBD;
|
||||
case '\u0103': return 0xBE;
|
||||
case '\u0219': return 0xBF;
|
||||
case '\u00BF': return 0xC0;
|
||||
case '\u00A1': return 0xC1;
|
||||
case '\u00AC': return 0xC2;
|
||||
case '\u221A': return 0xC3;
|
||||
case '\u0192': return 0xC4;
|
||||
case '\u2248': return 0xC5;
|
||||
case '\u2206': return 0xC6;
|
||||
case '\u00AB': return 0xC7;
|
||||
case '\u00BB': return 0xC8;
|
||||
case '\u2026': return 0xC9;
|
||||
case '\u00A0': return 0xCA;
|
||||
case '\u00C0': return 0xCB;
|
||||
case '\u00C3': return 0xCC;
|
||||
case '\u00D5': return 0xCD;
|
||||
case '\u0152': return 0xCE;
|
||||
case '\u0153': return 0xCF;
|
||||
case '\u2013': return 0xD0;
|
||||
case '\u2014': return 0xD1;
|
||||
case '\u201C': return 0xD2;
|
||||
case '\u201D': return 0xD3;
|
||||
case '\u2018': return 0xD4;
|
||||
case '\u2019': return 0xD5;
|
||||
case '\u00F7': return 0xD6;
|
||||
case '\u25CA': return 0xD7;
|
||||
case '\u00FF': return 0xD8;
|
||||
case '\u0178': return 0xD9;
|
||||
case '\u2044': return 0xDA;
|
||||
case '\u20AC': return 0xDB;
|
||||
case '\u2039': return 0xDC;
|
||||
case '\u203A': return 0xDD;
|
||||
case '\u021A': return 0xDE;
|
||||
case '\u021B': return 0xDF;
|
||||
case '\u2021': return 0xE0;
|
||||
case '\u00B7': return 0xE1;
|
||||
case '\u201A': return 0xE2;
|
||||
case '\u201E': return 0xE3;
|
||||
case '\u2030': return 0xE4;
|
||||
case '\u00C2': return 0xE5;
|
||||
case '\u00CA': return 0xE6;
|
||||
case '\u00C1': return 0xE7;
|
||||
case '\u00CB': return 0xE8;
|
||||
case '\u00C8': return 0xE9;
|
||||
case '\u00CD': return 0xEA;
|
||||
case '\u00CE': return 0xEB;
|
||||
case '\u00CF': return 0xEC;
|
||||
case '\u00CC': return 0xED;
|
||||
case '\u00D3': return 0xEE;
|
||||
case '\u00D4': return 0xEF;
|
||||
case '\uF8FF': return 0xF0;
|
||||
case '\u00D2': return 0xF1;
|
||||
case '\u00DA': return 0xF2;
|
||||
case '\u00DB': return 0xF3;
|
||||
case '\u00D9': return 0xF4;
|
||||
case '\u0131': return 0xF5;
|
||||
case '\u02C6': return 0xF6;
|
||||
case '\u02DC': return 0xF7;
|
||||
case '\u00AF': return 0xF8;
|
||||
case '\u02D8': return 0xF9;
|
||||
case '\u02D9': return 0xFA;
|
||||
case '\u02DA': return 0xFB;
|
||||
case '\u00B8': return 0xFC;
|
||||
case '\u02DD': return 0xFD;
|
||||
case '\u02DB': return 0xFE;
|
||||
case '\u02C7': return 0xFF;
|
||||
default:
|
||||
// Fallback to '?'
|
||||
return 0x3F;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
734
Claunia.Encoding/MacTurkish.cs
Normal file
734
Claunia.Encoding/MacTurkish.cs
Normal file
@@ -0,0 +1,734 @@
|
||||
//
|
||||
// AtariST.cs
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright © 2016-2019 Natalia Portillo
|
||||
//
|
||||
// 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 Mac Turkish character encoding of Unicode characters.
|
||||
/// </summary>
|
||||
public class MacTurkish : Encoding
|
||||
{
|
||||
const string _bodyname = "x-mac-turkish";
|
||||
const int _codepage = 10081;
|
||||
const string _encodingname = "Turkish (Mac)";
|
||||
const string _headername = "x-mac-turkish";
|
||||
const string _webname = "x-mac-turkish";
|
||||
const int _windowsCodepage = 10081;
|
||||
|
||||
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>
|
||||
/// The Macintosh Turkish to Unicode character map.
|
||||
/// </summary>
|
||||
static readonly char[] MacTurkishTable =
|
||||
{
|
||||
// 0x00
|
||||
'\u0000', '\u0001', '\u0002', '\u0003', '\u0004', '\u0005', '\u0006', '\u0007',
|
||||
// 0x08
|
||||
'\u0008', '\u0009', '\u000A', '\u000B', '\u000C', '\u000D', '\u000E', '\u000F',
|
||||
// 0x10
|
||||
'\u0010', '\u0011', '\u0012', '\u0013', '\u0014', '\u0015', '\u0016', '\u0017',
|
||||
// 0x18
|
||||
'\u0018', '\u0019', '\u001A', '\u001B', '\u001C', '\u001D', '\u001E', '\u001F',
|
||||
// 0x20
|
||||
'\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027',
|
||||
// 0x28
|
||||
'\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F',
|
||||
// 0x30
|
||||
'\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037',
|
||||
// 0x38
|
||||
'\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F',
|
||||
// 0x40
|
||||
'\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047',
|
||||
// 0x48
|
||||
'\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F',
|
||||
// 0x50
|
||||
'\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057',
|
||||
// 0x58
|
||||
'\u0058', '\u0059', '\u005A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F',
|
||||
// 0x60
|
||||
'\u0060', '\u0061', '\u0062', '\u0063', '\u0064', '\u0065', '\u0066', '\u0067',
|
||||
// 0x68
|
||||
'\u0068', '\u0069', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F',
|
||||
// 0x70
|
||||
'\u0070', '\u0071', '\u0072', '\u0073', '\u0074', '\u0075', '\u0076', '\u0077',
|
||||
// 0x78
|
||||
'\u0078', '\u0079', '\u007A', '\u007B', '\u007C', '\u007D', '\u007E', '\u007F',
|
||||
// 0x80
|
||||
'\u00C4', '\u00C5', '\u00C7', '\u00C9', '\u00D1', '\u00D6', '\u00DC', '\u00E1',
|
||||
// 0x88
|
||||
'\u00E0', '\u00E2', '\u00E4', '\u00E3', '\u00E5', '\u00E7', '\u00E9', '\u00E8',
|
||||
// 0x90
|
||||
'\u00EA', '\u00EB', '\u00ED', '\u00EC', '\u00EE', '\u00EF', '\u00F1', '\u00F3',
|
||||
// 0x98
|
||||
'\u00F2', '\u00F4', '\u00F6', '\u00F5', '\u00FA', '\u00F9', '\u00FB', '\u00FC',
|
||||
// 0xA0
|
||||
'\u2020', '\u00B0', '\u00A2', '\u00A3', '\u00A7', '\u2022', '\u00B6', '\u00DF',
|
||||
// 0xA8
|
||||
'\u00AE', '\u00A9', '\u2122', '\u00B4', '\u00A8', '\u2260', '\u00C6', '\u00D8',
|
||||
// 0xB0
|
||||
'\u221E', '\u00B1', '\u2264', '\u2265', '\u00A5', '\u00B5', '\u2202', '\u2211',
|
||||
// 0xB8
|
||||
'\u220F', '\u03C0', '\u222B', '\u00AA', '\u00BA', '\u03A9', '\u00E6', '\u00F8',
|
||||
// 0xC0
|
||||
'\u00BF', '\u00A1', '\u00AC', '\u221A', '\u0192', '\u2248', '\u2206', '\u00AB',
|
||||
// 0xC8
|
||||
'\u00BB', '\u2026', '\u00A0', '\u00C0', '\u00C3', '\u00D5', '\u0152', '\u0153',
|
||||
// 0xD0
|
||||
'\u2013', '\u2014', '\u201C', '\u201D', '\u2018', '\u2019', '\u00F7', '\u25CA',
|
||||
// 0xD8
|
||||
'\u00FF', '\u0178', '\u011E', '\u011F', '\u0130', '\u0131', '\u015E', '\u015F',
|
||||
// 0xE0
|
||||
'\u2021', '\u00B7', '\u201A', '\u201E', '\u2030', '\u00C2', '\u00CA', '\u00C1',
|
||||
// 0xE8
|
||||
'\u00CB', '\u00C8', '\u00CD', '\u00CE', '\u00CF', '\u00CC', '\u00D3', '\u00D4',
|
||||
// 0xF0
|
||||
'\uF8FF', '\u00D2', '\u00DA', '\u00D8', '\u00D9', '\uF8A0', '\u02C6', '\u02DC',
|
||||
// 0xF8
|
||||
'\u00AF', '\u02D8', '\u02D9', '\u02DA', '\u00B8', '\u02DD', '\u02DB', '\u02C7'
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for displaying content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserDisplay => browserDisplay;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for saving content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserSave => 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 => 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 => mailNewsSave;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding is read-only.
|
||||
/// </summary>
|
||||
/// <value>The is single byte.</value>
|
||||
public override bool IsReadOnly => readOnly;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding uses single-byte code points.
|
||||
/// </summary>
|
||||
public override bool IsSingleByte => singleByte;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the code page identifier of the current Encoding.
|
||||
/// </summary>
|
||||
public override int CodePage => _codepage;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent body tags
|
||||
/// </summary>
|
||||
public override string BodyName => _bodyname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent header tags
|
||||
/// </summary>
|
||||
public override string HeaderName => _headername;
|
||||
|
||||
/// <summary>
|
||||
/// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.
|
||||
/// </summary>
|
||||
public override string WebName => _webname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the human-readable description of the current encoding.
|
||||
/// </summary>
|
||||
public override string EncodingName => _encodingname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Windows operating system code page that most closely corresponds to the current encoding.
|
||||
/// </summary>
|
||||
public override int WindowsCodePage => _windowsCodepage;
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string" />.
|
||||
/// </summary>
|
||||
/// <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) =>
|
||||
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) => 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) => 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) => 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() => 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 override string GetString(byte[] bytes) => 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) =>
|
||||
new string(GetChars(bytes, index, count));
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Mac Turkish character to an Unicode character
|
||||
/// </summary>
|
||||
/// <returns>Unicode character.</returns>
|
||||
/// <param name="character">Mac Turkish character.</param>
|
||||
static char GetChar(byte character) => MacTurkishTable[character];
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Unicode character to an Mac Turkish character
|
||||
/// </summary>
|
||||
/// <returns>Mac Turkish 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 '\u005C': return 0x5C;
|
||||
case '\u005D': return 0x5D;
|
||||
case '\u005E': return 0x5E;
|
||||
case '\u005F': return 0x5F;
|
||||
case '\u0060': return 0x60;
|
||||
case '\u0061': return 0x61;
|
||||
case '\u0062': return 0x62;
|
||||
case '\u0063': return 0x63;
|
||||
case '\u0064': return 0x64;
|
||||
case '\u0065': return 0x65;
|
||||
case '\u0066': return 0x66;
|
||||
case '\u0067': return 0x67;
|
||||
case '\u0068': return 0x68;
|
||||
case '\u0069': return 0x69;
|
||||
case '\u006A': return 0x6A;
|
||||
case '\u006B': return 0x6B;
|
||||
case '\u006C': return 0x6C;
|
||||
case '\u006D': return 0x6D;
|
||||
case '\u006E': return 0x6E;
|
||||
case '\u006F': return 0x6F;
|
||||
case '\u0070': return 0x70;
|
||||
case '\u0071': return 0x71;
|
||||
case '\u0072': return 0x72;
|
||||
case '\u0073': return 0x73;
|
||||
case '\u0074': return 0x74;
|
||||
case '\u0075': return 0x75;
|
||||
case '\u0076': return 0x76;
|
||||
case '\u0077': return 0x77;
|
||||
case '\u0078': return 0x78;
|
||||
case '\u0079': return 0x79;
|
||||
case '\u007A': return 0x7A;
|
||||
case '\u007B': return 0x7B;
|
||||
case '\u007C': return 0x7C;
|
||||
case '\u007D': return 0x7D;
|
||||
case '\u007E': return 0x7E;
|
||||
case '\u007F': return 0x7F;
|
||||
case '\u00C4': return 0x80;
|
||||
case '\u00C5': return 0x81;
|
||||
case '\u00C7': return 0x82;
|
||||
case '\u00C9': return 0x83;
|
||||
case '\u00D1': return 0x84;
|
||||
case '\u00D6': return 0x85;
|
||||
case '\u00DC': return 0x86;
|
||||
case '\u00E1': return 0x87;
|
||||
case '\u00E0': return 0x88;
|
||||
case '\u00E2': return 0x89;
|
||||
case '\u00E4': return 0x8A;
|
||||
case '\u00E3': return 0x8B;
|
||||
case '\u00E5': return 0x8C;
|
||||
case '\u00E7': return 0x8D;
|
||||
case '\u00E9': return 0x8E;
|
||||
case '\u00E8': return 0x8F;
|
||||
case '\u00EA': return 0x90;
|
||||
case '\u00EB': return 0x91;
|
||||
case '\u00ED': return 0x92;
|
||||
case '\u00EC': return 0x93;
|
||||
case '\u00EE': return 0x94;
|
||||
case '\u00EF': return 0x95;
|
||||
case '\u00F1': return 0x96;
|
||||
case '\u00F3': return 0x97;
|
||||
case '\u00F2': return 0x98;
|
||||
case '\u00F4': return 0x99;
|
||||
case '\u00F6': return 0x9A;
|
||||
case '\u00F5': return 0x9B;
|
||||
case '\u00FA': return 0x9C;
|
||||
case '\u00F9': return 0x9D;
|
||||
case '\u00FB': return 0x9E;
|
||||
case '\u00FC': return 0x9F;
|
||||
case '\u2020': return 0xA0;
|
||||
case '\u00B0': return 0xA1;
|
||||
case '\u00A2': return 0xA2;
|
||||
case '\u00A3': return 0xA3;
|
||||
case '\u00A7': return 0xA4;
|
||||
case '\u2022': return 0xA5;
|
||||
case '\u00B6': return 0xA6;
|
||||
case '\u00DF': return 0xA7;
|
||||
case '\u00AE': return 0xA8;
|
||||
case '\u00A9': return 0xA9;
|
||||
case '\u2122': return 0xAA;
|
||||
case '\u00B4': return 0xAB;
|
||||
case '\u00A8': return 0xAC;
|
||||
case '\u2260': return 0xAD;
|
||||
case '\u00C6': return 0xAE;
|
||||
case '\u00D8': return 0xAF;
|
||||
case '\u221E': return 0xB0;
|
||||
case '\u00B1': return 0xB1;
|
||||
case '\u2264': return 0xB2;
|
||||
case '\u2265': return 0xB3;
|
||||
case '\u00A5': return 0xB4;
|
||||
case '\u00B5': return 0xB5;
|
||||
case '\u2202': return 0xB6;
|
||||
case '\u2211': return 0xB7;
|
||||
case '\u220F': return 0xB8;
|
||||
case '\u03C0': return 0xB9;
|
||||
case '\u222B': return 0xBA;
|
||||
case '\u00AA': return 0xBB;
|
||||
case '\u00BA': return 0xBC;
|
||||
case '\u03A9': return 0xBD;
|
||||
case '\u00E6': return 0xBE;
|
||||
case '\u00F8': return 0xBF;
|
||||
case '\u00BF': return 0xC0;
|
||||
case '\u00A1': return 0xC1;
|
||||
case '\u00AC': return 0xC2;
|
||||
case '\u221A': return 0xC3;
|
||||
case '\u0192': return 0xC4;
|
||||
case '\u2248': return 0xC5;
|
||||
case '\u2206': return 0xC6;
|
||||
case '\u00AB': return 0xC7;
|
||||
case '\u00BB': return 0xC8;
|
||||
case '\u2026': return 0xC9;
|
||||
case '\u00A0': return 0xCA;
|
||||
case '\u00C0': return 0xCB;
|
||||
case '\u00C3': return 0xCC;
|
||||
case '\u00D5': return 0xCD;
|
||||
case '\u0152': return 0xCE;
|
||||
case '\u0153': return 0xCF;
|
||||
case '\u2013': return 0xD0;
|
||||
case '\u2014': return 0xD1;
|
||||
case '\u201C': return 0xD2;
|
||||
case '\u201D': return 0xD3;
|
||||
case '\u2018': return 0xD4;
|
||||
case '\u2019': return 0xD5;
|
||||
case '\u00F7': return 0xD6;
|
||||
case '\u05CA': return 0xD7;
|
||||
case '\u00FF': return 0xD8;
|
||||
case '\u0178': return 0xD9;
|
||||
case '\u011E': return 0xDA;
|
||||
case '\u011F': return 0xDB;
|
||||
case '\u0130': return 0xDC;
|
||||
case '\u0131': return 0xDD;
|
||||
case '\u015E': return 0xDE;
|
||||
case '\u015F': return 0xDF;
|
||||
case '\u2021': return 0xE0;
|
||||
case '\u00B7': return 0xE1;
|
||||
case '\u201A': return 0xE2;
|
||||
case '\u201E': return 0xE3;
|
||||
case '\u2030': return 0xE4;
|
||||
case '\u00C2': return 0xE5;
|
||||
case '\u00CA': return 0xE6;
|
||||
case '\u00C1': return 0xE7;
|
||||
case '\u00CB': return 0xE8;
|
||||
case '\u00C8': return 0xE9;
|
||||
case '\u00CD': return 0xEA;
|
||||
case '\u00CE': return 0xEB;
|
||||
case '\u00CF': return 0xEC;
|
||||
case '\u00CC': return 0xED;
|
||||
case '\u00D3': return 0xEE;
|
||||
case '\u00D4': return 0xEF;
|
||||
case '\uF8FF': return 0xF0;
|
||||
case '\u00D2': return 0xF1;
|
||||
case '\u00DA': return 0xF2;
|
||||
case '\u00DB': return 0xF3;
|
||||
case '\u00D9': return 0xF4;
|
||||
case '\uF8A0': return 0xF5;
|
||||
case '\u02C6': return 0xF6;
|
||||
case '\u02DC': return 0xF7;
|
||||
case '\u00AF': return 0xF8;
|
||||
case '\u02D8': return 0xF9;
|
||||
case '\u02D9': return 0xFA;
|
||||
case '\u02DA': return 0xFB;
|
||||
case '\u00B8': return 0xFC;
|
||||
case '\u02DD': return 0xFD;
|
||||
case '\u02DB': return 0xFE;
|
||||
case '\u02C7': return 0xFF;
|
||||
default:
|
||||
// Fallback to '?'
|
||||
return 0x3F;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
734
Claunia.Encoding/MacUkrainian.cs
Normal file
734
Claunia.Encoding/MacUkrainian.cs
Normal file
@@ -0,0 +1,734 @@
|
||||
//
|
||||
// AtariST.cs
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright © 2016-2019 Natalia Portillo
|
||||
//
|
||||
// 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 Mac Ukrainian character encoding of Unicode characters.
|
||||
/// </summary>
|
||||
public class MacUkrainian : Encoding
|
||||
{
|
||||
const string _bodyname = "x-mac-ukrainian";
|
||||
const int _codepage = 10017;
|
||||
const string _encodingname = "Ukrainian (Mac)";
|
||||
const string _headername = "x-mac-ukrainian";
|
||||
const string _webname = "x-mac-ukrainian";
|
||||
const int _windowsCodepage = 10017;
|
||||
|
||||
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>
|
||||
/// The Macintosh Ukrainian to Unicode character map.
|
||||
/// </summary>
|
||||
static readonly char[] MacUkrainianTable =
|
||||
{
|
||||
// 0x00
|
||||
'\u0000', '\u0001', '\u0002', '\u0003', '\u0004', '\u0005', '\u0006', '\u0007',
|
||||
// 0x08
|
||||
'\u0008', '\u0009', '\u000A', '\u000B', '\u000C', '\u000D', '\u000E', '\u000F',
|
||||
// 0x10
|
||||
'\u0010', '\u0011', '\u0012', '\u0013', '\u0014', '\u0015', '\u0016', '\u0017',
|
||||
// 0x18
|
||||
'\u0018', '\u0019', '\u001A', '\u001B', '\u001C', '\u001D', '\u001E', '\u001F',
|
||||
// 0x20
|
||||
'\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027',
|
||||
// 0x28
|
||||
'\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F',
|
||||
// 0x30
|
||||
'\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037',
|
||||
// 0x38
|
||||
'\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F',
|
||||
// 0x40
|
||||
'\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047',
|
||||
// 0x48
|
||||
'\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F',
|
||||
// 0x50
|
||||
'\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057',
|
||||
// 0x58
|
||||
'\u0058', '\u0059', '\u005A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F',
|
||||
// 0x60
|
||||
'\u0060', '\u0061', '\u0062', '\u0063', '\u0064', '\u0065', '\u0066', '\u0067',
|
||||
// 0x68
|
||||
'\u0068', '\u0069', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F',
|
||||
// 0x70
|
||||
'\u0070', '\u0071', '\u0072', '\u0073', '\u0074', '\u0075', '\u0076', '\u0077',
|
||||
// 0x78
|
||||
'\u0078', '\u0079', '\u007A', '\u007B', '\u007C', '\u007D', '\u007E', '\u007F',
|
||||
// 0x80
|
||||
'\u0410', '\u0411', '\u0412', '\u0413', '\u0414', '\u0415', '\u0416', '\u0417',
|
||||
// 0x88
|
||||
'\u0418', '\u0419', '\u041A', '\u041B', '\u041C', '\u041D', '\u041E', '\u041F',
|
||||
// 0x90
|
||||
'\u0420', '\u0421', '\u0422', '\u0423', '\u0424', '\u0425', '\u0426', '\u0427',
|
||||
// 0x98
|
||||
'\u0428', '\u0429', '\u042A', '\u042B', '\u042C', '\u042D', '\u042E', '\u042F',
|
||||
// 0xA0
|
||||
'\u2020', '\u00B0', '\u0490', '\u00A3', '\u00A7', '\u2022', '\u00B6', '\u0406',
|
||||
// 0xA8
|
||||
'\u00AE', '\u00A9', '\u2122', '\u0402', '\u0452', '\u2260', '\u0403', '\u0453',
|
||||
// 0xB0
|
||||
'\u221E', '\u00B1', '\u2264', '\u2265', '\u0456', '\u00B5', '\u0491', '\u0408',
|
||||
// 0xB8
|
||||
'\u0404', '\u0454', '\u0407', '\u0457', '\u0409', '\u0459', '\u040A', '\u045A',
|
||||
// 0xC0
|
||||
'\u0458', '\u0405', '\u00AC', '\u221A', '\u0192', '\u2248', '\u2206', '\u00AB',
|
||||
// 0xC8
|
||||
'\u00BB', '\u2026', '\u00A0', '\u040B', '\u045B', '\u040C', '\u045C', '\u0455',
|
||||
// 0xD0
|
||||
'\u2013', '\u2014', '\u201C', '\u201D', '\u2018', '\u2019', '\u00F7', '\u201E',
|
||||
// 0xD8
|
||||
'\u040E', '\u045E', '\u040F', '\u045F', '\u2116', '\u0401', '\u0451', '\u044F',
|
||||
// 0xE0
|
||||
'\u0430', '\u0431', '\u0432', '\u0433', '\u0434', '\u0435', '\u0436', '\u0437',
|
||||
// 0xE8
|
||||
'\u0438', '\u0439', '\u043A', '\u043B', '\u043C', '\u043D', '\u043E', '\u043F',
|
||||
// 0xF0
|
||||
'\u0440', '\u0441', '\u0442', '\u0443', '\u0444', '\u0445', '\u0446', '\u0447',
|
||||
// 0xF8
|
||||
'\u0448', '\u0449', '\u044A', '\u044B', '\u044C', '\u044D', '\u044E', '\u20AC'
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for displaying content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserDisplay => browserDisplay;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for saving content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserSave => 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 => 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 => mailNewsSave;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding is read-only.
|
||||
/// </summary>
|
||||
/// <value>The is single byte.</value>
|
||||
public override bool IsReadOnly => readOnly;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding uses single-byte code points.
|
||||
/// </summary>
|
||||
public override bool IsSingleByte => singleByte;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the code page identifier of the current Encoding.
|
||||
/// </summary>
|
||||
public override int CodePage => _codepage;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent body tags
|
||||
/// </summary>
|
||||
public override string BodyName => _bodyname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent header tags
|
||||
/// </summary>
|
||||
public override string HeaderName => _headername;
|
||||
|
||||
/// <summary>
|
||||
/// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.
|
||||
/// </summary>
|
||||
public override string WebName => _webname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the human-readable description of the current encoding.
|
||||
/// </summary>
|
||||
public override string EncodingName => _encodingname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Windows operating system code page that most closely corresponds to the current encoding.
|
||||
/// </summary>
|
||||
public override int WindowsCodePage => _windowsCodepage;
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string" />.
|
||||
/// </summary>
|
||||
/// <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) =>
|
||||
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) => 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) => 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) => 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() => 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 override string GetString(byte[] bytes) => 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) =>
|
||||
new string(GetChars(bytes, index, count));
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Mac Ukrainian character to an Unicode character
|
||||
/// </summary>
|
||||
/// <returns>Unicode character.</returns>
|
||||
/// <param name="character">Mac Ukrainian character.</param>
|
||||
static char GetChar(byte character) => MacUkrainianTable[character];
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Unicode character to an Mac Ukrainian character
|
||||
/// </summary>
|
||||
/// <returns>Mac Ukrainian 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 '\u005C': return 0x5C;
|
||||
case '\u005D': return 0x5D;
|
||||
case '\u005E': return 0x5E;
|
||||
case '\u005F': return 0x5F;
|
||||
case '\u0060': return 0x60;
|
||||
case '\u0061': return 0x61;
|
||||
case '\u0062': return 0x62;
|
||||
case '\u0063': return 0x63;
|
||||
case '\u0064': return 0x64;
|
||||
case '\u0065': return 0x65;
|
||||
case '\u0066': return 0x66;
|
||||
case '\u0067': return 0x67;
|
||||
case '\u0068': return 0x68;
|
||||
case '\u0069': return 0x69;
|
||||
case '\u006A': return 0x6A;
|
||||
case '\u006B': return 0x6B;
|
||||
case '\u006C': return 0x6C;
|
||||
case '\u006D': return 0x6D;
|
||||
case '\u006E': return 0x6E;
|
||||
case '\u006F': return 0x6F;
|
||||
case '\u0070': return 0x70;
|
||||
case '\u0071': return 0x71;
|
||||
case '\u0072': return 0x72;
|
||||
case '\u0073': return 0x73;
|
||||
case '\u0074': return 0x74;
|
||||
case '\u0075': return 0x75;
|
||||
case '\u0076': return 0x76;
|
||||
case '\u0077': return 0x77;
|
||||
case '\u0078': return 0x78;
|
||||
case '\u0079': return 0x79;
|
||||
case '\u007A': return 0x7A;
|
||||
case '\u007B': return 0x7B;
|
||||
case '\u007C': return 0x7C;
|
||||
case '\u007D': return 0x7D;
|
||||
case '\u007E': return 0x7E;
|
||||
case '\u007F': return 0x7F;
|
||||
case '\u0410': return 0x80;
|
||||
case '\u0411': return 0x81;
|
||||
case '\u0412': return 0x82;
|
||||
case '\u0413': return 0x83;
|
||||
case '\u0414': return 0x84;
|
||||
case '\u0415': return 0x85;
|
||||
case '\u0416': return 0x86;
|
||||
case '\u0417': return 0x87;
|
||||
case '\u0418': return 0x88;
|
||||
case '\u0419': return 0x89;
|
||||
case '\u041A': return 0x8A;
|
||||
case '\u041B': return 0x8B;
|
||||
case '\u041C': return 0x8C;
|
||||
case '\u041D': return 0x8D;
|
||||
case '\u041E': return 0x8E;
|
||||
case '\u041F': return 0x8F;
|
||||
case '\u0420': return 0x90;
|
||||
case '\u0421': return 0x91;
|
||||
case '\u0422': return 0x92;
|
||||
case '\u0423': return 0x93;
|
||||
case '\u0424': return 0x94;
|
||||
case '\u0425': return 0x95;
|
||||
case '\u0426': return 0x96;
|
||||
case '\u0427': return 0x97;
|
||||
case '\u0428': return 0x98;
|
||||
case '\u0429': return 0x99;
|
||||
case '\u042A': return 0x9A;
|
||||
case '\u042B': return 0x9B;
|
||||
case '\u042C': return 0x9C;
|
||||
case '\u042D': return 0x9D;
|
||||
case '\u042E': return 0x9E;
|
||||
case '\u042F': return 0x9F;
|
||||
case '\u2020': return 0xA0;
|
||||
case '\u00B0': return 0xA1;
|
||||
case '\u0490': return 0xA2;
|
||||
case '\u00A3': return 0xA3;
|
||||
case '\u00A7': return 0xA4;
|
||||
case '\u2022': return 0xA5;
|
||||
case '\u00B6': return 0xA6;
|
||||
case '\u0406': return 0xA7;
|
||||
case '\u00AE': return 0xA8;
|
||||
case '\u00A9': return 0xA9;
|
||||
case '\u2122': return 0xAA;
|
||||
case '\u0402': return 0xAB;
|
||||
case '\u0452': return 0xAC;
|
||||
case '\u2260': return 0xAD;
|
||||
case '\u0403': return 0xAE;
|
||||
case '\u0453': return 0xAF;
|
||||
case '\u221E': return 0xB0;
|
||||
case '\u00B1': return 0xB1;
|
||||
case '\u2264': return 0xB2;
|
||||
case '\u2265': return 0xB3;
|
||||
case '\u0456': return 0xB4;
|
||||
case '\u00B5': return 0xB5;
|
||||
case '\u0491': return 0xB6;
|
||||
case '\u0408': return 0xB7;
|
||||
case '\u0404': return 0xB8;
|
||||
case '\u0454': return 0xB9;
|
||||
case '\u0407': return 0xBA;
|
||||
case '\u0457': return 0xBB;
|
||||
case '\u0409': return 0xBC;
|
||||
case '\u0459': return 0xBD;
|
||||
case '\u040A': return 0xBE;
|
||||
case '\u045A': return 0xBF;
|
||||
case '\u0458': return 0xC0;
|
||||
case '\u0405': return 0xC1;
|
||||
case '\u00AC': return 0xC2;
|
||||
case '\u221A': return 0xC3;
|
||||
case '\u0192': return 0xC4;
|
||||
case '\u2248': return 0xC5;
|
||||
case '\u2206': return 0xC6;
|
||||
case '\u00AB': return 0xC7;
|
||||
case '\u00BB': return 0xC8;
|
||||
case '\u2026': return 0xC9;
|
||||
case '\u00A0': return 0xCA;
|
||||
case '\u040B': return 0xCB;
|
||||
case '\u045B': return 0xCC;
|
||||
case '\u040C': return 0xCD;
|
||||
case '\u045C': return 0xCE;
|
||||
case '\u0455': return 0xCF;
|
||||
case '\u2013': return 0xD0;
|
||||
case '\u2014': return 0xD1;
|
||||
case '\u201C': return 0xD2;
|
||||
case '\u201D': return 0xD3;
|
||||
case '\u2018': return 0xD4;
|
||||
case '\u2019': return 0xD5;
|
||||
case '\u00F7': return 0xD6;
|
||||
case '\u201E': return 0xD7;
|
||||
case '\u040E': return 0xD8;
|
||||
case '\u045E': return 0xD9;
|
||||
case '\u040F': return 0xDA;
|
||||
case '\u045F': return 0xDB;
|
||||
case '\u2116': return 0xDC;
|
||||
case '\u0401': return 0xDD;
|
||||
case '\u0451': return 0xDE;
|
||||
case '\u044F': return 0xDF;
|
||||
case '\u0430': return 0xE0;
|
||||
case '\u0431': return 0xE1;
|
||||
case '\u0432': return 0xE2;
|
||||
case '\u0433': return 0xE3;
|
||||
case '\u0434': return 0xE4;
|
||||
case '\u0435': return 0xE5;
|
||||
case '\u0436': return 0xE6;
|
||||
case '\u0437': return 0xE7;
|
||||
case '\u0438': return 0xE8;
|
||||
case '\u0439': return 0xE9;
|
||||
case '\u043A': return 0xEA;
|
||||
case '\u043B': return 0xEB;
|
||||
case '\u043C': return 0xEC;
|
||||
case '\u043D': return 0xED;
|
||||
case '\u043E': return 0xEE;
|
||||
case '\u043F': return 0xEF;
|
||||
case '\u0440': return 0xF0;
|
||||
case '\u0441': return 0xF1;
|
||||
case '\u0442': return 0xF2;
|
||||
case '\u0443': return 0xF3;
|
||||
case '\u0444': return 0xF4;
|
||||
case '\u0445': return 0xF5;
|
||||
case '\u0446': return 0xF6;
|
||||
case '\u0447': return 0xF7;
|
||||
case '\u0448': return 0xF8;
|
||||
case '\u0449': return 0xF9;
|
||||
case '\u044A': return 0xFA;
|
||||
case '\u044B': return 0xFB;
|
||||
case '\u044C': return 0xFC;
|
||||
case '\u044D': return 0xFD;
|
||||
case '\u044E': return 0xFE;
|
||||
case '\u20AC': return 0xFF;
|
||||
default:
|
||||
// Fallback to '?'
|
||||
return 0x3F;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
// Author:
|
||||
// Michael Drüing <darkstar@drueing.de>
|
||||
//
|
||||
// Copyright (c) 2016 © Michael Drüing
|
||||
// Copyright © 2016-2019 Michael Drüing
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -29,135 +29,171 @@ using System;
|
||||
namespace Claunia.Encoding
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents an Commodore PET Standard Code for Information Interchange (aka CBM ASCII) character encoding of Unicode characters.
|
||||
/// Represents an Commodore PET Standard Code for Information Interchange (aka CBM ASCII) character encoding of Unicode
|
||||
/// characters.
|
||||
/// </summary>
|
||||
public class PETSCII : System.Text.Encoding
|
||||
public class PETSCII : Encoding
|
||||
{
|
||||
const string _bodyname = "petscii";
|
||||
const int _codepage = 0;
|
||||
const string _encodingname = "PET Standard Code for Information Interchange";
|
||||
const string _headername = "petscii";
|
||||
const string _webname = "";
|
||||
const int _windowsCodepage = 0;
|
||||
const string _bodyname = "petscii";
|
||||
const int _codepage = 0;
|
||||
const string _encodingname = "Commodore PET Standard Code for Information Interchange";
|
||||
const string _headername = "petscii";
|
||||
const string _webname = "";
|
||||
const int _windowsCodepage = 0;
|
||||
|
||||
const bool browserDisplay = false;
|
||||
const bool browserSave = false;
|
||||
const bool browserDisplay = false;
|
||||
const bool browserSave = false;
|
||||
const bool mailNewsDisplay = false;
|
||||
const bool mailNewsSave = false;
|
||||
const bool readOnly = false;
|
||||
const bool singleByte = true;
|
||||
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.
|
||||
/// The PETSCII to Unicode character map, unshifted (default) variant.
|
||||
/// </summary>
|
||||
public bool IsBrowserDisplay
|
||||
/// <remarks>Reference used: http://style64.org/petscii/ and others.</remarks>
|
||||
static readonly char[] PETSCIITable =
|
||||
{
|
||||
get { return browserDisplay; }
|
||||
}
|
||||
// 0x00
|
||||
'\u0000', '\u0000', '\u0000', '\u0003', '\u0000', '\u0000', '\u0000', '\u0000',
|
||||
// 0x08
|
||||
'\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u000A', '\u0000', '\u0000',
|
||||
// 0x10
|
||||
'\u0000', '\u0000', '\u0000', '\u0000', '\u0008', '\u0000', '\u0000', '\u0000',
|
||||
// 0x18
|
||||
'\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000',
|
||||
// 0x20
|
||||
'\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027',
|
||||
// 0x28
|
||||
'\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F',
|
||||
// 0x30
|
||||
'\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037',
|
||||
// 0x38
|
||||
'\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F',
|
||||
// 0x40
|
||||
'\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047',
|
||||
// 0x48
|
||||
'\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F',
|
||||
// 0x50
|
||||
'\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057',
|
||||
// 0x58
|
||||
'\u0058', '\u0059', '\u005A', '\u005B', '\u00A3', '\u005D', '\u2191', '\u2190',
|
||||
// 0x60
|
||||
'\u2500', '\u2660', '\u2502', '\u2500', '\u0000', '\u0000', '\u0000', '\u0000',
|
||||
// 0x68
|
||||
'\u0000', '\u256E', '\u2570', '\u256F', '\u0000', '\u2572', '\u2571', '\u0000',
|
||||
// 0x70
|
||||
'\u0000', '\u2022', '\u0000', '\u2665', '\u0000', '\u256D', '\u2573', '\u25CB',
|
||||
// 0x78
|
||||
'\u2663', '\u0000', '\u2666', '\u253C', '\u0000', '\u2502', '\u03C0', '\u25E5',
|
||||
// 0x80
|
||||
'\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000',
|
||||
// 0x88
|
||||
'\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u2028', '\u0000', '\u0000',
|
||||
// 0x90
|
||||
'\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000',
|
||||
// 0x98
|
||||
'\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000',
|
||||
// 0xA0
|
||||
'\u00A0', '\u258C', '\u2584', '\u2594', '\u2581', '\u258E', '\u2592', '\u0000',
|
||||
// 0xA8
|
||||
'\u0000', '\u25E4', '\u258A', '\u251C', '\u2597', '\u2514', '\u2510', '\u2582',
|
||||
// 0xB0
|
||||
'\u250C', '\u2534', '\u252C', '\u2524', '\u258E', '\u258D', '\u0000', '\u0000',
|
||||
// 0xB8
|
||||
'\u0000', '\u2583', '\u0000', '\u2596', '\u259D', '\u2518', '\u2598', '\u259A',
|
||||
// 0xC0 (repeats 0x60 - 0x67)
|
||||
'\u2500', '\u2660', '\u2502', '\u2500', '\u0000', '\u0000', '\u0000', '\u0000',
|
||||
// 0xC8 (repeats 0x68 - 0x6F)
|
||||
'\u0000', '\u256E', '\u2570', '\u256F', '\u0000', '\u2572', '\u2571', '\u0000',
|
||||
// 0xD0 (repeats 0x70 - 0x77)
|
||||
'\u0000', '\u2022', '\u0000', '\u2665', '\u0000', '\u256D', '\u2573', '\u25CB',
|
||||
// 0xD8 (repeats 0x78 - 0x7F)
|
||||
'\u2663', '\u0000', '\u2666', '\u253C', '\u0000', '\u2502', '\u03C0', '\u25E5',
|
||||
// 0xE0 (repeats 0xA0 - 0xA7)
|
||||
'\u00A0', '\u258C', '\u2584', '\u2594', '\u2581', '\u258E', '\u2592', '\u0000',
|
||||
// 0xE8 (repeats 0xA8 - 0xAF)
|
||||
'\u0000', '\u25E4', '\u258A', '\u251C', '\u2597', '\u2514', '\u2510', '\u2582',
|
||||
// 0xF0 (repeats 0xB0 - 0xB7)
|
||||
'\u250C', '\u2534', '\u252C', '\u2524', '\u258E', '\u258D', '\u0000', '\u0000',
|
||||
// 0xF8 (repeats 0xB8 - 0xBF)
|
||||
'\u0000', '\u2583', '\u0000', '\u2596', '\u259D', '\u2518', '\u2598', '\u259A'
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for saving content.
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for displaying content.
|
||||
/// </summary>
|
||||
public bool IsBrowserSave
|
||||
{
|
||||
get { return browserSave; }
|
||||
}
|
||||
public override bool IsBrowserDisplay => browserDisplay;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content.
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for saving content.
|
||||
/// </summary>
|
||||
public bool IsMailNewsDisplay
|
||||
{
|
||||
get { return mailNewsDisplay; }
|
||||
}
|
||||
public override bool IsBrowserSave => browserSave;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content.
|
||||
/// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content.
|
||||
/// </summary>
|
||||
public bool IsMailNewsSave
|
||||
{
|
||||
get { return mailNewsSave; }
|
||||
}
|
||||
public override bool IsMailNewsDisplay => mailNewsDisplay;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding is read-only.
|
||||
/// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content.
|
||||
/// </summary>
|
||||
public bool IsReadOnly
|
||||
{
|
||||
get { return readOnly; }
|
||||
}
|
||||
public override bool IsMailNewsSave => mailNewsSave;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding uses single-byte code points.
|
||||
/// Gets a value indicating whether the current encoding is read-only.
|
||||
/// </summary>
|
||||
public bool IsSingleByte
|
||||
{
|
||||
get { return singleByte; }
|
||||
}
|
||||
public override bool IsReadOnly => readOnly;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the code page identifier of the current Encoding.
|
||||
/// Gets a value indicating whether the current encoding uses single-byte code points.
|
||||
/// </summary>
|
||||
public int CodePage
|
||||
{
|
||||
get { return _codepage; }
|
||||
}
|
||||
public override bool IsSingleByte => singleByte;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent body tags
|
||||
/// Gets the code page identifier of the current Encoding.
|
||||
/// </summary>
|
||||
public string BodyName
|
||||
{
|
||||
get { return _bodyname; }
|
||||
}
|
||||
public override int CodePage => _codepage;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent header tags
|
||||
/// Gets a name for the current encoding that can be used with mail agent body tags
|
||||
/// </summary>
|
||||
public string HeaderName
|
||||
{
|
||||
get { return _headername; }
|
||||
}
|
||||
public override string BodyName => _bodyname;
|
||||
|
||||
/// <summary>
|
||||
/// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.
|
||||
/// Gets a name for the current encoding that can be used with mail agent header tags
|
||||
/// </summary>
|
||||
public override string WebName
|
||||
{
|
||||
get { return _webname; }
|
||||
}
|
||||
public override string HeaderName => _headername;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the human-readable description of the current encoding.
|
||||
/// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.
|
||||
/// </summary>
|
||||
public string EncodingName
|
||||
{
|
||||
get { return _encodingname; }
|
||||
}
|
||||
public override string WebName => _webname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Windows operating system code page that most closely corresponds to the current encoding.
|
||||
/// Gets the human-readable description of the current encoding.
|
||||
/// </summary>
|
||||
public int WindowsCodePage
|
||||
{
|
||||
get { return _windowsCodepage; }
|
||||
}
|
||||
public override string EncodingName => _encodingname;
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string"/>.
|
||||
/// Gets the Windows operating system code page that most closely corresponds to the current encoding.
|
||||
/// </summary>
|
||||
public override int WindowsCodePage => _windowsCodepage;
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string" />.
|
||||
/// </summary>
|
||||
/// <returns>The number of bytes produced by encoding the specified characters.</returns>
|
||||
/// <param name="s">The <see cref="string"/> containing the set of characters to encode.</param>
|
||||
/// <param name="s">The <see cref="string" /> containing the set of characters to encode.</param>
|
||||
public override int GetByteCount(string s)
|
||||
{
|
||||
if (s == null)
|
||||
throw new ArgumentNullException(nameof(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.
|
||||
/// 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>
|
||||
@@ -165,60 +201,53 @@ namespace Claunia.Encoding
|
||||
/// <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(chars == null) throw new ArgumentNullException(nameof(chars));
|
||||
|
||||
if (index < 0 || index >= chars.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
if(index < 0 || index >= chars.Length) throw new ArgumentOutOfRangeException(nameof(index));
|
||||
|
||||
if (count < 0 || index + count > chars.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
if(count < 0 || index + count > chars.Length) throw new ArgumentOutOfRangeException(nameof(index));
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the number of bytes produced by encoding all the characters in the specified character array.
|
||||
/// Calculates the number of bytes produced by encoding all the characters in the specified character array.
|
||||
/// </summary>
|
||||
/// <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));
|
||||
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.
|
||||
/// 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="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);
|
||||
}
|
||||
public override int GetBytes(string s, int charIndex, int charCount, byte[] bytes, int byteIndex) =>
|
||||
GetBytes(s.ToCharArray(), charIndex, charCount, bytes, byteIndex);
|
||||
|
||||
/// <summary>
|
||||
/// Encodes all the characters in the specified string into a sequence of bytes.
|
||||
/// Encodes all the characters in the specified string into a sequence of bytes.
|
||||
/// </summary>
|
||||
/// <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));
|
||||
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.
|
||||
/// 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>
|
||||
@@ -228,43 +257,33 @@ namespace Claunia.Encoding
|
||||
/// <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(chars == null) throw new ArgumentNullException(nameof(chars));
|
||||
|
||||
if (bytes == null)
|
||||
throw new ArgumentNullException(nameof(bytes));
|
||||
if(bytes == null) throw new ArgumentNullException(nameof(bytes));
|
||||
|
||||
if (charIndex < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||
if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||
|
||||
if (charCount < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(charCount));
|
||||
if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount));
|
||||
|
||||
if (byteIndex < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||
if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||
|
||||
if (charIndex >= chars.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||
if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||
|
||||
if (charCount + charIndex > chars.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(charCount));
|
||||
if(charCount + charIndex > chars.Length) throw new ArgumentOutOfRangeException(nameof(charCount));
|
||||
|
||||
if (byteIndex >= bytes.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||
if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||
|
||||
if (byteIndex + charCount > bytes.Length)
|
||||
throw new ArgumentException(nameof(bytes));
|
||||
if(byteIndex + charCount > bytes.Length) throw new ArgumentException(nameof(bytes));
|
||||
|
||||
byte[] temp = GetBytes(chars, charIndex, charCount);
|
||||
|
||||
for (int i = 0; i < temp.Length; i++)
|
||||
bytes[i + byteIndex] = temp[i];
|
||||
for(int i = 0; i < temp.Length; i++) bytes[i + byteIndex] = temp[i];
|
||||
|
||||
return charCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encodes a set of characters from the specified character array into a sequence of bytes.
|
||||
/// Encodes a set of characters from the specified character array into a sequence of bytes.
|
||||
/// </summary>
|
||||
/// <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>
|
||||
@@ -272,48 +291,37 @@ namespace Claunia.Encoding
|
||||
/// <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(chars == null) throw new ArgumentNullException(nameof(chars));
|
||||
|
||||
if (index < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
if(index < 0) throw new ArgumentOutOfRangeException(nameof(index));
|
||||
|
||||
if (count < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(count));
|
||||
if(count < 0) throw new ArgumentOutOfRangeException(nameof(count));
|
||||
|
||||
if (count + index > chars.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(count));
|
||||
if(count + index > chars.Length) throw new ArgumentOutOfRangeException(nameof(count));
|
||||
|
||||
byte[] bytes = new byte[count];
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
bytes[i] = GetByte(chars[index + i]);
|
||||
for(int i = 0; i < count; i++) bytes[i] = GetByte(chars[index + i]);
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encodes all the characters in the specified character array into a sequence of bytes.
|
||||
/// Encodes all the characters in the specified character array into a sequence of bytes.
|
||||
/// </summary>
|
||||
/// <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);
|
||||
}
|
||||
public override byte[] GetBytes(char[] chars) => GetBytes(chars, 0, chars.Length);
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the number of characters produced by decoding all the bytes in the specified byte array.
|
||||
/// Calculates the number of characters produced by decoding all the bytes in the specified byte array.
|
||||
/// </summary>
|
||||
/// <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);
|
||||
}
|
||||
public override int GetCharCount(byte[] bytes) => GetCharCount(bytes, 0, bytes.Length);
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array.
|
||||
/// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array.
|
||||
/// </summary>
|
||||
/// <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>
|
||||
@@ -321,23 +329,19 @@ namespace Claunia.Encoding
|
||||
/// <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(bytes == null) throw new ArgumentNullException(nameof(bytes));
|
||||
|
||||
if (index < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
if(index < 0) throw new ArgumentOutOfRangeException(nameof(index));
|
||||
|
||||
if (count < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(count));
|
||||
if(count < 0) throw new ArgumentOutOfRangeException(nameof(count));
|
||||
|
||||
if (count + index > bytes.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(count));
|
||||
if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count));
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a sequence of bytes from the specified byte array into the specified character array.
|
||||
/// Decodes a sequence of bytes from the specified byte array into the specified character array.
|
||||
/// </summary>
|
||||
/// <returns>The actual number of characters written into chars.</returns>
|
||||
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
|
||||
@@ -347,53 +351,40 @@ namespace Claunia.Encoding
|
||||
/// <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(bytes == null) throw new ArgumentNullException(nameof(bytes));
|
||||
|
||||
if (chars == null)
|
||||
throw new ArgumentNullException(nameof(chars));
|
||||
if(chars == null) throw new ArgumentNullException(nameof(chars));
|
||||
|
||||
if (byteIndex < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||
if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||
|
||||
if (byteCount < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(byteCount));
|
||||
if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount));
|
||||
|
||||
if (charIndex < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||
if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||
|
||||
if (byteIndex >= bytes.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||
if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||
|
||||
if (byteCount + byteIndex > bytes.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(byteCount));
|
||||
if(byteCount + byteIndex > bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteCount));
|
||||
|
||||
if (charIndex >= chars.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||
if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||
|
||||
if (charIndex + byteCount > chars.Length)
|
||||
throw new ArgumentException(nameof(chars));
|
||||
if(charIndex + byteCount > chars.Length) throw new ArgumentException(nameof(chars));
|
||||
|
||||
char[] temp = GetChars(bytes, byteIndex, byteCount);
|
||||
|
||||
for (int i = 0; i < temp.Length; i++)
|
||||
chars[i + charIndex] = temp[i];
|
||||
for(int i = 0; i < temp.Length; i++) chars[i + charIndex] = temp[i];
|
||||
|
||||
return byteCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes all the bytes in the specified byte array into a set of characters.
|
||||
/// Decodes all the bytes in the specified byte array into a set of characters.
|
||||
/// </summary>
|
||||
/// <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);
|
||||
}
|
||||
public override char[] GetChars(byte[] bytes) => GetChars(bytes, 0, bytes.Length);
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a sequence of bytes from the specified byte array into a set of characters.
|
||||
/// Decodes a sequence of bytes from the specified byte array into a set of characters.
|
||||
/// </summary>
|
||||
/// <returns>The chars.</returns>
|
||||
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
|
||||
@@ -401,183 +392,88 @@ namespace Claunia.Encoding
|
||||
/// <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(bytes == null) throw new ArgumentNullException(nameof(bytes));
|
||||
|
||||
if (index < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
if(index < 0) throw new ArgumentOutOfRangeException(nameof(index));
|
||||
|
||||
if (count < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(count));
|
||||
if(count < 0) throw new ArgumentOutOfRangeException(nameof(count));
|
||||
|
||||
if (count + index > bytes.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(count));
|
||||
if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count));
|
||||
|
||||
char[] chars = new char[count];
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
chars[i] = GetChar(bytes[index + i]);
|
||||
for(int i = 0; i < count; i++) chars[i] = GetChar(bytes[index + i]);
|
||||
|
||||
return chars;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the maximum number of bytes produced by encoding the specified number of characters.
|
||||
/// Calculates the maximum number of bytes produced by encoding the specified number of characters.
|
||||
/// </summary>
|
||||
/// <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));
|
||||
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.
|
||||
/// 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));
|
||||
if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount));
|
||||
|
||||
return byteCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a sequence of bytes that specifies the encoding used.
|
||||
/// 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];
|
||||
}
|
||||
public override byte[] GetPreamble() => new byte[0];
|
||||
|
||||
/// <summary>
|
||||
/// Decodes all the bytes in the specified byte array into a string.
|
||||
/// Decodes all the bytes in the specified byte array into a string.
|
||||
/// </summary>
|
||||
/// <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);
|
||||
}
|
||||
public override string GetString(byte[] bytes) => GetString(bytes, 0, bytes.Length);
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a sequence of bytes from the specified byte array into a string.
|
||||
/// Decodes a sequence of bytes from the specified byte array into a string.
|
||||
/// </summary>
|
||||
/// <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));
|
||||
}
|
||||
public override string GetString(byte[] bytes, int index, int count) =>
|
||||
new string(GetChars(bytes, index, count));
|
||||
|
||||
/// <summary>
|
||||
/// The PETSCII to Unicode character map, unshifted (default) variant.
|
||||
/// </summary>
|
||||
/// <remarks>Reference used: http://style64.org/petscii/ and others.</remarks>
|
||||
static readonly char[] PETSCIITable = {
|
||||
// 0x00
|
||||
'\u0000','\u0000','\u0000','\u0003','\u0000','\u0000','\u0000','\u0000',
|
||||
// 0x08
|
||||
'\u0000','\u0000','\u0000','\u0000','\u0000','\u000A','\u0000','\u0000',
|
||||
// 0x10
|
||||
'\u0000','\u0000','\u0000','\u0000','\u0008','\u0000','\u0000','\u0000',
|
||||
// 0x18
|
||||
'\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000',
|
||||
// 0x20
|
||||
'\u0020','\u0021','\u0022','\u0023','\u0024','\u0025','\u0026','\u0027',
|
||||
// 0x28
|
||||
'\u0028','\u0029','\u002A','\u002B','\u002C','\u002D','\u002E','\u002F',
|
||||
// 0x30
|
||||
'\u0030','\u0031','\u0032','\u0033','\u0034','\u0035','\u0036','\u0037',
|
||||
// 0x38
|
||||
'\u0038','\u0039','\u003A','\u003B','\u003C','\u003D','\u003E','\u003F',
|
||||
// 0x40
|
||||
'\u0040','\u0041','\u0042','\u0043','\u0044','\u0045','\u0046','\u0047',
|
||||
// 0x48
|
||||
'\u0048','\u0049','\u004A','\u004B','\u004C','\u004D','\u004E','\u004F',
|
||||
// 0x50
|
||||
'\u0050','\u0051','\u0052','\u0053','\u0054','\u0055','\u0056','\u0057',
|
||||
// 0x58
|
||||
'\u0058','\u0059','\u005A','\u005B','\u00A3','\u005D','\u2191','\u2190',
|
||||
// 0x60
|
||||
'\u2500','\u2660','\u2502','\u2500','\u0000','\u0000','\u0000','\u0000',
|
||||
// 0x68
|
||||
'\u0000','\u256E','\u2570','\u256F','\u0000','\u2572','\u2571','\u0000',
|
||||
// 0x70
|
||||
'\u0000','\u2022','\u0000','\u2665','\u0000','\u256D','\u2573','\u25CB',
|
||||
// 0x78
|
||||
'\u2663','\u0000','\u2666','\u253C','\u0000','\u2502','\u03C0','\u25E5',
|
||||
// 0x80
|
||||
'\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000',
|
||||
// 0x88
|
||||
'\u0000','\u0000','\u0000','\u0000','\u0000','\u2028','\u0000','\u0000',
|
||||
// 0x90
|
||||
'\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000',
|
||||
// 0x98
|
||||
'\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000',
|
||||
// 0xA0
|
||||
'\u00A0','\u258C','\u2584','\u2594','\u2581','\u258E','\u2592','\u0000',
|
||||
// 0xA8
|
||||
'\u0000','\u25E4','\u258A','\u251C','\u2597','\u2514','\u2510','\u2582',
|
||||
// 0xB0
|
||||
'\u250C','\u2534','\u252C','\u2524','\u258E','\u258D','\u0000','\u0000',
|
||||
// 0xB8
|
||||
'\u0000','\u2583','\u0000','\u2596','\u259D','\u2518','\u2598','\u259A',
|
||||
// 0xC0 (repeats 0x60 - 0x67)
|
||||
'\u2500','\u2660','\u2502','\u2500','\u0000','\u0000','\u0000','\u0000',
|
||||
// 0xC8 (repeats 0x68 - 0x6F)
|
||||
'\u0000','\u256E','\u2570','\u256F','\u0000','\u2572','\u2571','\u0000',
|
||||
// 0xD0 (repeats 0x70 - 0x77)
|
||||
'\u0000','\u2022','\u0000','\u2665','\u0000','\u256D','\u2573','\u25CB',
|
||||
// 0xD8 (repeats 0x78 - 0x7F)
|
||||
'\u2663','\u0000','\u2666','\u253C','\u0000','\u2502','\u03C0','\u25E5',
|
||||
// 0xE0 (repeats 0xA0 - 0xA7)
|
||||
'\u00A0','\u258C','\u2584','\u2594','\u2581','\u258E','\u2592','\u0000',
|
||||
// 0xE8 (repeats 0xA8 - 0xAF)
|
||||
'\u0000','\u25E4','\u258A','\u251C','\u2597','\u2514','\u2510','\u2582',
|
||||
// 0xF0 (repeats 0xB0 - 0xB7)
|
||||
'\u250C','\u2534','\u252C','\u2524','\u258E','\u258D','\u0000','\u0000',
|
||||
// 0xF8 (repeats 0xB8 - 0xBF)
|
||||
'\u0000','\u2583','\u0000','\u2596','\u259D','\u2518','\u2598','\u259A',
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Converts a PETSCII character to an Unicode character
|
||||
/// Converts a PETSCII character to an Unicode character
|
||||
/// </summary>
|
||||
/// <returns>Unicode character.</returns>
|
||||
/// <param name="character">PETSCII character.</param>
|
||||
static char GetChar(byte character)
|
||||
{
|
||||
return PETSCIITable[character];
|
||||
}
|
||||
static char GetChar(byte character) => PETSCIITable[character];
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Unicode character to an PETSCII character
|
||||
/// Converts a Unicode character to an PETSCII character
|
||||
/// </summary>
|
||||
/// <returns>PETSCII character.</returns>
|
||||
/// <param name="character">Unicode character.</param>
|
||||
static byte GetByte(char character)
|
||||
{
|
||||
if (character == 0x0000)
|
||||
{
|
||||
// TODO: would returning 0x00 be more correct?
|
||||
return 0x3F;
|
||||
}
|
||||
if(character == 0x0000) return 0x3F;
|
||||
|
||||
for (int i = 0; i < 256; i++)
|
||||
{
|
||||
for(int i = 0; i < 256; i++)
|
||||
// TODO: convert this to a gigantic switch statement too?
|
||||
if (PETSCIITable[i] == character)
|
||||
if(PETSCIITable[i] == character)
|
||||
return (byte)i;
|
||||
}
|
||||
|
||||
// Fallback to '?'
|
||||
return 0x3F;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright (c) 2016 © Claunia.com
|
||||
// Copyright © 2016-2019 Natalia Portillo
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -23,26 +23,29 @@
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System;
|
||||
|
||||
namespace Claunia.Encoding
|
||||
{
|
||||
/// <summary>
|
||||
/// Class containing pangrams for several languages that can be used to test encoding.
|
||||
/// Class containing pangrams for several languages that can be used to test encoding.
|
||||
/// </summary>
|
||||
public static class Pangrams
|
||||
{
|
||||
/// <summary>A pangram that contains all (or most) Arabic characters.</summary>
|
||||
public const string Arabic = "صِف خَلقَ خَودِ كَمِثلِ الشَمسِ إِذ بَزَغَت — يَحظى الضَجيعُ بِها نَجلاءَ مِعطارِ";
|
||||
public const string Arabic =
|
||||
"صِف خَلقَ خَودِ كَمِثلِ الشَمسِ إِذ بَزَغَت — يَحظى الضَجيعُ بِها نَجلاءَ مِعطارِ";
|
||||
/// <summary>A pangram that contains all (or most) Azeri characters.</summary>
|
||||
public const string Azeri = "Zəfər, jaketini də papağını da götür, bu axşam hava çox soyuq olacaq.";
|
||||
/// <summary>A pangram that contains all (or most) Basque characters.</summary>
|
||||
public const string Basque = "Vaudeville itxurako filmean, yogi ñaño bat jipoitzen dute Quebec-en, whiski truk";
|
||||
/// <summary>A pangram that contains all (or most) Breton characters.</summary>
|
||||
public const string Breton = "Yec’hed mat Jakez ! Skarzhit ar gwerennoù-mañ, kavet e vo gwin betek fin ho puhez.";
|
||||
public const string Breton =
|
||||
"Yec’hed mat Jakez ! Skarzhit ar gwerennoù-mañ, kavet e vo gwin betek fin ho puhez.";
|
||||
/// <summary>A pangram that contains all (or most) Bulgarian characters.</summary>
|
||||
public const string Bulgarian = "Хълцащ змей плюе шофьор стигнал чуждия бивак.";
|
||||
/// <summary>A pangram that contains all (or most) Catalan characters.</summary>
|
||||
public const string Catalan = "«Dóna amor que seràs feliç!». Això, il·lús company geniüt, ja és un lluït rètol blavís d’onze kWh.";
|
||||
public const string Catalan =
|
||||
"«Dóna amor que seràs feliç!». Això, il·lús company geniüt, ja és un lluït rètol blavís d’onze kWh.";
|
||||
/// <summary>A pangram that contains Traditional Chinese characters.</summary>
|
||||
public const string ChineseTraditional = "視野無限廣,窗外有藍天";
|
||||
/// <summary>A pangram that contains Simplified Chinese characters.</summary>
|
||||
@@ -50,9 +53,11 @@ namespace Claunia.Encoding
|
||||
/// <summary>A pangram that contains all (or most) Croatian characters.</summary>
|
||||
public const string Croatian = "Gojazni đačić s biciklom drži hmelj i finu vatu u džepu nošnje.";
|
||||
/// <summary>A pangram that contains all (or most) Czech characters.</summary>
|
||||
public const string Czech = "Nechť již hříšné saxofony ďáblů rozezvučí síň úděsnými tóny waltzu, tanga a quickstepu.";
|
||||
public const string Czech =
|
||||
"Nechť již hříšné saxofony ďáblů rozezvučí síň úděsnými tóny waltzu, tanga a quickstepu.";
|
||||
/// <summary>A pangram that contains all (or most) Danish characters.</summary>
|
||||
public const string Danish = "Quizdeltagerne spiste jordbær med fløde, mens cirkusklovnen Walther spillede på xylofon.";
|
||||
public const string Danish =
|
||||
"Quizdeltagerne spiste jordbær med fløde, mens cirkusklovnen Walther spillede på xylofon.";
|
||||
/// <summary>A pangram that contains all (or most) Dutch characters.</summary>
|
||||
public const string Dutch = "Pa’s wijze lynx bezag vroom het fikse aquaduct.";
|
||||
/// <summary>A pangram that contains all (or most) English characters.</summary>
|
||||
@@ -62,17 +67,22 @@ namespace Claunia.Encoding
|
||||
/// <summary>A pangram that contains all (or most) Estonian characters.</summary>
|
||||
public const string Estonian = "Põdur Zagrebi tšellomängija-följetonist Ciqo külmetas kehvas garaažis.";
|
||||
/// <summary>A pangram that contains all (or most) Finnish characters.</summary>
|
||||
public const string Finnish = "Fahrenheit ja Celsius yrjösivät Åsan backgammon-peliin, Volkswagenissa, daiquirin ja ZX81:n yhteisvaikutuksesta.";
|
||||
public const string Finnish =
|
||||
"Fahrenheit ja Celsius yrjösivät Åsan backgammon-peliin, Volkswagenissa, daiquirin ja ZX81:n yhteisvaikutuksesta.";
|
||||
/// <summary>A pangram that contains all (or most) French characters.</summary>
|
||||
public const string French = "Le cœur déçu mais l'âme plutôt naïve, Louÿs rêva de crapaüter en canoë au delà des îles, près du mälströn où brûlent les novæ.";
|
||||
public const string French =
|
||||
"Le cœur déçu mais l'âme plutôt naïve, Louÿs rêva de crapaüter en canoë au delà des îles, près du mälströn où brûlent les novæ.";
|
||||
/// <summary>A pangram that contains all (or most) Galician characters.</summary>
|
||||
public const string Galician = "Necesitamos unha tipografía chuliña de cor kiwi, que lle zorregue unha labazada visual á xente.";
|
||||
public const string Galician =
|
||||
"Necesitamos unha tipografía chuliña de cor kiwi, que lle zorregue unha labazada visual á xente.";
|
||||
/// <summary>A pangram that contains all (or most) German characters.</summary>
|
||||
public const string German = "Falsches Üben von Xylophonmusik quält jeden größeren Zwerg.";
|
||||
/// <summary>A pangram that contains all (or most) Greek characters.</summary>
|
||||
public const string Greek = "Ταχίστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός Takhístè alôpèx vaphês psèménè gè, draskelízei ypér nòthroý kynós.";
|
||||
public const string Greek =
|
||||
"Ταχίστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός Takhístè alôpèx vaphês psèménè gè, draskelízei ypér nòthroý kynós.";
|
||||
/// <summary>A pangram that contains all (or most) Hebrew characters.</summary>
|
||||
public const string Hebrew = "לכן חכו לי נאם יהוה ליום קומי לעד, כי משפטי לאסף גוים לקבצי ממלכות, לשפך עליהם זעמי כל חרון אפי, כי באש קנאתי תאכל כל הארץ";
|
||||
public const string Hebrew =
|
||||
"לכן חכו לי נאם יהוה ליום קומי לעד, כי משפטי לאסף גוים לקבצי ממלכות, לשפך עליהם זעמי כל חרון אפי, כי באש קנאתי תאכל כל הארץ";
|
||||
/// <summary>A pangram that contains all (or most) Hungarian characters.</summary>
|
||||
public const string Hungarian = "Jó foxim és don Quijote húszwattos lámpánál ülve egy pár bűvös cipőt készít.";
|
||||
/// <summary>A pangram that contains all (or most) Icelandic characters.</summary>
|
||||
@@ -81,7 +91,7 @@ namespace Claunia.Encoding
|
||||
public const string Irish = "Ċuaiġ bé ṁórṡáċ le dlúṫspád fíorḟinn trí hata mo ḋea-ṗorcáin ḃig";
|
||||
/// <summary>A pangram that contains all (or most) Japanese kanas.</summary>
|
||||
public const string Japanese = "いろはにほへと ちりぬるを わかよたれそ つねならむ うゐのおくやま けふこえて あさきゆめみし ゑひもせす(ん)";
|
||||
/// <summary><see cref="Japanese"/> using Kanjis</summary>
|
||||
/// <summary><see cref="Japanese" /> using Kanjis</summary>
|
||||
public const string JapaneseKanji = "色は匂へど 散りぬるを 我が世誰ぞ 常ならむ 有為の奥山 今日越えて 浅き夢見じ 酔ひもせず(ん)";
|
||||
/// <summary>A pangram that contains all (or most) Korean characters.</summary>
|
||||
public const string Korean = "키스의 고유조건은 입술끼리 만나야 하고 특별한 기술은 필요치 않다";
|
||||
@@ -96,21 +106,25 @@ namespace Claunia.Encoding
|
||||
/// <summary>A pangram that contains all (or most) Polish characters.</summary>
|
||||
public const string Polish = "Jeżu klątw, spłódź Finom część gry hańb!";
|
||||
/// <summary>A pangram that contains all (or most) Portuguese characters.</summary>
|
||||
public const string Portuguese = "À noite, vovô Kowalsky vê o ímã cair no pé do pingüim queixoso e vovó põe açúcar no chá de tâmaras do jabuti feliz.";
|
||||
public const string Portuguese =
|
||||
"À noite, vovô Kowalsky vê o ímã cair no pé do pingüim queixoso e vovó põe açúcar no chá de tâmaras do jabuti feliz.";
|
||||
/// <summary>A pangram that contains all (or most) Romanian characters.</summary>
|
||||
public const string Romanian = "Înjurând pițigăiat, zoofobul comandă vexat whisky și tequila.";
|
||||
/// <summary>A pangram that contains all (or most) Russian characters.</summary>
|
||||
public const string Russian = "Широкая электрификация южных губерний даст мощный толчок подъёму сельского хозяйства.";
|
||||
public const string Russian =
|
||||
"Широкая электрификация южных губерний даст мощный толчок подъёму сельского хозяйства.";
|
||||
/// <summary>A pangram that contains all (or most) Scottish Gaelic characters.</summary>
|
||||
public const string Scottish = "Mus d’fhàg Cèit-Ùna ròp Ì le ob.";
|
||||
/// <summary>A pangram that contains all (or most) Serbian characters.</summary>
|
||||
public const string Serbian = "Gojazni đačić s biciklom drži hmelj i finu vatu u džepu nošnje.";
|
||||
/// <summary>A pangram that contains all (or most) Slovak characters.</summary>
|
||||
public const string Slovak = "Kŕdeľ šťastných ďatľov učí pri ústí Váhu mĺkveho koňa obhrýzať kôru a žrať čerstvé mäso.";
|
||||
public const string Slovak =
|
||||
"Kŕdeľ šťastných ďatľov učí pri ústí Váhu mĺkveho koňa obhrýzať kôru a žrať čerstvé mäso.";
|
||||
/// <summary>A pangram that contains all (or most) Slovenian characters.</summary>
|
||||
public const string Slovenian = "Besni dirkač iz formule žuga cehu poštarjev.";
|
||||
/// <summary>A pangram that contains all (or most) Spanish characters.</summary>
|
||||
public const string Spanish = "El veloz murciélago hindú comía feliz cardillo y kiwi. La cigüeña tocaba el saxofón detrás del palenque de paja.";
|
||||
public const string Spanish =
|
||||
"El veloz murciélago hindú comía feliz cardillo y kiwi. La cigüeña tocaba el saxofón detrás del palenque de paja.";
|
||||
/// <summary>A pangram that contains all (or most) Swedish characters.</summary>
|
||||
public const string Swedish = "Flygande bäckasiner söka hwila på mjuka tuvor.";
|
||||
/// <summary>A pangram that contains all (or most) Turkish characters.</summary>
|
||||
@@ -118,5 +132,4 @@ namespace Claunia.Encoding
|
||||
/// <summary>A pangram that contains all (or most) Welsh characters.</summary>
|
||||
public const string Welsh = "Parciais fy jac codi baw hud llawn dŵr ger tŷ Mabon.";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo claunia@claunia.com
|
||||
//
|
||||
// Copyright (c) 2016, © Claunia.com
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the [ORGANIZATION] nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
// Information about this assembly is defined by the following attributes.
|
||||
// Change them to the values specific to your project.
|
||||
|
||||
[assembly: AssemblyTitle ("Claunia.Encoding")]
|
||||
[assembly: AssemblyDescription ("")]
|
||||
[assembly: AssemblyConfiguration ("")]
|
||||
[assembly: AssemblyCompany ("Claunia.com")]
|
||||
[assembly: AssemblyProduct ("")]
|
||||
[assembly: AssemblyCopyright ("© Claunia.com")]
|
||||
[assembly: AssemblyTrademark ("")]
|
||||
[assembly: AssemblyCulture ("")]
|
||||
|
||||
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
|
||||
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
|
||||
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
|
||||
|
||||
[assembly: AssemblyVersion ("1.0.*")]
|
||||
|
||||
// The following attributes are used to specify the signing key for the assembly,
|
||||
// if desired. See the Mono documentation for more information about signing.
|
||||
|
||||
//[assembly: AssemblyDelaySign(false)]
|
||||
//[assembly: AssemblyKeyFile("")]
|
||||
|
||||
527
Claunia.Encoding/Radix50.cs
Normal file
527
Claunia.Encoding/Radix50.cs
Normal file
@@ -0,0 +1,527 @@
|
||||
//
|
||||
// Apple II.cs
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright © 2016-2019 Natalia Portillo
|
||||
//
|
||||
// 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 Radix-50 (PDP-11) character encoding of Unicode characters.
|
||||
/// </summary>
|
||||
public class Radix50 : Encoding
|
||||
{
|
||||
const string _bodyname = "radix50";
|
||||
const int _codepage = 0;
|
||||
const string _encodingname = "Western European (Radix-50)";
|
||||
const string _headername = "radix50";
|
||||
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 = false;
|
||||
|
||||
/// <summary>
|
||||
/// The Radix-50 to Unicode character map, when bits are shifted right
|
||||
/// </summary>
|
||||
static readonly char[] Radix50Table =
|
||||
{
|
||||
// 0x00
|
||||
'\u0020', '\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', '\u0024', '\u002E', '\u0025', '\u0030', '\u0031',
|
||||
// 0x20
|
||||
'\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039',
|
||||
// 0x28 (unused but legal)
|
||||
'\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000',
|
||||
// 0x30 (unused but legal)
|
||||
'\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000',
|
||||
// 0x38 (unused but legal)
|
||||
'\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000'
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for displaying content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserDisplay => browserDisplay;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for saving content.
|
||||
/// </summary>
|
||||
public override bool IsBrowserSave => 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 => 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 => mailNewsSave;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding is read-only.
|
||||
/// </summary>
|
||||
/// <value>The is single byte.</value>
|
||||
public override bool IsReadOnly => readOnly;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding uses single-byte code points.
|
||||
/// </summary>
|
||||
public override bool IsSingleByte => singleByte;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the code page identifier of the current Encoding.
|
||||
/// </summary>
|
||||
public override int CodePage => _codepage;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent body tags
|
||||
/// </summary>
|
||||
public override string BodyName => _bodyname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent header tags
|
||||
/// </summary>
|
||||
public override string HeaderName => _headername;
|
||||
|
||||
/// <summary>
|
||||
/// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.
|
||||
/// </summary>
|
||||
public override string WebName => _webname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the human-readable description of the current encoding.
|
||||
/// </summary>
|
||||
public override string EncodingName => _encodingname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Windows operating system code page that most closely corresponds to the current encoding.
|
||||
/// </summary>
|
||||
public override int WindowsCodePage => _windowsCodepage;
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string" />.
|
||||
/// </summary>
|
||||
/// <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 * 6 % 8 > 0 ? s.Length * 6 / 8 + 1 : s.Length * 6 / 8;
|
||||
}
|
||||
|
||||
/// <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 * 6 % 8 > 0 ? count * 6 / 8 + 1 : count * 6 / 8;
|
||||
}
|
||||
|
||||
/// <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 * 6 % 8 > 0 ? chars.Length * 6 / 8 + 1 : chars.Length * 6 / 8;
|
||||
}
|
||||
|
||||
/// <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) =>
|
||||
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 * 6 % 8 > 0 ? count * 6 / 8 + 1 : count * 6 / 8];
|
||||
int outPos = 0;
|
||||
|
||||
for(int i = 0; i < count; i++)
|
||||
{
|
||||
byte thisByte = GetByte(chars[index + i]);
|
||||
|
||||
switch(i % 4)
|
||||
{
|
||||
case 0:
|
||||
if(outPos >= bytes.Length) break;
|
||||
|
||||
bytes[outPos] = (byte)(thisByte << 2);
|
||||
break;
|
||||
case 1:
|
||||
if(outPos + 1 >= bytes.Length) break;
|
||||
|
||||
bytes[outPos] += (byte)((thisByte & 0x30) >> 4);
|
||||
bytes[outPos + 1] = (byte)((thisByte & 0xF) << 4);
|
||||
break;
|
||||
case 2:
|
||||
if(outPos + 2 >= bytes.Length) break;
|
||||
|
||||
bytes[outPos + 1] += (byte)((thisByte & 0x3C) >> 2);
|
||||
bytes[outPos + 2] = (byte)((thisByte & 0x3) << 6);
|
||||
break;
|
||||
case 3:
|
||||
if(outPos + 2 >= bytes.Length) break;
|
||||
|
||||
bytes[outPos + 2] += (byte)(thisByte & 0x3F);
|
||||
outPos += 3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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) => 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) => 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 * 8 / 6;
|
||||
}
|
||||
|
||||
/// <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) => 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 * 8 / 6];
|
||||
|
||||
// aaaaaabb bbbbcccc ccdddddd
|
||||
|
||||
int outPos = 0;
|
||||
for(int i = 0; i < count; i++)
|
||||
{
|
||||
byte rd50;
|
||||
switch(i % 3)
|
||||
{
|
||||
case 0:
|
||||
rd50 = (byte)((bytes[index + i] & 0xFC) >> 2);
|
||||
chars[outPos] = GetChar(rd50);
|
||||
outPos++;
|
||||
break;
|
||||
case 1:
|
||||
rd50 = (byte)(((bytes[index + i - 1] & 0x03) << 4) + ((bytes[index + i] & 0xF0) >> 4));
|
||||
chars[outPos] = GetChar(rd50);
|
||||
outPos++;
|
||||
break;
|
||||
case 2:
|
||||
rd50 =
|
||||
(byte)(((bytes[index + i - 1] & 0x0F) << 2) + ((bytes[index + i] & 0xC0) >> 6));
|
||||
chars[outPos] = GetChar(rd50);
|
||||
chars[outPos + 1] = GetChar((byte)(bytes[index + i] & 0x3F));
|
||||
outPos += 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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 * 6 % 8 > 0 ? charCount * 6 / 8 + 1 : charCount * 6 / 8;
|
||||
}
|
||||
|
||||
/// <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 * 8 / 6;
|
||||
}
|
||||
|
||||
/// <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() => 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 override string GetString(byte[] bytes) => 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) =>
|
||||
new string(GetChars(bytes, index, count));
|
||||
|
||||
/// <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) => Radix50Table[character & 0x3F];
|
||||
|
||||
/// <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 0x00;
|
||||
case '\u0041': return 0x01;
|
||||
case '\u0042': return 0x02;
|
||||
case '\u0043': return 0x03;
|
||||
case '\u0044': return 0x04;
|
||||
case '\u0045': return 0x05;
|
||||
case '\u0046': return 0x06;
|
||||
case '\u0047': return 0x07;
|
||||
case '\u0048': return 0x08;
|
||||
case '\u0049': return 0x09;
|
||||
case '\u004A': return 0x0A;
|
||||
case '\u004B': return 0x0B;
|
||||
case '\u004C': return 0x0C;
|
||||
case '\u004D': return 0x0D;
|
||||
case '\u004E': return 0x0E;
|
||||
case '\u004F': return 0x0F;
|
||||
case '\u0050': return 0x10;
|
||||
case '\u0051': return 0x11;
|
||||
case '\u0052': return 0x12;
|
||||
case '\u0053': return 0x13;
|
||||
case '\u0054': return 0x14;
|
||||
case '\u0055': return 0x15;
|
||||
case '\u0056': return 0x16;
|
||||
case '\u0057': return 0x17;
|
||||
case '\u0058': return 0x18;
|
||||
case '\u0059': return 0x19;
|
||||
case '\u005A': return 0x1A;
|
||||
case '\u0024': return 0x1B;
|
||||
case '\u002E': return 0x1C;
|
||||
case '\u0025': return 0x1D;
|
||||
case '\u0030': return 0x1E;
|
||||
case '\u0031': return 0x1F;
|
||||
case '\u0032': return 0x20;
|
||||
case '\u0033': return 0x21;
|
||||
case '\u0034': return 0x22;
|
||||
case '\u0035': return 0x23;
|
||||
case '\u0036': return 0x24;
|
||||
case '\u0037': return 0x25;
|
||||
case '\u0038': return 0x26;
|
||||
case '\u0039': return 0x27;
|
||||
default:
|
||||
// Fallback to '.'
|
||||
return 0x1C;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright (c) 2016 © Claunia.com
|
||||
// Copyright © 2016-2019 Natalia Portillo
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -29,124 +29,170 @@ using System;
|
||||
namespace Claunia.Encoding
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a ZX80 character encoding of Unicode characters.
|
||||
/// Represents a ZX80 character encoding of Unicode characters.
|
||||
/// </summary>
|
||||
public class ZX80 : System.Text.Encoding
|
||||
public class ZX80 : Encoding
|
||||
{
|
||||
const string _bodyname = "zx80";
|
||||
const int _codepage = 0;
|
||||
const string _encodingname = "Sinclair ZX80 character set";
|
||||
const string _headername = "zx80";
|
||||
const string _webname = "";
|
||||
const int _windowsCodepage = 0;
|
||||
const string _bodyname = "zx80";
|
||||
const int _codepage = 0;
|
||||
const string _encodingname = "Sinclair ZX80 character set";
|
||||
const string _headername = "zx80";
|
||||
const string _webname = "";
|
||||
const int _windowsCodepage = 0;
|
||||
|
||||
const bool browserDisplay = false;
|
||||
const bool browserSave = false;
|
||||
const bool browserDisplay = false;
|
||||
const bool browserSave = false;
|
||||
const bool mailNewsDisplay = false;
|
||||
const bool mailNewsSave = false;
|
||||
const bool readOnly = false;
|
||||
const bool singleByte = true;
|
||||
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.
|
||||
/// The ZX80 to Unicode character map.
|
||||
/// </summary>
|
||||
public bool IsBrowserDisplay {
|
||||
get { return browserDisplay; }
|
||||
}
|
||||
static readonly char[] ZX80Table =
|
||||
{
|
||||
// 0x00
|
||||
'\u0020', '\u0022', '\u258C', '\u2584', '\u2598', '\u259D', '\u2596', '\u2597',
|
||||
// 0x08
|
||||
'\u259E', '\u2592', '\uFFFD', '\uFFFD', '\u00A3', '\u0024', '\u003A', '\u003F',
|
||||
// 0x10
|
||||
'\u0028', '\u0029', '\u002D', '\u002B', '\u002A', '\u002F', '\u003D', '\u003E',
|
||||
// 0x18
|
||||
'\u003C', '\u003B', '\u002C', '\u002E', '\u0030', '\u0031', '\u0032', '\u0033',
|
||||
// 0x20
|
||||
'\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039', '\u0041', '\u0042',
|
||||
// 0x28
|
||||
'\u0043', '\u0044', '\u0045', '\u0046', '\u0047', '\u0048', '\u0049', '\u004A',
|
||||
// 0x30
|
||||
'\u004B', '\u004C', '\u004D', '\u004E', '\u004F', '\u0050', '\u0051', '\u0052',
|
||||
// 0x38
|
||||
'\u0053', '\u0054', '\u0055', '\u0056', '\u0057', '\u0058', '\u0059', '\u005A',
|
||||
// 0x40
|
||||
'\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000',
|
||||
// 0x48
|
||||
'\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000',
|
||||
// 0x50
|
||||
'\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000',
|
||||
// 0x58
|
||||
'\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000',
|
||||
// 0x60
|
||||
'\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000',
|
||||
// 0x68
|
||||
'\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000',
|
||||
// 0x70
|
||||
'\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\u000D', '\uFFFD', '\u000A', '\u0008',
|
||||
// 0x78
|
||||
'\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000',
|
||||
// 0x80
|
||||
'\u2588', '\uFFFD', '\u2590', '\u2580', '\u2599', '\u259C', '\u259B', '\u259A',
|
||||
// 0x88
|
||||
'\u2592', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD',
|
||||
// 0x90
|
||||
'\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD',
|
||||
// 0x98
|
||||
'\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD',
|
||||
// 0xA0
|
||||
'\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD',
|
||||
// 0xA8
|
||||
'\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD',
|
||||
// 0xB0
|
||||
'\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD',
|
||||
// 0xB8
|
||||
'\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD',
|
||||
// 0xC0
|
||||
'\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000',
|
||||
// 0xC8
|
||||
'\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000',
|
||||
// 0xD0
|
||||
'\u0000', '\u0000', '\u0000', '\u0000', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF',
|
||||
// 0xD8
|
||||
'\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF',
|
||||
// 0xE0
|
||||
'\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF',
|
||||
// 0xE8
|
||||
'\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF',
|
||||
// 0xF0
|
||||
'\uFFFF', '\u0000', '\u0000', '\uFFFF', '\uFFFF', '\u0000', '\uFFFF', '\uFFFF',
|
||||
// 0xF8
|
||||
'\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\u0000'
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for saving content.
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for displaying content.
|
||||
/// </summary>
|
||||
public bool IsBrowserSave {
|
||||
get { return browserSave; }
|
||||
}
|
||||
public override bool IsBrowserDisplay => browserDisplay;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content.
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for saving content.
|
||||
/// </summary>
|
||||
public bool IsMailNewsDisplay {
|
||||
get { return mailNewsDisplay; }
|
||||
}
|
||||
public override bool IsBrowserSave => browserSave;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content.
|
||||
/// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content.
|
||||
/// </summary>
|
||||
public bool IsMailNewsSave {
|
||||
get { return mailNewsSave; }
|
||||
}
|
||||
public override bool IsMailNewsDisplay => mailNewsDisplay;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding is read-only.
|
||||
/// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content.
|
||||
/// </summary>
|
||||
public override bool IsMailNewsSave => mailNewsSave;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding is read-only.
|
||||
/// </summary>
|
||||
/// <value>The is single byte.</value>
|
||||
public bool IsReadOnly {
|
||||
get { return readOnly; }
|
||||
}
|
||||
public override bool IsReadOnly => readOnly;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding uses single-byte code points.
|
||||
/// Gets a value indicating whether the current encoding uses single-byte code points.
|
||||
/// </summary>
|
||||
public bool IsSingleByte {
|
||||
get { return singleByte; }
|
||||
}
|
||||
public override bool IsSingleByte => singleByte;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the code page identifier of the current Encoding.
|
||||
/// Gets the code page identifier of the current Encoding.
|
||||
/// </summary>
|
||||
public int CodePage {
|
||||
get { return _codepage; }
|
||||
}
|
||||
public override int CodePage => _codepage;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent body tags
|
||||
/// Gets a name for the current encoding that can be used with mail agent body tags
|
||||
/// </summary>
|
||||
public string BodyName {
|
||||
get { return _bodyname; }
|
||||
}
|
||||
public override string BodyName => _bodyname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent header tags
|
||||
/// Gets a name for the current encoding that can be used with mail agent header tags
|
||||
/// </summary>
|
||||
public string HeaderName {
|
||||
get { return _headername; }
|
||||
}
|
||||
public override string HeaderName => _headername;
|
||||
|
||||
/// <summary>
|
||||
/// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.
|
||||
/// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.
|
||||
/// </summary>
|
||||
public override string WebName {
|
||||
get { return _webname; }
|
||||
}
|
||||
public override string WebName => _webname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the human-readable description of the current encoding.
|
||||
/// Gets the human-readable description of the current encoding.
|
||||
/// </summary>
|
||||
public string EncodingName {
|
||||
get { return _encodingname; }
|
||||
}
|
||||
public override string EncodingName => _encodingname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Windows operating system code page that most closely corresponds to the current encoding.
|
||||
/// Gets the Windows operating system code page that most closely corresponds to the current encoding.
|
||||
/// </summary>
|
||||
public int WindowsCodePage {
|
||||
get { return _windowsCodepage; }
|
||||
}
|
||||
public override int WindowsCodePage => _windowsCodepage;
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string"/>.
|
||||
/// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string" />.
|
||||
/// </summary>
|
||||
/// <returns>The number of bytes produced by encoding the specified characters.</returns>
|
||||
/// <param name="s">The <see cref="string"/> containing the set of characters to encode.</param>
|
||||
/// <param name="s">The <see cref="string" /> containing the set of characters to encode.</param>
|
||||
public override int GetByteCount(string s)
|
||||
{
|
||||
if(s == null)
|
||||
throw new ArgumentNullException(nameof(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.
|
||||
/// 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>
|
||||
@@ -154,60 +200,53 @@ namespace Claunia.Encoding
|
||||
/// <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(chars == null) throw new ArgumentNullException(nameof(chars));
|
||||
|
||||
if(index < 0 || index >= chars.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
if(index < 0 || index >= chars.Length) throw new ArgumentOutOfRangeException(nameof(index));
|
||||
|
||||
if(count < 0 || index + count > chars.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
if(count < 0 || index + count > chars.Length) throw new ArgumentOutOfRangeException(nameof(index));
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the number of bytes produced by encoding all the characters in the specified character array.
|
||||
/// Calculates the number of bytes produced by encoding all the characters in the specified character array.
|
||||
/// </summary>
|
||||
/// <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));
|
||||
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.
|
||||
/// 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="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);
|
||||
}
|
||||
public override int GetBytes(string s, int charIndex, int charCount, byte[] bytes, int byteIndex) =>
|
||||
GetBytes(s.ToCharArray(), charIndex, charCount, bytes, byteIndex);
|
||||
|
||||
/// <summary>
|
||||
/// Encodes all the characters in the specified string into a sequence of bytes.
|
||||
/// Encodes all the characters in the specified string into a sequence of bytes.
|
||||
/// </summary>
|
||||
/// <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));
|
||||
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.
|
||||
/// 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>
|
||||
@@ -217,43 +256,33 @@ namespace Claunia.Encoding
|
||||
/// <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(chars == null) throw new ArgumentNullException(nameof(chars));
|
||||
|
||||
if(bytes == null)
|
||||
throw new ArgumentNullException(nameof(bytes));
|
||||
if(bytes == null) throw new ArgumentNullException(nameof(bytes));
|
||||
|
||||
if(charIndex < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||
if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||
|
||||
if(charCount < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(charCount));
|
||||
if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount));
|
||||
|
||||
if(byteIndex < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||
if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||
|
||||
if(charIndex >= chars.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||
if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||
|
||||
if(charCount + charIndex > chars.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(charCount));
|
||||
if(charCount + charIndex > chars.Length) throw new ArgumentOutOfRangeException(nameof(charCount));
|
||||
|
||||
if(byteIndex >= bytes.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||
if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||
|
||||
if(byteIndex + charCount > bytes.Length)
|
||||
throw new ArgumentException(nameof(bytes));
|
||||
if(byteIndex + charCount > bytes.Length) throw new ArgumentException(nameof(bytes));
|
||||
|
||||
byte[] temp = GetBytes(chars, charIndex, charCount);
|
||||
|
||||
for(int i = 0; i < temp.Length; i++)
|
||||
bytes[i + byteIndex] = temp[i];
|
||||
for(int i = 0; i < temp.Length; i++) bytes[i + byteIndex] = temp[i];
|
||||
|
||||
return charCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encodes a set of characters from the specified character array into a sequence of bytes.
|
||||
/// Encodes a set of characters from the specified character array into a sequence of bytes.
|
||||
/// </summary>
|
||||
/// <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>
|
||||
@@ -261,48 +290,37 @@ namespace Claunia.Encoding
|
||||
/// <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(chars == null) throw new ArgumentNullException(nameof(chars));
|
||||
|
||||
if(index < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
if(index < 0) throw new ArgumentOutOfRangeException(nameof(index));
|
||||
|
||||
if(count < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(count));
|
||||
if(count < 0) throw new ArgumentOutOfRangeException(nameof(count));
|
||||
|
||||
if(count + index > chars.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(count));
|
||||
if(count + index > chars.Length) throw new ArgumentOutOfRangeException(nameof(count));
|
||||
|
||||
byte[] bytes = new byte[count];
|
||||
|
||||
for(int i = 0; i < count; i++)
|
||||
bytes[i] = GetByte(chars[index + i]);
|
||||
for(int i = 0; i < count; i++) bytes[i] = GetByte(chars[index + i]);
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encodes all the characters in the specified character array into a sequence of bytes.
|
||||
/// Encodes all the characters in the specified character array into a sequence of bytes.
|
||||
/// </summary>
|
||||
/// <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);
|
||||
}
|
||||
public override byte[] GetBytes(char[] chars) => GetBytes(chars, 0, chars.Length);
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the number of characters produced by decoding all the bytes in the specified byte array.
|
||||
/// Calculates the number of characters produced by decoding all the bytes in the specified byte array.
|
||||
/// </summary>
|
||||
/// <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);
|
||||
}
|
||||
public override int GetCharCount(byte[] bytes) => GetCharCount(bytes, 0, bytes.Length);
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array.
|
||||
/// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array.
|
||||
/// </summary>
|
||||
/// <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>
|
||||
@@ -310,23 +328,19 @@ namespace Claunia.Encoding
|
||||
/// <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(bytes == null) throw new ArgumentNullException(nameof(bytes));
|
||||
|
||||
if(index < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
if(index < 0) throw new ArgumentOutOfRangeException(nameof(index));
|
||||
|
||||
if(count < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(count));
|
||||
if(count < 0) throw new ArgumentOutOfRangeException(nameof(count));
|
||||
|
||||
if(count + index > bytes.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(count));
|
||||
if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count));
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a sequence of bytes from the specified byte array into the specified character array.
|
||||
/// Decodes a sequence of bytes from the specified byte array into the specified character array.
|
||||
/// </summary>
|
||||
/// <returns>The actual number of characters written into chars.</returns>
|
||||
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
|
||||
@@ -336,53 +350,40 @@ namespace Claunia.Encoding
|
||||
/// <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(bytes == null) throw new ArgumentNullException(nameof(bytes));
|
||||
|
||||
if(chars == null)
|
||||
throw new ArgumentNullException(nameof(chars));
|
||||
if(chars == null) throw new ArgumentNullException(nameof(chars));
|
||||
|
||||
if(byteIndex < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||
if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||
|
||||
if(byteCount < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(byteCount));
|
||||
if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount));
|
||||
|
||||
if(charIndex < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||
if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||
|
||||
if(byteIndex >= bytes.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||
if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||
|
||||
if(byteCount + byteIndex > bytes.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(byteCount));
|
||||
if(byteCount + byteIndex > bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteCount));
|
||||
|
||||
if(charIndex >= chars.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||
if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||
|
||||
if(charIndex + byteCount > chars.Length)
|
||||
throw new ArgumentException(nameof(chars));
|
||||
if(charIndex + byteCount > chars.Length) throw new ArgumentException(nameof(chars));
|
||||
|
||||
char[] temp = GetChars(bytes, byteIndex, byteCount);
|
||||
|
||||
for(int i = 0; i < temp.Length; i++)
|
||||
chars[i + charIndex] = temp[i];
|
||||
for(int i = 0; i < temp.Length; i++) chars[i + charIndex] = temp[i];
|
||||
|
||||
return byteCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes all the bytes in the specified byte array into a set of characters.
|
||||
/// Decodes all the bytes in the specified byte array into a set of characters.
|
||||
/// </summary>
|
||||
/// <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);
|
||||
}
|
||||
public override char[] GetChars(byte[] bytes) => GetChars(bytes, 0, bytes.Length);
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a sequence of bytes from the specified byte array into a set of characters.
|
||||
/// Decodes a sequence of bytes from the specified byte array into a set of characters.
|
||||
/// </summary>
|
||||
/// <returns>The chars.</returns>
|
||||
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
|
||||
@@ -390,317 +391,157 @@ namespace Claunia.Encoding
|
||||
/// <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(bytes == null) throw new ArgumentNullException(nameof(bytes));
|
||||
|
||||
if(index < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
if(index < 0) throw new ArgumentOutOfRangeException(nameof(index));
|
||||
|
||||
if(count < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(count));
|
||||
if(count < 0) throw new ArgumentOutOfRangeException(nameof(count));
|
||||
|
||||
if(count + index > bytes.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(count));
|
||||
if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count));
|
||||
|
||||
char[] chars = new char[count];
|
||||
|
||||
for(int i = 0; i < count; i++)
|
||||
chars[i] = GetChar(bytes[index + i]);
|
||||
for(int i = 0; i < count; i++) chars[i] = GetChar(bytes[index + i]);
|
||||
|
||||
return chars;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the maximum number of bytes produced by encoding the specified number of characters.
|
||||
/// Calculates the maximum number of bytes produced by encoding the specified number of characters.
|
||||
/// </summary>
|
||||
/// <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));
|
||||
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.
|
||||
/// 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));
|
||||
if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount));
|
||||
|
||||
return byteCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a sequence of bytes that specifies the encoding used.
|
||||
/// 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];
|
||||
}
|
||||
public override byte[] GetPreamble() => new byte[0];
|
||||
|
||||
/// <summary>
|
||||
/// Decodes all the bytes in the specified byte array into a string.
|
||||
/// Decodes all the bytes in the specified byte array into a string.
|
||||
/// </summary>
|
||||
/// <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);
|
||||
}
|
||||
public override string GetString(byte[] bytes) => GetString(bytes, 0, bytes.Length);
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a sequence of bytes from the specified byte array into a string.
|
||||
/// Decodes a sequence of bytes from the specified byte array into a string.
|
||||
/// </summary>
|
||||
/// <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));
|
||||
}
|
||||
public override string GetString(byte[] bytes, int index, int count) =>
|
||||
new string(GetChars(bytes, index, count));
|
||||
|
||||
/// <summary>
|
||||
/// The ZX80 to Unicode character map.
|
||||
/// </summary>
|
||||
static readonly char[] ZX80Table = {
|
||||
// 0x00
|
||||
'\u0020','\u0022','\u258C','\u2584','\u2598','\u259D','\u2596','\u2597',
|
||||
// 0x08
|
||||
'\u259E','\u2592','\uFFFD','\uFFFD','\u00A3','\u0024','\u003A','\u003F',
|
||||
// 0x10
|
||||
'\u0028','\u0029','\u002D','\u002B','\u002A','\u002F','\u003D','\u003E',
|
||||
// 0x18
|
||||
'\u003C','\u003B','\u002C','\u002E','\u0030','\u0031','\u0032','\u0033',
|
||||
// 0x20
|
||||
'\u0034','\u0035','\u0036','\u0037','\u0038','\u0039','\u0041','\u0042',
|
||||
// 0x28
|
||||
'\u0043','\u0044','\u0045','\u0046','\u0047','\u0048','\u0049','\u004A',
|
||||
// 0x30
|
||||
'\u004B','\u004C','\u004D','\u004E','\u004F','\u0050','\u0051','\u0052',
|
||||
// 0x38
|
||||
'\u0053','\u0054','\u0055','\u0056','\u0057','\u0058','\u0059','\u005A',
|
||||
// 0x40
|
||||
'\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000',
|
||||
// 0x48
|
||||
'\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000',
|
||||
// 0x50
|
||||
'\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000',
|
||||
// 0x58
|
||||
'\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000',
|
||||
// 0x60
|
||||
'\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000',
|
||||
// 0x68
|
||||
'\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000',
|
||||
// 0x70
|
||||
'\uFFFF','\uFFFF','\uFFFF','\uFFFF','\u000D','\uFFFD','\u000A','\u0008',
|
||||
// 0x78
|
||||
'\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000',
|
||||
// 0x80
|
||||
'\u2588','\uFFFD','\u2590','\u2580','\u2599','\u259C','\u259B','\u259A',
|
||||
// 0x88
|
||||
'\u2592','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD',
|
||||
// 0x90
|
||||
'\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD',
|
||||
// 0x98
|
||||
'\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD',
|
||||
// 0xA0
|
||||
'\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD',
|
||||
// 0xA8
|
||||
'\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD',
|
||||
// 0xB0
|
||||
'\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD',
|
||||
// 0xB8
|
||||
'\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD',
|
||||
// 0xC0
|
||||
'\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000',
|
||||
// 0xC8
|
||||
'\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000',
|
||||
// 0xD0
|
||||
'\u0000','\u0000','\u0000','\u0000','\uFFFF','\uFFFF','\uFFFF','\uFFFF',
|
||||
// 0xD8
|
||||
'\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF',
|
||||
// 0xE0
|
||||
'\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF',
|
||||
// 0xE8
|
||||
'\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF',
|
||||
// 0xF0
|
||||
'\uFFFF','\u0000','\u0000','\uFFFF','\uFFFF','\u0000','\uFFFF','\uFFFF',
|
||||
// 0xF8
|
||||
'\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\u0000'
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Converts a ZX80 character to an Unicode character
|
||||
/// Converts a ZX80 character to an Unicode character
|
||||
/// </summary>
|
||||
/// <returns>Unicode character.</returns>
|
||||
/// <param name="character">ZX80 character.</param>
|
||||
static char GetChar(byte character)
|
||||
{
|
||||
return ZX80Table[character];
|
||||
}
|
||||
static char GetChar(byte character) => ZX80Table[character];
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Unicode character to an ZX80 character
|
||||
/// Converts a Unicode character to an ZX80 character
|
||||
/// </summary>
|
||||
/// <returns>ZX80 character.</returns>
|
||||
/// <param name="character">Unicode character.</param>
|
||||
static byte GetByte(char character)
|
||||
{
|
||||
switch(character) {
|
||||
case '\u0020':
|
||||
return 0x00;
|
||||
case '\u0022':
|
||||
return 0x01;
|
||||
case '\u258C':
|
||||
return 0x02;
|
||||
case '\u2584':
|
||||
return 0x03;
|
||||
case '\u2598':
|
||||
return 0x04;
|
||||
case '\u259D':
|
||||
return 0x05;
|
||||
case '\u2596':
|
||||
return 0x06;
|
||||
case '\u2597':
|
||||
return 0x07;
|
||||
case '\u259E':
|
||||
return 0x08;
|
||||
case '\u2592':
|
||||
return 0x09;
|
||||
case '\u00A3':
|
||||
return 0x0C;
|
||||
case '\u0024':
|
||||
return 0x0D;
|
||||
case '\u003A':
|
||||
return 0x0E;
|
||||
case '\u003F':
|
||||
return 0x0F;
|
||||
case '\u0028':
|
||||
return 0x10;
|
||||
case '\u0029':
|
||||
return 0x11;
|
||||
case '\u002D':
|
||||
return 0x12;
|
||||
case '\u002B':
|
||||
return 0x13;
|
||||
case '\u002A':
|
||||
return 0x14;
|
||||
case '\u002F':
|
||||
return 0x15;
|
||||
case '\u003D':
|
||||
return 0x16;
|
||||
case '\u003E':
|
||||
return 0x17;
|
||||
case '\u003C':
|
||||
return 0x18;
|
||||
case '\u003B':
|
||||
return 0x19;
|
||||
case '\u002C':
|
||||
return 0x1A;
|
||||
case '\u002E':
|
||||
return 0x1B;
|
||||
case '\u0030':
|
||||
return 0x1C;
|
||||
case '\u0031':
|
||||
return 0x1D;
|
||||
case '\u0032':
|
||||
return 0x1E;
|
||||
case '\u0033':
|
||||
return 0x1F;
|
||||
case '\u0034':
|
||||
return 0x20;
|
||||
case '\u0035':
|
||||
return 0x21;
|
||||
case '\u0036':
|
||||
return 0x22;
|
||||
case '\u0037':
|
||||
return 0x23;
|
||||
case '\u0038':
|
||||
return 0x24;
|
||||
case '\u0039':
|
||||
return 0x25;
|
||||
case '\u0041':
|
||||
return 0x26;
|
||||
case '\u0042':
|
||||
return 0x27;
|
||||
case '\u0043':
|
||||
return 0x28;
|
||||
case '\u0044':
|
||||
return 0x29;
|
||||
case '\u0045':
|
||||
return 0x2A;
|
||||
case '\u0046':
|
||||
return 0x2B;
|
||||
case '\u0047':
|
||||
return 0x2C;
|
||||
case '\u0048':
|
||||
return 0x2D;
|
||||
case '\u0049':
|
||||
return 0x2E;
|
||||
case '\u004A':
|
||||
return 0x2F;
|
||||
case '\u004B':
|
||||
return 0x30;
|
||||
case '\u004C':
|
||||
return 0x31;
|
||||
case '\u004D':
|
||||
return 0x32;
|
||||
case '\u004E':
|
||||
return 0x33;
|
||||
case '\u004F':
|
||||
return 0x34;
|
||||
case '\u0050':
|
||||
return 0x35;
|
||||
case '\u0051':
|
||||
return 0x36;
|
||||
case '\u0052':
|
||||
return 0x37;
|
||||
case '\u0053':
|
||||
return 0x38;
|
||||
case '\u0054':
|
||||
return 0x39;
|
||||
case '\u0055':
|
||||
return 0x3A;
|
||||
case '\u0056':
|
||||
return 0x3B;
|
||||
case '\u0057':
|
||||
return 0x3C;
|
||||
case '\u0058':
|
||||
return 0x3D;
|
||||
case '\u0059':
|
||||
return 0x3E;
|
||||
case '\u005A':
|
||||
return 0x3F;
|
||||
case '\u000D':
|
||||
return 0x74;
|
||||
case '\u000A':
|
||||
return 0x76;
|
||||
case '\u0008':
|
||||
return 0x77;
|
||||
case '\u2588':
|
||||
return 0x80;
|
||||
case '\u2590':
|
||||
return 0x82;
|
||||
case '\u2580':
|
||||
return 0x83;
|
||||
case '\u259F':
|
||||
return 0x84;
|
||||
case '\u2599':
|
||||
return 0x85;
|
||||
case '\u259C':
|
||||
return 0x86;
|
||||
case '\u259B':
|
||||
return 0x87;
|
||||
case '\u259A':
|
||||
return 0x88;
|
||||
switch(character)
|
||||
{
|
||||
case '\u0020': return 0x00;
|
||||
case '\u0022': return 0x01;
|
||||
case '\u258C': return 0x02;
|
||||
case '\u2584': return 0x03;
|
||||
case '\u2598': return 0x04;
|
||||
case '\u259D': return 0x05;
|
||||
case '\u2596': return 0x06;
|
||||
case '\u2597': return 0x07;
|
||||
case '\u259E': return 0x08;
|
||||
case '\u2592': return 0x09;
|
||||
case '\u00A3': return 0x0C;
|
||||
case '\u0024': return 0x0D;
|
||||
case '\u003A': return 0x0E;
|
||||
case '\u003F': return 0x0F;
|
||||
case '\u0028': return 0x10;
|
||||
case '\u0029': return 0x11;
|
||||
case '\u002D': return 0x12;
|
||||
case '\u002B': return 0x13;
|
||||
case '\u002A': return 0x14;
|
||||
case '\u002F': return 0x15;
|
||||
case '\u003D': return 0x16;
|
||||
case '\u003E': return 0x17;
|
||||
case '\u003C': return 0x18;
|
||||
case '\u003B': return 0x19;
|
||||
case '\u002C': return 0x1A;
|
||||
case '\u002E': return 0x1B;
|
||||
case '\u0030': return 0x1C;
|
||||
case '\u0031': return 0x1D;
|
||||
case '\u0032': return 0x1E;
|
||||
case '\u0033': return 0x1F;
|
||||
case '\u0034': return 0x20;
|
||||
case '\u0035': return 0x21;
|
||||
case '\u0036': return 0x22;
|
||||
case '\u0037': return 0x23;
|
||||
case '\u0038': return 0x24;
|
||||
case '\u0039': return 0x25;
|
||||
case '\u0041': return 0x26;
|
||||
case '\u0042': return 0x27;
|
||||
case '\u0043': return 0x28;
|
||||
case '\u0044': return 0x29;
|
||||
case '\u0045': return 0x2A;
|
||||
case '\u0046': return 0x2B;
|
||||
case '\u0047': return 0x2C;
|
||||
case '\u0048': return 0x2D;
|
||||
case '\u0049': return 0x2E;
|
||||
case '\u004A': return 0x2F;
|
||||
case '\u004B': return 0x30;
|
||||
case '\u004C': return 0x31;
|
||||
case '\u004D': return 0x32;
|
||||
case '\u004E': return 0x33;
|
||||
case '\u004F': return 0x34;
|
||||
case '\u0050': return 0x35;
|
||||
case '\u0051': return 0x36;
|
||||
case '\u0052': return 0x37;
|
||||
case '\u0053': return 0x38;
|
||||
case '\u0054': return 0x39;
|
||||
case '\u0055': return 0x3A;
|
||||
case '\u0056': return 0x3B;
|
||||
case '\u0057': return 0x3C;
|
||||
case '\u0058': return 0x3D;
|
||||
case '\u0059': return 0x3E;
|
||||
case '\u005A': return 0x3F;
|
||||
case '\u000D': return 0x74;
|
||||
case '\u000A': return 0x76;
|
||||
case '\u0008': return 0x77;
|
||||
case '\u2588': return 0x80;
|
||||
case '\u2590': return 0x82;
|
||||
case '\u2580': return 0x83;
|
||||
case '\u259F': return 0x84;
|
||||
case '\u2599': return 0x85;
|
||||
case '\u259C': return 0x86;
|
||||
case '\u259B': return 0x87;
|
||||
case '\u259A': return 0x88;
|
||||
default:
|
||||
// Fallback to '?'
|
||||
return 0x0F;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright (c) 2016 © Claunia.com
|
||||
// Copyright © 2016-2019 Natalia Portillo
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -29,124 +29,170 @@ using System;
|
||||
namespace Claunia.Encoding
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a ZX81 character encoding of Unicode characters.
|
||||
/// Represents a ZX81 character encoding of Unicode characters.
|
||||
/// </summary>
|
||||
public class ZX81 : System.Text.Encoding
|
||||
public class ZX81 : Encoding
|
||||
{
|
||||
const string _bodyname = "zx81";
|
||||
const int _codepage = 0;
|
||||
const string _encodingname = "Sinclair ZX81 character set";
|
||||
const string _headername = "zx81";
|
||||
const string _webname = "";
|
||||
const int _windowsCodepage = 0;
|
||||
const string _bodyname = "zx81";
|
||||
const int _codepage = 0;
|
||||
const string _encodingname = "Sinclair ZX81 character set";
|
||||
const string _headername = "zx81";
|
||||
const string _webname = "";
|
||||
const int _windowsCodepage = 0;
|
||||
|
||||
const bool browserDisplay = false;
|
||||
const bool browserSave = false;
|
||||
const bool browserDisplay = false;
|
||||
const bool browserSave = false;
|
||||
const bool mailNewsDisplay = false;
|
||||
const bool mailNewsSave = false;
|
||||
const bool readOnly = false;
|
||||
const bool singleByte = true;
|
||||
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.
|
||||
/// The ZX81 to Unicode character map.
|
||||
/// </summary>
|
||||
public bool IsBrowserDisplay {
|
||||
get { return browserDisplay; }
|
||||
}
|
||||
static readonly char[] ZX81Table =
|
||||
{
|
||||
// 0x00
|
||||
'\u0020', '\u2598', '\u259D', '\u2580', '\u2596', '\u258C', '\u259E', '\u259B',
|
||||
// 0x08
|
||||
'\u2592', '\uFFFD', '\uFFFD', '\u0022', '\u00A3', '\u0024', '\u003A', '\u003F',
|
||||
// 0x10
|
||||
'\u0028', '\u0029', '\u003E', '\u003C', '\u003D', '\u002B', '\u002D', '\u002A',
|
||||
// 0x18
|
||||
'\u002F', '\u003B', '\u002C', '\u002E', '\u0030', '\u0031', '\u0032', '\u0033',
|
||||
// 0x20
|
||||
'\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039', '\u0041', '\u0042',
|
||||
// 0x28
|
||||
'\u0043', '\u0044', '\u0045', '\u0046', '\u0047', '\u0048', '\u0049', '\u004A',
|
||||
// 0x30
|
||||
'\u004B', '\u004C', '\u004D', '\u004E', '\u004F', '\u0050', '\u0051', '\u0052',
|
||||
// 0x38
|
||||
'\u0053', '\u0054', '\u0055', '\u0056', '\u0057', '\u0058', '\u0059', '\u005A',
|
||||
// 0x40
|
||||
'\uFFFF', '\uFFFF', '\uFFFF', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000',
|
||||
// 0x48
|
||||
'\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000',
|
||||
// 0x50
|
||||
'\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000',
|
||||
// 0x58
|
||||
'\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000',
|
||||
// 0x60
|
||||
'\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000',
|
||||
// 0x68
|
||||
'\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000',
|
||||
// 0x70
|
||||
'\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\u000A', '\u0008',
|
||||
// 0x78
|
||||
'\uFFFF', '\uFFFF', '\u0000', '\u0000', '\u0000', '\u0000', '\uFFFF', '\uFFFF',
|
||||
// 0x80
|
||||
'\u2588', '\u259F', '\u2599', '\u2584', '\u259C', '\u2590', '\u259A', '\u2597',
|
||||
// 0x88
|
||||
'\u2592', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD',
|
||||
// 0x90
|
||||
'\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD',
|
||||
// 0x98
|
||||
'\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD',
|
||||
// 0xA0
|
||||
'\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD',
|
||||
// 0xA8
|
||||
'\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD',
|
||||
// 0xB0
|
||||
'\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD',
|
||||
// 0xB8
|
||||
'\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD', '\uFFFD',
|
||||
// 0xC0
|
||||
'\uFFFF', '\uFFFF', '\uFFFF', '\u0000', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF',
|
||||
// 0xC8
|
||||
'\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF',
|
||||
// 0xD0
|
||||
'\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF',
|
||||
// 0xD8
|
||||
'\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF',
|
||||
// 0xE0
|
||||
'\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF',
|
||||
// 0xE8
|
||||
'\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF',
|
||||
// 0xF0
|
||||
'\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF',
|
||||
// 0xF8
|
||||
'\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF', '\uFFFF'
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for saving content.
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for displaying content.
|
||||
/// </summary>
|
||||
public bool IsBrowserSave {
|
||||
get { return browserSave; }
|
||||
}
|
||||
public override bool IsBrowserDisplay => browserDisplay;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content.
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for saving content.
|
||||
/// </summary>
|
||||
public bool IsMailNewsDisplay {
|
||||
get { return mailNewsDisplay; }
|
||||
}
|
||||
public override bool IsBrowserSave => browserSave;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content.
|
||||
/// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content.
|
||||
/// </summary>
|
||||
public bool IsMailNewsSave {
|
||||
get { return mailNewsSave; }
|
||||
}
|
||||
public override bool IsMailNewsDisplay => mailNewsDisplay;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding is read-only.
|
||||
/// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content.
|
||||
/// </summary>
|
||||
public override bool IsMailNewsSave => mailNewsSave;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding is read-only.
|
||||
/// </summary>
|
||||
/// <value>The is single byte.</value>
|
||||
public bool IsReadOnly {
|
||||
get { return readOnly; }
|
||||
}
|
||||
public override bool IsReadOnly => readOnly;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding uses single-byte code points.
|
||||
/// Gets a value indicating whether the current encoding uses single-byte code points.
|
||||
/// </summary>
|
||||
public bool IsSingleByte {
|
||||
get { return singleByte; }
|
||||
}
|
||||
public override bool IsSingleByte => singleByte;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the code page identifier of the current Encoding.
|
||||
/// Gets the code page identifier of the current Encoding.
|
||||
/// </summary>
|
||||
public int CodePage {
|
||||
get { return _codepage; }
|
||||
}
|
||||
public override int CodePage => _codepage;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent body tags
|
||||
/// Gets a name for the current encoding that can be used with mail agent body tags
|
||||
/// </summary>
|
||||
public string BodyName {
|
||||
get { return _bodyname; }
|
||||
}
|
||||
public override string BodyName => _bodyname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a name for the current encoding that can be used with mail agent header tags
|
||||
/// Gets a name for the current encoding that can be used with mail agent header tags
|
||||
/// </summary>
|
||||
public string HeaderName {
|
||||
get { return _headername; }
|
||||
}
|
||||
public override string HeaderName => _headername;
|
||||
|
||||
/// <summary>
|
||||
/// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.
|
||||
/// Ggets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.
|
||||
/// </summary>
|
||||
public override string WebName {
|
||||
get { return _webname; }
|
||||
}
|
||||
public override string WebName => _webname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the human-readable description of the current encoding.
|
||||
/// Gets the human-readable description of the current encoding.
|
||||
/// </summary>
|
||||
public string EncodingName {
|
||||
get { return _encodingname; }
|
||||
}
|
||||
public override string EncodingName => _encodingname;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Windows operating system code page that most closely corresponds to the current encoding.
|
||||
/// Gets the Windows operating system code page that most closely corresponds to the current encoding.
|
||||
/// </summary>
|
||||
public int WindowsCodePage {
|
||||
get { return _windowsCodepage; }
|
||||
}
|
||||
public override int WindowsCodePage => _windowsCodepage;
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string"/>.
|
||||
/// Calculates the number of bytes produced by encoding the characters in the specified <see cref="string" />.
|
||||
/// </summary>
|
||||
/// <returns>The number of bytes produced by encoding the specified characters.</returns>
|
||||
/// <param name="s">The <see cref="string"/> containing the set of characters to encode.</param>
|
||||
/// <param name="s">The <see cref="string" /> containing the set of characters to encode.</param>
|
||||
public override int GetByteCount(string s)
|
||||
{
|
||||
if(s == null)
|
||||
throw new ArgumentNullException(nameof(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.
|
||||
/// 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>
|
||||
@@ -154,60 +200,53 @@ namespace Claunia.Encoding
|
||||
/// <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(chars == null) throw new ArgumentNullException(nameof(chars));
|
||||
|
||||
if(index < 0 || index >= chars.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
if(index < 0 || index >= chars.Length) throw new ArgumentOutOfRangeException(nameof(index));
|
||||
|
||||
if(count < 0 || index + count > chars.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
if(count < 0 || index + count > chars.Length) throw new ArgumentOutOfRangeException(nameof(index));
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the number of bytes produced by encoding all the characters in the specified character array.
|
||||
/// Calculates the number of bytes produced by encoding all the characters in the specified character array.
|
||||
/// </summary>
|
||||
/// <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));
|
||||
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.
|
||||
/// 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="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);
|
||||
}
|
||||
public override int GetBytes(string s, int charIndex, int charCount, byte[] bytes, int byteIndex) =>
|
||||
GetBytes(s.ToCharArray(), charIndex, charCount, bytes, byteIndex);
|
||||
|
||||
/// <summary>
|
||||
/// Encodes all the characters in the specified string into a sequence of bytes.
|
||||
/// Encodes all the characters in the specified string into a sequence of bytes.
|
||||
/// </summary>
|
||||
/// <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));
|
||||
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.
|
||||
/// 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>
|
||||
@@ -217,43 +256,33 @@ namespace Claunia.Encoding
|
||||
/// <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(chars == null) throw new ArgumentNullException(nameof(chars));
|
||||
|
||||
if(bytes == null)
|
||||
throw new ArgumentNullException(nameof(bytes));
|
||||
if(bytes == null) throw new ArgumentNullException(nameof(bytes));
|
||||
|
||||
if(charIndex < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||
if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||
|
||||
if(charCount < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(charCount));
|
||||
if(charCount < 0) throw new ArgumentOutOfRangeException(nameof(charCount));
|
||||
|
||||
if(byteIndex < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||
if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||
|
||||
if(charIndex >= chars.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||
if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||
|
||||
if(charCount + charIndex > chars.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(charCount));
|
||||
if(charCount + charIndex > chars.Length) throw new ArgumentOutOfRangeException(nameof(charCount));
|
||||
|
||||
if(byteIndex >= bytes.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||
if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||
|
||||
if(byteIndex + charCount > bytes.Length)
|
||||
throw new ArgumentException(nameof(bytes));
|
||||
if(byteIndex + charCount > bytes.Length) throw new ArgumentException(nameof(bytes));
|
||||
|
||||
byte[] temp = GetBytes(chars, charIndex, charCount);
|
||||
|
||||
for(int i = 0; i < temp.Length; i++)
|
||||
bytes[i + byteIndex] = temp[i];
|
||||
for(int i = 0; i < temp.Length; i++) bytes[i + byteIndex] = temp[i];
|
||||
|
||||
return charCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encodes a set of characters from the specified character array into a sequence of bytes.
|
||||
/// Encodes a set of characters from the specified character array into a sequence of bytes.
|
||||
/// </summary>
|
||||
/// <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>
|
||||
@@ -261,48 +290,37 @@ namespace Claunia.Encoding
|
||||
/// <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(chars == null) throw new ArgumentNullException(nameof(chars));
|
||||
|
||||
if(index < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
if(index < 0) throw new ArgumentOutOfRangeException(nameof(index));
|
||||
|
||||
if(count < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(count));
|
||||
if(count < 0) throw new ArgumentOutOfRangeException(nameof(count));
|
||||
|
||||
if(count + index > chars.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(count));
|
||||
if(count + index > chars.Length) throw new ArgumentOutOfRangeException(nameof(count));
|
||||
|
||||
byte[] bytes = new byte[count];
|
||||
|
||||
for(int i = 0; i < count; i++)
|
||||
bytes[i] = GetByte(chars[index + i]);
|
||||
for(int i = 0; i < count; i++) bytes[i] = GetByte(chars[index + i]);
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encodes all the characters in the specified character array into a sequence of bytes.
|
||||
/// Encodes all the characters in the specified character array into a sequence of bytes.
|
||||
/// </summary>
|
||||
/// <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);
|
||||
}
|
||||
public override byte[] GetBytes(char[] chars) => GetBytes(chars, 0, chars.Length);
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the number of characters produced by decoding all the bytes in the specified byte array.
|
||||
/// Calculates the number of characters produced by decoding all the bytes in the specified byte array.
|
||||
/// </summary>
|
||||
/// <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);
|
||||
}
|
||||
public override int GetCharCount(byte[] bytes) => GetCharCount(bytes, 0, bytes.Length);
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array.
|
||||
/// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array.
|
||||
/// </summary>
|
||||
/// <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>
|
||||
@@ -310,23 +328,19 @@ namespace Claunia.Encoding
|
||||
/// <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(bytes == null) throw new ArgumentNullException(nameof(bytes));
|
||||
|
||||
if(index < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
if(index < 0) throw new ArgumentOutOfRangeException(nameof(index));
|
||||
|
||||
if(count < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(count));
|
||||
if(count < 0) throw new ArgumentOutOfRangeException(nameof(count));
|
||||
|
||||
if(count + index > bytes.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(count));
|
||||
if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count));
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a sequence of bytes from the specified byte array into the specified character array.
|
||||
/// Decodes a sequence of bytes from the specified byte array into the specified character array.
|
||||
/// </summary>
|
||||
/// <returns>The actual number of characters written into chars.</returns>
|
||||
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
|
||||
@@ -336,53 +350,40 @@ namespace Claunia.Encoding
|
||||
/// <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(bytes == null) throw new ArgumentNullException(nameof(bytes));
|
||||
|
||||
if(chars == null)
|
||||
throw new ArgumentNullException(nameof(chars));
|
||||
if(chars == null) throw new ArgumentNullException(nameof(chars));
|
||||
|
||||
if(byteIndex < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||
if(byteIndex < 0) throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||
|
||||
if(byteCount < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(byteCount));
|
||||
if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount));
|
||||
|
||||
if(charIndex < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||
if(charIndex < 0) throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||
|
||||
if(byteIndex >= bytes.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||
if(byteIndex >= bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteIndex));
|
||||
|
||||
if(byteCount + byteIndex > bytes.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(byteCount));
|
||||
if(byteCount + byteIndex > bytes.Length) throw new ArgumentOutOfRangeException(nameof(byteCount));
|
||||
|
||||
if(charIndex >= chars.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||
if(charIndex >= chars.Length) throw new ArgumentOutOfRangeException(nameof(charIndex));
|
||||
|
||||
if(charIndex + byteCount > chars.Length)
|
||||
throw new ArgumentException(nameof(chars));
|
||||
if(charIndex + byteCount > chars.Length) throw new ArgumentException(nameof(chars));
|
||||
|
||||
char[] temp = GetChars(bytes, byteIndex, byteCount);
|
||||
|
||||
for(int i = 0; i < temp.Length; i++)
|
||||
chars[i + charIndex] = temp[i];
|
||||
for(int i = 0; i < temp.Length; i++) chars[i + charIndex] = temp[i];
|
||||
|
||||
return byteCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes all the bytes in the specified byte array into a set of characters.
|
||||
/// Decodes all the bytes in the specified byte array into a set of characters.
|
||||
/// </summary>
|
||||
/// <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);
|
||||
}
|
||||
public override char[] GetChars(byte[] bytes) => GetChars(bytes, 0, bytes.Length);
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a sequence of bytes from the specified byte array into a set of characters.
|
||||
/// Decodes a sequence of bytes from the specified byte array into a set of characters.
|
||||
/// </summary>
|
||||
/// <returns>The chars.</returns>
|
||||
/// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
|
||||
@@ -390,317 +391,157 @@ namespace Claunia.Encoding
|
||||
/// <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(bytes == null) throw new ArgumentNullException(nameof(bytes));
|
||||
|
||||
if(index < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
if(index < 0) throw new ArgumentOutOfRangeException(nameof(index));
|
||||
|
||||
if(count < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(count));
|
||||
if(count < 0) throw new ArgumentOutOfRangeException(nameof(count));
|
||||
|
||||
if(count + index > bytes.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(count));
|
||||
if(count + index > bytes.Length) throw new ArgumentOutOfRangeException(nameof(count));
|
||||
|
||||
char[] chars = new char[count];
|
||||
|
||||
for(int i = 0; i < count; i++)
|
||||
chars[i] = GetChar(bytes[index + i]);
|
||||
for(int i = 0; i < count; i++) chars[i] = GetChar(bytes[index + i]);
|
||||
|
||||
return chars;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the maximum number of bytes produced by encoding the specified number of characters.
|
||||
/// Calculates the maximum number of bytes produced by encoding the specified number of characters.
|
||||
/// </summary>
|
||||
/// <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));
|
||||
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.
|
||||
/// 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));
|
||||
if(byteCount < 0) throw new ArgumentOutOfRangeException(nameof(byteCount));
|
||||
|
||||
return byteCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a sequence of bytes that specifies the encoding used.
|
||||
/// 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];
|
||||
}
|
||||
public override byte[] GetPreamble() => new byte[0];
|
||||
|
||||
/// <summary>
|
||||
/// Decodes all the bytes in the specified byte array into a string.
|
||||
/// Decodes all the bytes in the specified byte array into a string.
|
||||
/// </summary>
|
||||
/// <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);
|
||||
}
|
||||
public override string GetString(byte[] bytes) => GetString(bytes, 0, bytes.Length);
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a sequence of bytes from the specified byte array into a string.
|
||||
/// Decodes a sequence of bytes from the specified byte array into a string.
|
||||
/// </summary>
|
||||
/// <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));
|
||||
}
|
||||
public override string GetString(byte[] bytes, int index, int count) =>
|
||||
new string(GetChars(bytes, index, count));
|
||||
|
||||
/// <summary>
|
||||
/// The ZX81 to Unicode character map.
|
||||
/// </summary>
|
||||
static readonly char[] ZX81Table = {
|
||||
// 0x00
|
||||
'\u0020','\u2598','\u259D','\u2580','\u2596','\u258C','\u259E','\u259B',
|
||||
// 0x08
|
||||
'\u2592','\uFFFD','\uFFFD','\u0022','\u00A3','\u0024','\u003A','\u003F',
|
||||
// 0x10
|
||||
'\u0028','\u0029','\u003E','\u003C','\u003D','\u002B','\u002D','\u002A',
|
||||
// 0x18
|
||||
'\u002F','\u003B','\u002C','\u002E','\u0030','\u0031','\u0032','\u0033',
|
||||
// 0x20
|
||||
'\u0034','\u0035','\u0036','\u0037','\u0038','\u0039','\u0041','\u0042',
|
||||
// 0x28
|
||||
'\u0043','\u0044','\u0045','\u0046','\u0047','\u0048','\u0049','\u004A',
|
||||
// 0x30
|
||||
'\u004B','\u004C','\u004D','\u004E','\u004F','\u0050','\u0051','\u0052',
|
||||
// 0x38
|
||||
'\u0053','\u0054','\u0055','\u0056','\u0057','\u0058','\u0059','\u005A',
|
||||
// 0x40
|
||||
'\uFFFF','\uFFFF','\uFFFF','\u0000','\u0000','\u0000','\u0000','\u0000',
|
||||
// 0x48
|
||||
'\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000',
|
||||
// 0x50
|
||||
'\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000',
|
||||
// 0x58
|
||||
'\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000',
|
||||
// 0x60
|
||||
'\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000',
|
||||
// 0x68
|
||||
'\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000',
|
||||
// 0x70
|
||||
'\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\u000A','\u0008',
|
||||
// 0x78
|
||||
'\uFFFF','\uFFFF','\u0000','\u0000','\u0000','\u0000','\uFFFF','\uFFFF',
|
||||
// 0x80
|
||||
'\u2588','\u259F','\u2599','\u2584','\u259C','\u2590','\u259A','\u2597',
|
||||
// 0x88
|
||||
'\u2592','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD',
|
||||
// 0x90
|
||||
'\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD',
|
||||
// 0x98
|
||||
'\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD',
|
||||
// 0xA0
|
||||
'\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD',
|
||||
// 0xA8
|
||||
'\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD',
|
||||
// 0xB0
|
||||
'\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD',
|
||||
// 0xB8
|
||||
'\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD','\uFFFD',
|
||||
// 0xC0
|
||||
'\uFFFF','\uFFFF','\uFFFF','\u0000','\uFFFF','\uFFFF','\uFFFF','\uFFFF',
|
||||
// 0xC8
|
||||
'\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF',
|
||||
// 0xD0
|
||||
'\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF',
|
||||
// 0xD8
|
||||
'\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF',
|
||||
// 0xE0
|
||||
'\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF',
|
||||
// 0xE8
|
||||
'\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF',
|
||||
// 0xF0
|
||||
'\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF',
|
||||
// 0xF8
|
||||
'\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF','\uFFFF'
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Converts a ZX81 character to an Unicode character
|
||||
/// Converts a ZX81 character to an Unicode character
|
||||
/// </summary>
|
||||
/// <returns>Unicode character.</returns>
|
||||
/// <param name="character">ZX81 character.</param>
|
||||
static char GetChar(byte character)
|
||||
{
|
||||
return ZX81Table[character];
|
||||
}
|
||||
static char GetChar(byte character) => ZX81Table[character];
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Unicode character to an ZX81 character
|
||||
/// Converts a Unicode character to an ZX81 character
|
||||
/// </summary>
|
||||
/// <returns>ZX81 character.</returns>
|
||||
/// <param name="character">Unicode character.</param>
|
||||
static byte GetByte(char character)
|
||||
{
|
||||
switch(character) {
|
||||
case '\u0020':
|
||||
return 0x00;
|
||||
case '\u2598':
|
||||
return 0x01;
|
||||
case '\u259D':
|
||||
return 0x02;
|
||||
case '\u2580':
|
||||
return 0x03;
|
||||
case '\u2596':
|
||||
return 0x04;
|
||||
case '\u258C':
|
||||
return 0x05;
|
||||
case '\u259E':
|
||||
return 0x06;
|
||||
case '\u259B':
|
||||
return 0x07;
|
||||
case '\u2592':
|
||||
return 0x08;
|
||||
case '\u0022':
|
||||
return 0x0B;
|
||||
case '\u00A3':
|
||||
return 0x0C;
|
||||
case '\u0024':
|
||||
return 0x0D;
|
||||
case '\u003A':
|
||||
return 0x0E;
|
||||
case '\u003F':
|
||||
return 0x0F;
|
||||
case '\u0028':
|
||||
return 0x10;
|
||||
case '\u0029':
|
||||
return 0x11;
|
||||
case '\u003E':
|
||||
return 0x12;
|
||||
case '\u003C':
|
||||
return 0x13;
|
||||
case '\u003D':
|
||||
return 0x14;
|
||||
case '\u002B':
|
||||
return 0x15;
|
||||
case '\u002D':
|
||||
return 0x16;
|
||||
case '\u002A':
|
||||
return 0x17;
|
||||
case '\u002F':
|
||||
return 0x18;
|
||||
case '\u003B':
|
||||
return 0x19;
|
||||
case '\u002C':
|
||||
return 0x1A;
|
||||
case '\u002E':
|
||||
return 0x1B;
|
||||
case '\u0030':
|
||||
return 0x1C;
|
||||
case '\u0031':
|
||||
return 0x1D;
|
||||
case '\u0032':
|
||||
return 0x1E;
|
||||
case '\u0033':
|
||||
return 0x1F;
|
||||
case '\u0034':
|
||||
return 0x20;
|
||||
case '\u0035':
|
||||
return 0x21;
|
||||
case '\u0036':
|
||||
return 0x22;
|
||||
case '\u0037':
|
||||
return 0x23;
|
||||
case '\u0038':
|
||||
return 0x24;
|
||||
case '\u0039':
|
||||
return 0x25;
|
||||
case '\u0041':
|
||||
return 0x26;
|
||||
case '\u0042':
|
||||
return 0x27;
|
||||
case '\u0043':
|
||||
return 0x28;
|
||||
case '\u0044':
|
||||
return 0x29;
|
||||
case '\u0045':
|
||||
return 0x2A;
|
||||
case '\u0046':
|
||||
return 0x2B;
|
||||
case '\u0047':
|
||||
return 0x2C;
|
||||
case '\u0048':
|
||||
return 0x2D;
|
||||
case '\u0049':
|
||||
return 0x2E;
|
||||
case '\u004A':
|
||||
return 0x2F;
|
||||
case '\u004B':
|
||||
return 0x30;
|
||||
case '\u004C':
|
||||
return 0x31;
|
||||
case '\u004D':
|
||||
return 0x32;
|
||||
case '\u004E':
|
||||
return 0x33;
|
||||
case '\u004F':
|
||||
return 0x34;
|
||||
case '\u0050':
|
||||
return 0x35;
|
||||
case '\u0051':
|
||||
return 0x36;
|
||||
case '\u0052':
|
||||
return 0x37;
|
||||
case '\u0053':
|
||||
return 0x38;
|
||||
case '\u0054':
|
||||
return 0x39;
|
||||
case '\u0055':
|
||||
return 0x3A;
|
||||
case '\u0056':
|
||||
return 0x3B;
|
||||
case '\u0057':
|
||||
return 0x3C;
|
||||
case '\u0058':
|
||||
return 0x3D;
|
||||
case '\u0059':
|
||||
return 0x3E;
|
||||
case '\u005A':
|
||||
return 0x3F;
|
||||
case '\u000D':
|
||||
return 0x74;
|
||||
case '\u000A':
|
||||
return 0x76;
|
||||
case '\u0008':
|
||||
return 0x77;
|
||||
case '\u2588':
|
||||
return 0x80;
|
||||
case '\u259F':
|
||||
return 0x81;
|
||||
case '\u2599':
|
||||
return 0x82;
|
||||
case '\u2584':
|
||||
return 0x83;
|
||||
case '\u259C':
|
||||
return 0x84;
|
||||
case '\u2590':
|
||||
return 0x85;
|
||||
case '\u259A':
|
||||
return 0x86;
|
||||
case '\u2597':
|
||||
return 0x87;
|
||||
switch(character)
|
||||
{
|
||||
case '\u0020': return 0x00;
|
||||
case '\u2598': return 0x01;
|
||||
case '\u259D': return 0x02;
|
||||
case '\u2580': return 0x03;
|
||||
case '\u2596': return 0x04;
|
||||
case '\u258C': return 0x05;
|
||||
case '\u259E': return 0x06;
|
||||
case '\u259B': return 0x07;
|
||||
case '\u2592': return 0x08;
|
||||
case '\u0022': return 0x0B;
|
||||
case '\u00A3': return 0x0C;
|
||||
case '\u0024': return 0x0D;
|
||||
case '\u003A': return 0x0E;
|
||||
case '\u003F': return 0x0F;
|
||||
case '\u0028': return 0x10;
|
||||
case '\u0029': return 0x11;
|
||||
case '\u003E': return 0x12;
|
||||
case '\u003C': return 0x13;
|
||||
case '\u003D': return 0x14;
|
||||
case '\u002B': return 0x15;
|
||||
case '\u002D': return 0x16;
|
||||
case '\u002A': return 0x17;
|
||||
case '\u002F': return 0x18;
|
||||
case '\u003B': return 0x19;
|
||||
case '\u002C': return 0x1A;
|
||||
case '\u002E': return 0x1B;
|
||||
case '\u0030': return 0x1C;
|
||||
case '\u0031': return 0x1D;
|
||||
case '\u0032': return 0x1E;
|
||||
case '\u0033': return 0x1F;
|
||||
case '\u0034': return 0x20;
|
||||
case '\u0035': return 0x21;
|
||||
case '\u0036': return 0x22;
|
||||
case '\u0037': return 0x23;
|
||||
case '\u0038': return 0x24;
|
||||
case '\u0039': return 0x25;
|
||||
case '\u0041': return 0x26;
|
||||
case '\u0042': return 0x27;
|
||||
case '\u0043': return 0x28;
|
||||
case '\u0044': return 0x29;
|
||||
case '\u0045': return 0x2A;
|
||||
case '\u0046': return 0x2B;
|
||||
case '\u0047': return 0x2C;
|
||||
case '\u0048': return 0x2D;
|
||||
case '\u0049': return 0x2E;
|
||||
case '\u004A': return 0x2F;
|
||||
case '\u004B': return 0x30;
|
||||
case '\u004C': return 0x31;
|
||||
case '\u004D': return 0x32;
|
||||
case '\u004E': return 0x33;
|
||||
case '\u004F': return 0x34;
|
||||
case '\u0050': return 0x35;
|
||||
case '\u0051': return 0x36;
|
||||
case '\u0052': return 0x37;
|
||||
case '\u0053': return 0x38;
|
||||
case '\u0054': return 0x39;
|
||||
case '\u0055': return 0x3A;
|
||||
case '\u0056': return 0x3B;
|
||||
case '\u0057': return 0x3C;
|
||||
case '\u0058': return 0x3D;
|
||||
case '\u0059': return 0x3E;
|
||||
case '\u005A': return 0x3F;
|
||||
case '\u000D': return 0x74;
|
||||
case '\u000A': return 0x76;
|
||||
case '\u0008': return 0x77;
|
||||
case '\u2588': return 0x80;
|
||||
case '\u259F': return 0x81;
|
||||
case '\u2599': return 0x82;
|
||||
case '\u2584': return 0x83;
|
||||
case '\u259C': return 0x84;
|
||||
case '\u2590': return 0x85;
|
||||
case '\u259A': return 0x86;
|
||||
case '\u2597': return 0x87;
|
||||
default:
|
||||
// Fallback to '?'
|
||||
return 0x0F;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="NuGet.Build.Packaging" version="0.1.248" targetFramework="portable45-net45+win8+wp8" developmentDependency="true" />
|
||||
<package id="NuGet.Build.Packaging" version="0.2.2" targetFramework="portable40-net40+sl5+win8+wp8" developmentDependency="true" />
|
||||
</packages>
|
||||
17
README.md
17
README.md
@@ -3,14 +3,29 @@
|
||||
|
||||
Library to provide codepage conversion to and from archaic and old computer systems and Unicode.
|
||||
|
||||
Copyright © 2016 Natalia Portillo <claunia@claunia.com>
|
||||
Copyright © 2016-2019 Natalia Portillo <claunia@claunia.com>
|
||||
|
||||
Supported encodings
|
||||
==============================
|
||||
* Apple II, IIc, IIe and IIgs
|
||||
* Apple Lisa
|
||||
* Atari Standard Code for Information Interchange (ATASCII)
|
||||
* Atari ST character set
|
||||
* Commodore PET Standard Code for Information Interchange (PETSCII)
|
||||
* DEC Radix-50
|
||||
* GEM Character Set
|
||||
* GEOS Character Set
|
||||
* MacArabic
|
||||
* MacCentralEuropean
|
||||
* MacCroatian
|
||||
* MacCyrillic
|
||||
* MacFarsi
|
||||
* MacGreek
|
||||
* MacHebrew
|
||||
* MacRoman
|
||||
* MacRomanian
|
||||
* MacTurkish
|
||||
* MacUkrainian
|
||||
* Sinclair ZX80 character set
|
||||
* Sinclair ZX81 character set
|
||||
* Sinclair ZX Spectrum character set
|
||||
|
||||
Reference in New Issue
Block a user