diff options
| author | joshaber <joshaber@gmail.com> | 2014-07-16 13:34:25 -0700 |
|---|---|---|
| committer | joshaber <joshaber@gmail.com> | 2014-07-16 13:34:25 -0700 |
| commit | b3af2d80d2d6393dada89c713baff9b3eba49a01 (patch) | |
| tree | ee90407f88e1a54b509f6f89b46288a57a316ac5 /src | |
| parent | df4cba0f2860f35ddea03e09d40ec27b9717db70 (diff) | |
| download | libgit2-b3af2d80d2d6393dada89c713baff9b3eba49a01.tar.gz | |
Just put it all in buffer.
Diffstat (limited to 'src')
| -rw-r--r-- | src/buf_text.c | 4 | ||||
| -rw-r--r-- | src/buf_text.h | 17 | ||||
| -rw-r--r-- | src/buffer.c | 11 |
3 files changed, 29 insertions, 3 deletions
diff --git a/src/buf_text.c b/src/buf_text.c index 0e93696cd..8d2b141b2 100644 --- a/src/buf_text.c +++ b/src/buf_text.c @@ -176,7 +176,7 @@ int git_buf_text_common_prefix(git_buf *buf, const git_strarray *strings) return 0; } -int git_buf_text_is_binary(const git_buf *buf) +bool git_buf_text_is_binary(const git_buf *buf) { const char *scan = buf->ptr, *end = buf->ptr + buf->size; git_bom_t bom; @@ -201,7 +201,7 @@ int git_buf_text_is_binary(const git_buf *buf) return ((printable >> 7) < nonprintable); } -int git_buf_text_contains_nul(const git_buf *buf) +bool git_buf_text_contains_nul(const git_buf *buf) { return (memchr(buf->ptr, '\0', buf->size) != NULL); } diff --git a/src/buf_text.h b/src/buf_text.h index 3415ac00f..e753a0244 100644 --- a/src/buf_text.h +++ b/src/buf_text.h @@ -7,7 +7,6 @@ #ifndef INCLUDE_buf_text_h__ #define INCLUDE_buf_text_h__ -#include "git2/buf_text.h" #include "buffer.h" typedef enum { @@ -79,6 +78,22 @@ extern int git_buf_text_lf_to_crlf(git_buf *tgt, const git_buf *src); extern int git_buf_text_common_prefix(git_buf *buf, const git_strarray *strs); /** + * Check quickly if buffer looks like it contains binary data + * + * @param buf Buffer to check + * @return true if buffer looks like non-text data + */ +extern bool git_buf_text_is_binary(const git_buf *buf); + +/** + * Check quickly if buffer contains a NUL byte + * + * @param buf Buffer to check + * @return true if buffer contains a NUL byte + */ +extern bool git_buf_text_contains_nul(const git_buf *buf); + +/** * Check if a buffer begins with a UTF BOM * * @param bom Set to the type of BOM detected or GIT_BOM_NONE diff --git a/src/buffer.c b/src/buffer.c index b8f8660ed..1bee9d70b 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -7,6 +7,7 @@ #include "buffer.h" #include "posix.h" #include "git2/buffer.h" +#include "buf_text.h" #include <ctype.h> /* Used as default value for git_buf->ptr so that people can always @@ -141,6 +142,16 @@ int git_buf_set(git_buf *buf, const void *data, size_t len) return 0; } +int git_buf_is_binary(const git_buf *buf) +{ + return git_buf_text_is_binary(buf); +} + +int git_buf_contains_nul(const git_buf *buf) +{ + return git_buf_text_contains_nul(buf); +} + int git_buf_sets(git_buf *buf, const char *string) { return git_buf_set(buf, string, string ? strlen(string) : 0); |
