qemacs-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemacs-commit] qemacs hex.c


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs hex.c
Date: Sun, 05 Jan 2014 23:23:09 +0000

CVSROOT:        /sources/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        14/01/05 23:23:09

Modified files:
        .              : hex.c 

Log message:
        improve hex/binary file detection
        
        * accept shiftin (^N) and shiftout (^O) ASCII control chars in text 
files
        * faster scan in detect_binary

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/hex.c?cvsroot=qemacs&r1=1.30&r2=1.31

Patches:
Index: hex.c
===================================================================
RCS file: /sources/qemacs/qemacs/hex.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -b -r1.30 -r1.31
--- hex.c       4 Jan 2014 17:27:03 -0000       1.30
+++ hex.c       5 Jan 2014 23:23:09 -0000       1.31
@@ -195,13 +195,14 @@
 
 static int detect_binary(const unsigned char *buf, int size)
 {
+    static const uint32_t magic = (1 << '\b') | (1 << '\t') | (1 << '\f') |
+                                  (1 << '\n') | (1 << '\r') | (1 << '\033') |
+                                  (1 << 0x0e) | (1 << 0x0f);
     int i, c;
 
     for (i = 0; i < size; i++) {
         c = buf[i];
-        if (c < 32 &&
-            (c != '\r' && c != '\n' && c != '\t' &&
-             c != '\033' && c != '\b' && c != '\f'))
+        if (c < 32 && !(magic & (1 << c)))
             return 1;
     }
     return 0;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]