in reply to dynamically detect code page
are Japanese (SJIS) and German (cpXXXX) the only languages?
since SJIS is a multibyte encoding and was created by MicroSloth to be semi-compatible with one of their old codepages... they did a hack and slash of the standard JIS/EUC type multibyte encodings. because of this SJIS is relatively easy to detect, if you try to treat a randomish string of 8-bit characters as SJIS and convert it to UTF-8 you'll most likely end up with invalid characters. a string of 7-bit characters in SJIS is just the same a 7-bit ASCII.
so take each line one at a time. if there are no 8-bit characters then the line could be anything, but it doesn't matter because all the characters are in the 7-bit ASCII range.
if there are 8-bit characters, pretend the line is SJIS and try to convert it to UTF-8. if there are errors, then the line is most likely not SJIS and instead is German (or some other single-byte codepage). if there are no errors then it's most likely SJIS Japanese.
as for telling apart other single-byte codepages... no idea.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: dynamically detect code page
by edwardt_tril (Sexton) on Feb 25, 2006 at 02:04 UTC | |
by edwardt_tril (Sexton) on Feb 25, 2006 at 04:05 UTC | |
by Anonymous Monk on Feb 25, 2006 at 11:37 UTC |