#define COSMOSDEBUG using System.Text; using Cosmos.Debug.Kernel; namespace Cosmos.System.ExtendedASCII { /* * Ideally we should use Dictionary or HashTable here but are yet not working in Cosmos so I have done * this replacement class for now... */ /// /// EncodingTable class. Used to manage codepage list. /// internal static class EncodingTable { /// /// Debugger inctanse of the "System" ring with the "EncodingTable" tag. /// private static Debugger mDebugger = new Debugger("System", "EncodingTable"); /// /// Create new inctanse of the class. /// static EncodingTable() { mDebugger.SendInternal("Inizializing Encoding Table"); Add(437, "IBM437", new CP437Enconding()); Add(858, "IBM0858", new CP858Enconding()); } /// /// Struct which used to hold description and encoding. /// private struct values { /// /// Description. /// public string desc; /// /// Encoding. /// public Encoding encoding; /// /// Create new inctanse of the struct. /// /// Description. /// Encoding. public values(string desc, Encoding encoding) { this.desc = desc; this.encoding = encoding; } }; /// /// Max codepage cache size. /// const int MaxCodepageChacheSize = 2048; /// /// Codepage cache. /// static values[] CodepageCache = new values[MaxCodepageChacheSize]; /// /// Add encoding to the encoding table. /// /// Codepage. /// Desciption. /// Encoding. public static void Add(int codepage, string desc, Encoding encoding) { mDebugger.SendInternal($"Adding codepage {codepage} desc {desc}"); CodepageCache[codepage] = new values(desc, encoding); } /// /// Get description, using codepage. /// /// Codepage. /// string value. public static string GetDescription(int codepage) => CodepageCache[codepage].desc; /// /// Get encoding, using codepage. /// /// Codepage. /// Encoding value. public static Encoding GetEncoding(int codepage) => CodepageCache[codepage].encoding; /// /// Get code page from description. /// /// Description. /// int value, -1 if not found. public static int GetCodePageFromDesc(string desc) { for (int idx = 0; idx < MaxCodepageChacheSize; idx++) { if (CodepageCache[idx].desc == desc) return idx; } /* Not found! */ return -1; } } }