Fossil SCM

Simplify some usage of if-statements. No change of functionality.

jan.nijtmans 2014-04-28 09:25 trunk
Commit 7458a18894b876573710690391a4c85c595e606f
1 file changed +2 -6
+2 -6
--- src/lookslike.c
+++ src/lookslike.c
@@ -231,15 +231,14 @@
231231
int looks_like_utf16(const Blob *pContent, int bReverse, int stopFlags){
232232
const WCHAR_T *z = (WCHAR_T *)blob_buffer(pContent);
233233
unsigned int n = blob_size(pContent);
234234
int j, c, flags = LOOK_NONE; /* Assume UTF-16 text, prove otherwise */
235235
236
- if( n==0 ) return flags; /* Empty file -> text */
237236
if( n%sizeof(WCHAR_T) ){
238237
flags |= LOOK_ODD; /* Odd number of bytes -> binary (UTF-8?) */
239
- if( n<sizeof(WCHAR_T) ) return flags; /* One byte -> binary (UTF-8?) */
240238
}
239
+ if( n<sizeof(WCHAR_T) ) return flags; /* Zero or One byte -> binary (UTF-8?) */
241240
c = *z;
242241
if( bReverse ){
243242
c = UTF16_SWAP(c);
244243
}
245244
if( c==0 ){
@@ -250,15 +249,12 @@
250249
flags |= LOOK_LONE_CR; /* More chars, next char is not LF */
251250
}
252251
}
253252
j = (c!='\n');
254253
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)) ){
256255
int c2 = c;
257
- if( flags&stopFlags ) break;
258
- n -= sizeof(WCHAR_T);
259
- if( n<sizeof(WCHAR_T) ) break;
260256
c = *++z;
261257
if( bReverse ){
262258
c = UTF16_SWAP(c);
263259
}
264260
++j;
265261
--- 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

Keyboard Shortcuts

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