Fossil SCM

Add support for detecting standalone carriage-return characters via the looks_like_utf*() functions.

mistachkin 2013-03-07 01:27 trunk
Commit 6c7185d9baa3bce7bbbf9cc121a61225966cba5a
1 file changed +10 -4
+10 -4
--- src/diff.c
+++ src/diff.c
@@ -69,14 +69,15 @@
6969
** Output flags for the looks_like_utf8() and looks_like_utf16() routines used
7070
** to convey status information about the blob content.
7171
*/
7272
#define LOOK_NONE ((int)0x00000000) /* Nothing special was found. */
7373
#define LOOK_NUL ((int)0x00000001) /* One or more NUL chars were found. */
74
-#define LOOK_LF ((int)0x00000002) /* One or more LF chars were found. */
75
-#define LOOK_CRLF ((int)0x00000004) /* One or more CR/LF pairs were found. */
76
-#define LOOK_LENGTH ((int)0x00000008) /* An over length line was found. */
77
-#define LOOK_ODD ((int)0x00000010) /* An odd number of bytes was found. */
74
+#define LOOK_CR ((int)0x00000002) /* One or more CR chars were found. */
75
+#define LOOK_LF ((int)0x00000004) /* One or more LF chars were found. */
76
+#define LOOK_CRLF ((int)0x00000008) /* One or more CR/LF pairs were found. */
77
+#define LOOK_LENGTH ((int)0x00000010) /* An over length line was found. */
78
+#define LOOK_ODD ((int)0x00000020) /* An odd number of bytes was found. */
7879
#endif /* INTERFACE */
7980
8081
/*
8182
** Maximum length of a line in a text file, in bytes. (2**13 = 8192 bytes)
8283
*/
@@ -256,10 +257,12 @@
256257
if( j>LENGTH_MASK ){
257258
if( pFlags ) *pFlags |= LOOK_LENGTH;
258259
result = 0; /* Very long line -> binary */
259260
}
260261
j = 0;
262
+ }else if( c=='\r' ){
263
+ if( pFlags ) *pFlags |= LOOK_CR;
261264
}
262265
}
263266
if( j>LENGTH_MASK ){
264267
if( pFlags ) *pFlags |= LOOK_LENGTH;
265268
result = 0; /* Very long line -> binary */
@@ -357,10 +360,12 @@
357360
if( j>UTF16_LENGTH_MASK ){
358361
if( pFlags ) *pFlags |= LOOK_LENGTH;
359362
result = 0; /* Very long line -> binary */
360363
}
361364
j = 0;
365
+ }else if( c==UTF16BE_CR || c==UTF16LE_CR ){
366
+ if( pFlags ) *pFlags |= LOOK_CR;
362367
}
363368
}
364369
if( j>UTF16_LENGTH_MASK ){
365370
if( pFlags ) *pFlags |= LOOK_LENGTH;
366371
result = 0; /* Very long line -> binary */
@@ -2487,11 +2492,12 @@
24872492
fossil_print("File \"%s\" has %d bytes.\n",g.argv[2],blob_size(&blob));
24882493
fossil_print("Starts with UTF-8 BOM: %s\n",fUtf8?"yes":"no");
24892494
fossil_print("Starts with UTF-16 BOM: %s\n",fUtf16?"yes":"no");
24902495
fossil_print("Looks like UTF-%s: %s\n",fUtf16?"16":"8",eType?"yes":"no");
24912496
fossil_print("Has flag LOOK_NUL: %s\n",(lookFlags&LOOK_NUL)?"yes":"no");
2497
+ fossil_print("Has flag LOOK_CR: %s\n",(lookFlags&LOOK_CR)?"yes":"no");
24922498
fossil_print("Has flag LOOK_LF: %s\n",(lookFlags&LOOK_LF)?"yes":"no");
24932499
fossil_print("Has flag LOOK_CRLF: %s\n",(lookFlags&LOOK_CRLF)?"yes":"no");
24942500
fossil_print("Has flag LOOK_LENGTH: %s\n",(lookFlags&LOOK_LENGTH)?"yes":"no");
24952501
fossil_print("Has flag LOOK_ODD: %s\n",(lookFlags&LOOK_ODD)?"yes":"no");
24962502
blob_reset(&blob);
24972503
}
24982504
--- src/diff.c
+++ src/diff.c
@@ -69,14 +69,15 @@
69 ** Output flags for the looks_like_utf8() and looks_like_utf16() routines used
70 ** to convey status information about the blob content.
71 */
72 #define LOOK_NONE ((int)0x00000000) /* Nothing special was found. */
73 #define LOOK_NUL ((int)0x00000001) /* One or more NUL chars were found. */
74 #define LOOK_LF ((int)0x00000002) /* One or more LF chars were found. */
75 #define LOOK_CRLF ((int)0x00000004) /* One or more CR/LF pairs were found. */
76 #define LOOK_LENGTH ((int)0x00000008) /* An over length line was found. */
77 #define LOOK_ODD ((int)0x00000010) /* An odd number of bytes was found. */
 
78 #endif /* INTERFACE */
79
80 /*
81 ** Maximum length of a line in a text file, in bytes. (2**13 = 8192 bytes)
82 */
@@ -256,10 +257,12 @@
256 if( j>LENGTH_MASK ){
257 if( pFlags ) *pFlags |= LOOK_LENGTH;
258 result = 0; /* Very long line -> binary */
259 }
260 j = 0;
 
 
261 }
262 }
263 if( j>LENGTH_MASK ){
264 if( pFlags ) *pFlags |= LOOK_LENGTH;
265 result = 0; /* Very long line -> binary */
@@ -357,10 +360,12 @@
357 if( j>UTF16_LENGTH_MASK ){
358 if( pFlags ) *pFlags |= LOOK_LENGTH;
359 result = 0; /* Very long line -> binary */
360 }
361 j = 0;
 
 
362 }
363 }
364 if( j>UTF16_LENGTH_MASK ){
365 if( pFlags ) *pFlags |= LOOK_LENGTH;
366 result = 0; /* Very long line -> binary */
@@ -2487,11 +2492,12 @@
2487 fossil_print("File \"%s\" has %d bytes.\n",g.argv[2],blob_size(&blob));
2488 fossil_print("Starts with UTF-8 BOM: %s\n",fUtf8?"yes":"no");
2489 fossil_print("Starts with UTF-16 BOM: %s\n",fUtf16?"yes":"no");
2490 fossil_print("Looks like UTF-%s: %s\n",fUtf16?"16":"8",eType?"yes":"no");
2491 fossil_print("Has flag LOOK_NUL: %s\n",(lookFlags&LOOK_NUL)?"yes":"no");
 
2492 fossil_print("Has flag LOOK_LF: %s\n",(lookFlags&LOOK_LF)?"yes":"no");
2493 fossil_print("Has flag LOOK_CRLF: %s\n",(lookFlags&LOOK_CRLF)?"yes":"no");
2494 fossil_print("Has flag LOOK_LENGTH: %s\n",(lookFlags&LOOK_LENGTH)?"yes":"no");
2495 fossil_print("Has flag LOOK_ODD: %s\n",(lookFlags&LOOK_ODD)?"yes":"no");
2496 blob_reset(&blob);
2497 }
2498
--- src/diff.c
+++ src/diff.c
@@ -69,14 +69,15 @@
69 ** Output flags for the looks_like_utf8() and looks_like_utf16() routines used
70 ** to convey status information about the blob content.
71 */
72 #define LOOK_NONE ((int)0x00000000) /* Nothing special was found. */
73 #define LOOK_NUL ((int)0x00000001) /* One or more NUL chars were found. */
74 #define LOOK_CR ((int)0x00000002) /* One or more CR chars were found. */
75 #define LOOK_LF ((int)0x00000004) /* One or more LF chars were found. */
76 #define LOOK_CRLF ((int)0x00000008) /* One or more CR/LF pairs were found. */
77 #define LOOK_LENGTH ((int)0x00000010) /* An over length line was found. */
78 #define LOOK_ODD ((int)0x00000020) /* An odd number of bytes was found. */
79 #endif /* INTERFACE */
80
81 /*
82 ** Maximum length of a line in a text file, in bytes. (2**13 = 8192 bytes)
83 */
@@ -256,10 +257,12 @@
257 if( j>LENGTH_MASK ){
258 if( pFlags ) *pFlags |= LOOK_LENGTH;
259 result = 0; /* Very long line -> binary */
260 }
261 j = 0;
262 }else if( c=='\r' ){
263 if( pFlags ) *pFlags |= LOOK_CR;
264 }
265 }
266 if( j>LENGTH_MASK ){
267 if( pFlags ) *pFlags |= LOOK_LENGTH;
268 result = 0; /* Very long line -> binary */
@@ -357,10 +360,12 @@
360 if( j>UTF16_LENGTH_MASK ){
361 if( pFlags ) *pFlags |= LOOK_LENGTH;
362 result = 0; /* Very long line -> binary */
363 }
364 j = 0;
365 }else if( c==UTF16BE_CR || c==UTF16LE_CR ){
366 if( pFlags ) *pFlags |= LOOK_CR;
367 }
368 }
369 if( j>UTF16_LENGTH_MASK ){
370 if( pFlags ) *pFlags |= LOOK_LENGTH;
371 result = 0; /* Very long line -> binary */
@@ -2487,11 +2492,12 @@
2492 fossil_print("File \"%s\" has %d bytes.\n",g.argv[2],blob_size(&blob));
2493 fossil_print("Starts with UTF-8 BOM: %s\n",fUtf8?"yes":"no");
2494 fossil_print("Starts with UTF-16 BOM: %s\n",fUtf16?"yes":"no");
2495 fossil_print("Looks like UTF-%s: %s\n",fUtf16?"16":"8",eType?"yes":"no");
2496 fossil_print("Has flag LOOK_NUL: %s\n",(lookFlags&LOOK_NUL)?"yes":"no");
2497 fossil_print("Has flag LOOK_CR: %s\n",(lookFlags&LOOK_CR)?"yes":"no");
2498 fossil_print("Has flag LOOK_LF: %s\n",(lookFlags&LOOK_LF)?"yes":"no");
2499 fossil_print("Has flag LOOK_CRLF: %s\n",(lookFlags&LOOK_CRLF)?"yes":"no");
2500 fossil_print("Has flag LOOK_LENGTH: %s\n",(lookFlags&LOOK_LENGTH)?"yes":"no");
2501 fossil_print("Has flag LOOK_ODD: %s\n",(lookFlags&LOOK_ODD)?"yes":"no");
2502 blob_reset(&blob);
2503 }
2504

Keyboard Shortcuts

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