[Qt-interest] How to check between "Text" and "Non-Text" File

Bruce Cran Bruce.Cran at iongeo.com
Tue Apr 20 12:36:06 CEST 2010


On 20/04/10 09:30, Aaron Lewis wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 04/20/2010 04:13 PM, Jeroen De Wachter wrote:
>> Hey yogesh,
>>
>> I don't know if you ever worked with the file command? Its sole purpose
>> is to classify files.
>> Maybe you can get some ideas from the source code.
>
> File command just reads the header of a file , and sometimes it can be
> forged , but it's an common way to detect file types , like RAR:
>
> Header Signature is `52 61 72 21' in hex , `Rar!' in ascii.
>
> Generally speaking , there's no good way to check if the file is totally
> plain text , but a single character.
>
> Just as Frederic suggested , try bool QChar::isPrint()

It's fairly common for text files to contain occasional non-ASCII 
characters. For example a file like 
http://svn.freebsd.org/viewvc/base/head/sys/compat/linprocfs/linprocfs.c?revision=206597&view=markup 
often trips up "less" into thinking it's a binary file due to the 
inclusion of 'ø'.

-- 
Bruce Cran

This email and any files transmitted with it are confidential and are intended solely for the use of the individual or entity to whom they are addressed.  If you are not the original recipient or the person responsible for delivering the email to the intended recipient, be advised that you have received this email in error, and that any use, dissemination, forwarding, printing, or copying of this email is strictly prohibited. If you received this email in error, please immediately notify the sender and delete the original.






More information about the Qt-interest-old mailing list