[Qt-interest] How to detect Text codec

Thiago Macieira thiago at kde.org
Mon May 16 16:28:23 CEST 2011


On Monday, 16 de May de 2011 13:06:30 NoRulez wrote:
> Hi,
> 
> can anybody give me a hint to detect the text codec used in a text file?

You don't. You can try to load with several different codecs and check which 
one works best. Also note that there may be several codecs that load without 
errors. There are many heuristic algorithms for detecting, with varying 
success rates.

My recommendation is that you don't ask this question. Instead, your code 
should know the codec before you open the file. Either that information is 
saved somewhere else, like out-of-band information, or you know the file is 
encoded in the locale codec or it is enforced to be UTF-8.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Product Manager - Nokia, Qt Development Frameworks
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110516/092a44b3/attachment.bin 


More information about the Qt-interest-old mailing list