Commit ba4faf6e by Patrick Steinhardt

buf_text: remove `offset` parameter of BOM detection function

The function to detect a BOM takes an offset where it shall look for a
BOM. No caller uses that, and searching for the BOM in the middle of a
buffer seems to be very unlikely, as a BOM should only ever exist at
file start.

Remove the parameter, as it has already caused confusion due to its
weirdness.
parent 2eea5f1c
...@@ -188,7 +188,7 @@ bool git_buf_text_is_binary(const git_buf *buf) ...@@ -188,7 +188,7 @@ bool git_buf_text_is_binary(const git_buf *buf)
git_bom_t bom; git_bom_t bom;
int printable = 0, nonprintable = 0; int printable = 0, nonprintable = 0;
scan += git_buf_text_detect_bom(&bom, buf, 0); scan += git_buf_text_detect_bom(&bom, buf);
if (bom > GIT_BOM_UTF8) if (bom > GIT_BOM_UTF8)
return 1; return 1;
...@@ -215,18 +215,18 @@ bool git_buf_text_contains_nul(const git_buf *buf) ...@@ -215,18 +215,18 @@ bool git_buf_text_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_text_detect_bom(git_bom_t *bom, const git_buf *buf, size_t offset) int git_buf_text_detect_bom(git_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_BOM_NONE;
/* need at least 2 bytes after offset to look for any BOM */ /* need at least 2 bytes to look for any BOM */
if (buf->size < offset + 2) if (buf->size < 2)
return 0; return 0;
ptr = buf->ptr + offset; ptr = buf->ptr;
len = buf->size - offset; len = buf->size;
switch (*ptr++) { switch (*ptr++) {
case 0: case 0:
...@@ -274,7 +274,7 @@ bool git_buf_text_gather_stats( ...@@ -274,7 +274,7 @@ bool git_buf_text_gather_stats(
memset(stats, 0, sizeof(*stats)); memset(stats, 0, sizeof(*stats));
/* BOM detection */ /* BOM detection */
skip = git_buf_text_detect_bom(&stats->bom, buf, 0); skip = git_buf_text_detect_bom(&stats->bom, buf);
if (skip_bom) if (skip_bom)
scan += skip; scan += skip;
......
...@@ -99,11 +99,9 @@ extern bool git_buf_text_contains_nul(const git_buf *buf); ...@@ -99,11 +99,9 @@ extern bool git_buf_text_contains_nul(const git_buf *buf);
* *
* @param bom Set to the type of BOM detected or GIT_BOM_NONE * @param bom Set to the type of BOM detected or GIT_BOM_NONE
* @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
* @param offset Offset into buffer to look for 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_text_detect_bom( extern int git_buf_text_detect_bom(git_bom_t *bom, const git_buf *buf);
git_bom_t *bom, const git_buf *buf, size_t offset);
/** /**
* Gather stats for a piece of text * Gather stats for a piece of text
......
...@@ -217,7 +217,7 @@ static int skip_bom(git_parse_ctx *parser) ...@@ -217,7 +217,7 @@ 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_bom_t bom;
int bom_offset = git_buf_text_detect_bom(&bom, &buf, 0); int bom_offset = git_buf_text_detect_bom(&bom, &buf);
if (bom == GIT_BOM_UTF8) if (bom == GIT_BOM_UTF8)
git_parse_advance_chars(parser, bom_offset); git_parse_advance_chars(parser, bom_offset);
......
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