mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-24 12:35:31 +00:00
Done EncodingTable api docs
This commit is contained in:
parent
472e2775dd
commit
430551773f
1 changed files with 51 additions and 1 deletions
|
|
@ -8,10 +8,19 @@ namespace Cosmos.System.ExtendedASCII
|
||||||
* Ideally we should use Dictionary or HashTable here but are yet not working in Cosmos so I have done
|
* Ideally we should use Dictionary or HashTable here but are yet not working in Cosmos so I have done
|
||||||
* this replacement class for now...
|
* this replacement class for now...
|
||||||
*/
|
*/
|
||||||
|
/// <summary>
|
||||||
|
/// EncodingTable class. Used to manage codepage list.
|
||||||
|
/// </summary>
|
||||||
internal static class EncodingTable
|
internal static class EncodingTable
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Debugger inctanse of the "System" with the "EncodingTable" tag.
|
||||||
|
/// </summary>
|
||||||
private static Debugger mDebugger = new Debugger("System", "EncodingTable");
|
private static Debugger mDebugger = new Debugger("System", "EncodingTable");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create new inctanse of the <see cref="EncodingTable"/> class.
|
||||||
|
/// </summary>
|
||||||
static EncodingTable()
|
static EncodingTable()
|
||||||
{
|
{
|
||||||
mDebugger.SendInternal("Inizializing Encoding Table");
|
mDebugger.SendInternal("Inizializing Encoding Table");
|
||||||
|
|
@ -20,11 +29,25 @@ namespace Cosmos.System.ExtendedASCII
|
||||||
Add(858, "IBM0858", new CP858Enconding());
|
Add(858, "IBM0858", new CP858Enconding());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Struct which used to hold description and encoding.
|
||||||
|
/// </summary>
|
||||||
private struct values
|
private struct values
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Description.
|
||||||
|
/// </summary>
|
||||||
public string desc;
|
public string desc;
|
||||||
|
/// <summary>
|
||||||
|
/// Encoding.
|
||||||
|
/// </summary>
|
||||||
public Encoding encoding;
|
public Encoding encoding;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create new inctanse of the <see cref="values"/> struct.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="desc">Description.</param>
|
||||||
|
/// <param name="encoding">Encoding.</param>
|
||||||
public values(string desc, Encoding encoding)
|
public values(string desc, Encoding encoding)
|
||||||
{
|
{
|
||||||
this.desc = desc;
|
this.desc = desc;
|
||||||
|
|
@ -32,19 +55,46 @@ namespace Cosmos.System.ExtendedASCII
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Max codepage cache size.
|
||||||
|
/// </summary>
|
||||||
const int MaxCodepageChacheSize = 2048;
|
const int MaxCodepageChacheSize = 2048;
|
||||||
|
/// <summary>
|
||||||
|
/// Codepage cache.
|
||||||
|
/// </summary>
|
||||||
static values[] CodepageCache = new values[MaxCodepageChacheSize];
|
static values[] CodepageCache = new values[MaxCodepageChacheSize];
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add encoding to the encoding table.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="codepage">Codepage.</param>
|
||||||
|
/// <param name="desc">Desciption.</param>
|
||||||
|
/// <param name="encoding">Encoding.</param>
|
||||||
public static void Add(int codepage, string desc, Encoding encoding)
|
public static void Add(int codepage, string desc, Encoding encoding)
|
||||||
{
|
{
|
||||||
mDebugger.SendInternal($"Adding codepage {codepage} desc {desc}");
|
mDebugger.SendInternal($"Adding codepage {codepage} desc {desc}");
|
||||||
CodepageCache[codepage] = new values(desc, encoding);
|
CodepageCache[codepage] = new values(desc, encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get description, using codepage.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="codepage">Codepage.</param>
|
||||||
|
/// <returns>string value.</returns>
|
||||||
public static string GetDescription(int codepage) => CodepageCache[codepage].desc;
|
public static string GetDescription(int codepage) => CodepageCache[codepage].desc;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get encoding, using codepage.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="codepage">Codepage.</param>
|
||||||
|
/// <returns>Encoding value.</returns>
|
||||||
public static Encoding GetEncoding(int codepage) => CodepageCache[codepage].encoding;
|
public static Encoding GetEncoding(int codepage) => CodepageCache[codepage].encoding;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get code page from description.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="desc">Description.</param>
|
||||||
|
/// <returns>int value, -1 if not found.</returns>
|
||||||
public static int GetCodePageFromDesc(string desc)
|
public static int GetCodePageFromDesc(string desc)
|
||||||
{
|
{
|
||||||
for (int idx = 0; idx < MaxCodepageChacheSize; idx++)
|
for (int idx = 0; idx < MaxCodepageChacheSize; idx++)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue