Commit aa993f76 by Edward Thomson

buf: introduce `git_buf_truncate_at`

parent 646bae34
...@@ -600,6 +600,13 @@ void git_buf_shorten(git_buf *buf, size_t amount) ...@@ -600,6 +600,13 @@ void git_buf_shorten(git_buf *buf, size_t amount)
git_buf_clear(buf); git_buf_clear(buf);
} }
void git_buf_truncate_at_char(git_buf *buf, char separator)
{
ssize_t idx = git_buf_find(buf, separator);
if (idx >= 0)
git_buf_truncate(buf, (size_t)idx);
}
void git_buf_rtruncate_at_char(git_buf *buf, char separator) void git_buf_rtruncate_at_char(git_buf *buf, char separator)
{ {
ssize_t idx = git_buf_rfind_next(buf, separator); ssize_t idx = git_buf_rfind_next(buf, separator);
......
...@@ -171,6 +171,7 @@ void git_buf_consume_bytes(git_buf *buf, size_t len); ...@@ -171,6 +171,7 @@ void git_buf_consume_bytes(git_buf *buf, size_t len);
void git_buf_consume(git_buf *buf, const char *end); void git_buf_consume(git_buf *buf, const char *end);
void git_buf_truncate(git_buf *buf, size_t len); void git_buf_truncate(git_buf *buf, size_t len);
void git_buf_shorten(git_buf *buf, size_t amount); void git_buf_shorten(git_buf *buf, size_t amount);
void git_buf_truncate_at_char(git_buf *buf, char separator);
void git_buf_rtruncate_at_char(git_buf *path, char separator); void git_buf_rtruncate_at_char(git_buf *path, char separator);
/** General join with separator */ /** General join with separator */
......
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