4 ms·
If it's a mix of UTF-8 and a single-byte encoding, you can guess, because UTF-8 is nice enough to be obvious when you guessed wrong. The command-line version o
by rspeer 10y ago
If it's a mix of UTF-8 and a single-byte encoding, you can guess, because UTF-8 is nice enough to be obvious when you guessed wrong.
The command-line version of ftfy [1] can handle a distinct encoding for each line with a near-zero rate of false positives. (No guarantees the output will be correct, especially if you read it as the wrong single-byte encoding initially, but it will be no worse than what you put in, because it won't replace correct text with incorrect text.)
There is no JS version of ftfy, and there won't be until JS can represent all Unicode characters without surrogates.
[1] https://github.com/LuminosoInsight/python-ftfy https://github.com/LuminosoInsight/python-ftfy