blob: 6bbcf31a831d60faf119fdc3f82f1eb10233e255 [file] [log] [blame]
Johannes Schindelin9e832662006-12-22 22:06:08 +01001#ifndef GIT_UTF8_H
2#define GIT_UTF8_H
3
Junio C Hamano396ccf12008-01-06 19:02:22 -08004typedef unsigned int ucs_char_t; /* assuming 32bit int */
5
Nguyễn Thái Ngọc Duy16406322013-04-19 09:08:52 +10006size_t display_mode_esc_sequence_len(const char *s);
Junio C Hamano44b25b82008-01-02 01:49:58 -08007int utf8_width(const char **start, size_t *remainder_p);
Nguyễn Thái Ngọc Duy2bc1e7e2013-04-19 09:08:45 +10008int utf8_strnwidth(const char *string, int len, int skip_ansi);
Geoffrey Thomas8a9391e2009-01-30 04:41:28 -05009int utf8_strwidth(const char *string);
Johannes Schindelin9e832662006-12-22 22:06:08 +010010int is_utf8(const char *text);
Junio C Hamano677cfed2006-12-30 12:20:43 -080011int is_encoding_utf8(const char *name);
Junio C Hamano0e18bcd2012-10-18 22:41:56 -070012int same_encoding(const char *, const char *);
Jeff King46210852013-07-09 20:18:40 -040013__attribute__((format (printf, 2, 3)))
Jiang Xinc0821962013-02-09 14:31:09 +080014int utf8_fprintf(FILE *, const char *, ...);
Junio C Hamano677cfed2006-12-30 12:20:43 -080015
Junio C Hamanodde843e2015-04-16 10:45:29 -070016extern const char utf8_bom[];
17extern int skip_utf8_bom(char **, size_t);
18
Steffen Prohaskae0db1762012-12-11 06:59:22 +010019void strbuf_add_wrapped_text(struct strbuf *buf,
Johannes Schindelina94410c2008-11-10 18:47:00 +010020 const char *text, int indent, int indent2, int width);
Steffen Prohaskae0db1762012-12-11 06:59:22 +010021void strbuf_add_wrapped_bytes(struct strbuf *buf, const char *data, int len,
Jeff King98acc832011-02-23 04:50:19 -050022 int indent, int indent2, int width);
Nguyễn Thái Ngọc Duya7f01c62013-04-19 09:08:51 +100023void strbuf_utf8_replace(struct strbuf *sb, int pos, int width,
24 const char *subst);
Johannes Schindelin9e832662006-12-22 22:06:08 +010025
Junio C Hamanob45974a2006-12-23 23:36:55 -080026#ifndef NO_ICONV
Nguyễn Thái Ngọc Duyb782bba2013-04-19 09:08:46 +100027char *reencode_string_iconv(const char *in, size_t insz,
28 iconv_t conv, int *outsz);
29char *reencode_string_len(const char *in, int insz,
30 const char *out_encoding,
31 const char *in_encoding,
32 int *outsz);
Junio C Hamanob45974a2006-12-23 23:36:55 -080033#else
Eric Sunshinee654eb22015-06-05 02:42:16 -040034static inline char *reencode_string_len(const char *a, int b,
35 const char *c, const char *d, int *e)
36{ if (e) *e = 0; return NULL; }
Junio C Hamanob45974a2006-12-23 23:36:55 -080037#endif
38
Nguyễn Thái Ngọc Duyb782bba2013-04-19 09:08:46 +100039static inline char *reencode_string(const char *in,
40 const char *out_encoding,
41 const char *in_encoding)
42{
43 return reencode_string_len(in, strlen(in),
44 out_encoding, in_encoding,
45 NULL);
46}
47
Kirill Smelkov6cd3c052013-03-07 14:55:07 +040048int mbs_chrlen(const char **text, size_t *remainder_p, const char *encoding);
49
Jeff King6162a1d2014-12-15 17:56:59 -050050/*
Li Peng832c0e52016-05-06 20:36:46 +080051 * Returns true if the path would match ".git" after HFS case-folding.
Jeff King6162a1d2014-12-15 17:56:59 -050052 * The path should be NUL-terminated, but we will match variants of both ".git\0"
53 * and ".git/..." (but _not_ ".../.git"). This makes it suitable for both fsck
54 * and verify_path().
55 */
56int is_hfs_dotgit(const char *path);
57
Karthik Nayak110dcda2015-09-10 21:18:19 +053058typedef enum {
59 ALIGN_LEFT,
60 ALIGN_MIDDLE,
61 ALIGN_RIGHT
62} align_type;
63
64/*
65 * Align the string given and store it into a strbuf as per the
66 * 'position' and 'width'. If the given string length is larger than
67 * 'width' than then the input string is not truncated and no
68 * alignment is done.
69 */
70void strbuf_utf8_align(struct strbuf *buf, align_type position, unsigned int width,
71 const char *s);
72
Johannes Schindelin9e832662006-12-22 22:06:08 +010073#endif