diff --git a/docs/technical/strbuf.txt b/docs/technical/strbuf.txt index b481e7e..d8a1fe4 100644 --- a/docs/technical/strbuf.txt +++ b/docs/technical/strbuf.txt @@ -90,7 +90,8 @@ NOTE: This doesn't shrink the memory block `strbuf_rchop()`:: - Chops off everything to the right of the rightmost 'ch' encountered in the string. + Chops off everything to the right of the rightmost 'ch' encountered in the string. + + Returns a pointer to the where the rightmost 'ch' was located (that now is \'\0') or `NULL` if 'ch' does not exists in ->buf. `strbuf_rev()`:: diff --git a/src/strbuf.c b/src/strbuf.c index 00ded75..f57b575 100644 --- a/src/strbuf.c +++ b/src/strbuf.c @@ -169,12 +169,13 @@ void strbuf_append_repeat(strbuf_t *s, char ch, size_t len) { strbuf_setlen(s, s->len + len); } -void strbuf_rchop(strbuf_t *s, char ch) { +char* strbuf_rchop(strbuf_t *s, char ch) { char *n = memrchr(s->buf, ch, s->len); if (n) strbuf_setlen(s, n - s->buf); + return n; } void strbuf_term(strbuf_t *s, char ch) { diff --git a/src/strbuf.h b/src/strbuf.h index 25fdb14..ca4a393 100644 --- a/src/strbuf.h +++ b/src/strbuf.h @@ -54,7 +54,7 @@ void strbuf_append_ch(strbuf_t *s, char ch); void strbuf_append_repeat(strbuf_t *s, char ch, size_t len); -void strbuf_rchop(strbuf_t *s, char ch); +char* strbuf_rchop(strbuf_t *s, char ch); void strbuf_term(strbuf_t *s, char ch);