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( ...@@ -122,7 +122,7 @@ int git_attr_file__load(
struct stat st; struct stat st;
bool nonexistent = false; bool nonexistent = false;
int bom_offset; int bom_offset;
git_bom_t bom; git_buf_bom_t bom;
git_oid id; git_oid id;
git_object_size_t blobsize; git_object_size_t blobsize;
...@@ -193,7 +193,7 @@ int git_attr_file__load( ...@@ -193,7 +193,7 @@ int git_attr_file__load(
content_str = git_buf_cstr(&content); content_str = git_buf_cstr(&content);
bom_offset = git_buf_detect_bom(&bom, &content); bom_offset = git_buf_detect_bom(&bom, &content);
if (bom == GIT_BOM_UTF8) if (bom == GIT_BUF_BOM_UTF8)
content_str += bom_offset; content_str += bom_offset;
/* store the key of the attr_reader; don't bother with cache /* 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) ...@@ -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) int git_buf_is_binary(const git_buf *buf)
{ {
const char *scan = buf->ptr, *end = buf->ptr + buf->size; const char *scan = buf->ptr, *end = buf->ptr + buf->size;
git_bom_t bom; git_buf_bom_t bom;
int printable = 0, nonprintable = 0; int printable = 0, nonprintable = 0;
scan += git_buf_detect_bom(&bom, buf); scan += git_buf_detect_bom(&bom, buf);
if (bom > GIT_BOM_UTF8) if (bom > GIT_BUF_BOM_UTF8)
return 1; return 1;
while (scan < end) { while (scan < end) {
...@@ -1257,12 +1257,12 @@ int git_buf_contains_nul(const git_buf *buf) ...@@ -1257,12 +1257,12 @@ int git_buf_contains_nul(const git_buf *buf)
return (memchr(buf->ptr, '\0', buf->size) != NULL); 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; const char *ptr;
size_t len; size_t len;
*bom = GIT_BOM_NONE; *bom = GIT_BUF_BOM_NONE;
/* need at least 2 bytes to look for any BOM */ /* need at least 2 bytes to look for any BOM */
if (buf->size < 2) if (buf->size < 2)
return 0; return 0;
...@@ -1273,19 +1273,19 @@ int git_buf_detect_bom(git_bom_t *bom, const git_buf *buf) ...@@ -1273,19 +1273,19 @@ int git_buf_detect_bom(git_bom_t *bom, const git_buf *buf)
switch (*ptr++) { switch (*ptr++) {
case 0: case 0:
if (len >= 4 && ptr[0] == 0 && ptr[1] == '\xFE' && ptr[2] == '\xFF') { 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; return 4;
} }
break; break;
case '\xEF': case '\xEF':
if (len >= 3 && ptr[0] == '\xBB' && ptr[1] == '\xBF') { if (len >= 3 && ptr[0] == '\xBB' && ptr[1] == '\xBF') {
*bom = GIT_BOM_UTF8; *bom = GIT_BUF_BOM_UTF8;
return 3; return 3;
} }
break; break;
case '\xFE': case '\xFE':
if (*ptr == '\xFF') { if (*ptr == '\xFF') {
*bom = GIT_BOM_UTF16_BE; *bom = GIT_BUF_BOM_UTF16_BE;
return 2; return 2;
} }
break; break;
...@@ -1293,10 +1293,10 @@ int git_buf_detect_bom(git_bom_t *bom, const git_buf *buf) ...@@ -1293,10 +1293,10 @@ int git_buf_detect_bom(git_bom_t *bom, const git_buf *buf)
if (*ptr != '\xFE') if (*ptr != '\xFE')
break; break;
if (len >= 4 && ptr[1] == 0 && ptr[2] == 0) { if (len >= 4 && ptr[1] == 0 && ptr[2] == 0) {
*bom = GIT_BOM_UTF32_LE; *bom = GIT_BUF_BOM_UTF32_LE;
return 4; return 4;
} else { } else {
*bom = GIT_BOM_UTF16_LE; *bom = GIT_BUF_BOM_UTF16_LE;
return 2; return 2;
} }
break; break;
......
...@@ -18,16 +18,16 @@ ...@@ -18,16 +18,16 @@
*/ */
typedef enum { typedef enum {
GIT_BOM_NONE = 0, GIT_BUF_BOM_NONE = 0,
GIT_BOM_UTF8 = 1, GIT_BUF_BOM_UTF8 = 1,
GIT_BOM_UTF16_LE = 2, GIT_BUF_BOM_UTF16_LE = 2,
GIT_BOM_UTF16_BE = 3, GIT_BUF_BOM_UTF16_BE = 3,
GIT_BOM_UTF32_LE = 4, GIT_BUF_BOM_UTF32_LE = 4,
GIT_BOM_UTF32_BE = 5 GIT_BUF_BOM_UTF32_BE = 5
} git_bom_t; } git_buf_bom_t;
typedef struct { 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 nul, cr, lf, crlf; /* NUL, CR, LF and CRLF counts */
unsigned int printable, nonprintable; /* These are just approximations! */ unsigned int printable, nonprintable; /* These are just approximations! */
} git_buf_text_stats; } git_buf_text_stats;
...@@ -293,7 +293,7 @@ extern int git_buf_common_prefix(git_buf *buf, const git_strarray *strs); ...@@ -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 * @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) * @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 * Gather stats for a piece of text
......
...@@ -228,10 +228,10 @@ fail_parse: ...@@ -228,10 +228,10 @@ fail_parse:
static int skip_bom(git_parse_ctx *parser) static int skip_bom(git_parse_ctx *parser)
{ {
git_buf buf = GIT_BUF_INIT_CONST(parser->content, parser->content_len); 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); 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); git_parse_advance_chars(parser, bom_offset);
/* TODO: reference implementation is pretty stupid with BoM */ /* 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] = { ...@@ -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, 2, 2, 2, 6, 0 },
{ 0, 0, 4, 4, 1, 31, 0 }, { 0, 0, 4, 4, 1, 31, 0 },
{ 0, 1, 1, 2, 1, 9, 5 }, { 0, 1, 1, 2, 1, 9, 5 },
{ GIT_BOM_UTF8, 0, 0, 1, 0, 16, 0 }, { GIT_BUF_BOM_UTF8, 0, 0, 1, 0, 16, 0 },
{ GIT_BOM_UTF8, 0, 2, 2, 2, 27, 0 }, { GIT_BUF_BOM_UTF8, 0, 2, 2, 2, 27, 0 },
{ GIT_BOM_UTF16_BE, 5, 0, 0, 0, 7, 5 }, { GIT_BUF_BOM_UTF16_BE, 5, 0, 0, 0, 7, 5 },
}; };
void test_object_blob_filter__initialize(void) 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