Fossil SCM

Enhancements to the lookslike functions.

drh 2015-12-23 01:37 trunk merge
Commit 6b292eaa78192628c071bc3553a64102c3ada2b9
1 file changed +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; /* More chars, next char is 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; /* More chars, next char is not LF */
125122
}
126123
}
127124
}
@@ -242,17 +239,16 @@
242239
c = UTF16_SWAP(c);
243240
}
244241
if( c==0 ){
245242
flags |= LOOK_NUL; /* NUL character in a file -> binary */
246243
}else if( c=='\r' ){
247
- flags |= LOOK_CR;
248244
if( n<(2*sizeof(WCHAR_T)) || UTF16_SWAP_IF(bReverse, z[1])!='\n' ){
249245
flags |= LOOK_LONE_CR; /* More chars, next char is not LF */
250246
}
251247
}
252248
j = (c!='\n');
253
- if( !j ) flags |= (LOOK_LF | LOOK_LONE_LF); /* Found LF as first char */
249
+ if( !j ) flags |= (LOOK_LONE_LF); /* Found LF as first char */
254250
while( !(flags&stopFlags) && ((n-=sizeof(WCHAR_T))>=sizeof(WCHAR_T)) ){
255251
int c2 = c;
256252
c = *++z;
257253
if( bReverse ){
258254
c = UTF16_SWAP(c);
@@ -259,22 +255,20 @@
259255
}
260256
++j;
261257
if( c==0 ){
262258
flags |= LOOK_NUL; /* NUL character in a file -> binary */
263259
}else if( c=='\n' ){
264
- flags |= LOOK_LF;
265260
if( c2=='\r' ){
266
- flags |= (LOOK_CR | LOOK_CRLF); /* Found LF preceded by CR */
261
+ flags |= (LOOK_CRLF); /* Found LF preceded by CR */
267262
}else{
268263
flags |= LOOK_LONE_LF;
269264
}
270265
if( j>UTF16_LENGTH_MASK ){
271266
flags |= LOOK_LONG; /* Very long line -> binary */
272267
}
273268
j = 0;
274269
}else if( c=='\r' ){
275
- flags |= LOOK_CR;
276270
if( n<(2*sizeof(WCHAR_T)) || UTF16_SWAP_IF(bReverse, z[1])!='\n' ){
277271
flags |= LOOK_LONE_CR; /* More chars, next char is not LF */
278272
}
279273
}
280274
}
281275
--- 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; /* More chars, next char is 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; /* More chars, next char is not LF */
125 }
126 }
127 }
@@ -242,17 +239,16 @@
242 c = UTF16_SWAP(c);
243 }
244 if( c==0 ){
245 flags |= LOOK_NUL; /* NUL character in a file -> binary */
246 }else if( c=='\r' ){
247 flags |= LOOK_CR;
248 if( n<(2*sizeof(WCHAR_T)) || UTF16_SWAP_IF(bReverse, z[1])!='\n' ){
249 flags |= LOOK_LONE_CR; /* More chars, next char is not LF */
250 }
251 }
252 j = (c!='\n');
253 if( !j ) flags |= (LOOK_LF | LOOK_LONE_LF); /* Found LF as first char */
254 while( !(flags&stopFlags) && ((n-=sizeof(WCHAR_T))>=sizeof(WCHAR_T)) ){
255 int c2 = c;
256 c = *++z;
257 if( bReverse ){
258 c = UTF16_SWAP(c);
@@ -259,22 +255,20 @@
259 }
260 ++j;
261 if( c==0 ){
262 flags |= LOOK_NUL; /* NUL character in a file -> binary */
263 }else if( c=='\n' ){
264 flags |= LOOK_LF;
265 if( c2=='\r' ){
266 flags |= (LOOK_CR | LOOK_CRLF); /* Found LF preceded by CR */
267 }else{
268 flags |= LOOK_LONE_LF;
269 }
270 if( j>UTF16_LENGTH_MASK ){
271 flags |= LOOK_LONG; /* Very long line -> binary */
272 }
273 j = 0;
274 }else if( c=='\r' ){
275 flags |= LOOK_CR;
276 if( n<(2*sizeof(WCHAR_T)) || UTF16_SWAP_IF(bReverse, z[1])!='\n' ){
277 flags |= LOOK_LONE_CR; /* More chars, next char is not LF */
278 }
279 }
280 }
281
--- 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; /* More chars, next char is 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; /* More chars, next char is not LF */
122 }
123 }
124 }
@@ -242,17 +239,16 @@
239 c = UTF16_SWAP(c);
240 }
241 if( c==0 ){
242 flags |= LOOK_NUL; /* NUL character in a file -> binary */
243 }else if( c=='\r' ){
 
244 if( n<(2*sizeof(WCHAR_T)) || UTF16_SWAP_IF(bReverse, z[1])!='\n' ){
245 flags |= LOOK_LONE_CR; /* More chars, next char is not LF */
246 }
247 }
248 j = (c!='\n');
249 if( !j ) flags |= (LOOK_LONE_LF); /* Found LF as first char */
250 while( !(flags&stopFlags) && ((n-=sizeof(WCHAR_T))>=sizeof(WCHAR_T)) ){
251 int c2 = c;
252 c = *++z;
253 if( bReverse ){
254 c = UTF16_SWAP(c);
@@ -259,22 +255,20 @@
255 }
256 ++j;
257 if( c==0 ){
258 flags |= LOOK_NUL; /* NUL character in a file -> binary */
259 }else if( c=='\n' ){
 
260 if( c2=='\r' ){
261 flags |= (LOOK_CRLF); /* Found LF preceded by CR */
262 }else{
263 flags |= LOOK_LONE_LF;
264 }
265 if( j>UTF16_LENGTH_MASK ){
266 flags |= LOOK_LONG; /* Very long line -> binary */
267 }
268 j = 0;
269 }else if( c=='\r' ){
 
270 if( n<(2*sizeof(WCHAR_T)) || UTF16_SWAP_IF(bReverse, z[1])!='\n' ){
271 flags |= LOOK_LONE_CR; /* More chars, next char is not LF */
272 }
273 }
274 }
275

Keyboard Shortcuts

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