Johannes Schindelin | 9e83266 | 2006-12-22 22:06:08 +0100 | [diff] [blame] | 1 | #ifndef GIT_UTF8_H |
| 2 | #define GIT_UTF8_H |
| 3 | |
Junio C Hamano | 396ccf1 | 2008-01-06 19:02:22 -0800 | [diff] [blame] | 4 | typedef unsigned int ucs_char_t; /* assuming 32bit int */ |
| 5 | |
Nguyễn Thái Ngọc Duy | 1640632 | 2013-04-19 09:08:52 +1000 | [diff] [blame] | 6 | size_t display_mode_esc_sequence_len(const char *s); |
Junio C Hamano | 44b25b8 | 2008-01-02 01:49:58 -0800 | [diff] [blame] | 7 | int utf8_width(const char **start, size_t *remainder_p); |
Nguyễn Thái Ngọc Duy | 2bc1e7e | 2013-04-19 09:08:45 +1000 | [diff] [blame] | 8 | int utf8_strnwidth(const char *string, int len, int skip_ansi); |
Geoffrey Thomas | 8a9391e | 2009-01-30 04:41:28 -0500 | [diff] [blame] | 9 | int utf8_strwidth(const char *string); |
Johannes Schindelin | 9e83266 | 2006-12-22 22:06:08 +0100 | [diff] [blame] | 10 | int is_utf8(const char *text); |
Junio C Hamano | 677cfed | 2006-12-30 12:20:43 -0800 | [diff] [blame] | 11 | int is_encoding_utf8(const char *name); |
Junio C Hamano | 0e18bcd | 2012-10-18 22:41:56 -0700 | [diff] [blame] | 12 | int same_encoding(const char *, const char *); |
Jeff King | 4621085 | 2013-07-09 20:18:40 -0400 | [diff] [blame] | 13 | __attribute__((format (printf, 2, 3))) |
Jiang Xin | c082196 | 2013-02-09 14:31:09 +0800 | [diff] [blame] | 14 | int utf8_fprintf(FILE *, const char *, ...); |
Junio C Hamano | 677cfed | 2006-12-30 12:20:43 -0800 | [diff] [blame] | 15 | |
Junio C Hamano | dde843e | 2015-04-16 10:45:29 -0700 | [diff] [blame] | 16 | extern const char utf8_bom[]; |
| 17 | extern int skip_utf8_bom(char **, size_t); |
| 18 | |
Steffen Prohaska | e0db176 | 2012-12-11 06:59:22 +0100 | [diff] [blame] | 19 | void strbuf_add_wrapped_text(struct strbuf *buf, |
Johannes Schindelin | a94410c | 2008-11-10 18:47:00 +0100 | [diff] [blame] | 20 | const char *text, int indent, int indent2, int width); |
Steffen Prohaska | e0db176 | 2012-12-11 06:59:22 +0100 | [diff] [blame] | 21 | void strbuf_add_wrapped_bytes(struct strbuf *buf, const char *data, int len, |
Jeff King | 98acc83 | 2011-02-23 04:50:19 -0500 | [diff] [blame] | 22 | int indent, int indent2, int width); |
Nguyễn Thái Ngọc Duy | a7f01c6 | 2013-04-19 09:08:51 +1000 | [diff] [blame] | 23 | void strbuf_utf8_replace(struct strbuf *sb, int pos, int width, |
| 24 | const char *subst); |
Johannes Schindelin | 9e83266 | 2006-12-22 22:06:08 +0100 | [diff] [blame] | 25 | |
Junio C Hamano | b45974a | 2006-12-23 23:36:55 -0800 | [diff] [blame] | 26 | #ifndef NO_ICONV |
Nguyễn Thái Ngọc Duy | b782bba | 2013-04-19 09:08:46 +1000 | [diff] [blame] | 27 | char *reencode_string_iconv(const char *in, size_t insz, |
| 28 | iconv_t conv, int *outsz); |
| 29 | char *reencode_string_len(const char *in, int insz, |
| 30 | const char *out_encoding, |
| 31 | const char *in_encoding, |
| 32 | int *outsz); |
Junio C Hamano | b45974a | 2006-12-23 23:36:55 -0800 | [diff] [blame] | 33 | #else |
Eric Sunshine | e654eb2 | 2015-06-05 02:42:16 -0400 | [diff] [blame] | 34 | static 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 Hamano | b45974a | 2006-12-23 23:36:55 -0800 | [diff] [blame] | 37 | #endif |
| 38 | |
Nguyễn Thái Ngọc Duy | b782bba | 2013-04-19 09:08:46 +1000 | [diff] [blame] | 39 | static 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 Smelkov | 6cd3c05 | 2013-03-07 14:55:07 +0400 | [diff] [blame] | 48 | int mbs_chrlen(const char **text, size_t *remainder_p, const char *encoding); |
| 49 | |
Jeff King | 6162a1d | 2014-12-15 17:56:59 -0500 | [diff] [blame] | 50 | /* |
Li Peng | 832c0e5 | 2016-05-06 20:36:46 +0800 | [diff] [blame] | 51 | * Returns true if the path would match ".git" after HFS case-folding. |
Jeff King | 6162a1d | 2014-12-15 17:56:59 -0500 | [diff] [blame] | 52 | * 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 | */ |
| 56 | int is_hfs_dotgit(const char *path); |
| 57 | |
Karthik Nayak | 110dcda | 2015-09-10 21:18:19 +0530 | [diff] [blame] | 58 | typedef 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 | */ |
| 70 | void strbuf_utf8_align(struct strbuf *buf, align_type position, unsigned int width, |
| 71 | const char *s); |
| 72 | |
Johannes Schindelin | 9e83266 | 2006-12-22 22:06:08 +0100 | [diff] [blame] | 73 | #endif |