Fossil SCM

Rename blob_remove_cr() to blob_to_lf_only() since that is what it now does. Also, improvements to style and related comments.

mistachkin 2013-03-18 07:10 trunk
Commit 757585fb282536e4cf0deb7d1cd7426f80f82222
2 files changed +6 -8 +2 -2
+6 -8
--- src/blob.c
+++ src/blob.c
@@ -379,11 +379,11 @@
379379
pBlob->aData[newSize] = 0;
380380
}
381381
382382
/*
383383
** Make sure a blob is nul-terminated and is not a pointer to unmanaged
384
-** space. Return a pointer to the
384
+** space. Return a pointer to the data.
385385
*/
386386
char *blob_materialize(Blob *pBlob){
387387
blob_resize(pBlob, pBlob->nUsed);
388388
return pBlob->aData;
389389
}
@@ -1014,21 +1014,19 @@
10141014
}
10151015
}
10161016
#endif
10171017
10181018
/*
1019
-** Remove every \r character from the given blob. If not followed
1020
-** by \n, insert \n.
1019
+** Remove every \r character from the given blob, replacing each one with
1020
+** a \n character if it was not already part of a \r\n pair.
10211021
*/
1022
-void blob_remove_cr(Blob *p){
1022
+void blob_to_lf_only(Blob *p){
10231023
int i, j;
1024
- char *z;
1025
- blob_materialize(p);
1026
- z = p->aData;
1024
+ char *z = blob_materialize(p);
10271025
for(i=j=0; z[i]; i++){
10281026
if( z[i]!='\r' ) z[j++] = z[i];
1029
- else if( z[i+1]!='\n') z[j++] = '\n';
1027
+ else if( z[i+1]!='\n' ) z[j++] = '\n';
10301028
}
10311029
z[j] = 0;
10321030
p->nUsed = j;
10331031
}
10341032
10351033
--- src/blob.c
+++ src/blob.c
@@ -379,11 +379,11 @@
379 pBlob->aData[newSize] = 0;
380 }
381
382 /*
383 ** Make sure a blob is nul-terminated and is not a pointer to unmanaged
384 ** space. Return a pointer to the
385 */
386 char *blob_materialize(Blob *pBlob){
387 blob_resize(pBlob, pBlob->nUsed);
388 return pBlob->aData;
389 }
@@ -1014,21 +1014,19 @@
1014 }
1015 }
1016 #endif
1017
1018 /*
1019 ** Remove every \r character from the given blob. If not followed
1020 ** by \n, insert \n.
1021 */
1022 void blob_remove_cr(Blob *p){
1023 int i, j;
1024 char *z;
1025 blob_materialize(p);
1026 z = p->aData;
1027 for(i=j=0; z[i]; i++){
1028 if( z[i]!='\r' ) z[j++] = z[i];
1029 else if( z[i+1]!='\n') z[j++] = '\n';
1030 }
1031 z[j] = 0;
1032 p->nUsed = j;
1033 }
1034
1035
--- src/blob.c
+++ src/blob.c
@@ -379,11 +379,11 @@
379 pBlob->aData[newSize] = 0;
380 }
381
382 /*
383 ** Make sure a blob is nul-terminated and is not a pointer to unmanaged
384 ** space. Return a pointer to the data.
385 */
386 char *blob_materialize(Blob *pBlob){
387 blob_resize(pBlob, pBlob->nUsed);
388 return pBlob->aData;
389 }
@@ -1014,21 +1014,19 @@
1014 }
1015 }
1016 #endif
1017
1018 /*
1019 ** Remove every \r character from the given blob, replacing each one with
1020 ** a \n character if it was not already part of a \r\n pair.
1021 */
1022 void blob_to_lf_only(Blob *p){
1023 int i, j;
1024 char *z = blob_materialize(p);
 
 
1025 for(i=j=0; z[i]; i++){
1026 if( z[i]!='\r' ) z[j++] = z[i];
1027 else if( z[i+1]!='\n' ) z[j++] = '\n';
1028 }
1029 z[j] = 0;
1030 p->nUsed = j;
1031 }
1032
1033
+2 -2
--- src/checkin.c
+++ src/checkin.c
@@ -523,11 +523,11 @@
523523
}
524524
blob_append(&reply, zIn, -1);
525525
}
526526
}
527527
blob_to_utf8_no_bom(&reply, 1);
528
- blob_remove_cr(&reply);
528
+ blob_to_lf_only(&reply);
529529
file_delete(zFile);
530530
free(zFile);
531531
blob_zero(pComment);
532532
while( blob_line(&reply, &line) ){
533533
int i, n;
@@ -994,11 +994,11 @@
994994
int bomSize;
995995
const unsigned char *bom = get_utf8_bom(&bomSize);
996996
fwrite(bom, 1, bomSize, f);
997997
blob_to_utf8_no_bom(p, 0);
998998
}
999
- blob_remove_cr(p);
999
+ blob_to_lf_only(p);
10001000
fwrite(blob_buffer(p), 1, blob_size(p), f);
10011001
fclose(f);
10021002
return 1;
10031003
}else if( cReply!='y' && cReply!='Y' ){
10041004
fossil_fatal("Abandoning commit due to %s in %s",
10051005
--- src/checkin.c
+++ src/checkin.c
@@ -523,11 +523,11 @@
523 }
524 blob_append(&reply, zIn, -1);
525 }
526 }
527 blob_to_utf8_no_bom(&reply, 1);
528 blob_remove_cr(&reply);
529 file_delete(zFile);
530 free(zFile);
531 blob_zero(pComment);
532 while( blob_line(&reply, &line) ){
533 int i, n;
@@ -994,11 +994,11 @@
994 int bomSize;
995 const unsigned char *bom = get_utf8_bom(&bomSize);
996 fwrite(bom, 1, bomSize, f);
997 blob_to_utf8_no_bom(p, 0);
998 }
999 blob_remove_cr(p);
1000 fwrite(blob_buffer(p), 1, blob_size(p), f);
1001 fclose(f);
1002 return 1;
1003 }else if( cReply!='y' && cReply!='Y' ){
1004 fossil_fatal("Abandoning commit due to %s in %s",
1005
--- src/checkin.c
+++ src/checkin.c
@@ -523,11 +523,11 @@
523 }
524 blob_append(&reply, zIn, -1);
525 }
526 }
527 blob_to_utf8_no_bom(&reply, 1);
528 blob_to_lf_only(&reply);
529 file_delete(zFile);
530 free(zFile);
531 blob_zero(pComment);
532 while( blob_line(&reply, &line) ){
533 int i, n;
@@ -994,11 +994,11 @@
994 int bomSize;
995 const unsigned char *bom = get_utf8_bom(&bomSize);
996 fwrite(bom, 1, bomSize, f);
997 blob_to_utf8_no_bom(p, 0);
998 }
999 blob_to_lf_only(p);
1000 fwrite(blob_buffer(p), 1, blob_size(p), f);
1001 fclose(f);
1002 return 1;
1003 }else if( cReply!='y' && cReply!='Y' ){
1004 fossil_fatal("Abandoning commit due to %s in %s",
1005

Keyboard Shortcuts

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