buf: bom enum is in the buf namespace Instead of a `git_bom_t` that a `git_buf` function returns, let's keep it `git_buf_bom_t`.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
diff --git a/src/attr_file.c b/src/attr_file.c
index 6575e5a..8269272 100644
--- a/src/attr_file.c
+++ b/src/attr_file.c
@@ -122,7 +122,7 @@ int git_attr_file__load(
struct stat st;
bool nonexistent = false;
int bom_offset;
- git_bom_t bom;
+ git_buf_bom_t bom;
git_oid id;
git_object_size_t blobsize;
@@ -193,7 +193,7 @@ int git_attr_file__load(
content_str = git_buf_cstr(&content);
bom_offset = git_buf_detect_bom(&bom, &content);
- if (bom == GIT_BOM_UTF8)
+ if (bom == GIT_BUF_BOM_UTF8)
content_str += bom_offset;
/* store the key of the attr_reader; don't bother with cache
diff --git a/src/buffer.c b/src/buffer.c
index ffce73c..794e1f1 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1227,12 +1227,12 @@ int git_buf_common_prefix(git_buf *buf, const git_strarray *strings)
int git_buf_is_binary(const git_buf *buf)
{
const char *scan = buf->ptr, *end = buf->ptr + buf->size;
- git_bom_t bom;
+ git_buf_bom_t bom;
int printable = 0, nonprintable = 0;
scan += git_buf_detect_bom(&bom, buf);
- if (bom > GIT_BOM_UTF8)
+ if (bom > GIT_BUF_BOM_UTF8)
return 1;
while (scan < end) {
@@ -1257,12 +1257,12 @@ int git_buf_contains_nul(const git_buf *buf)
return (memchr(buf->ptr, '\0', buf->size) != NULL);
}
-int git_buf_detect_bom(git_bom_t *bom, const git_buf *buf)
+int git_buf_detect_bom(git_buf_bom_t *bom, const git_buf *buf)
{
const char *ptr;
size_t len;
- *bom = GIT_BOM_NONE;
+ *bom = GIT_BUF_BOM_NONE;
/* need at least 2 bytes to look for any BOM */
if (buf->size < 2)
return 0;
@@ -1273,19 +1273,19 @@ int git_buf_detect_bom(git_bom_t *bom, const git_buf *buf)
switch (*ptr++) {
case 0:
if (len >= 4 && ptr[0] == 0 && ptr[1] == '\xFE' && ptr[2] == '\xFF') {
- *bom = GIT_BOM_UTF32_BE;
+ *bom = GIT_BUF_BOM_UTF32_BE;
return 4;
}
break;
case '\xEF':
if (len >= 3 && ptr[0] == '\xBB' && ptr[1] == '\xBF') {
- *bom = GIT_BOM_UTF8;
+ *bom = GIT_BUF_BOM_UTF8;
return 3;
}
break;
case '\xFE':
if (*ptr == '\xFF') {
- *bom = GIT_BOM_UTF16_BE;
+ *bom = GIT_BUF_BOM_UTF16_BE;
return 2;
}
break;
@@ -1293,10 +1293,10 @@ int git_buf_detect_bom(git_bom_t *bom, const git_buf *buf)
if (*ptr != '\xFE')
break;
if (len >= 4 && ptr[1] == 0 && ptr[2] == 0) {
- *bom = GIT_BOM_UTF32_LE;
+ *bom = GIT_BUF_BOM_UTF32_LE;
return 4;
} else {
- *bom = GIT_BOM_UTF16_LE;
+ *bom = GIT_BUF_BOM_UTF16_LE;
return 2;
}
break;
diff --git a/src/buffer.h b/src/buffer.h
index e75ecc1..d043ed6 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -18,16 +18,16 @@
*/
typedef enum {
- GIT_BOM_NONE = 0,
- GIT_BOM_UTF8 = 1,
- GIT_BOM_UTF16_LE = 2,
- GIT_BOM_UTF16_BE = 3,
- GIT_BOM_UTF32_LE = 4,
- GIT_BOM_UTF32_BE = 5
-} git_bom_t;
+ GIT_BUF_BOM_NONE = 0,
+ GIT_BUF_BOM_UTF8 = 1,
+ GIT_BUF_BOM_UTF16_LE = 2,
+ GIT_BUF_BOM_UTF16_BE = 3,
+ GIT_BUF_BOM_UTF32_LE = 4,
+ GIT_BUF_BOM_UTF32_BE = 5
+} git_buf_bom_t;
typedef struct {
- git_bom_t bom; /* BOM found at head of text */
+ git_buf_bom_t bom; /* BOM found at head of text */
unsigned int nul, cr, lf, crlf; /* NUL, CR, LF and CRLF counts */
unsigned int printable, nonprintable; /* These are just approximations! */
} git_buf_text_stats;
@@ -293,7 +293,7 @@ extern int git_buf_common_prefix(git_buf *buf, const git_strarray *strs);
* @param buf Buffer in which to check the first bytes for a BOM
* @return Number of bytes of BOM data (or 0 if no BOM found)
*/
-extern int git_buf_detect_bom(git_bom_t *bom, const git_buf *buf);
+extern int git_buf_detect_bom(git_buf_bom_t *bom, const git_buf *buf);
/**
* Gather stats for a piece of text
diff --git a/src/config_parse.c b/src/config_parse.c
index ea32c36..a2d779b 100644
--- a/src/config_parse.c
+++ b/src/config_parse.c
@@ -228,10 +228,10 @@ fail_parse:
static int skip_bom(git_parse_ctx *parser)
{
git_buf buf = GIT_BUF_INIT_CONST(parser->content, parser->content_len);
- git_bom_t bom;
+ git_buf_bom_t bom;
int bom_offset = git_buf_detect_bom(&bom, &buf);
- if (bom == GIT_BOM_UTF8)
+ if (bom == GIT_BUF_BOM_UTF8)
git_parse_advance_chars(parser, bom_offset);
/* TODO: reference implementation is pretty stupid with BoM */
diff --git a/tests/object/blob/filter.c b/tests/object/blob/filter.c
index a3921f4..a8e3d30 100644
--- a/tests/object/blob/filter.c
+++ b/tests/object/blob/filter.c
@@ -43,9 +43,9 @@ static git_buf_text_stats g_crlf_filtered_stats[CRLF_NUM_TEST_OBJECTS] = {
{ 0, 0, 2, 2, 2, 6, 0 },
{ 0, 0, 4, 4, 1, 31, 0 },
{ 0, 1, 1, 2, 1, 9, 5 },
- { GIT_BOM_UTF8, 0, 0, 1, 0, 16, 0 },
- { GIT_BOM_UTF8, 0, 2, 2, 2, 27, 0 },
- { GIT_BOM_UTF16_BE, 5, 0, 0, 0, 7, 5 },
+ { GIT_BUF_BOM_UTF8, 0, 0, 1, 0, 16, 0 },
+ { GIT_BUF_BOM_UTF8, 0, 2, 2, 2, 27, 0 },
+ { GIT_BUF_BOM_UTF16_BE, 5, 0, 0, 0, 7, 5 },
};
void test_object_blob_filter__initialize(void)