Commit 14f6950b by Edward Thomson

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`.
parent d525e063
......@@ -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
......
......@@ -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;
......
......@@ -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
......
......@@ -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 */
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment