diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2021-09-13 11:40:38 -0400 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2021-09-14 09:18:22 -0400 |
commit | aa993f76ca556b06194e7da0f56afcf30cb5ee5e (patch) | |
tree | beff88cfb70c9a6558d5f4b88b433fcd5a1cb736 | |
parent | 646bae34c9962d308ea82c5d03f5862d20fcca02 (diff) | |
download | libgit2-aa993f76ca556b06194e7da0f56afcf30cb5ee5e.tar.gz |
buf: introduce `git_buf_truncate_at`
-rw-r--r-- | src/buffer.c | 7 | ||||
-rw-r--r-- | src/buffer.h | 1 |
2 files changed, 8 insertions, 0 deletions
diff --git a/src/buffer.c b/src/buffer.c index ab2a6139a..a57df1284 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -600,6 +600,13 @@ void git_buf_shorten(git_buf *buf, size_t amount) 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) { ssize_t idx = git_buf_rfind_next(buf, separator); diff --git a/src/buffer.h b/src/buffer.h index 7faa9fdc8..a356bebea 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -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_truncate(git_buf *buf, size_t len); 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); /** General join with separator */ |