diff --git a/docs/strbuf.txt b/docs/strbuf.txt index a62f756..474ff26 100644 --- a/docs/strbuf.txt +++ b/docs/strbuf.txt @@ -28,6 +28,14 @@ strbuf_append(): Like strncat() this function will append the buffer with the contents of 'str' and will always copy exactly 'len' bytes. (if memory can be obtained ofcourse) +strbuf_append_str(): + +Will add the C-string to the end of ->buf + +strbuf_append_ch(): + +Adds one character 'ch' to the end of ->buf + strbuf_reduce(): Will reduce ->buf by 'len' bytes from the end, Note that this don't shrink the memory block @@ -43,6 +51,10 @@ strbuf_rev(): Reverses the ->buf string. +strbuf_squeeze(): + +Squeezes "together" sequences of 'ch' into one character. + strbuf_release(): This function should be used to detach the ->buf member from the strbuf_t structure. diff --git a/src/common/strbuf.c b/src/common/strbuf.c index d859c07..64e08b3 100644 --- a/src/common/strbuf.c +++ b/src/common/strbuf.c @@ -89,7 +89,7 @@ void strbuf_free(strbuf_t *s) { strbuf_init(s); } -void strbuf_append(strbuf_t *s, void *ptr, size_t len) { +void strbuf_append(strbuf_t *s, const void *ptr, size_t len) { strbuf_expand(s, len); memcpy(s->buf + s->len, ptr, len); @@ -97,7 +97,7 @@ void strbuf_append(strbuf_t *s, void *ptr, size_t len) { s->buf[s->len] = '\0'; } -void strbuf_append_str(strbuf_t *s, char *str) { +void strbuf_append_str(strbuf_t *s, const char *str) { strbuf_append(s, str, strlen(str)); } @@ -157,7 +157,7 @@ void strbuf_squeeze(strbuf_t *s, char ch) { size_t np = p, of = 0; - for(; np >= 1 && s->buf[np-1] == ch; np--) + for(; np && s->buf[np-1] == ch; np--) of++; for(s->len -= of; np <= s->len; np++) s->buf[np] = s->buf[np + of]; diff --git a/src/common/strbuf.h b/src/common/strbuf.h index 187a4de..70750f3 100644 --- a/src/common/strbuf.h +++ b/src/common/strbuf.h @@ -33,9 +33,9 @@ char* strbuf_release(strbuf_t *s); void strbuf_free(strbuf_t *s); -void strbuf_append(strbuf_t *s, void *ptr, size_t len); +void strbuf_append(strbuf_t *s, const void *ptr, size_t len); -void strbuf_append_str(strbuf_t *s, char *str); +void strbuf_append_str(strbuf_t *s, const char *str); void strbuf_append_ch(strbuf_t *s, char ch);