Archived
1
0
Fork 0

strbuf: docs and const pointers.

This commit is contained in:
H Hautakoski 2010-09-14 12:54:56 +02:00 committed by Henrik Hautakoski
parent 850df3fc87
commit ccdad9c6aa
3 changed files with 17 additions and 5 deletions

View file

@ -28,6 +28,14 @@ strbuf_append():
Like strncat() this function will append the buffer with the contents of 'str' 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) 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(): strbuf_reduce():
Will reduce ->buf by 'len' bytes from the end, Note that this don't shrink the memory block 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. Reverses the ->buf string.
strbuf_squeeze():
Squeezes "together" sequences of 'ch' into one character.
strbuf_release(): strbuf_release():
This function should be used to detach the ->buf member from the strbuf_t structure. This function should be used to detach the ->buf member from the strbuf_t structure.

View file

@ -89,7 +89,7 @@ void strbuf_free(strbuf_t *s) {
strbuf_init(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); strbuf_expand(s, len);
memcpy(s->buf + s->len, ptr, 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'; 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)); strbuf_append(s, str, strlen(str));
} }
@ -157,7 +157,7 @@ void strbuf_squeeze(strbuf_t *s, char ch) {
size_t np = p, of = 0; size_t np = p, of = 0;
for(; np >= 1 && s->buf[np-1] == ch; np--) for(; np && s->buf[np-1] == ch; np--)
of++; of++;
for(s->len -= of; np <= s->len; np++) for(s->len -= of; np <= s->len; np++)
s->buf[np] = s->buf[np + of]; s->buf[np] = s->buf[np + of];

View file

@ -33,9 +33,9 @@ char* strbuf_release(strbuf_t *s);
void strbuf_free(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); void strbuf_append_ch(strbuf_t *s, char ch);