Fossil SCM

Allow the get_utf8_bom function to return the size as well.

mistachkin 2012-11-19 20:39 UTC convert_before_commit_v2
Commit d857d20bef0e5945d3c7f1302cf884e3e27b07f0
3 files changed +6 -4 +7 -5 +3 -2
+6 -4
--- src/checkin.c
+++ src/checkin.c
@@ -570,12 +570,13 @@
570570
int parent_rid,
571571
const char *zUserOvrd
572572
){
573573
Blob prompt;
574574
#ifdef _WIN32
575
- const unsigned char *bom = get_utf8_bom();
576
- blob_init(&prompt, (const char *) bom, 3);
575
+ int bomSize;
576
+ const unsigned char *bom = get_utf8_bom(&bomSize);
577
+ blob_init(&prompt, (const char *) bom, bomSize);
577578
if( zInit && zInit[0]) {
578579
blob_append(&prompt, zInit, -1);
579580
}
580581
#else
581582
blob_init(&prompt, zInit, -1);
@@ -948,12 +949,13 @@
948949
FILE *f;
949950
blob_write_to_file(p, zOrig);
950951
fossil_free(zOrig);
951952
f = fossil_fopen(zFilename, "wb");
952953
if( fUnicode ) {
953
- const unsigned char *bom = get_utf8_bom();
954
- fwrite(bom, 1, 3, f);
954
+ int bomSize;
955
+ const unsigned char *bom = get_utf8_bom(&bomSize);
956
+ fwrite(bom, 1, bomSize, f);
955957
blob_to_utf8_no_bom(p, 0);
956958
}
957959
blob_remove_cr(p);
958960
fwrite(blob_buffer(p), 1, blob_size(p), f);
959961
fclose(f);
960962
--- src/checkin.c
+++ src/checkin.c
@@ -570,12 +570,13 @@
570 int parent_rid,
571 const char *zUserOvrd
572 ){
573 Blob prompt;
574 #ifdef _WIN32
575 const unsigned char *bom = get_utf8_bom();
576 blob_init(&prompt, (const char *) bom, 3);
 
577 if( zInit && zInit[0]) {
578 blob_append(&prompt, zInit, -1);
579 }
580 #else
581 blob_init(&prompt, zInit, -1);
@@ -948,12 +949,13 @@
948 FILE *f;
949 blob_write_to_file(p, zOrig);
950 fossil_free(zOrig);
951 f = fossil_fopen(zFilename, "wb");
952 if( fUnicode ) {
953 const unsigned char *bom = get_utf8_bom();
954 fwrite(bom, 1, 3, f);
 
955 blob_to_utf8_no_bom(p, 0);
956 }
957 blob_remove_cr(p);
958 fwrite(blob_buffer(p), 1, blob_size(p), f);
959 fclose(f);
960
--- src/checkin.c
+++ src/checkin.c
@@ -570,12 +570,13 @@
570 int parent_rid,
571 const char *zUserOvrd
572 ){
573 Blob prompt;
574 #ifdef _WIN32
575 int bomSize;
576 const unsigned char *bom = get_utf8_bom(&bomSize);
577 blob_init(&prompt, (const char *) bom, bomSize);
578 if( zInit && zInit[0]) {
579 blob_append(&prompt, zInit, -1);
580 }
581 #else
582 blob_init(&prompt, zInit, -1);
@@ -948,12 +949,13 @@
949 FILE *f;
950 blob_write_to_file(p, zOrig);
951 fossil_free(zOrig);
952 f = fossil_fopen(zFilename, "wb");
953 if( fUnicode ) {
954 int bomSize;
955 const unsigned char *bom = get_utf8_bom(&bomSize);
956 fwrite(bom, 1, bomSize, f);
957 blob_to_utf8_no_bom(p, 0);
958 }
959 blob_remove_cr(p);
960 fwrite(blob_buffer(p), 1, blob_size(p), f);
961 fclose(f);
962
+7 -5
--- src/diff.c
+++ src/diff.c
@@ -326,25 +326,27 @@
326326
327327
/*
328328
** This function returns an array of bytes representing the byte-order-mark
329329
** for UTF-8.
330330
*/
331
-const unsigned char *get_utf8_bom(){
332
- static const unsigned char bom[] = { 0xEF, 0xBB, 0xBF };
331
+const unsigned char *get_utf8_bom(int *pnByte){
332
+ static const unsigned char bom[] = { 0xEF, 0xBB, 0xBF, 0x00, 0x00, 0x00 };
333
+ if( pnByte ) *pnByte = 3;
333334
return bom;
334335
}
335336
336337
/*
337338
** This function returns non-zero if the blob starts with a UTF-8
338339
** byte-order-mark (BOM).
339340
*/
340341
int starts_with_utf8_bom(const Blob *pContent){
341342
const char *z = blob_buffer(pContent);
342
- const unsigned char *bom = get_utf8_bom();
343
+ int bomSize;
344
+ const unsigned char *bom = get_utf8_bom(&bomSize);
343345
344
- if( blob_size(pContent)<3 ) return 0;
345
- return memcmp(z, bom, 3)==0;
346
+ if( blob_size(pContent)<bomSize ) return 0;
347
+ return memcmp(z, bom, bomSize)==0;
346348
}
347349
348350
/*
349351
** This function returns non-zero if the blob starts with a UTF-16le or
350352
** UTF-16be byte-order-mark (BOM).
351353
--- src/diff.c
+++ src/diff.c
@@ -326,25 +326,27 @@
326
327 /*
328 ** This function returns an array of bytes representing the byte-order-mark
329 ** for UTF-8.
330 */
331 const unsigned char *get_utf8_bom(){
332 static const unsigned char bom[] = { 0xEF, 0xBB, 0xBF };
 
333 return bom;
334 }
335
336 /*
337 ** This function returns non-zero if the blob starts with a UTF-8
338 ** byte-order-mark (BOM).
339 */
340 int starts_with_utf8_bom(const Blob *pContent){
341 const char *z = blob_buffer(pContent);
342 const unsigned char *bom = get_utf8_bom();
 
343
344 if( blob_size(pContent)<3 ) return 0;
345 return memcmp(z, bom, 3)==0;
346 }
347
348 /*
349 ** This function returns non-zero if the blob starts with a UTF-16le or
350 ** UTF-16be byte-order-mark (BOM).
351
--- src/diff.c
+++ src/diff.c
@@ -326,25 +326,27 @@
326
327 /*
328 ** This function returns an array of bytes representing the byte-order-mark
329 ** for UTF-8.
330 */
331 const unsigned char *get_utf8_bom(int *pnByte){
332 static const unsigned char bom[] = { 0xEF, 0xBB, 0xBF, 0x00, 0x00, 0x00 };
333 if( pnByte ) *pnByte = 3;
334 return bom;
335 }
336
337 /*
338 ** This function returns non-zero if the blob starts with a UTF-8
339 ** byte-order-mark (BOM).
340 */
341 int starts_with_utf8_bom(const Blob *pContent){
342 const char *z = blob_buffer(pContent);
343 int bomSize;
344 const unsigned char *bom = get_utf8_bom(&bomSize);
345
346 if( blob_size(pContent)<bomSize ) return 0;
347 return memcmp(z, bom, bomSize)==0;
348 }
349
350 /*
351 ** This function returns non-zero if the blob starts with a UTF-16le or
352 ** UTF-16be byte-order-mark (BOM).
353
+3 -2
--- src/stash.c
+++ src/stash.c
@@ -159,12 +159,13 @@
159159
verify_all_options();
160160
if( zComment==0 ){
161161
Blob prompt; /* Prompt for stash comment */
162162
Blob comment; /* User comment reply */
163163
#ifdef _WIN32
164
- const unsigned char *bom = get_utf8_bom();
165
- blob_init(&prompt, (const char *) bom, 3);
164
+ int bomSize;
165
+ const unsigned char *bom = get_utf8_bom(&bomSize);
166
+ blob_init(&prompt, (const char *) bom, bomSize);
166167
#else
167168
blob_zero(&prompt);
168169
#endif
169170
blob_append(&prompt,
170171
"\n"
171172
--- src/stash.c
+++ src/stash.c
@@ -159,12 +159,13 @@
159 verify_all_options();
160 if( zComment==0 ){
161 Blob prompt; /* Prompt for stash comment */
162 Blob comment; /* User comment reply */
163 #ifdef _WIN32
164 const unsigned char *bom = get_utf8_bom();
165 blob_init(&prompt, (const char *) bom, 3);
 
166 #else
167 blob_zero(&prompt);
168 #endif
169 blob_append(&prompt,
170 "\n"
171
--- src/stash.c
+++ src/stash.c
@@ -159,12 +159,13 @@
159 verify_all_options();
160 if( zComment==0 ){
161 Blob prompt; /* Prompt for stash comment */
162 Blob comment; /* User comment reply */
163 #ifdef _WIN32
164 int bomSize;
165 const unsigned char *bom = get_utf8_bom(&bomSize);
166 blob_init(&prompt, (const char *) bom, bomSize);
167 #else
168 blob_zero(&prompt);
169 #endif
170 blob_append(&prompt,
171 "\n"
172

Keyboard Shortcuts

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