[Qt-interest] How to determine the character set of a text file at run-time?

Thiago Macieira thiago.macieira at trolltech.com
Sun Aug 16 23:13:24 CEST 2009


Robert Hairgrove wrote:
>Is there an easy cross-platform way of doing it using Qt's API?

There is no way, Qt or not.

You can try to guess and there are many heuristic algorithms out there 
(most commonly found on web browsers, actually), but none is 100%. You can 
get some high rate, though, but the algorithm may be very complex.

>And what about UTF-8 files (with and without a BOM at the beginning of
>the file)?

UTF-8 is one quite easy to detect because it's fairly structured. But it's 
also not 100%.


-- 
Thiago Macieira - thiago.macieira (AT) nokia.com
  Senior Product Manager - Nokia, Qt Development Frameworks
     Sandakerveien 116, NO-0402 Oslo, Norway

Qt Developer Days 2009 | Registration Now Open!
Munich, Germany: Oct 12 - 14     San Francisco, California: Nov 2 - 4
      http://qt.nokia.com/qtdevdays2009
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090816/060c261b/attachment.bin 


More information about the Qt-interest-old mailing list