Fossil SCM
Simplify some usage of if-statements. No change of functionality.
Commit
7458a18894b876573710690391a4c85c595e606f
Parent
5f24da1360e6540…
1 file changed
+2
-6
+2
-6
| --- src/lookslike.c | ||
| +++ src/lookslike.c | ||
| @@ -231,15 +231,14 @@ | ||
| 231 | 231 | int looks_like_utf16(const Blob *pContent, int bReverse, int stopFlags){ |
| 232 | 232 | const WCHAR_T *z = (WCHAR_T *)blob_buffer(pContent); |
| 233 | 233 | unsigned int n = blob_size(pContent); |
| 234 | 234 | int j, c, flags = LOOK_NONE; /* Assume UTF-16 text, prove otherwise */ |
| 235 | 235 | |
| 236 | - if( n==0 ) return flags; /* Empty file -> text */ | |
| 237 | 236 | if( n%sizeof(WCHAR_T) ){ |
| 238 | 237 | flags |= LOOK_ODD; /* Odd number of bytes -> binary (UTF-8?) */ |
| 239 | - if( n<sizeof(WCHAR_T) ) return flags; /* One byte -> binary (UTF-8?) */ | |
| 240 | 238 | } |
| 239 | + if( n<sizeof(WCHAR_T) ) return flags; /* Zero or One byte -> binary (UTF-8?) */ | |
| 241 | 240 | c = *z; |
| 242 | 241 | if( bReverse ){ |
| 243 | 242 | c = UTF16_SWAP(c); |
| 244 | 243 | } |
| 245 | 244 | if( c==0 ){ |
| @@ -250,15 +249,12 @@ | ||
| 250 | 249 | flags |= LOOK_LONE_CR; /* More chars, next char is not LF */ |
| 251 | 250 | } |
| 252 | 251 | } |
| 253 | 252 | j = (c!='\n'); |
| 254 | 253 | if( !j ) flags |= (LOOK_LF | LOOK_LONE_LF); /* Found LF as first char */ |
| 255 | - while( 1 ){ | |
| 254 | + while( !(flags&stopFlags) && ((n-=sizeof(WCHAR_T))>=sizeof(WCHAR_T)) ){ | |
| 256 | 255 | int c2 = c; |
| 257 | - if( flags&stopFlags ) break; | |
| 258 | - n -= sizeof(WCHAR_T); | |
| 259 | - if( n<sizeof(WCHAR_T) ) break; | |
| 260 | 256 | c = *++z; |
| 261 | 257 | if( bReverse ){ |
| 262 | 258 | c = UTF16_SWAP(c); |
| 263 | 259 | } |
| 264 | 260 | ++j; |
| 265 | 261 |
| --- src/lookslike.c | |
| +++ src/lookslike.c | |
| @@ -231,15 +231,14 @@ | |
| 231 | int looks_like_utf16(const Blob *pContent, int bReverse, int stopFlags){ |
| 232 | const WCHAR_T *z = (WCHAR_T *)blob_buffer(pContent); |
| 233 | unsigned int n = blob_size(pContent); |
| 234 | int j, c, flags = LOOK_NONE; /* Assume UTF-16 text, prove otherwise */ |
| 235 | |
| 236 | if( n==0 ) return flags; /* Empty file -> text */ |
| 237 | if( n%sizeof(WCHAR_T) ){ |
| 238 | flags |= LOOK_ODD; /* Odd number of bytes -> binary (UTF-8?) */ |
| 239 | if( n<sizeof(WCHAR_T) ) return flags; /* One byte -> binary (UTF-8?) */ |
| 240 | } |
| 241 | c = *z; |
| 242 | if( bReverse ){ |
| 243 | c = UTF16_SWAP(c); |
| 244 | } |
| 245 | if( c==0 ){ |
| @@ -250,15 +249,12 @@ | |
| 250 | flags |= LOOK_LONE_CR; /* More chars, next char is not LF */ |
| 251 | } |
| 252 | } |
| 253 | j = (c!='\n'); |
| 254 | if( !j ) flags |= (LOOK_LF | LOOK_LONE_LF); /* Found LF as first char */ |
| 255 | while( 1 ){ |
| 256 | int c2 = c; |
| 257 | if( flags&stopFlags ) break; |
| 258 | n -= sizeof(WCHAR_T); |
| 259 | if( n<sizeof(WCHAR_T) ) break; |
| 260 | c = *++z; |
| 261 | if( bReverse ){ |
| 262 | c = UTF16_SWAP(c); |
| 263 | } |
| 264 | ++j; |
| 265 |
| --- src/lookslike.c | |
| +++ src/lookslike.c | |
| @@ -231,15 +231,14 @@ | |
| 231 | int looks_like_utf16(const Blob *pContent, int bReverse, int stopFlags){ |
| 232 | const WCHAR_T *z = (WCHAR_T *)blob_buffer(pContent); |
| 233 | unsigned int n = blob_size(pContent); |
| 234 | int j, c, flags = LOOK_NONE; /* Assume UTF-16 text, prove otherwise */ |
| 235 | |
| 236 | if( n%sizeof(WCHAR_T) ){ |
| 237 | flags |= LOOK_ODD; /* Odd number of bytes -> binary (UTF-8?) */ |
| 238 | } |
| 239 | if( n<sizeof(WCHAR_T) ) return flags; /* Zero or One byte -> binary (UTF-8?) */ |
| 240 | c = *z; |
| 241 | if( bReverse ){ |
| 242 | c = UTF16_SWAP(c); |
| 243 | } |
| 244 | if( c==0 ){ |
| @@ -250,15 +249,12 @@ | |
| 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 | } |
| 260 | ++j; |
| 261 |