mirror of
https://github.com/git/git.git
synced 2024-06-08 00:46:11 +02:00
strbuf: add strbuf_reencode helper
This is a convenience wrapper around `reencode_string_len` and `strbuf_attach`. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
e31316263a
commit
d4241f52d1
|
@ -125,6 +125,11 @@ Functions
|
||||||
|
|
||||||
Strip whitespace from the end of a string.
|
Strip whitespace from the end of a string.
|
||||||
|
|
||||||
|
`strbuf_reencode`::
|
||||||
|
|
||||||
|
Replace the contents of the strbuf with a reencoded form. Returns -1
|
||||||
|
on error, 0 on success.
|
||||||
|
|
||||||
`strbuf_cmp`::
|
`strbuf_cmp`::
|
||||||
|
|
||||||
Compare two buffers. Returns an integer less than, equal to, or greater
|
Compare two buffers. Returns an integer less than, equal to, or greater
|
||||||
|
|
17
strbuf.c
17
strbuf.c
|
@ -1,5 +1,6 @@
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
#include "refs.h"
|
#include "refs.h"
|
||||||
|
#include "utf8.h"
|
||||||
|
|
||||||
int starts_with(const char *str, const char *prefix)
|
int starts_with(const char *str, const char *prefix)
|
||||||
{
|
{
|
||||||
|
@ -106,6 +107,22 @@ void strbuf_ltrim(struct strbuf *sb)
|
||||||
sb->buf[sb->len] = '\0';
|
sb->buf[sb->len] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int strbuf_reencode(struct strbuf *sb, const char *from, const char *to)
|
||||||
|
{
|
||||||
|
char *out;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
if (same_encoding(from, to))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
out = reencode_string_len(sb->buf, sb->len, to, from, &len);
|
||||||
|
if (!out)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
strbuf_attach(sb, out, len, len);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
struct strbuf **strbuf_split_buf(const char *str, size_t slen,
|
struct strbuf **strbuf_split_buf(const char *str, size_t slen,
|
||||||
int terminator, int max)
|
int terminator, int max)
|
||||||
{
|
{
|
||||||
|
|
1
strbuf.h
1
strbuf.h
|
@ -45,6 +45,7 @@ static inline void strbuf_setlen(struct strbuf *sb, size_t len)
|
||||||
extern void strbuf_trim(struct strbuf *);
|
extern void strbuf_trim(struct strbuf *);
|
||||||
extern void strbuf_rtrim(struct strbuf *);
|
extern void strbuf_rtrim(struct strbuf *);
|
||||||
extern void strbuf_ltrim(struct strbuf *);
|
extern void strbuf_ltrim(struct strbuf *);
|
||||||
|
extern int strbuf_reencode(struct strbuf *sb, const char *from, const char *to);
|
||||||
extern int strbuf_cmp(const struct strbuf *, const struct strbuf *);
|
extern int strbuf_cmp(const struct strbuf *, const struct strbuf *);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue