You should be able to do it by looking at the first two bytes to detect UCS2/UTF-16;
A UCS2 file would normally have a Byte Order Marker (BOM) Which is *either* 0xFF 0xFE or 0xFE 0xFF (depending on the endian-ness of your processor.
Now you fall into the realm of multibyte. In the parsers I've designed, where there is no other meta data (like an XML prolog, or some encoding information from HTTP) is to firstly attempt to parse as UTF8 (it's dead handy that the conversion is relatively trival) -- if it fails (so it finds an invalid UTF-8 character sequence) I fall back to the current locale.
* Actually Windows boxen use UCS2, not UTF-16; Strictly speaking, UTF-16 is a superset of this, and the UTF-16 is binary backwardly compatible with UCS2.
In reply to Re: Re: Re: Reading and writing to unicode files
by RatArsed
in thread Reading and writing to unicode files
by cbingel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |