Git-Raw

 view release on metacpan or  search on metacpan

deps/libgit2/src/libgit2/attr_file.c  view on Meta::CPAN

		break;
	}
	default:
		git_error_set(GIT_ERROR_INVALID, "unknown file source %d", source->type);
		return -1;
	}

	if ((error = git_attr_file__new(&file, entry, source)) < 0)
		goto cleanup;

	/* advance over a UTF8 BOM */
	content_str = git_str_cstr(&content);
	bom_offset = git_str_detect_bom(&bom, &content);

	if (bom == GIT_STR_BOM_UTF8)
		content_str += bom_offset;

	/* store the key of the attr_reader; don't bother with cache
	 * invalidation during the same attr reader session.
	 */
	if (attr_session)
		file->session_key = attr_session->key;

	if (parser && (error = parser(repo, file, content_str, allow_macros)) < 0) {
		git_attr_file__free(file);

deps/libgit2/src/libgit2/config_parse.c  view on Meta::CPAN

	git__free(name);
	return -1;
}

static int skip_bom(git_parse_ctx *parser)
{
	git_str buf = GIT_STR_INIT_CONST(parser->content, parser->content_len);
	git_str_bom_t bom;
	int bom_offset = git_str_detect_bom(&bom, &buf);

	if (bom == GIT_STR_BOM_UTF8)
		git_parse_advance_chars(parser, bom_offset);

	/* TODO: reference implementation is pretty stupid with BoM */

	return 0;
}

/*
	(* basic types *)
	digit = "0".."9"

deps/libgit2/src/util/str.c  view on Meta::CPAN

}

int git_str_is_binary(const git_str *buf)
{
	const char *scan = buf->ptr, *end = buf->ptr + buf->size;
	git_str_bom_t bom;
	int printable = 0, nonprintable = 0;

	scan += git_str_detect_bom(&bom, buf);

	if (bom > GIT_STR_BOM_UTF8)
		return 1;

	while (scan < end) {
		unsigned char c = *scan++;

		/* Printable characters are those above SPACE (0x1F) excluding DEL,
		 * and including BS, ESC and FF.
		 */
		if ((c > 0x1F && c != 127) || c == '\b' || c == '\033' || c == '\014')
			printable++;

deps/libgit2/src/util/str.c  view on Meta::CPAN

int git_str_contains_nul(const git_str *buf)
{
	return (memchr(buf->ptr, '\0', buf->size) != NULL);
}

int git_str_detect_bom(git_str_bom_t *bom, const git_str *buf)
{
	const char *ptr;
	size_t len;

	*bom = GIT_STR_BOM_NONE;
	/* need at least 2 bytes to look for any BOM */
	if (buf->size < 2)
		return 0;

	ptr = buf->ptr;
	len = buf->size;

	switch (*ptr++) {
	case 0:
		if (len >= 4 && ptr[0] == 0 && ptr[1] == '\xFE' && ptr[2] == '\xFF') {
			*bom = GIT_STR_BOM_UTF32_BE;
			return 4;
		}
		break;
	case '\xEF':
		if (len >= 3 && ptr[0] == '\xBB' && ptr[1] == '\xBF') {
			*bom = GIT_STR_BOM_UTF8;
			return 3;
		}
		break;
	case '\xFE':
		if (*ptr == '\xFF') {
			*bom = GIT_STR_BOM_UTF16_BE;
			return 2;
		}
		break;
	case '\xFF':
		if (*ptr != '\xFE')
			break;
		if (len >= 4 && ptr[1] == 0 && ptr[2] == 0) {
			*bom = GIT_STR_BOM_UTF32_LE;
			return 4;
		} else {
			*bom = GIT_STR_BOM_UTF16_LE;
			return 2;
		}
		break;
	default:
		break;
	}

	return 0;
}

bool git_str_gather_text_stats(
	git_str_text_stats *stats, const git_str *buf, bool skip_bom)
{
	const char *scan = buf->ptr, *end = buf->ptr + buf->size;
	int skip;

	memset(stats, 0, sizeof(*stats));

	/* BOM detection */
	skip = git_str_detect_bom(&stats->bom, buf);
	if (skip_bom)
		scan += skip;

	/* Ignore EOF character */
	if (buf->size > 0 && end[-1] == '\032')
		end--;

	/* Counting loop */
	while (scan < end) {

deps/libgit2/src/util/str.h  view on Meta::CPAN


#include "git2_util.h"

struct git_str {
	char *ptr;
	size_t asize;
	size_t size;
};

typedef enum {
	GIT_STR_BOM_NONE = 0,
	GIT_STR_BOM_UTF8 = 1,
	GIT_STR_BOM_UTF16_LE = 2,
	GIT_STR_BOM_UTF16_BE = 3,
	GIT_STR_BOM_UTF32_LE = 4,
	GIT_STR_BOM_UTF32_BE = 5
} git_str_bom_t;

typedef struct {
	git_str_bom_t bom; /* BOM found at head of text */
	unsigned int nul, cr, lf, crlf; /* NUL, CR, LF and CRLF counts */
	unsigned int printable, nonprintable; /* These are just approximations! */
} git_str_text_stats;

extern char git_str__initstr[];
extern char git_str__oom[];

/* Use to initialize string buffer structure when git_str is on stack */
#define GIT_STR_INIT { git_str__initstr, 0, 0 }

deps/libgit2/src/util/str.h  view on Meta::CPAN

extern int git_str_lf_to_crlf(git_str *tgt, const git_str *src);

/**
 * Fill string buffer with the common prefix of a array of strings
 *
 * String buffer will be set to empty if there is no common prefix
 */
extern int git_str_common_prefix(git_str *buf, char *const *const strings, size_t count);

/**
 * Check if a string buffer begins with a UTF BOM
 *
 * @param bom Set to the type of BOM detected or GIT_BOM_NONE
 * @param str String buffer in which to check the first bytes for a BOM
 * @return Number of bytes of BOM data (or 0 if no BOM found)
 */
extern int git_str_detect_bom(git_str_bom_t *bom, const git_str *str);

/**
 * Gather stats for a piece of text
 *
 * Fill the `stats` structure with counts of unreadable characters, carriage
 * returns, etc, so it can be used in heuristics.  This automatically skips
 * a trailing EOF (\032 character).  Also it will look for a BOM at the
 * start of the text and can be told to skip that as well.
 *
 * @param stats Structure to be filled in
 * @param str Text to process
 * @param skip_bom Exclude leading BOM from stats if true
 * @return Does the string buffer heuristically look like binary data
 */
extern bool git_str_gather_text_stats(
	git_str_text_stats *stats, const git_str *str, bool skip_bom);

/**
* Check quickly if string buffer looks like it contains binary data
*
* @param str string buffer to check
* @return 1 if string buffer looks like non-text data



( run in 0.643 second using v1.01-cache-2.11-cpan-e9daa2b36ef )