OK.. going to take some risk. This is part of Airio code. Does it help?
{
using System;
using System.Collections;
using System.Text;
public static class Strings
{
private static Hashtable encs = new Hashtable();
private static string pages = "LEBGCTJSKH";
public static string CharsLFSToStandard(string lts)
{
if (string.IsNullOrEmpty(lts))
{
return "";
}
StringBuilder builder = new StringBuilder(lts);
return builder.Replace("^l", "<").Replace("^r", ">").Replace("^v", "|").Replace("^s", "/").Replace("^d", @"\").Replace("^a", "*").Replace("^q", "?").Replace("^c", ":").Replace("^t", "\"").Replace("^h", "#").Replace("^^", "^").ToString();
}
public static string CharsStandardToLFS(string stl)
{
if (string.IsNullOrEmpty(stl))
{
return "";
}
StringBuilder builder = new StringBuilder(stl);
return builder.Replace("^", "^^").Replace("<", "^l").Replace(">", "^r").Replace("|", "^v").Replace("/", "^s").Replace(@"\", "^d").Replace("*", "^a").Replace("?", "^q").Replace(":", "^c").Replace("\"", "^t").Replace("#", "^h").ToString();
}
public static byte[] GetBytes(string str)
{
if (encs.Count == 0)
{
InitEncodings();
}
byte[] destinationArray = new byte[str.Length * 4];
byte[] sourceArray = new byte[0];
char ch = 'L';
Encoding encoding = (Encoding) encs[ch];
int destinationIndex = 0;
bool flag = false;
int num2 = -1;
char[] chars = str.ToCharArray();
for (int i = 0; i < chars.Length; i++)
{
if (((chars[i] == '^') && (i < (chars.Length - 1))) && (chars[i + 1] == '8'))
{
destinationArray[destinationIndex++] = (byte) chars[i++];
destinationArray[destinationIndex++] = (byte) chars[i];
ch = 'L';
encoding = (Encoding) encs[ch];
}
else
{
try
{
sourceArray = encoding.GetBytes(chars, i, 1);
}
catch (EncoderFallbackException exception)
{
if (++num2 < pages.Length)
{
ch = pages[num2];
encoding = (Encoding) encs[ch];
flag = true;
i--;
goto Label_0169;
}
Helpers.OnStaticMessage("WARNING : Unknown character to encode - " + exception.CharUnknown);
destinationArray[destinationIndex++] = (byte) chars[i];
}
if (flag)
{
destinationArray[destinationIndex++] = 0x5e;
destinationArray[destinationIndex++] = (byte) ch;
flag = false;
}
Array.Copy(sourceArray, 0, destinationArray, destinationIndex, sourceArray.Length);
destinationIndex += sourceArray.Length;
num2 = -1;
Label_0169:;
}
}
Array.Resize<byte>(ref destinationArray, destinationIndex);
return destinationArray;
}
public static byte[] GetRawBytes(string str)
{
if (encs.Count == 0)
{
InitEncodings();
}
byte[] array = new byte[str.Length * 4];
int newSize = 0;
for (int i = 0; i < str.Length; i++)
{
array[newSize++] = (byte) str[i];
}
Array.Resize<byte>(ref array, newSize);
return array;
}
public static string GetRawString(byte[] pack)
{
if (encs.Count == 0)
{
InitEncodings();
}
StringBuilder builder = new StringBuilder("");
for (int i = 0; i < pack.Length; i++)
{
if (pack[i] == 0)
{
break;
}
builder.Append((char) pack[i]);
}
return builder.ToString();
}
public static string GetString(byte[] pack)
{
if (encs.Count == 0)
{
InitEncodings();
}
StringBuilder builder = new StringBuilder("");
Encoding encoding = (Encoding) encs['E'];
Encoding encoding2 = (Encoding) encs['L'];
int index = 0;
bool flag = false;
for (int i = 0; i < pack.Length; i++)
{
if ((encoding != encoding2) || flag)
{
index = i;
encoding = encoding2;
flag = false;
}
if ((pack[i] == 0x5e) && (i < (pack.Length - 1)))
{
if (encs.ContainsKey((char) pack[i + 1]))
{
encoding2 = (Encoding) encs[(char) pack[i + 1]];
flag = true;
}
if (pack[i + 1] == 0x38)
{
encoding2 = (Encoding) encs['L'];
}
if (pack[i + 1] == 0x5e)
{
i++;
}
}
if (((encoding != encoding2) || (pack[i] == 0)) || ((i == (pack.Length - 1)) || flag))
{
try
{
if ((encoding != encoding2) || flag)
{
builder.Append(encoding.GetChars(pack, index, i++ - index));
}
else
{
if (pack[i] == 0)
{
builder.Append(encoding2.GetChars(pack, index, i - index));
break;
}
builder.Append(encoding2.GetChars(pack, index, pack.Length - index));
}
}
catch (DecoderFallbackException exception)
{
Helpers.OnStaticMessage(string.Concat(new object[] { "WARNING : Unknown bytes to decode - ", exception.BytesUnknown[0], (exception.BytesUnknown.Length > 1) ? (" " + exception.BytesUnknown[1]) : "", (exception.BytesUnknown.Length > 2) ? (" " + exception.BytesUnknown[2]) : "", (exception.BytesUnknown.Length > 3) ? (" " + exception.BytesUnknown[3]) : "" }));
builder.Append('?');
index = (index + exception.Index) + exception.BytesUnknown.Length;
i = index - 1;
}
}
}
return builder.ToString();
}
private static void InitEncodings()
{
encs.Add('L', Encoding.GetEncoding(0x4e4, new EncoderExceptionFallback(), new DecoderExceptionFallback()));
encs.Add('E', Encoding.GetEncoding(0x4e2, new EncoderExceptionFallback(), new DecoderExceptionFallback()));
try
{
encs.Add('B', Encoding.GetEncoding(0x6fbb, new EncoderExceptionFallback(), new DecoderExceptionFallback()));
}
catch
{
encs.Add('B', Encoding.GetEncoding(0x4e9, new EncoderExceptionFallback(), new DecoderExceptionFallback()));
Helpers.OnStaticMessage("INFO : Using CP01257 instead of CP28603");
}
encs.Add('G', Encoding.GetEncoding(0x6fb5, new EncoderExceptionFallback(), new DecoderExceptionFallback()));
encs.Add('C', Encoding.GetEncoding(0x4e3, new EncoderExceptionFallback(), new DecoderExceptionFallback()));
encs.Add('T', Encoding.GetEncoding(0x6fb7, new EncoderExceptionFallback(), new DecoderExceptionFallback()));
encs.Add('J', Encoding.GetEncoding(0x3a4, new EncoderExceptionFallback(), new DecoderExceptionFallback()));
encs.Add('S', Encoding.GetEncoding(0x3a8, new EncoderExceptionFallback(), new DecoderExceptionFallback()));
encs.Add('K', Encoding.GetEncoding(0x3b5, new EncoderExceptionFallback(), new DecoderExceptionFallback()));
encs.Add('H', Encoding.GetEncoding(950, new EncoderExceptionFallback(), new DecoderExceptionFallback()));
}
public static string RawToEncoded(string url)
{
StringBuilder builder = new StringBuilder("");
for (int i = 0; i < url.Length; i++)
{
if (((byte) url[i]) > 0x7f)
{
builder.Append('%' + ((byte) url[i]).ToString("X"));
}
else
{
char ch = url[i];
builder.Append(Uri.EscapeDataString(ch.ToString()));
}
}
return builder.ToString();
}
public static string RawToUTF(string raw)
{
return GetString(GetRawBytes(raw)).Trim();
}
public static string RemoveColor(string ncl)
{
if (string.IsNullOrEmpty(ncl))
{
return "";
}
StringBuilder builder = new StringBuilder(ncl);
return builder.Replace("^0", "").Replace("^1", "").Replace("^2", "").Replace("^3", "").Replace("^4", "").Replace("^5", "").Replace("^6", "").Replace("^7", "").Replace("^8", "").Replace("^9", "").ToString();
}
public static string UTFToRaw(string utf)
{
return GetRawString(GetBytes(utf.Trim()));
}
}
}