Fossil SCM

Merge trunk

jan.nijtmans 2016-06-17 07:39 trunk merge
Commit 4887295ab8ec9a56c3f53d9105a85dc642641357
2 files changed +13 -19 +13 -19
+13 -19
--- src/lookslike.c
+++ src/lookslike.c
@@ -37,21 +37,21 @@
3737
** Output flags for the looks_like_utf8() and looks_like_utf16() routines used
3838
** to convey status information about the blob content.
3939
*/
4040
#define LOOK_NONE ((int)0x00000000) /* Nothing special was found. */
4141
#define LOOK_NUL ((int)0x00000001) /* One or more NUL chars were found. */
42
-#define LOOK_CR ((int)0x00000002) /* One or more CR chars were found. */
43
-#define LOOK_LONE_CR ((int)0x00000004) /* An unpaired CR char was found. */
44
-#define LOOK_LF ((int)0x00000008) /* One or more LF chars were found. */
45
-#define LOOK_LONE_LF ((int)0x00000010) /* An unpaired LF char was found. */
46
-#define LOOK_CRLF ((int)0x00000020) /* One or more CR/LF pairs were found. */
47
-#define LOOK_LONG ((int)0x00000040) /* An over length line was found. */
48
-#define LOOK_ODD ((int)0x00000080) /* An odd number of bytes was found. */
49
-#define LOOK_SHORT ((int)0x00000100) /* Unable to perform full check. */
50
-#define LOOK_INVALID ((int)0x00000200) /* Invalid sequence was found. */
42
+#define LOOK_LONE_CR ((int)0x00000002) /* An unpaired CR char was found. */
43
+#define LOOK_LONE_LF ((int)0x00000004) /* An unpaired LF char was found. */
44
+#define LOOK_CRLF ((int)0x00000008) /* One or more CR/LF pairs were found. */
45
+#define LOOK_LONG ((int)0x00000010) /* An over length line was found. */
46
+#define LOOK_ODD ((int)0x00000020) /* An odd number of bytes was found. */
47
+#define LOOK_SHORT ((int)0x00000040) /* Unable to perform full check. */
48
+#define LOOK_INVALID ((int)0x00000080) /* Invalid sequence was found. */
5149
#define LOOK_BINARY (LOOK_NUL | LOOK_LONG | LOOK_SHORT) /* May be binary. */
5250
#define LOOK_EOL (LOOK_LONE_CR | LOOK_LONE_LF | LOOK_CRLF) /* Line seps. */
51
+#define LOOK_CR (LOOK_LONE_CR | LOOK_CRLF) /* One or more CR chars. */
52
+#define LOOK_LF (LOOK_LONE_LF | LOOK_CRLF) /* One or more LF chars. */
5353
#endif /* INTERFACE */
5454
5555
5656
/*
5757
** This function attempts to scan each logical line within the blob to
@@ -93,35 +93,32 @@
9393
if( n==0 ) return flags; /* Empty file -> text */
9494
c = *z;
9595
if( c==0 ){
9696
flags |= LOOK_NUL; /* NUL character in a file -> binary */
9797
}else if( c=='\r' ){
98
- flags |= LOOK_CR;
9998
if( n<=1 || z[1]!='\n' ){
10099
flags |= LOOK_LONE_CR; /* Not enough chars or next char not LF */
101100
}
102101
}
103102
j = (c!='\n');
104
- if( !j ) flags |= (LOOK_LF | LOOK_LONE_LF); /* Found LF as first char */
103
+ if( !j ) flags |= (LOOK_LONE_LF); /* Found LF as first char */
105104
while( !(flags&stopFlags) && --n>0 ){
106105
int c2 = c;
107106
c = *++z; ++j;
108107
if( c==0 ){
109108
flags |= LOOK_NUL; /* NUL character in a file -> binary */
110109
}else if( c=='\n' ){
111
- flags |= LOOK_LF;
112110
if( c2=='\r' ){
113
- flags |= (LOOK_CR | LOOK_CRLF); /* Found LF preceded by CR */
111
+ flags |= (LOOK_CRLF); /* Found LF preceded by CR */
114112
}else{
115113
flags |= LOOK_LONE_LF;
116114
}
117115
if( j>LENGTH_MASK ){
118116
flags |= LOOK_LONG; /* Very long line -> binary */
119117
}
120118
j = 0;
121119
}else if( c=='\r' ){
122
- flags |= LOOK_CR;
123120
if( n<=1 || z[1]!='\n' ){
124121
flags |= LOOK_LONE_CR; /* Not enough chars or next char not LF */
125122
}
126123
}
127124
}
@@ -273,17 +270,16 @@
273270
c = UTF16_SWAP(c);
274271
}
275272
if( c==0 ){
276273
flags |= LOOK_NUL; /* NUL character in a file -> binary */
277274
}else if( c=='\r' ){
278
- flags |= LOOK_CR;
279275
if( n<(2*sizeof(WCHAR_T)) || UTF16_SWAP_IF(bReverse, z[1])!='\n' ){
280276
flags |= LOOK_LONE_CR; /* Not enough chars or next char not LF */
281277
}
282278
}
283279
j = (c!='\n');
284
- if( !j ) flags |= (LOOK_LF | LOOK_LONE_LF); /* Found LF as first char */
280
+ if( !j ) flags |= (LOOK_LONE_LF); /* Found LF as first char */
285281
while( !(flags&stopFlags) && ((n-=sizeof(WCHAR_T))>=sizeof(WCHAR_T)) ){
286282
int c2 = c;
287283
c = *++z;
288284
if( bReverse ){
289285
c = UTF16_SWAP(c);
@@ -290,22 +286,20 @@
290286
}
291287
++j;
292288
if( c==0 ){
293289
flags |= LOOK_NUL; /* NUL character in a file -> binary */
294290
}else if( c=='\n' ){
295
- flags |= LOOK_LF;
296291
if( c2=='\r' ){
297
- flags |= (LOOK_CR | LOOK_CRLF); /* Found LF preceded by CR */
292
+ flags |= (LOOK_CRLF); /* Found LF preceded by CR */
298293
}else{
299294
flags |= LOOK_LONE_LF;
300295
}
301296
if( j>UTF16_LENGTH_MASK ){
302297
flags |= LOOK_LONG; /* Very long line -> binary */
303298
}
304299
j = 0;
305300
}else if( c=='\r' ){
306
- flags |= LOOK_CR;
307301
if( n<(2*sizeof(WCHAR_T)) || UTF16_SWAP_IF(bReverse, z[1])!='\n' ){
308302
flags |= LOOK_LONE_CR; /* Not enough chars or next char not LF */
309303
}
310304
}
311305
}
312306
--- src/lookslike.c
+++ src/lookslike.c
@@ -37,21 +37,21 @@
37 ** Output flags for the looks_like_utf8() and looks_like_utf16() routines used
38 ** to convey status information about the blob content.
39 */
40 #define LOOK_NONE ((int)0x00000000) /* Nothing special was found. */
41 #define LOOK_NUL ((int)0x00000001) /* One or more NUL chars were found. */
42 #define LOOK_CR ((int)0x00000002) /* One or more CR chars were found. */
43 #define LOOK_LONE_CR ((int)0x00000004) /* An unpaired CR char was found. */
44 #define LOOK_LF ((int)0x00000008) /* One or more LF chars were found. */
45 #define LOOK_LONE_LF ((int)0x00000010) /* An unpaired LF char was found. */
46 #define LOOK_CRLF ((int)0x00000020) /* One or more CR/LF pairs were found. */
47 #define LOOK_LONG ((int)0x00000040) /* An over length line was found. */
48 #define LOOK_ODD ((int)0x00000080) /* An odd number of bytes was found. */
49 #define LOOK_SHORT ((int)0x00000100) /* Unable to perform full check. */
50 #define LOOK_INVALID ((int)0x00000200) /* Invalid sequence was found. */
51 #define LOOK_BINARY (LOOK_NUL | LOOK_LONG | LOOK_SHORT) /* May be binary. */
52 #define LOOK_EOL (LOOK_LONE_CR | LOOK_LONE_LF | LOOK_CRLF) /* Line seps. */
 
 
53 #endif /* INTERFACE */
54
55
56 /*
57 ** This function attempts to scan each logical line within the blob to
@@ -93,35 +93,32 @@
93 if( n==0 ) return flags; /* Empty file -> text */
94 c = *z;
95 if( c==0 ){
96 flags |= LOOK_NUL; /* NUL character in a file -> binary */
97 }else if( c=='\r' ){
98 flags |= LOOK_CR;
99 if( n<=1 || z[1]!='\n' ){
100 flags |= LOOK_LONE_CR; /* Not enough chars or next char not LF */
101 }
102 }
103 j = (c!='\n');
104 if( !j ) flags |= (LOOK_LF | LOOK_LONE_LF); /* Found LF as first char */
105 while( !(flags&stopFlags) && --n>0 ){
106 int c2 = c;
107 c = *++z; ++j;
108 if( c==0 ){
109 flags |= LOOK_NUL; /* NUL character in a file -> binary */
110 }else if( c=='\n' ){
111 flags |= LOOK_LF;
112 if( c2=='\r' ){
113 flags |= (LOOK_CR | LOOK_CRLF); /* Found LF preceded by CR */
114 }else{
115 flags |= LOOK_LONE_LF;
116 }
117 if( j>LENGTH_MASK ){
118 flags |= LOOK_LONG; /* Very long line -> binary */
119 }
120 j = 0;
121 }else if( c=='\r' ){
122 flags |= LOOK_CR;
123 if( n<=1 || z[1]!='\n' ){
124 flags |= LOOK_LONE_CR; /* Not enough chars or next char not LF */
125 }
126 }
127 }
@@ -273,17 +270,16 @@
273 c = UTF16_SWAP(c);
274 }
275 if( c==0 ){
276 flags |= LOOK_NUL; /* NUL character in a file -> binary */
277 }else if( c=='\r' ){
278 flags |= LOOK_CR;
279 if( n<(2*sizeof(WCHAR_T)) || UTF16_SWAP_IF(bReverse, z[1])!='\n' ){
280 flags |= LOOK_LONE_CR; /* Not enough chars or next char not LF */
281 }
282 }
283 j = (c!='\n');
284 if( !j ) flags |= (LOOK_LF | LOOK_LONE_LF); /* Found LF as first char */
285 while( !(flags&stopFlags) && ((n-=sizeof(WCHAR_T))>=sizeof(WCHAR_T)) ){
286 int c2 = c;
287 c = *++z;
288 if( bReverse ){
289 c = UTF16_SWAP(c);
@@ -290,22 +286,20 @@
290 }
291 ++j;
292 if( c==0 ){
293 flags |= LOOK_NUL; /* NUL character in a file -> binary */
294 }else if( c=='\n' ){
295 flags |= LOOK_LF;
296 if( c2=='\r' ){
297 flags |= (LOOK_CR | LOOK_CRLF); /* Found LF preceded by CR */
298 }else{
299 flags |= LOOK_LONE_LF;
300 }
301 if( j>UTF16_LENGTH_MASK ){
302 flags |= LOOK_LONG; /* Very long line -> binary */
303 }
304 j = 0;
305 }else if( c=='\r' ){
306 flags |= LOOK_CR;
307 if( n<(2*sizeof(WCHAR_T)) || UTF16_SWAP_IF(bReverse, z[1])!='\n' ){
308 flags |= LOOK_LONE_CR; /* Not enough chars or next char not LF */
309 }
310 }
311 }
312
--- src/lookslike.c
+++ src/lookslike.c
@@ -37,21 +37,21 @@
37 ** Output flags for the looks_like_utf8() and looks_like_utf16() routines used
38 ** to convey status information about the blob content.
39 */
40 #define LOOK_NONE ((int)0x00000000) /* Nothing special was found. */
41 #define LOOK_NUL ((int)0x00000001) /* One or more NUL chars were found. */
42 #define LOOK_LONE_CR ((int)0x00000002) /* An unpaired CR char was found. */
43 #define LOOK_LONE_LF ((int)0x00000004) /* An unpaired LF char was found. */
44 #define LOOK_CRLF ((int)0x00000008) /* One or more CR/LF pairs were found. */
45 #define LOOK_LONG ((int)0x00000010) /* An over length line was found. */
46 #define LOOK_ODD ((int)0x00000020) /* An odd number of bytes was found. */
47 #define LOOK_SHORT ((int)0x00000040) /* Unable to perform full check. */
48 #define LOOK_INVALID ((int)0x00000080) /* Invalid sequence was found. */
 
 
49 #define LOOK_BINARY (LOOK_NUL | LOOK_LONG | LOOK_SHORT) /* May be binary. */
50 #define LOOK_EOL (LOOK_LONE_CR | LOOK_LONE_LF | LOOK_CRLF) /* Line seps. */
51 #define LOOK_CR (LOOK_LONE_CR | LOOK_CRLF) /* One or more CR chars. */
52 #define LOOK_LF (LOOK_LONE_LF | LOOK_CRLF) /* One or more LF chars. */
53 #endif /* INTERFACE */
54
55
56 /*
57 ** This function attempts to scan each logical line within the blob to
@@ -93,35 +93,32 @@
93 if( n==0 ) return flags; /* Empty file -> text */
94 c = *z;
95 if( c==0 ){
96 flags |= LOOK_NUL; /* NUL character in a file -> binary */
97 }else if( c=='\r' ){
 
98 if( n<=1 || z[1]!='\n' ){
99 flags |= LOOK_LONE_CR; /* Not enough chars or next char not LF */
100 }
101 }
102 j = (c!='\n');
103 if( !j ) flags |= (LOOK_LONE_LF); /* Found LF as first char */
104 while( !(flags&stopFlags) && --n>0 ){
105 int c2 = c;
106 c = *++z; ++j;
107 if( c==0 ){
108 flags |= LOOK_NUL; /* NUL character in a file -> binary */
109 }else if( c=='\n' ){
 
110 if( c2=='\r' ){
111 flags |= (LOOK_CRLF); /* Found LF preceded by CR */
112 }else{
113 flags |= LOOK_LONE_LF;
114 }
115 if( j>LENGTH_MASK ){
116 flags |= LOOK_LONG; /* Very long line -> binary */
117 }
118 j = 0;
119 }else if( c=='\r' ){
 
120 if( n<=1 || z[1]!='\n' ){
121 flags |= LOOK_LONE_CR; /* Not enough chars or next char not LF */
122 }
123 }
124 }
@@ -273,17 +270,16 @@
270 c = UTF16_SWAP(c);
271 }
272 if( c==0 ){
273 flags |= LOOK_NUL; /* NUL character in a file -> binary */
274 }else if( c=='\r' ){
 
275 if( n<(2*sizeof(WCHAR_T)) || UTF16_SWAP_IF(bReverse, z[1])!='\n' ){
276 flags |= LOOK_LONE_CR; /* Not enough chars or next char not LF */
277 }
278 }
279 j = (c!='\n');
280 if( !j ) flags |= (LOOK_LONE_LF); /* Found LF as first char */
281 while( !(flags&stopFlags) && ((n-=sizeof(WCHAR_T))>=sizeof(WCHAR_T)) ){
282 int c2 = c;
283 c = *++z;
284 if( bReverse ){
285 c = UTF16_SWAP(c);
@@ -290,22 +286,20 @@
286 }
287 ++j;
288 if( c==0 ){
289 flags |= LOOK_NUL; /* NUL character in a file -> binary */
290 }else if( c=='\n' ){
 
291 if( c2=='\r' ){
292 flags |= (LOOK_CRLF); /* Found LF preceded by CR */
293 }else{
294 flags |= LOOK_LONE_LF;
295 }
296 if( j>UTF16_LENGTH_MASK ){
297 flags |= LOOK_LONG; /* Very long line -> binary */
298 }
299 j = 0;
300 }else if( c=='\r' ){
 
301 if( n<(2*sizeof(WCHAR_T)) || UTF16_SWAP_IF(bReverse, z[1])!='\n' ){
302 flags |= LOOK_LONE_CR; /* Not enough chars or next char not LF */
303 }
304 }
305 }
306
+13 -19
--- src/lookslike.c
+++ src/lookslike.c
@@ -37,21 +37,21 @@
3737
** Output flags for the looks_like_utf8() and looks_like_utf16() routines used
3838
** to convey status information about the blob content.
3939
*/
4040
#define LOOK_NONE ((int)0x00000000) /* Nothing special was found. */
4141
#define LOOK_NUL ((int)0x00000001) /* One or more NUL chars were found. */
42
-#define LOOK_CR ((int)0x00000002) /* One or more CR chars were found. */
43
-#define LOOK_LONE_CR ((int)0x00000004) /* An unpaired CR char was found. */
44
-#define LOOK_LF ((int)0x00000008) /* One or more LF chars were found. */
45
-#define LOOK_LONE_LF ((int)0x00000010) /* An unpaired LF char was found. */
46
-#define LOOK_CRLF ((int)0x00000020) /* One or more CR/LF pairs were found. */
47
-#define LOOK_LONG ((int)0x00000040) /* An over length line was found. */
48
-#define LOOK_ODD ((int)0x00000080) /* An odd number of bytes was found. */
49
-#define LOOK_SHORT ((int)0x00000100) /* Unable to perform full check. */
50
-#define LOOK_INVALID ((int)0x00000200) /* Invalid sequence was found. */
42
+#define LOOK_LONE_CR ((int)0x00000002) /* An unpaired CR char was found. */
43
+#define LOOK_LONE_LF ((int)0x00000004) /* An unpaired LF char was found. */
44
+#define LOOK_CRLF ((int)0x00000008) /* One or more CR/LF pairs were found. */
45
+#define LOOK_LONG ((int)0x00000010) /* An over length line was found. */
46
+#define LOOK_ODD ((int)0x00000020) /* An odd number of bytes was found. */
47
+#define LOOK_SHORT ((int)0x00000040) /* Unable to perform full check. */
48
+#define LOOK_INVALID ((int)0x00000080) /* Invalid sequence was found. */
5149
#define LOOK_BINARY (LOOK_NUL | LOOK_LONG | LOOK_SHORT) /* May be binary. */
5250
#define LOOK_EOL (LOOK_LONE_CR | LOOK_LONE_LF | LOOK_CRLF) /* Line seps. */
51
+#define LOOK_CR (LOOK_LONE_CR | LOOK_CRLF) /* One or more CR chars. */
52
+#define LOOK_LF (LOOK_LONE_LF | LOOK_CRLF) /* One or more LF chars. */
5353
#endif /* INTERFACE */
5454
5555
5656
/*
5757
** This function attempts to scan each logical line within the blob to
@@ -93,35 +93,32 @@
9393
if( n==0 ) return flags; /* Empty file -> text */
9494
c = *z;
9595
if( c==0 ){
9696
flags |= LOOK_NUL; /* NUL character in a file -> binary */
9797
}else if( c=='\r' ){
98
- flags |= LOOK_CR;
9998
if( n<=1 || z[1]!='\n' ){
10099
flags |= LOOK_LONE_CR; /* Not enough chars or next char not LF */
101100
}
102101
}
103102
j = (c!='\n');
104
- if( !j ) flags |= (LOOK_LF | LOOK_LONE_LF); /* Found LF as first char */
103
+ if( !j ) flags |= (LOOK_LONE_LF); /* Found LF as first char */
105104
while( !(flags&stopFlags) && --n>0 ){
106105
int c2 = c;
107106
c = *++z; ++j;
108107
if( c==0 ){
109108
flags |= LOOK_NUL; /* NUL character in a file -> binary */
110109
}else if( c=='\n' ){
111
- flags |= LOOK_LF;
112110
if( c2=='\r' ){
113
- flags |= (LOOK_CR | LOOK_CRLF); /* Found LF preceded by CR */
111
+ flags |= (LOOK_CRLF); /* Found LF preceded by CR */
114112
}else{
115113
flags |= LOOK_LONE_LF;
116114
}
117115
if( j>LENGTH_MASK ){
118116
flags |= LOOK_LONG; /* Very long line -> binary */
119117
}
120118
j = 0;
121119
}else if( c=='\r' ){
122
- flags |= LOOK_CR;
123120
if( n<=1 || z[1]!='\n' ){
124121
flags |= LOOK_LONE_CR; /* Not enough chars or next char not LF */
125122
}
126123
}
127124
}
@@ -273,17 +270,16 @@
273270
c = UTF16_SWAP(c);
274271
}
275272
if( c==0 ){
276273
flags |= LOOK_NUL; /* NUL character in a file -> binary */
277274
}else if( c=='\r' ){
278
- flags |= LOOK_CR;
279275
if( n<(2*sizeof(WCHAR_T)) || UTF16_SWAP_IF(bReverse, z[1])!='\n' ){
280276
flags |= LOOK_LONE_CR; /* Not enough chars or next char not LF */
281277
}
282278
}
283279
j = (c!='\n');
284
- if( !j ) flags |= (LOOK_LF | LOOK_LONE_LF); /* Found LF as first char */
280
+ if( !j ) flags |= (LOOK_LONE_LF); /* Found LF as first char */
285281
while( !(flags&stopFlags) && ((n-=sizeof(WCHAR_T))>=sizeof(WCHAR_T)) ){
286282
int c2 = c;
287283
c = *++z;
288284
if( bReverse ){
289285
c = UTF16_SWAP(c);
@@ -290,22 +286,20 @@
290286
}
291287
++j;
292288
if( c==0 ){
293289
flags |= LOOK_NUL; /* NUL character in a file -> binary */
294290
}else if( c=='\n' ){
295
- flags |= LOOK_LF;
296291
if( c2=='\r' ){
297
- flags |= (LOOK_CR | LOOK_CRLF); /* Found LF preceded by CR */
292
+ flags |= (LOOK_CRLF); /* Found LF preceded by CR */
298293
}else{
299294
flags |= LOOK_LONE_LF;
300295
}
301296
if( j>UTF16_LENGTH_MASK ){
302297
flags |= LOOK_LONG; /* Very long line -> binary */
303298
}
304299
j = 0;
305300
}else if( c=='\r' ){
306
- flags |= LOOK_CR;
307301
if( n<(2*sizeof(WCHAR_T)) || UTF16_SWAP_IF(bReverse, z[1])!='\n' ){
308302
flags |= LOOK_LONE_CR; /* Not enough chars or next char not LF */
309303
}
310304
}
311305
}
312306
--- src/lookslike.c
+++ src/lookslike.c
@@ -37,21 +37,21 @@
37 ** Output flags for the looks_like_utf8() and looks_like_utf16() routines used
38 ** to convey status information about the blob content.
39 */
40 #define LOOK_NONE ((int)0x00000000) /* Nothing special was found. */
41 #define LOOK_NUL ((int)0x00000001) /* One or more NUL chars were found. */
42 #define LOOK_CR ((int)0x00000002) /* One or more CR chars were found. */
43 #define LOOK_LONE_CR ((int)0x00000004) /* An unpaired CR char was found. */
44 #define LOOK_LF ((int)0x00000008) /* One or more LF chars were found. */
45 #define LOOK_LONE_LF ((int)0x00000010) /* An unpaired LF char was found. */
46 #define LOOK_CRLF ((int)0x00000020) /* One or more CR/LF pairs were found. */
47 #define LOOK_LONG ((int)0x00000040) /* An over length line was found. */
48 #define LOOK_ODD ((int)0x00000080) /* An odd number of bytes was found. */
49 #define LOOK_SHORT ((int)0x00000100) /* Unable to perform full check. */
50 #define LOOK_INVALID ((int)0x00000200) /* Invalid sequence was found. */
51 #define LOOK_BINARY (LOOK_NUL | LOOK_LONG | LOOK_SHORT) /* May be binary. */
52 #define LOOK_EOL (LOOK_LONE_CR | LOOK_LONE_LF | LOOK_CRLF) /* Line seps. */
 
 
53 #endif /* INTERFACE */
54
55
56 /*
57 ** This function attempts to scan each logical line within the blob to
@@ -93,35 +93,32 @@
93 if( n==0 ) return flags; /* Empty file -> text */
94 c = *z;
95 if( c==0 ){
96 flags |= LOOK_NUL; /* NUL character in a file -> binary */
97 }else if( c=='\r' ){
98 flags |= LOOK_CR;
99 if( n<=1 || z[1]!='\n' ){
100 flags |= LOOK_LONE_CR; /* Not enough chars or next char not LF */
101 }
102 }
103 j = (c!='\n');
104 if( !j ) flags |= (LOOK_LF | LOOK_LONE_LF); /* Found LF as first char */
105 while( !(flags&stopFlags) && --n>0 ){
106 int c2 = c;
107 c = *++z; ++j;
108 if( c==0 ){
109 flags |= LOOK_NUL; /* NUL character in a file -> binary */
110 }else if( c=='\n' ){
111 flags |= LOOK_LF;
112 if( c2=='\r' ){
113 flags |= (LOOK_CR | LOOK_CRLF); /* Found LF preceded by CR */
114 }else{
115 flags |= LOOK_LONE_LF;
116 }
117 if( j>LENGTH_MASK ){
118 flags |= LOOK_LONG; /* Very long line -> binary */
119 }
120 j = 0;
121 }else if( c=='\r' ){
122 flags |= LOOK_CR;
123 if( n<=1 || z[1]!='\n' ){
124 flags |= LOOK_LONE_CR; /* Not enough chars or next char not LF */
125 }
126 }
127 }
@@ -273,17 +270,16 @@
273 c = UTF16_SWAP(c);
274 }
275 if( c==0 ){
276 flags |= LOOK_NUL; /* NUL character in a file -> binary */
277 }else if( c=='\r' ){
278 flags |= LOOK_CR;
279 if( n<(2*sizeof(WCHAR_T)) || UTF16_SWAP_IF(bReverse, z[1])!='\n' ){
280 flags |= LOOK_LONE_CR; /* Not enough chars or next char not LF */
281 }
282 }
283 j = (c!='\n');
284 if( !j ) flags |= (LOOK_LF | LOOK_LONE_LF); /* Found LF as first char */
285 while( !(flags&stopFlags) && ((n-=sizeof(WCHAR_T))>=sizeof(WCHAR_T)) ){
286 int c2 = c;
287 c = *++z;
288 if( bReverse ){
289 c = UTF16_SWAP(c);
@@ -290,22 +286,20 @@
290 }
291 ++j;
292 if( c==0 ){
293 flags |= LOOK_NUL; /* NUL character in a file -> binary */
294 }else if( c=='\n' ){
295 flags |= LOOK_LF;
296 if( c2=='\r' ){
297 flags |= (LOOK_CR | LOOK_CRLF); /* Found LF preceded by CR */
298 }else{
299 flags |= LOOK_LONE_LF;
300 }
301 if( j>UTF16_LENGTH_MASK ){
302 flags |= LOOK_LONG; /* Very long line -> binary */
303 }
304 j = 0;
305 }else if( c=='\r' ){
306 flags |= LOOK_CR;
307 if( n<(2*sizeof(WCHAR_T)) || UTF16_SWAP_IF(bReverse, z[1])!='\n' ){
308 flags |= LOOK_LONE_CR; /* Not enough chars or next char not LF */
309 }
310 }
311 }
312
--- src/lookslike.c
+++ src/lookslike.c
@@ -37,21 +37,21 @@
37 ** Output flags for the looks_like_utf8() and looks_like_utf16() routines used
38 ** to convey status information about the blob content.
39 */
40 #define LOOK_NONE ((int)0x00000000) /* Nothing special was found. */
41 #define LOOK_NUL ((int)0x00000001) /* One or more NUL chars were found. */
42 #define LOOK_LONE_CR ((int)0x00000002) /* An unpaired CR char was found. */
43 #define LOOK_LONE_LF ((int)0x00000004) /* An unpaired LF char was found. */
44 #define LOOK_CRLF ((int)0x00000008) /* One or more CR/LF pairs were found. */
45 #define LOOK_LONG ((int)0x00000010) /* An over length line was found. */
46 #define LOOK_ODD ((int)0x00000020) /* An odd number of bytes was found. */
47 #define LOOK_SHORT ((int)0x00000040) /* Unable to perform full check. */
48 #define LOOK_INVALID ((int)0x00000080) /* Invalid sequence was found. */
 
 
49 #define LOOK_BINARY (LOOK_NUL | LOOK_LONG | LOOK_SHORT) /* May be binary. */
50 #define LOOK_EOL (LOOK_LONE_CR | LOOK_LONE_LF | LOOK_CRLF) /* Line seps. */
51 #define LOOK_CR (LOOK_LONE_CR | LOOK_CRLF) /* One or more CR chars. */
52 #define LOOK_LF (LOOK_LONE_LF | LOOK_CRLF) /* One or more LF chars. */
53 #endif /* INTERFACE */
54
55
56 /*
57 ** This function attempts to scan each logical line within the blob to
@@ -93,35 +93,32 @@
93 if( n==0 ) return flags; /* Empty file -> text */
94 c = *z;
95 if( c==0 ){
96 flags |= LOOK_NUL; /* NUL character in a file -> binary */
97 }else if( c=='\r' ){
 
98 if( n<=1 || z[1]!='\n' ){
99 flags |= LOOK_LONE_CR; /* Not enough chars or next char not LF */
100 }
101 }
102 j = (c!='\n');
103 if( !j ) flags |= (LOOK_LONE_LF); /* Found LF as first char */
104 while( !(flags&stopFlags) && --n>0 ){
105 int c2 = c;
106 c = *++z; ++j;
107 if( c==0 ){
108 flags |= LOOK_NUL; /* NUL character in a file -> binary */
109 }else if( c=='\n' ){
 
110 if( c2=='\r' ){
111 flags |= (LOOK_CRLF); /* Found LF preceded by CR */
112 }else{
113 flags |= LOOK_LONE_LF;
114 }
115 if( j>LENGTH_MASK ){
116 flags |= LOOK_LONG; /* Very long line -> binary */
117 }
118 j = 0;
119 }else if( c=='\r' ){
 
120 if( n<=1 || z[1]!='\n' ){
121 flags |= LOOK_LONE_CR; /* Not enough chars or next char not LF */
122 }
123 }
124 }
@@ -273,17 +270,16 @@
270 c = UTF16_SWAP(c);
271 }
272 if( c==0 ){
273 flags |= LOOK_NUL; /* NUL character in a file -> binary */
274 }else if( c=='\r' ){
 
275 if( n<(2*sizeof(WCHAR_T)) || UTF16_SWAP_IF(bReverse, z[1])!='\n' ){
276 flags |= LOOK_LONE_CR; /* Not enough chars or next char not LF */
277 }
278 }
279 j = (c!='\n');
280 if( !j ) flags |= (LOOK_LONE_LF); /* Found LF as first char */
281 while( !(flags&stopFlags) && ((n-=sizeof(WCHAR_T))>=sizeof(WCHAR_T)) ){
282 int c2 = c;
283 c = *++z;
284 if( bReverse ){
285 c = UTF16_SWAP(c);
@@ -290,22 +286,20 @@
286 }
287 ++j;
288 if( c==0 ){
289 flags |= LOOK_NUL; /* NUL character in a file -> binary */
290 }else if( c=='\n' ){
 
291 if( c2=='\r' ){
292 flags |= (LOOK_CRLF); /* Found LF preceded by CR */
293 }else{
294 flags |= LOOK_LONE_LF;
295 }
296 if( j>UTF16_LENGTH_MASK ){
297 flags |= LOOK_LONG; /* Very long line -> binary */
298 }
299 j = 0;
300 }else if( c=='\r' ){
 
301 if( n<(2*sizeof(WCHAR_T)) || UTF16_SWAP_IF(bReverse, z[1])!='\n' ){
302 flags |= LOOK_LONE_CR; /* Not enough chars or next char not LF */
303 }
304 }
305 }
306

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button