From 2affdfa03b3c7bbf4d032f27e7d6ba2c1a57cdc9 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 18 Aug 2016 22:08:40 +0100 Subject: [PATCH] First version, supports only Apple Lisa encoding. --- .gitignore | 40 + Claunia.Encoding.Tests/ChangeLog | 7 + .../Claunia.Encoding.Tests.csproj | 48 + Claunia.Encoding.Tests/LisaRoman.cs | 178 ++++ Claunia.Encoding.Tests/packages.config | 4 + Claunia.Encoding.sln | 58 + Claunia.Encoding/ChangeLog | 9 + Claunia.Encoding/Claunia.Encoding.csproj | 61 ++ Claunia.Encoding/Encoding.cs | 34 + Claunia.Encoding/LisaRoman.cs | 993 ++++++++++++++++++ Claunia.Encoding/Pangrams.cs | 76 ++ Claunia.Encoding/Properties/AssemblyInfo.cs | 54 + LICENSE.MIT | 19 + README.md | 10 + 14 files changed, 1591 insertions(+) create mode 100644 .gitignore create mode 100644 Claunia.Encoding.Tests/ChangeLog create mode 100644 Claunia.Encoding.Tests/Claunia.Encoding.Tests.csproj create mode 100644 Claunia.Encoding.Tests/LisaRoman.cs create mode 100644 Claunia.Encoding.Tests/packages.config create mode 100644 Claunia.Encoding.sln create mode 100644 Claunia.Encoding/ChangeLog create mode 100644 Claunia.Encoding/Claunia.Encoding.csproj create mode 100644 Claunia.Encoding/Encoding.cs create mode 100644 Claunia.Encoding/LisaRoman.cs create mode 100644 Claunia.Encoding/Pangrams.cs create mode 100644 Claunia.Encoding/Properties/AssemblyInfo.cs create mode 100644 LICENSE.MIT create mode 100644 README.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7bbcfed --- /dev/null +++ b/.gitignore @@ -0,0 +1,40 @@ +#Autosave files +*~ + +#build +[Oo]bj/ +[Bb]in/ +packages/ +TestResults/ + +# globs +Makefile.in +*.DS_Store +*.sln.cache +*.suo +*.cache +*.pidb +*.userprefs +*.usertasks +config.log +config.make +config.status +aclocal.m4 +install-sh +autom4te.cache/ +*.user +*.tar.gz +tarballs/ +test-results/ +Thumbs.db + +#Mac bundle stuff +*.dmg +*.app + +#resharper +*_Resharper.* +*.Resharper + +#dotCover +*.dotCover diff --git a/Claunia.Encoding.Tests/ChangeLog b/Claunia.Encoding.Tests/ChangeLog new file mode 100644 index 0000000..5a69a37 --- /dev/null +++ b/Claunia.Encoding.Tests/ChangeLog @@ -0,0 +1,7 @@ +2016-08-18 Natalia Portillo + + * LisaRoman.cs: + * packages.config: + * Claunia.Encoding.Tests.csproj: First version, supports only + Apple Lisa encoding. + diff --git a/Claunia.Encoding.Tests/Claunia.Encoding.Tests.csproj b/Claunia.Encoding.Tests/Claunia.Encoding.Tests.csproj new file mode 100644 index 0000000..f7476b9 --- /dev/null +++ b/Claunia.Encoding.Tests/Claunia.Encoding.Tests.csproj @@ -0,0 +1,48 @@ + + + + Debug + AnyCPU + {94C931C5-EA3A-4AB2-80F5-1BE083C237C3} + Library + Claunia.Encoding.Tests + Claunia.Encoding.Tests + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + false + + + true + bin\Release + prompt + 4 + false + + + + + ..\packages\NUnit.2.6.4\lib\nunit.framework.dll + + + + + + + + + + + {85DA90BC-9F49-4579-B4D1-4FF2D5925D7F} + Claunia.Encoding + + + + \ No newline at end of file diff --git a/Claunia.Encoding.Tests/LisaRoman.cs b/Claunia.Encoding.Tests/LisaRoman.cs new file mode 100644 index 0000000..74d506c --- /dev/null +++ b/Claunia.Encoding.Tests/LisaRoman.cs @@ -0,0 +1,178 @@ +// +// LisaRoman.cs +// +// Author: +// Natalia Portillo +// +// Copyright (c) 2016 © Claunia.com +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using NUnit.Framework; +using Claunia.Encoding; + +namespace Claunia.Encoding.Tests +{ + [TestFixture()] + 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 }; + 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 }; + + 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}; + const string Currency = "¢£§¥"; + readonly byte[] CurrencyBytes = { 0xA2, 0xA3, 0xA4, 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() + { + byte[] byteArray; + + 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); + } + + [Test()] + public void LisaToUnicode() + { + string testString; + + testString = Encoding.LisaEncoding.GetString(PunctuationsBytes); + Assert.AreEqual(Punctuations, testString); + testString = Encoding.LisaEncoding.GetString(DigitsBytes); + Assert.AreEqual(Digits, testString); + testString = Encoding.LisaEncoding.GetString(UpperLatinBytes); + Assert.AreEqual(UpperLatin, testString); + testString = Encoding.LisaEncoding.GetString(LowerLatinBytes); + Assert.AreEqual(LowerLatin, testString); + + testString = Encoding.LisaEncoding.GetString(SpanishBytes); + Assert.AreEqual(Spanish, testString); + testString = Encoding.LisaEncoding.GetString(FrenchBytes); + Assert.AreEqual(French, testString); + testString = Encoding.LisaEncoding.GetString(GermanBytes); + Assert.AreEqual(German, testString); + testString = Encoding.LisaEncoding.GetString(NorwegianBytes); + Assert.AreEqual(Norwegian, testString); + testString = Encoding.LisaEncoding.GetString(PortugueseBytes); + Assert.AreEqual(Portuguese, testString); + + testString = Encoding.LisaEncoding.GetString(TypographicBytes); + Assert.AreEqual(Typographic, testString); + testString = Encoding.LisaEncoding.GetString(CurrencyBytes); + Assert.AreEqual(Currency, testString); + testString = Encoding.LisaEncoding.GetString(MathematicsBytes); + Assert.AreEqual(Mathematics, testString); + } + + [Test()] + public void LisaPangrams() + { + 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); + } + } +} \ No newline at end of file diff --git a/Claunia.Encoding.Tests/packages.config b/Claunia.Encoding.Tests/packages.config new file mode 100644 index 0000000..c714ef3 --- /dev/null +++ b/Claunia.Encoding.Tests/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Claunia.Encoding.sln b/Claunia.Encoding.sln new file mode 100644 index 0000000..2332a3f --- /dev/null +++ b/Claunia.Encoding.sln @@ -0,0 +1,58 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Claunia.Encoding", "Claunia.Encoding\Claunia.Encoding.csproj", "{85DA90BC-9F49-4579-B4D1-4FF2D5925D7F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Claunia.Encoding.Tests", "Claunia.Encoding.Tests\Claunia.Encoding.Tests.csproj", "{94C931C5-EA3A-4AB2-80F5-1BE083C237C3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {85DA90BC-9F49-4579-B4D1-4FF2D5925D7F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {85DA90BC-9F49-4579-B4D1-4FF2D5925D7F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {85DA90BC-9F49-4579-B4D1-4FF2D5925D7F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {85DA90BC-9F49-4579-B4D1-4FF2D5925D7F}.Release|Any CPU.Build.0 = Release|Any CPU + {94C931C5-EA3A-4AB2-80F5-1BE083C237C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {94C931C5-EA3A-4AB2-80F5-1BE083C237C3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {94C931C5-EA3A-4AB2-80F5-1BE083C237C3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {94C931C5-EA3A-4AB2-80F5-1BE083C237C3}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(MonoDevelopProperties) = preSolution + 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 + $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 + EndGlobalSection +EndGlobal diff --git a/Claunia.Encoding/ChangeLog b/Claunia.Encoding/ChangeLog new file mode 100644 index 0000000..5a39af5 --- /dev/null +++ b/Claunia.Encoding/ChangeLog @@ -0,0 +1,9 @@ +2016-08-18 Natalia Portillo + + * Encoding.cs: + * Pangrams.cs: + * LisaRoman.cs: + * Claunia.Encoding.csproj: + * AssemblyInfo.cs: First version, supports only Apple Lisa + encoding. + diff --git a/Claunia.Encoding/Claunia.Encoding.csproj b/Claunia.Encoding/Claunia.Encoding.csproj new file mode 100644 index 0000000..700e384 --- /dev/null +++ b/Claunia.Encoding/Claunia.Encoding.csproj @@ -0,0 +1,61 @@ + + + + Debug + AnyCPU + {85DA90BC-9F49-4579-B4D1-4FF2D5925D7F} + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + true + Library + Claunia.Encoding + Claunia.Encoding + v4.5 + Profile78 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + bin\Debug\Claunia.Encoding.xml + false + + + true + bin\Release + prompt + 4 + bin\Release\Claunia.Encoding.xml + false + + + + + + + + + + LICENSE.MIT + PreserveNewest + + + README.md + PreserveNewest + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Claunia.Encoding/Encoding.cs b/Claunia.Encoding/Encoding.cs new file mode 100644 index 0000000..9f46a4c --- /dev/null +++ b/Claunia.Encoding/Encoding.cs @@ -0,0 +1,34 @@ +// +// Encoding.cs +// +// Author: +// Natalia Portillo +// +// Copyright (c) 2016 © Claunia.com +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +namespace Claunia.Encoding +{ + public static class Encoding + { + public static System.Text.Encoding LisaEncoding = new LisaRoman(); + } +} + diff --git a/Claunia.Encoding/LisaRoman.cs b/Claunia.Encoding/LisaRoman.cs new file mode 100644 index 0000000..13f3f04 --- /dev/null +++ b/Claunia.Encoding/LisaRoman.cs @@ -0,0 +1,993 @@ +// +// LisaRoman.cs +// +// Author: +// Natalia Portillo +// +// Copyright (c) 2016 © Claunia.com +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; + +namespace Claunia.Encoding +{ + public class LisaRoman : System.Text.Encoding + { + const string _bodyname = "lisa"; + const int _codepage = 0; + const string _encodingname = "Apple Lisa"; + const string _headername = "lisa"; + const string _webname = "lisa"; + const int _windowsCodepage = 10000; + + const bool browserDisplay = false; + const bool browserSave = false; + const bool mailNewsDisplay = false; + const bool mailNewsSave = false; + const bool readOnly = false; + const bool singleByte = true; + + /// + /// Gets a value indicating whether the current encoding can be used by browser clients for displaying content. + /// + public bool IsBrowserDisplay { + get { return browserDisplay; } + } + + /// + /// Gets a value indicating whether the current encoding can be used by browser clients for saving content. + /// + public bool IsBrowserSave { + get { return browserSave; } + } + + /// + /// Gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. + /// + public bool IsMailNewsDisplay { + get { return mailNewsDisplay; } + } + + /// + /// Gets a value indicating whether the current encoding can be used by mail and news clients for saving content. + /// + public bool IsMailNewsSave { + get { return mailNewsSave; } + } + + /// + /// Gets a value indicating whether the current encoding is read-only. + /// + /// The is single byte. + public bool IsReadOnly { + get { return readOnly; } + } + + /// + /// Gets a value indicating whether the current encoding uses single-byte code points. + /// + public bool IsSingleByte { + get { return singleByte; } + } + + /// + /// Gets the code page identifier of the current Encoding. + /// + public int CodePage { + get { return _codepage; } + } + + /// + /// Gets a name for the current encoding that can be used with mail agent body tags + /// + public string BodyName { + get { return _bodyname; } + } + + /// + /// Gets a name for the current encoding that can be used with mail agent header tags + /// + public string HeaderName { + get { return _headername; } + } + + public override string WebName { + get { return _webname; } + } + + /// + /// Gets the human-readable description of the current encoding. + /// + public string EncodingName { + get { return _encodingname; } + } + + /// + /// Gets the Windows operating system code page that most closely corresponds to the current encoding. + /// + public int WindowsCodePage { + get { return _windowsCodepage; } + } + + /// + /// Calculates the number of bytes produced by encoding the characters in the specified . + /// + /// The number of bytes produced by encoding the specified characters. + /// The containing the set of characters to encode. + public override int GetByteCount(string s) + { + if(s == null) + throw new ArgumentNullException(nameof(s)); + + return s.Length; + } + + /// + /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. + /// + /// The number of bytes produced by encoding the specified characters. + /// The character array containing the set of characters to encode. + /// The index of the first character to encode. + /// The number of characters to encode. + public override int GetByteCount(char[] chars, int index, int count) + { + if(chars == null) + throw new ArgumentNullException(nameof(chars)); + + if(index < 0 || index >= chars.Length) + throw new ArgumentOutOfRangeException(nameof(index)); + + if(count < 0 || index + count > chars.Length) + throw new ArgumentOutOfRangeException(nameof(index)); + + return count; + } + + /// + /// Calculates the number of bytes produced by encoding all the characters in the specified character array. + /// + /// The number of bytes produced by encoding all the characters in the specified character array. + /// The character array containing the characters to encode. + public override int GetByteCount(char[] chars) + { + if(chars == null) + throw new ArgumentNullException(nameof(chars)); + + return chars.Length; + } + + /// + /// Encodes a set of characters from the specified into the specified byte array. + /// + /// The actual number of bytes written into bytes. + /// The containing the set of characters to encode. + /// The index of the first character to encode. + /// The number of characters to encode. + /// The byte array to contain the resulting sequence of bytes. + /// The index at which to start writing the resulting sequence of bytes. + public override int GetBytes(string s, int charIndex, int charCount, byte[] bytes, int byteIndex) + { + return GetBytes(s.ToCharArray(), charIndex, charCount, bytes, byteIndex); + } + + /// + /// Encodes all the characters in the specified string into a sequence of bytes. + /// + /// A byte array containing the results of encoding the specified set of characters. + /// The string containing the characters to encode. + public override byte[] GetBytes(string s) + { + if(s == null) + throw new ArgumentNullException(nameof(s)); + + return GetBytes(s.ToCharArray(), 0, s.Length); + } + + /// + /// Encodes a set of characters from the specified character array into the specified byte array. + /// + /// The actual number of bytes written into bytes. + /// The character array containing the set of characters to encode. + /// The index of the first character to encode. + /// The number of characters to encode. + /// The byte array to contain the resulting sequence of bytes. + /// The index at which to start writing the resulting sequence of bytes. + public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) + { + if(chars == null) + throw new ArgumentNullException(nameof(chars)); + + if(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; + } + + /// + /// Encodes a set of characters from the specified character array into a sequence of bytes. + /// + /// A byte array containing the results of encoding the specified set of characters. + /// The character array containing the set of characters to encode. + /// The index of the first character to encode. + /// The number of characters to encode. + public override byte[] GetBytes(char[] chars, int index, int count) + { + if(chars == null) + throw new ArgumentNullException(nameof(chars)); + + if(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; + } + + /// + /// Encodes all the characters in the specified character array into a sequence of bytes. + /// + /// A byte array containing the results of encoding the specified set of characters. + /// The character array containing the characters to encode. + public override byte[] GetBytes(char[] chars) + { + return GetBytes(chars, 0, chars.Length); + } + + /// + /// Calculates the number of characters produced by decoding all the bytes in the specified byte array. + /// + /// The number of characters produced by decoding the specified sequence of bytes. + /// The byte array containing the sequence of bytes to decode. + public override int GetCharCount(byte[] bytes) + { + return GetCharCount(bytes, 0, bytes.Length); + } + + /// + /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. + /// + /// The number of characters produced by decoding the specified sequence of bytes. + /// The byte array containing the sequence of bytes to decode. + /// The index of the first byte to decode. + /// The number of bytes to decode. + public override int GetCharCount(byte[] bytes, int index, int count) + { + if(bytes == null) + throw new ArgumentNullException(nameof(bytes)); + + if(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; + } + + /// + /// Decodes a sequence of bytes from the specified byte array into the specified character array. + /// + /// The actual number of characters written into chars. + /// The byte array containing the sequence of bytes to decode. + /// The index of the first byte to decode. + /// The number of bytes to decode. + /// The character array to contain the resulting set of characters. + /// The index at which to start writing the resulting set of characters. + public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) + { + if(bytes == null) + throw new ArgumentNullException(nameof(bytes)); + + if(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; + } + + /// + /// Decodes all the bytes in the specified byte array into a set of characters. + /// + /// A character array containing the results of decoding the specified sequence of bytes. + /// The byte array containing the sequence of bytes to decode. + public override char[] GetChars(byte[] bytes) + { + return GetChars(bytes, 0, bytes.Length); + } + + /// + /// Decodes a sequence of bytes from the specified byte array into a set of characters. + /// + /// The chars. + /// The byte array containing the sequence of bytes to decode. + /// The index of the first byte to decode. + /// The number of bytes to decode. + public override char[] GetChars(byte[] bytes, int index, int count) + { + if(bytes == null) + throw new ArgumentNullException(nameof(bytes)); + + if(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; + } + + /// + /// Calculates the maximum number of bytes produced by encoding the specified number of characters. + /// + /// The maximum number of bytes produced by encoding the specified number of characters. + /// The number of characters to encode. + public override int GetMaxByteCount(int charCount) + { + if(charCount < 0) + throw new ArgumentOutOfRangeException(nameof(charCount)); + + return charCount; + } + + /// + /// Calculates the maximum number of characters produced by decoding the specified number of bytes. + /// + /// The maximum number of characters produced by decoding the specified number of bytes. + /// The number of bytes to decode. + public override int GetMaxCharCount(int byteCount) + { + if(byteCount < 0) + throw new ArgumentOutOfRangeException(nameof(byteCount)); + + return byteCount; + } + + /// + /// Returns a sequence of bytes that specifies the encoding used. + /// + /// A byte array of length zero, as a preamble is not required. + public override byte[] GetPreamble() + { + return new byte[0]; + } + + /// + /// Decodes all the bytes in the specified byte array into a string. + /// + /// A string that contains the results of decoding the specified sequence of bytes. + /// The byte array containing the sequence of bytes to decode. + public string GetString(byte[] bytes) + { + return GetString(bytes, 0, bytes.Length); + } + + /// + /// Decodes a sequence of bytes from the specified byte array into a string. + /// + /// A string that contains the results of decoding the specified sequence of bytes. + /// The byte array containing the sequence of bytes to decode. + /// The index of the first byte to decode. + /// The number of bytes to decode. + public override string GetString(byte[] bytes, int index, int count) + { + return new string(GetChars(bytes, index, count)); + } + + /// + /// The Lisa to Unicode character map. + /// MacRoman is a superset of LisaRoman. + /// + static readonly char[] LisaRomanTable = { + // 0x00 + '\u0000','\u0001','\u0002','\u0003','\u0004','\u0005','\u0006','\u0007', + // 0x08 + '\u0008','\u0009','\u000A','\u000B','\u000C','\u000D','\u000E','\u000F', + // 0x10 + '\u0010','\u0011','\u0012','\u0013','\u0014','\u0015','\u0016','\u0017', + // 0x18 + '\u0018','\u0019','\u001A','\u001B','\u001C','\u001D','\u001E','\u001F', + // 0x20 + '\u0020','\u0021','\u0022','\u0023','\u0024','\u0025','\u0026','\u0027', + // 0x28 + '\u0028','\u0029','\u002A','\u002B','\u002C','\u002D','\u002E','\u002F', + // 0x30 + '\u0030','\u0031','\u0032','\u0033','\u0034','\u0035','\u0036','\u0037', + // 0x38 + '\u0038','\u0039','\u003A','\u003B','\u003C','\u003D','\u003E','\u003F', + // 0x40 + '\u0040','\u0041','\u0042','\u0043','\u0044','\u0045','\u0046','\u0047', + // 0x48 + '\u0048','\u0049','\u004A','\u004B','\u004C','\u004D','\u004E','\u004F', + // 0x50 + '\u0050','\u0051','\u0052','\u0053','\u0054','\u0055','\u0056','\u0057', + // 0x58 + '\u0058','\u0059','\u005A','\u005B','\u005C','\u005D','\u005E','\u005F', + // 0x60 + '\u0060','\u0061','\u0062','\u0063','\u0064','\u0065','\u0066','\u0067', + // 0x68 + '\u0068','\u0069','\u006A','\u006B','\u006C','\u006D','\u006E','\u006F', + // 0x70 + '\u0070','\u0071','\u0072','\u0073','\u0074','\u0075','\u0076','\u0077', + // 0x78 + '\u0078','\u0079','\u007A','\u007B','\u007C','\u007D','\u007E','\u2588', + // 0x80 + '\u00C4','\u00C5','\u00C7','\u00C9','\u00D1','\u00D6','\u00DC','\u00E1', + // 0x88 + '\u00E0','\u00E2','\u00E4','\u00E3','\u00E5','\u00E7','\u00E9','\u00E8', + // 0x90 + '\u00EA','\u00EB','\u00ED','\u00EC','\u00EE','\u00EF','\u00F1','\u00F3', + // 0x98 + '\u00F2','\u00F4','\u00F6','\u00F5','\u00FA','\u00F9','\u00FB','\u00FC', + // 0xA0 + '\u2020','\u00B0','\u00A2','\u00A3','\u00A7','\u2022','\u00B6','\u00DF', + // 0xA8 + '\u00AE','\u00A9','\u2122','\u00B4','\u00A8','\u2260','\u00C6','\u00D8', + // 0xB0 + '\u221E','\u00B1','\u2264','\u2265','\u00A5','\u00B5','\u2202','\u2211', + // 0xB8 + '\u220F','\u03C0','\u222B','\u00AA','\u00BA','\u03A9','\u00E6','\u00F8', + // 0xC0 + '\u00BF','\u00A1','\u00AC','\u221A','\u0192','\u2248','\u2206','\u00AB', + // 0xC8 + '\u00BB','\u2026','\u00A0','\u00C0','\u00C3','\u00D5','\u0152','\u0153', + // 0xD0 + '\u2013','\u2014','\u201C','\u201D','\u2018','\u2019','\u00F7','\u25CA', + // 0xD8 + '\u00FF','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', + // 0xE0 + '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', + // 0xE8 + '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', + // 0xF0 + '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000', + // 0xF8 + '\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000','\u0000' + }; + + /// + /// Converts a LisaRoman character to an Unicode character + /// + /// Unicode character. + /// LisaRoman character. + static char GetChar(byte character) + { + return LisaRomanTable[character]; + } + + /// + /// Converts a Unicode character to an LisaRoman character + /// + /// LisaRoman character. + /// Unicode character. + static byte GetByte(char character) + { + switch(character) { + case '\u0000': + return 0x00; + case '\u0001': + return 0x01; + case '\u0002': + return 0x02; + case '\u0003': + return 0x03; + case '\u0004': + return 0x04; + case '\u0005': + return 0x05; + case '\u0006': + return 0x06; + case '\u0007': + return 0x07; + case '\u0008': + return 0x08; + case '\u0009': + return 0x09; + case '\u000A': + return 0x0A; + case '\u000B': + return 0x0B; + case '\u000C': + return 0x0C; + case '\u000D': + return 0x0D; + case '\u000E': + return 0x0E; + case '\u000F': + return 0x0F; + case '\u0010': + return 0x10; + case '\u0011': + return 0x11; + case '\u0012': + return 0x12; + case '\u0013': + return 0x13; + case '\u0014': + return 0x14; + case '\u0015': + return 0x15; + case '\u0016': + return 0x16; + case '\u0017': + return 0x17; + case '\u0018': + return 0x18; + case '\u0019': + return 0x19; + case '\u001A': + return 0x1A; + case '\u001B': + return 0x1B; + case '\u001C': + return 0x1C; + case '\u001D': + return 0x1D; + case '\u001E': + return 0x1E; + case '\u001F': + return 0x1F; + case '\u0020': + return 0x20; + case '\u0021': + return 0x21; + case '\u0022': + return 0x22; + case '\u0023': + return 0x23; + case '\u0024': + return 0x24; + case '\u0025': + return 0x25; + case '\u0026': + return 0x26; + case '\u0027': + return 0x27; + case '\u0028': + return 0x28; + case '\u0029': + return 0x29; + case '\u002A': + return 0x2A; + case '\u002B': + return 0x2B; + case '\u002C': + return 0x2C; + case '\u002D': + return 0x2D; + case '\u002E': + return 0x2E; + case '\u002F': + return 0x2F; + case '\u0030': + return 0x30; + case '\u0031': + return 0x31; + case '\u0032': + return 0x32; + case '\u0033': + return 0x33; + case '\u0034': + return 0x34; + case '\u0035': + return 0x35; + case '\u0036': + return 0x36; + case '\u0037': + return 0x37; + case '\u0038': + return 0x38; + case '\u0039': + return 0x39; + case '\u003A': + return 0x3A; + case '\u003B': + return 0x3B; + case '\u003C': + return 0x3C; + case '\u003D': + return 0x3D; + case '\u003E': + return 0x3E; + case '\u003F': + return 0x3F; + case '\u0040': + return 0x40; + case '\u0041': + return 0x41; + case '\u0042': + return 0x42; + case '\u0043': + return 0x43; + case '\u0044': + return 0x44; + case '\u0045': + return 0x45; + case '\u0046': + return 0x46; + case '\u0047': + return 0x47; + case '\u0048': + return 0x48; + case '\u0049': + return 0x49; + case '\u004A': + return 0x4A; + case '\u004B': + return 0x4B; + case '\u004C': + return 0x4C; + case '\u004D': + return 0x4D; + case '\u004E': + return 0x4E; + case '\u004F': + return 0x4F; + case '\u0050': + return 0x50; + case '\u0051': + return 0x51; + case '\u0052': + return 0x52; + case '\u0053': + return 0x53; + case '\u0054': + return 0x54; + case '\u0055': + return 0x55; + case '\u0056': + return 0x56; + case '\u0057': + return 0x57; + case '\u0058': + return 0x58; + case '\u0059': + return 0x59; + case '\u005A': + return 0x5A; + case '\u005B': + return 0x5B; + case '\u005C': + return 0x5C; + case '\u005D': + return 0x5D; + case '\u005E': + return 0x5E; + case '\u005F': + return 0x5F; + case '\u0060': + return 0x60; + case '\u0061': + return 0x61; + case '\u0062': + return 0x62; + case '\u0063': + return 0x63; + case '\u0064': + return 0x64; + case '\u0065': + return 0x65; + case '\u0066': + return 0x66; + case '\u0067': + return 0x67; + case '\u0068': + return 0x68; + case '\u0069': + return 0x69; + case '\u006A': + return 0x6A; + case '\u006B': + return 0x6B; + case '\u006C': + return 0x6C; + case '\u006D': + return 0x6D; + case '\u006E': + return 0x6E; + case '\u006F': + return 0x6F; + case '\u0070': + return 0x70; + case '\u0071': + return 0x71; + case '\u0072': + return 0x72; + case '\u0073': + return 0x73; + case '\u0074': + return 0x74; + case '\u0075': + return 0x75; + case '\u0076': + return 0x76; + case '\u0077': + return 0x77; + case '\u0078': + return 0x78; + case '\u0079': + return 0x79; + case '\u007A': + return 0x7A; + case '\u007B': + return 0x7B; + case '\u007C': + return 0x7C; + case '\u007D': + return 0x7D; + case '\u007E': + return 0x7E; + case '\u2588': + return 0x7F; + case '\u00C4': + return 0x80; + case '\u00C5': + return 0x81; + case '\u00C7': + return 0x82; + case '\u00C9': + return 0x83; + case '\u00D1': + return 0x84; + case '\u00D6': + return 0x85; + case '\u00DC': + return 0x86; + case '\u00E1': + return 0x87; + case '\u00E0': + return 0x88; + case '\u00E2': + return 0x89; + case '\u00E4': + return 0x8A; + case '\u00E3': + return 0x8B; + case '\u00E5': + return 0x8C; + case '\u00E7': + return 0x8D; + case '\u00E9': + return 0x8E; + case '\u00E8': + return 0x8F; + case '\u00EA': + return 0x90; + case '\u00EB': + return 0x91; + case '\u00ED': + return 0x92; + case '\u00EC': + return 0x93; + case '\u00EE': + return 0x94; + case '\u00EF': + return 0x95; + case '\u00F1': + return 0x96; + case '\u00F3': + return 0x97; + case '\u00F2': + return 0x98; + case '\u00F4': + return 0x99; + case '\u00F6': + return 0x9A; + case '\u00F5': + return 0x9B; + case '\u00FA': + return 0x9C; + case '\u00F9': + return 0x9D; + case '\u00FB': + return 0x9E; + case '\u00FC': + return 0x9F; + case '\u2020': + return 0xA0; + case '\u00B0': + return 0xA1; + case '\u00A2': + return 0xA2; + case '\u00A3': + return 0xA3; + case '\u00A7': + return 0xA4; + case '\u2022': + return 0xA5; + case '\u00B6': + return 0xA6; + case '\u00DF': + return 0xA7; + case '\u00AE': + return 0xA8; + case '\u00A9': + return 0xA9; + case '\u2122': + return 0xAA; + case '\u00B4': + return 0xAB; + case '\u00A8': + return 0xAC; + case '\u2260': + return 0xAD; + case '\u00C6': + return 0xAE; + case '\u00D8': + return 0xAF; + case '\u221E': + return 0xB0; + case '\u00B1': + return 0xB1; + case '\u2264': + return 0xB2; + case '\u2265': + return 0xB3; + case '\u00A5': + return 0xB4; + case '\u00B5': + return 0xB5; + case '\u2202': + return 0xB6; + case '\u2211': + return 0xB7; + case '\u220F': + return 0xB8; + case '\u03C0': + return 0xB9; + case '\u222B': + return 0xBA; + case '\u00AA': + return 0xBB; + case '\u00BA': + return 0xBC; + case '\u03A9': + return 0xBD; + case '\u00E6': + return 0xBE; + case '\u00F8': + return 0xBF; + case '\u00BF': + return 0xC0; + case '\u00A1': + return 0xC1; + case '\u00AC': + return 0xC2; + case '\u221A': + return 0xC3; + case '\u0192': + return 0xC4; + case '\u2248': + return 0xC5; + case '\u2206': + return 0xC6; + case '\u00AB': + return 0xC7; + case '\u00BB': + return 0xC8; + case '\u2026': + return 0xC9; + case '\u00A0': + return 0xCA; + case '\u00C0': + return 0xCB; + case '\u00C3': + return 0xCC; + case '\u00D5': + return 0xCD; + case '\u0152': + return 0xCE; + case '\u0153': + return 0xCF; + case '\u2013': + return 0xD0; + case '\u2014': + return 0xD1; + case '\u201C': + return 0xD2; + case '\u201D': + return 0xD3; + case '\u2018': + return 0xD4; + case '\u2019': + return 0xD5; + case '\u00F7': + return 0xD6; + case '\u25CA': + return 0xD7; + case '\u00FF': + return 0xD8; + default: + // Fallback to '?' + return 0x3F; + } + } + } +} diff --git a/Claunia.Encoding/Pangrams.cs b/Claunia.Encoding/Pangrams.cs new file mode 100644 index 0000000..f95640c --- /dev/null +++ b/Claunia.Encoding/Pangrams.cs @@ -0,0 +1,76 @@ +// +// Pangrams.cs +// +// Author: +// Natalia Portillo +// +// Copyright (c) 2016 © Claunia.com +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +using System; +namespace Claunia.Encoding +{ + public static class Pangrams + { + public const string Arabic = "صِف خَلقَ خَودِ كَمِثلِ الشَمسِ إِذ بَزَغَت — يَحظى الضَجيعُ بِها نَجلاءَ مِعطارِ"; + public const string Azeri = "Zəfər, jaketini də papağını da götür, bu axşam hava çox soyuq olacaq."; + public const string Basque = "Vaudeville itxurako filmean, yogi ñaño bat jipoitzen dute Quebec-en, whiski truk"; + public const string Breton = "Yec’hed mat Jakez ! Skarzhit ar gwerennoù-mañ, kavet e vo gwin betek fin ho puhez."; + public const string Bulgarian = "Хълцащ змей плюе шофьор стигнал чуждия бивак."; + 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 ChineseTraditional = "視野無限廣,窗外有藍天"; + public const string ChineseSimplified = "Innovation in China 中国智造,慧及全球"; + public const string Croatian = "Gojazni đačić s biciklom drži hmelj i finu vatu u džepu nošnje."; + public const string Czech = "Nechť již hříšné saxofony ďáblů rozezvučí síň úděsnými tóny waltzu, tanga a quickstepu."; + public const string Danish = "Quizdeltagerne spiste jordbær med fløde, mens cirkusklovnen Walther spillede på xylofon."; + public const string Dutch = "Pa’s wijze lynx bezag vroom het fikse aquaduct."; + public const string English = "The quick brown fox jumps over the lazy dog."; + public const string Esperanto = "Eble ĉiu kvazaŭ-deca fuŝĥoraĵo ĝojigos homtipon."; + public const string Estonian = "Põdur Zagrebi tšellomängija-följetonist Ciqo külmetas kehvas garaažis."; + public const string Finnish = "Fahrenheit ja Celsius yrjösivät Åsan backgammon-peliin, Volkswagenissa, daiquirin ja ZX81:n yhteisvaikutuksesta."; + 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 Galician = "Necesitamos unha tipografía chuliña de cor kiwi, que lle zorregue unha labazada visual á xente."; + public const string German = "Falsches Üben von Xylophonmusik quält jeden größeren Zwerg."; + 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 Hebrew = "לכן חכו לי נאם יהוה ליום קומי לעד, כי משפטי לאסף גוים לקבצי ממלכות, לשפך עליהם זעמי כל חרון אפי, כי באש קנאתי תאכל כל הארץ"; + public const string Hungarian = "Jó foxim és don Quijote húszwattos lámpánál ülve egy pár bűvös cipőt készít."; + public const string Icelandic = "Kæmi ný öxi hér, ykist þjófum nú bæði víl og ádrepa."; + public const string Irish = "Ċuaiġ bé ṁórṡáċ le dlúṫspád fíorḟinn trí hata mo ḋea-ṗorcáin ḃig"; + public const string Japanese = "いろはにほへと ちりぬるを わかよたれそ つねならむ うゐのおくやま けふこえて あさきゆめみし ゑひもせす(ん)"; + public const string JapaneseKanji = "色は匂へど 散りぬるを 我が世誰ぞ 常ならむ 有為の奥山 今日越えて 浅き夢見じ 酔ひもせず(ん)"; + public const string Korean = "키스의 고유조건은 입술끼리 만나야 하고 특별한 기술은 필요치 않다"; + public const string Latvian = "Četri psihi faķīri vēlu vakarā zāģēja guļbūvei durvis, fonā šņācot mežam."; + public const string Lithuanian = "Įlinkdama fechtuotojo špaga sublykčiojusi pragręžė apvalų arbūzą"; + public const string Macedonian = "Ѕидарски пејзаж: шугав билмез со чудење џвака ќофте и кељ на туѓ цех."; + public const string Norwegian = "Jeg begynte å fortære en sandwich mens jeg kjørte taxi på vei til quiz"; + public const string Polish = "Jeżu klątw, spłódź Finom część gry hańb!"; + 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 Romanian = "Înjurând pițigăiat, zoofobul comandă vexat whisky și tequila."; + public const string Russian = "Широкая электрификация южных губерний даст мощный толчок подъёму сельского хозяйства."; + public const string Scottish = "Mus d’fhàg Cèit-Ùna ròp Ì le ob."; + public const string Serbian = "Gojazni đačić s biciklom drži hmelj i finu vatu u džepu nošnje."; + 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 Slovenian = "Besni dirkač iz formule žuga cehu poštarjev."; + 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 Swedish = "Flygande bäckasiner söka hwila på mjuka tuvor."; + public const string Turkish = "Pijamalı hasta yağız şoföre çabucak güvendi."; + public const string Welsh = "Parciais fy jac codi baw hud llawn dŵr ger tŷ Mabon."; + } +} + diff --git a/Claunia.Encoding/Properties/AssemblyInfo.cs b/Claunia.Encoding/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..5cb5d12 --- /dev/null +++ b/Claunia.Encoding/Properties/AssemblyInfo.cs @@ -0,0 +1,54 @@ +// +// 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("")] + diff --git a/LICENSE.MIT b/LICENSE.MIT new file mode 100644 index 0000000..98dc1fd --- /dev/null +++ b/LICENSE.MIT @@ -0,0 +1,19 @@ +Copyright (c) 2015-2016 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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..d7aa944 --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +Claunia.Encoding +================ + +Library to provide codepage conversion to and from archaic and old computer systems and Unicode. + +Copyright © 2016 Natalia Portillo + +Supported encodings +============================== +* Apple Lisa \ No newline at end of file