summaryrefslogtreecommitdiff
path: root/src/buffer.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2021-09-13 11:40:38 -0400
committerEdward Thomson <ethomson@edwardthomson.com>2021-09-14 09:18:22 -0400
commitaa993f76ca556b06194e7da0f56afcf30cb5ee5e (patch)
treebeff88cfb70c9a6558d5f4b88b433fcd5a1cb736 /src/buffer.c
parent646bae34c9962d308ea82c5d03f5862d20fcca02 (diff)
downloadlibgit2-aa993f76ca556b06194e7da0f56afcf30cb5ee5e.tar.gz
buf: introduce `git_buf_truncate_at`
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c7
1 files changed, 7 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);