mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-05 22:55:47 +00:00
Export git_buf_text_is_binary and git_buf_text_contains_nul.
So that users don’t need to implement binary detection themselves.
This commit is contained in:
parent
ad082501a7
commit
df4cba0f28
@ -13,6 +13,7 @@
|
||||
#include "git2/blame.h"
|
||||
#include "git2/branch.h"
|
||||
#include "git2/buffer.h"
|
||||
#include "git2/buf_text.h"
|
||||
#include "git2/checkout.h"
|
||||
#include "git2/cherrypick.h"
|
||||
#include "git2/clone.h"
|
||||
|
42
include/git2/buf_text.h
Normal file
42
include/git2/buf_text.h
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) the libgit2 contributors. All rights reserved.
|
||||
*
|
||||
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
||||
* a Linking Exception. For full terms see the included COPYING file.
|
||||
*/
|
||||
#ifndef INCLUDE_git_buf_text_h__
|
||||
#define INCLUDE_git_buf_text_h__
|
||||
|
||||
#include "common.h"
|
||||
#include "buffer.h"
|
||||
|
||||
/**
|
||||
* @file git2/buf_text.h
|
||||
* @brief Buffer text export structure
|
||||
*
|
||||
* @ingroup Git
|
||||
* @{
|
||||
*/
|
||||
GIT_BEGIN_DECL
|
||||
|
||||
/**
|
||||
* Check quickly if buffer looks like it contains binary data
|
||||
*
|
||||
* @param buf Buffer to check
|
||||
* @return 1 if buffer looks like non-text data
|
||||
*/
|
||||
GIT_EXTERN(int) git_buf_text_is_binary(const git_buf *buf);
|
||||
|
||||
/**
|
||||
* Check quickly if buffer contains a NUL byte
|
||||
*
|
||||
* @param buf Buffer to check
|
||||
* @return 1 if buffer contains a NUL byte
|
||||
*/
|
||||
GIT_EXTERN(int) git_buf_text_contains_nul(const git_buf *buf);
|
||||
|
||||
GIT_END_DECL
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif
|
@ -176,7 +176,7 @@ int git_buf_text_common_prefix(git_buf *buf, const git_strarray *strings)
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool git_buf_text_is_binary(const git_buf *buf)
|
||||
int 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 @@ bool git_buf_text_is_binary(const git_buf *buf)
|
||||
return ((printable >> 7) < nonprintable);
|
||||
}
|
||||
|
||||
bool git_buf_text_contains_nul(const git_buf *buf)
|
||||
int git_buf_text_contains_nul(const git_buf *buf)
|
||||
{
|
||||
return (memchr(buf->ptr, '\0', buf->size) != NULL);
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
#ifndef INCLUDE_buf_text_h__
|
||||
#define INCLUDE_buf_text_h__
|
||||
|
||||
#include "git2/buf_text.h"
|
||||
#include "buffer.h"
|
||||
|
||||
typedef enum {
|
||||
@ -77,22 +78,6 @@ 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
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user