MCPcopy Index your code
hub / github.com/git/git / strbuf_utf8_align

Function strbuf_utf8_align

utf8.c:820–839  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

818}
819
820void strbuf_utf8_align(struct strbuf *buf, align_type position, unsigned int width,
821 const char *s)
822{
823 size_t slen = strlen(s);
824 int display_len = utf8_strnwidth(s, slen, 0);
825 int utf8_compensation = slen - display_len;
826
827 if (display_len >= width) {
828 strbuf_addstr(buf, s);
829 return;
830 }
831
832 if (position == ALIGN_LEFT)
833 strbuf_addf(buf, "%-*s", width + utf8_compensation, s);
834 else if (position == ALIGN_MIDDLE) {
835 int left = (width - display_len) / 2;
836 strbuf_addf(buf, "%*s%-*s", left, "", width - left + utf8_compensation, s);
837 } else if (position == ALIGN_RIGHT)
838 strbuf_addf(buf, "%*s", width + utf8_compensation, s);
839}

Callers 3

end_align_handlerFunction · 0.85

Calls 3

utf8_strnwidthFunction · 0.85
strbuf_addstrFunction · 0.85
strbuf_addfFunction · 0.85

Tested by 1