sdether, thanks for updating LFSLib, your work is really appreciated.
Regarding going from unicode to LFS's structure - something like the following will do it:
public static string convertToLFSString(string str) {
string ret = "";
Encoding current = Encoding.GetEncoding(1252);
Encoding lat = Encoding.GetEncoding(1252);
Encoding jap = Encoding.GetEncoding(932);
Encoding greek = Encoding.GetEncoding(1253);
Encoding bal = Encoding.GetEncoding(1257);
Encoding cryl = Encoding.GetEncoding(1251);
Encoding euro = Encoding.GetEncoding(1250);
Encoding turk = Encoding.GetEncoding(1254);
char[] c = str.ToCharArray();
for (int i = 0; i < c.Length; ++i) {
if (current != jap && jap.GetBytes(c, i, 1)[0] != lat.GetBytes(c, i, 1)[0]) {
current = jap;
ret += "^J";
} else if (current != greek && greek.GetBytes(c, i, 1)[0] != lat.GetBytes(c, i, 1)[0]) {
current = greek;
ret += "^G";
} else if (current != bal && bal.GetBytes(c, i, 1)[0] != lat.GetBytes(c, i, 1)[0]) {
current = bal;
ret += "^B";
} else if (current != cryl && cryl.GetBytes(c, i, 1)[0] != lat.GetBytes(c, i, 1)[0]) {
current = cryl;
ret += "^C";
} else if (current != euro && euro.GetBytes(c, i, 1)[0] != lat.GetBytes(c, i, 1)[0]) {
current = euro;
ret += "^E";
} else if (current != turk && turk.GetBytes(c, i, 1)[0] != lat.GetBytes(c, i, 1)[0]) {
current = turk;
ret += "^T";
}
ret += lat.GetString(current.GetBytes(c, i, 1));
}
return ret;
}
However it has a fundamental problem - if the original LFS string that you converted to unicode has, for example, unnecessary ^Js, the strings won't match. For example, ノマed may have originally come as ^Jノ^Jマ^Led, or just ^Jマed and you simply don't know - so received/sent LFS strings won't match, and however you do the conversion, they never will (BFS deals with this by storing the raw data alongside the unicode equiv). This isn't a corner case hypothetical problem - I found that people put these extraneous conversion chars in _all the time_. It would be nice if LFS removed them as they were entered...
So maybe just let the application deal with it, or provide a (static?) method apps can use if they want to convert to unicode for display.
By the way, is your new version going to support going through the insim relay? I think I sent you a patch with copyright assigned to you...