Fossil SCM
Further refinements and more tests.
Commit
70ba07c368a139b13a2b3b4e2c2cac8e9cd370cb
Parent
10b47cc35082b1a…
2 files changed
+8
-6
+30
+8
-6
| --- src/comformat.c | ||
| +++ src/comformat.c | ||
| @@ -139,10 +139,14 @@ | ||
| 139 | 139 | } |
| 140 | 140 | if( c=='\n' ){ |
| 141 | 141 | charCnt = 0; |
| 142 | 142 | lineCnt++; |
| 143 | 143 | }else if( c=='\t' ){ |
| 144 | + int nextIndex = comment_next_space(zLine, index); | |
| 145 | + if( nextIndex<=0 || (nextIndex-index)>maxChars ){ | |
| 146 | + break; | |
| 147 | + } | |
| 144 | 148 | charCnt++; |
| 145 | 149 | if( maxChars<COMMENT_TAB_WIDTH ){ |
| 146 | 150 | fossil_print(" "); |
| 147 | 151 | break; |
| 148 | 152 | } |
| @@ -160,11 +164,11 @@ | ||
| 160 | 164 | } |
| 161 | 165 | fossil_print("%c", c); |
| 162 | 166 | if( maxChars==0 ) break; |
| 163 | 167 | if( c=='\n' ) break; |
| 164 | 168 | } |
| 165 | - if( charCnt>0 || lineCnt==0 ){ | |
| 169 | + if( charCnt>0 ){ | |
| 166 | 170 | fossil_print("\n"); |
| 167 | 171 | lineCnt++; |
| 168 | 172 | } |
| 169 | 173 | if( pLineCnt ){ |
| 170 | 174 | *pLineCnt += lineCnt; |
| @@ -194,23 +198,21 @@ | ||
| 194 | 198 | } |
| 195 | 199 | |
| 196 | 200 | /* |
| 197 | 201 | ** This function scans the specified comment line starting just after the |
| 198 | 202 | ** initial index and returns the index of the next spacing character -OR- |
| 199 | -** zero if such a character cannot be found. | |
| 203 | +** zero if such a character cannot be found. For the purposes of this | |
| 204 | +** algorithm, the NUL character is treated the same as a spacing character. | |
| 200 | 205 | */ |
| 201 | 206 | int comment_next_space( |
| 202 | 207 | const char *zLine, /* [in] The comment line being printed. */ |
| 203 | 208 | int index /* [in] The current character index being handled. */ |
| 204 | 209 | ){ |
| 205 | 210 | int nextIndex = index + 1; |
| 206 | 211 | for(;;){ |
| 207 | 212 | char c = zLine[nextIndex]; |
| 208 | - if( c==0 ){ | |
| 209 | - return 0; | |
| 210 | - } | |
| 211 | - if( fossil_isspace(c) ){ | |
| 213 | + if( c==0 || fossil_isspace(c) ){ | |
| 212 | 214 | return nextIndex; |
| 213 | 215 | } |
| 214 | 216 | nextIndex++; |
| 215 | 217 | } |
| 216 | 218 | return 0; /* NOT REACHED */ |
| 217 | 219 |
| --- src/comformat.c | |
| +++ src/comformat.c | |
| @@ -139,10 +139,14 @@ | |
| 139 | } |
| 140 | if( c=='\n' ){ |
| 141 | charCnt = 0; |
| 142 | lineCnt++; |
| 143 | }else if( c=='\t' ){ |
| 144 | charCnt++; |
| 145 | if( maxChars<COMMENT_TAB_WIDTH ){ |
| 146 | fossil_print(" "); |
| 147 | break; |
| 148 | } |
| @@ -160,11 +164,11 @@ | |
| 160 | } |
| 161 | fossil_print("%c", c); |
| 162 | if( maxChars==0 ) break; |
| 163 | if( c=='\n' ) break; |
| 164 | } |
| 165 | if( charCnt>0 || lineCnt==0 ){ |
| 166 | fossil_print("\n"); |
| 167 | lineCnt++; |
| 168 | } |
| 169 | if( pLineCnt ){ |
| 170 | *pLineCnt += lineCnt; |
| @@ -194,23 +198,21 @@ | |
| 194 | } |
| 195 | |
| 196 | /* |
| 197 | ** This function scans the specified comment line starting just after the |
| 198 | ** initial index and returns the index of the next spacing character -OR- |
| 199 | ** zero if such a character cannot be found. |
| 200 | */ |
| 201 | int comment_next_space( |
| 202 | const char *zLine, /* [in] The comment line being printed. */ |
| 203 | int index /* [in] The current character index being handled. */ |
| 204 | ){ |
| 205 | int nextIndex = index + 1; |
| 206 | for(;;){ |
| 207 | char c = zLine[nextIndex]; |
| 208 | if( c==0 ){ |
| 209 | return 0; |
| 210 | } |
| 211 | if( fossil_isspace(c) ){ |
| 212 | return nextIndex; |
| 213 | } |
| 214 | nextIndex++; |
| 215 | } |
| 216 | return 0; /* NOT REACHED */ |
| 217 |
| --- src/comformat.c | |
| +++ src/comformat.c | |
| @@ -139,10 +139,14 @@ | |
| 139 | } |
| 140 | if( c=='\n' ){ |
| 141 | charCnt = 0; |
| 142 | lineCnt++; |
| 143 | }else if( c=='\t' ){ |
| 144 | int nextIndex = comment_next_space(zLine, index); |
| 145 | if( nextIndex<=0 || (nextIndex-index)>maxChars ){ |
| 146 | break; |
| 147 | } |
| 148 | charCnt++; |
| 149 | if( maxChars<COMMENT_TAB_WIDTH ){ |
| 150 | fossil_print(" "); |
| 151 | break; |
| 152 | } |
| @@ -160,11 +164,11 @@ | |
| 164 | } |
| 165 | fossil_print("%c", c); |
| 166 | if( maxChars==0 ) break; |
| 167 | if( c=='\n' ) break; |
| 168 | } |
| 169 | if( charCnt>0 ){ |
| 170 | fossil_print("\n"); |
| 171 | lineCnt++; |
| 172 | } |
| 173 | if( pLineCnt ){ |
| 174 | *pLineCnt += lineCnt; |
| @@ -194,23 +198,21 @@ | |
| 198 | } |
| 199 | |
| 200 | /* |
| 201 | ** This function scans the specified comment line starting just after the |
| 202 | ** initial index and returns the index of the next spacing character -OR- |
| 203 | ** zero if such a character cannot be found. For the purposes of this |
| 204 | ** algorithm, the NUL character is treated the same as a spacing character. |
| 205 | */ |
| 206 | int comment_next_space( |
| 207 | const char *zLine, /* [in] The comment line being printed. */ |
| 208 | int index /* [in] The current character index being handled. */ |
| 209 | ){ |
| 210 | int nextIndex = index + 1; |
| 211 | for(;;){ |
| 212 | char c = zLine[nextIndex]; |
| 213 | if( c==0 || fossil_isspace(c) ){ |
| 214 | return nextIndex; |
| 215 | } |
| 216 | nextIndex++; |
| 217 | } |
| 218 | return 0; /* NOT REACHED */ |
| 219 |
+30
| --- test/comment.test | ||
| +++ test/comment.test | ||
| @@ -88,5 +88,35 @@ | ||
| 88 | 88 | |
| 89 | 89 | ############################################################################### |
| 90 | 90 | |
| 91 | 91 | fossil test-comment-format --wordbreak "*TEST* " "this is a test......................................................................................................................." 60 |
| 92 | 92 | test comment-15 {$RESULT eq "*TEST* this is a\n test.................................................\n .....................................................\n .................\n(4 lines output)"} |
| 93 | + | |
| 94 | +############################################################################### | |
| 95 | + | |
| 96 | +fossil test-comment-format "*TEST* " "this is a test......................................................................................................................." 60 | |
| 97 | +test comment-16 {$RESULT eq "*TEST* this is a\n test.................................................\n .....................................................\n .................\n(4 lines output)"} | |
| 98 | + | |
| 99 | +############################################################################### | |
| 100 | + | |
| 101 | +fossil test-comment-format --wordbreak "*TEST* " "this is a test......................................................................................................................." 60 | |
| 102 | +test comment-17 {$RESULT eq "*TEST* this is a\n test.................................................\n .....................................................\n .................\n(4 lines output)"} | |
| 103 | + | |
| 104 | +############################################################################### | |
| 105 | + | |
| 106 | +fossil test-comment-format "*TEST* " "one two three four five six seven eight nine ten eleven twelve" 60 | |
| 107 | +test comment-18 {$RESULT eq "*TEST* one two three four five six seven eight nine ten elev\n en twelve\n(2 lines output)"} | |
| 108 | + | |
| 109 | +############################################################################### | |
| 110 | + | |
| 111 | +fossil test-comment-format --wordbreak "*TEST* " "one two three four five six seven eight nine ten eleven twelve" 60 | |
| 112 | +test comment-19 {$RESULT eq "*TEST* one two three four five six seven eight nine ten\n eleven twelve\n(2 lines output)"} | |
| 113 | + | |
| 114 | +############################################################################### | |
| 115 | + | |
| 116 | +fossil test-comment-format "*TEST* " "one two three four five six seven eight nine ten eleven twelve" 60 | |
| 117 | +test comment-20 {$RESULT eq "*TEST* one two three four five\n six seven eight nine ten\n eleven twelve\n(3 lines output)"} | |
| 118 | + | |
| 119 | +############################################################################### | |
| 120 | + | |
| 121 | +fossil test-comment-format --wordbreak "*TEST* " "one two three four five six seven eight nine ten eleven twelve" 60 | |
| 122 | +test comment-21 {$RESULT eq "*TEST* one two three four five\n six seven eight nine ten\n eleven twelve\n(3 lines output)"} | |
| 93 | 123 |
| --- test/comment.test | |
| +++ test/comment.test | |
| @@ -88,5 +88,35 @@ | |
| 88 | |
| 89 | ############################################################################### |
| 90 | |
| 91 | fossil test-comment-format --wordbreak "*TEST* " "this is a test......................................................................................................................." 60 |
| 92 | test comment-15 {$RESULT eq "*TEST* this is a\n test.................................................\n .....................................................\n .................\n(4 lines output)"} |
| 93 |
| --- test/comment.test | |
| +++ test/comment.test | |
| @@ -88,5 +88,35 @@ | |
| 88 | |
| 89 | ############################################################################### |
| 90 | |
| 91 | fossil test-comment-format --wordbreak "*TEST* " "this is a test......................................................................................................................." 60 |
| 92 | test comment-15 {$RESULT eq "*TEST* this is a\n test.................................................\n .....................................................\n .................\n(4 lines output)"} |
| 93 | |
| 94 | ############################################################################### |
| 95 | |
| 96 | fossil test-comment-format "*TEST* " "this is a test......................................................................................................................." 60 |
| 97 | test comment-16 {$RESULT eq "*TEST* this is a\n test.................................................\n .....................................................\n .................\n(4 lines output)"} |
| 98 | |
| 99 | ############################################################################### |
| 100 | |
| 101 | fossil test-comment-format --wordbreak "*TEST* " "this is a test......................................................................................................................." 60 |
| 102 | test comment-17 {$RESULT eq "*TEST* this is a\n test.................................................\n .....................................................\n .................\n(4 lines output)"} |
| 103 | |
| 104 | ############################################################################### |
| 105 | |
| 106 | fossil test-comment-format "*TEST* " "one two three four five six seven eight nine ten eleven twelve" 60 |
| 107 | test comment-18 {$RESULT eq "*TEST* one two three four five six seven eight nine ten elev\n en twelve\n(2 lines output)"} |
| 108 | |
| 109 | ############################################################################### |
| 110 | |
| 111 | fossil test-comment-format --wordbreak "*TEST* " "one two three four five six seven eight nine ten eleven twelve" 60 |
| 112 | test comment-19 {$RESULT eq "*TEST* one two three four five six seven eight nine ten\n eleven twelve\n(2 lines output)"} |
| 113 | |
| 114 | ############################################################################### |
| 115 | |
| 116 | fossil test-comment-format "*TEST* " "one two three four five six seven eight nine ten eleven twelve" 60 |
| 117 | test comment-20 {$RESULT eq "*TEST* one two three four five\n six seven eight nine ten\n eleven twelve\n(3 lines output)"} |
| 118 | |
| 119 | ############################################################################### |
| 120 | |
| 121 | fossil test-comment-format --wordbreak "*TEST* " "one two three four five six seven eight nine ten eleven twelve" 60 |
| 122 | test comment-21 {$RESULT eq "*TEST* one two three four five\n six seven eight nine ten\n eleven twelve\n(3 lines output)"} |
| 123 |