git-2.22.0/utf8.c
/*
 * Returns first character length in bytes for multi-byte `text` according to
 * `encoding`.
 *
 * - The `text` pointer is updated to point at the next character.
 * - When `remainder_p` is not NULL, on entry `*remainder_p` is how much bytes
 *   we can consume from text, and on exit `*remainder_p` is reduced by returned
 *   character length. Otherwise `text` is treated as limited by NUL.
 */
Returns first character length in bytes for multi-byte `text` according to
`encoding`.

- The `text` pointer is updated to point at the next character.
Returns first character length in bytes for multi - byte ` text ` according to ` encoding ` . - The ` text ` pointer is updated to point at the next character .
int mbs_chrlen(const char **text, size_t *remainder_p, const char *encoding)
{
	int chrlen;
	const char *p = *text;
	size_t r = (remainder_p ? *remainder_p : SIZE_MAX);
	if (r < 1)
		return 0;
	if (is_encoding_utf8(encoding)) {
		pick_one_utf8_char(&p, &r);
		chrlen = p ? (p - *text)
			   : 1 ;
	}
	else {
		chrlen = 1;
	}
	*text += chrlen;
	if (remainder_p)
		*remainder_p -= chrlen;
	return chrlen;
}
int mbs_chrlen ( const char * * text , size_t * remainder_p , const char * encoding ) { int chrlen ; const char * p = * text ; size_t r = ( remainder_p ? * remainder_p : SIZE_MAX ) ; if ( r < 1 ) return 0 ; if ( is_encoding_utf8 ( encoding ) ) { pick_one_utf8_char ( & p , & r ) ; chrlen = p ? ( p - * text ) : 1 ; } else { chrlen = 1 ; } * text += chrlen ; if ( remainder_p ) * remainder_p -= chrlen ; return chrlen ; }
Returns first character length in bytes for multi-byte `text` according to
 `encoding`.
Returns first character length in bytes for multi - byte ` text ` according to ` encoding ` .
/* not valid UTF-8 -> raw byte sequence */ /*
		 * TODO use iconv to decode one char and obtain its chrlen
		 * for now, let's treat encodings != UTF-8 as one-byte
		 */