Archived
1
0
Fork 0

strbuf.c: let strbuf_rchop return a value

This commit is contained in:
Henrik Hautakoski 2011-02-11 17:47:57 +01:00
parent a1766126a2
commit 79f18e6671
3 changed files with 5 additions and 3 deletions

View file

@ -90,7 +90,8 @@ NOTE: This doesn't shrink the memory block
`strbuf_rchop()`:: `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()`:: `strbuf_rev()`::

View file

@ -169,12 +169,13 @@ void strbuf_append_repeat(strbuf_t *s, char ch, size_t len) {
strbuf_setlen(s, s->len + 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); char *n = memrchr(s->buf, ch, s->len);
if (n) if (n)
strbuf_setlen(s, n - s->buf); strbuf_setlen(s, n - s->buf);
return n;
} }
void strbuf_term(strbuf_t *s, char ch) { void strbuf_term(strbuf_t *s, char ch) {

View file

@ -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_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); void strbuf_term(strbuf_t *s, char ch);