Browse Source

Add strbuf_cmp.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Pierre Habouzit 18 years ago committed by Junio C Hamano
parent
commit
45f66f6463
  1. 12
      strbuf.c
  2. 1
      strbuf.h

12
strbuf.c

@ -50,6 +50,18 @@ void strbuf_rtrim(struct strbuf *sb) @@ -50,6 +50,18 @@ void strbuf_rtrim(struct strbuf *sb)
sb->buf[sb->len] = '\0';
}

int strbuf_cmp(struct strbuf *a, struct strbuf *b)
{
int cmp;
if (a->len < b->len) {
cmp = memcmp(a->buf, b->buf, a->len);
return cmp ? cmp : -1;
} else {
cmp = memcmp(a->buf, b->buf, b->len);
return cmp ? cmp : a->len != b->len;
}
}

void strbuf_splice(struct strbuf *sb, size_t pos, size_t len,
const void *data, size_t dlen)
{

1
strbuf.h

@ -78,6 +78,7 @@ static inline void strbuf_setlen(struct strbuf *sb, size_t len) { @@ -78,6 +78,7 @@ static inline void strbuf_setlen(struct strbuf *sb, size_t len) {

/*----- content related -----*/
extern void strbuf_rtrim(struct strbuf *);
extern int strbuf_cmp(struct strbuf *, struct strbuf *);

/*----- add data in your buffer -----*/
static inline void strbuf_addch(struct strbuf *sb, int c) {

Loading…
Cancel
Save