From 110dcda50d5ddaf3557666eea3b012a6ccc74dce Mon Sep 17 00:00:00 2001 From: Karthik Nayak Date: Thu, 10 Sep 2015 21:18:19 +0530 Subject: utf8: add function to align a string into given strbuf Add strbuf_utf8_align() which will align a given string into a strbuf as per given align_type and width. If the width is greater than the string length then no alignment is performed. Helped-by: Eric Sunshine Mentored-by: Christian Couder Mentored-by: Matthieu Moy Signed-off-by: Karthik Nayak Signed-off-by: Junio C Hamano --- utf8.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'utf8.h') diff --git a/utf8.h b/utf8.h index 5a9e94bee6..7930b44f19 100644 --- a/utf8.h +++ b/utf8.h @@ -55,4 +55,19 @@ int mbs_chrlen(const char **text, size_t *remainder_p, const char *encoding); */ int is_hfs_dotgit(const char *path); +typedef enum { + ALIGN_LEFT, + ALIGN_MIDDLE, + ALIGN_RIGHT +} align_type; + +/* + * Align the string given and store it into a strbuf as per the + * 'position' and 'width'. If the given string length is larger than + * 'width' than then the input string is not truncated and no + * alignment is done. + */ +void strbuf_utf8_align(struct strbuf *buf, align_type position, unsigned int width, + const char *s); + #endif -- cgit v1.2.3