MCPcopy Index your code
hub / github.com/git/git / ensure_utf8

Function ensure_utf8

commit.c:1663–1686  ·  view source on GitHub ↗

* This ensures that the buffer is in proper utf8 format. * * If it isn't, it assumes any non-utf8 characters are Latin1, * and does the conversion. */

Source from the content-addressed store, hash-verified

1661 * and does the conversion.
1662 */
1663static int ensure_utf8(struct strbuf *buf)
1664{
1665 int ok = 1;
1666 size_t pos = 0;
1667
1668 for (;;) {
1669 size_t bad;
1670 unsigned char c;
1671 unsigned char replace[2];
1672
1673 if (!has_invalid_utf8(buf->buf + pos, buf->len - pos, &bad))
1674 return ok;
1675 pos += bad;
1676 ok = 0;
1677 c = buf->buf[pos];
1678 strbuf_remove(buf, pos, 1);
1679
1680 /* We know 'c' must be in the range 128-255 */
1681 replace[0] = 0xc0 + (c >> 6);
1682 replace[1] = 0x80 + (c & 0x3f);
1683 strbuf_insert(buf, pos, replace, 2);
1684 pos += 2;
1685 }
1686}
1687
1688static const char commit_utf8_warn[] =
1689N_("Warning: commit message did not conform to UTF-8.\n"

Callers 1

commit_tree_extendedFunction · 0.85

Calls 3

has_invalid_utf8Function · 0.85
strbuf_removeFunction · 0.85
strbuf_insertFunction · 0.85

Tested by

no test coverage detected