Fossil SCM
Further improve clarity.
Commit
11e2c6e611d9caca1b21380fbfb86c568afc835a
Parent
8017c358ba77159…
1 file changed
+8
-6
+8
-6
| --- src/diff.c | ||
| +++ src/diff.c | ||
| @@ -119,20 +119,22 @@ | ||
| 119 | 119 | }; |
| 120 | 120 | |
| 121 | 121 | /* |
| 122 | 122 | ** Count the number of lines in the input string. Include the last line |
| 123 | 123 | ** in the count even if it lacks the \n terminator. If an empty string |
| 124 | -** is specified, the number of lines is zero. | |
| 124 | +** is specified, the number of lines is zero. For the purposes of this | |
| 125 | +** function, a string is considered empty if it contains no characters | |
| 126 | +** -OR- it contains only NUL characters. | |
| 125 | 127 | */ |
| 126 | 128 | static int count_lines( |
| 127 | 129 | const char *z, |
| 128 | 130 | int n |
| 129 | 131 | ){ |
| 130 | 132 | int nLine; |
| 131 | 133 | const char *zNL, *z2; |
| 132 | 134 | for(nLine=0, z2=z; (zNL = fossil_strchr(z2,-1,'\n'))!=0; z2=zNL+1, nLine++){} |
| 133 | - if( z2[0]!=0 ) nLine++; | |
| 135 | + if( z2[0]!='\0' ) nLine++; | |
| 134 | 136 | return nLine; |
| 135 | 137 | } |
| 136 | 138 | |
| 137 | 139 | /* |
| 138 | 140 | ** Return an array of DLine objects containing a pointer to the |
| @@ -159,11 +161,11 @@ | ||
| 159 | 161 | unsigned int h, h2; |
| 160 | 162 | DLine *a; |
| 161 | 163 | const char *zNL; |
| 162 | 164 | |
| 163 | 165 | nLine = count_lines(z, n); |
| 164 | - assert( nLine>0 || z[0]==0 ); | |
| 166 | + assert( nLine>0 || z[0]=='\0' ); | |
| 165 | 167 | a = fossil_malloc( sizeof(a[0])*nLine ); |
| 166 | 168 | memset(a, 0, sizeof(a[0])*nLine); |
| 167 | 169 | if( nLine==0 ){ |
| 168 | 170 | if( fossil_strchr(z,n,'\0')!=0 ){ |
| 169 | 171 | fossil_free(a); |
| @@ -193,11 +195,11 @@ | ||
| 193 | 195 | } |
| 194 | 196 | if( (diffFlags & DIFF_IGNORE_ALLWS)==DIFF_IGNORE_ALLWS ){ |
| 195 | 197 | int numws = 0; |
| 196 | 198 | while( s<k && fossil_isspace(z[s]) ){ s++; } |
| 197 | 199 | for(h=0, x=s; x<k; x++){ |
| 198 | - if( z[x]==0 ){ | |
| 200 | + if( z[x]=='\0' ){ | |
| 199 | 201 | fossil_free(a); |
| 200 | 202 | return 0; |
| 201 | 203 | } |
| 202 | 204 | if( fossil_isspace(z[x]) ){ |
| 203 | 205 | ++numws; |
| @@ -207,11 +209,11 @@ | ||
| 207 | 209 | } |
| 208 | 210 | } |
| 209 | 211 | k -= numws; |
| 210 | 212 | }else{ |
| 211 | 213 | for(h=0, x=s; x<k; x++){ |
| 212 | - if( z[x]==0 ){ | |
| 214 | + if( z[x]=='\0' ){ | |
| 213 | 215 | fossil_free(a); |
| 214 | 216 | return 0; |
| 215 | 217 | } |
| 216 | 218 | h += z[x]; |
| 217 | 219 | h *= 0x9e3779b1; |
| @@ -222,11 +224,11 @@ | ||
| 222 | 224 | h2 = h % nLine; |
| 223 | 225 | a[i].iNext = a[h2].iHash; |
| 224 | 226 | a[h2].iHash = i+1; |
| 225 | 227 | z += nn+1; n -= nn+1; |
| 226 | 228 | i++; |
| 227 | - }while( zNL[0] && zNL[1] ); | |
| 229 | + }while( zNL[0]!='\0' && zNL[1]!='\0' ); | |
| 228 | 230 | assert( i==nLine ); |
| 229 | 231 | |
| 230 | 232 | /* Return results */ |
| 231 | 233 | *pnLine = nLine; |
| 232 | 234 | return a; |
| 233 | 235 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -119,20 +119,22 @@ | |
| 119 | }; |
| 120 | |
| 121 | /* |
| 122 | ** Count the number of lines in the input string. Include the last line |
| 123 | ** in the count even if it lacks the \n terminator. If an empty string |
| 124 | ** is specified, the number of lines is zero. |
| 125 | */ |
| 126 | static int count_lines( |
| 127 | const char *z, |
| 128 | int n |
| 129 | ){ |
| 130 | int nLine; |
| 131 | const char *zNL, *z2; |
| 132 | for(nLine=0, z2=z; (zNL = fossil_strchr(z2,-1,'\n'))!=0; z2=zNL+1, nLine++){} |
| 133 | if( z2[0]!=0 ) nLine++; |
| 134 | return nLine; |
| 135 | } |
| 136 | |
| 137 | /* |
| 138 | ** Return an array of DLine objects containing a pointer to the |
| @@ -159,11 +161,11 @@ | |
| 159 | unsigned int h, h2; |
| 160 | DLine *a; |
| 161 | const char *zNL; |
| 162 | |
| 163 | nLine = count_lines(z, n); |
| 164 | assert( nLine>0 || z[0]==0 ); |
| 165 | a = fossil_malloc( sizeof(a[0])*nLine ); |
| 166 | memset(a, 0, sizeof(a[0])*nLine); |
| 167 | if( nLine==0 ){ |
| 168 | if( fossil_strchr(z,n,'\0')!=0 ){ |
| 169 | fossil_free(a); |
| @@ -193,11 +195,11 @@ | |
| 193 | } |
| 194 | if( (diffFlags & DIFF_IGNORE_ALLWS)==DIFF_IGNORE_ALLWS ){ |
| 195 | int numws = 0; |
| 196 | while( s<k && fossil_isspace(z[s]) ){ s++; } |
| 197 | for(h=0, x=s; x<k; x++){ |
| 198 | if( z[x]==0 ){ |
| 199 | fossil_free(a); |
| 200 | return 0; |
| 201 | } |
| 202 | if( fossil_isspace(z[x]) ){ |
| 203 | ++numws; |
| @@ -207,11 +209,11 @@ | |
| 207 | } |
| 208 | } |
| 209 | k -= numws; |
| 210 | }else{ |
| 211 | for(h=0, x=s; x<k; x++){ |
| 212 | if( z[x]==0 ){ |
| 213 | fossil_free(a); |
| 214 | return 0; |
| 215 | } |
| 216 | h += z[x]; |
| 217 | h *= 0x9e3779b1; |
| @@ -222,11 +224,11 @@ | |
| 222 | h2 = h % nLine; |
| 223 | a[i].iNext = a[h2].iHash; |
| 224 | a[h2].iHash = i+1; |
| 225 | z += nn+1; n -= nn+1; |
| 226 | i++; |
| 227 | }while( zNL[0] && zNL[1] ); |
| 228 | assert( i==nLine ); |
| 229 | |
| 230 | /* Return results */ |
| 231 | *pnLine = nLine; |
| 232 | return a; |
| 233 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -119,20 +119,22 @@ | |
| 119 | }; |
| 120 | |
| 121 | /* |
| 122 | ** Count the number of lines in the input string. Include the last line |
| 123 | ** in the count even if it lacks the \n terminator. If an empty string |
| 124 | ** is specified, the number of lines is zero. For the purposes of this |
| 125 | ** function, a string is considered empty if it contains no characters |
| 126 | ** -OR- it contains only NUL characters. |
| 127 | */ |
| 128 | static int count_lines( |
| 129 | const char *z, |
| 130 | int n |
| 131 | ){ |
| 132 | int nLine; |
| 133 | const char *zNL, *z2; |
| 134 | for(nLine=0, z2=z; (zNL = fossil_strchr(z2,-1,'\n'))!=0; z2=zNL+1, nLine++){} |
| 135 | if( z2[0]!='\0' ) nLine++; |
| 136 | return nLine; |
| 137 | } |
| 138 | |
| 139 | /* |
| 140 | ** Return an array of DLine objects containing a pointer to the |
| @@ -159,11 +161,11 @@ | |
| 161 | unsigned int h, h2; |
| 162 | DLine *a; |
| 163 | const char *zNL; |
| 164 | |
| 165 | nLine = count_lines(z, n); |
| 166 | assert( nLine>0 || z[0]=='\0' ); |
| 167 | a = fossil_malloc( sizeof(a[0])*nLine ); |
| 168 | memset(a, 0, sizeof(a[0])*nLine); |
| 169 | if( nLine==0 ){ |
| 170 | if( fossil_strchr(z,n,'\0')!=0 ){ |
| 171 | fossil_free(a); |
| @@ -193,11 +195,11 @@ | |
| 195 | } |
| 196 | if( (diffFlags & DIFF_IGNORE_ALLWS)==DIFF_IGNORE_ALLWS ){ |
| 197 | int numws = 0; |
| 198 | while( s<k && fossil_isspace(z[s]) ){ s++; } |
| 199 | for(h=0, x=s; x<k; x++){ |
| 200 | if( z[x]=='\0' ){ |
| 201 | fossil_free(a); |
| 202 | return 0; |
| 203 | } |
| 204 | if( fossil_isspace(z[x]) ){ |
| 205 | ++numws; |
| @@ -207,11 +209,11 @@ | |
| 209 | } |
| 210 | } |
| 211 | k -= numws; |
| 212 | }else{ |
| 213 | for(h=0, x=s; x<k; x++){ |
| 214 | if( z[x]=='\0' ){ |
| 215 | fossil_free(a); |
| 216 | return 0; |
| 217 | } |
| 218 | h += z[x]; |
| 219 | h *= 0x9e3779b1; |
| @@ -222,11 +224,11 @@ | |
| 224 | h2 = h % nLine; |
| 225 | a[i].iNext = a[h2].iHash; |
| 226 | a[h2].iHash = i+1; |
| 227 | z += nn+1; n -= nn+1; |
| 228 | i++; |
| 229 | }while( zNL[0]!='\0' && zNL[1]!='\0' ); |
| 230 | assert( i==nLine ); |
| 231 | |
| 232 | /* Return results */ |
| 233 | *pnLine = nLine; |
| 234 | return a; |
| 235 |