Archived
1
0
Fork 0

common/strbuf: added chop function

This commit is contained in:
Henrik Hautakoski 2010-09-29 22:21:38 +02:00
parent 69b418472e
commit 3abbb2b63e
3 changed files with 42 additions and 0 deletions

View file

@ -12,6 +12,7 @@
#include <string.h>
#include "xalloc.h"
#include "strbuf.h"
#include "debug.h"
#define CHNK_SIZE 128
@ -91,6 +92,20 @@ void strbuf_append_ch(strbuf_t *s, char ch) {
s->buf[s->len] = '\0';
}
void strbuf_rchop(strbuf_t *s, char ch) {
int i;
for(i=s->len-1; i >= 0; i--) {
if (s->buf[i] == ch) {
s->buf[i] = '\0';
s->len = i;
break;
}
}
}
void strbuf_term(strbuf_t *s, char ch) {
if (s->buf[s->len-1] != ch)

View file

@ -39,6 +39,8 @@ void strbuf_append_str(strbuf_t *s, const char *str);
void strbuf_append_ch(strbuf_t *s, char ch);
void strbuf_rchop(strbuf_t *s, char ch);
void strbuf_term(strbuf_t *s, char ch);
void strbuf_trim(strbuf_t *s);