Skip to content

Commit

Permalink
Merge branch 'gt/maint-1.6.1-utf8-width' into maint-1.6.1
Browse files Browse the repository at this point in the history
* gt/maint-1.6.1-utf8-width:
  builtin-blame.c: Use utf8_strwidth for author's names
  utf8: add utf8_strwidth()
  • Loading branch information
Junio C Hamano committed Mar 13, 2009
2 parents 2f5bfa7 + ffaf9cc commit c26901a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
12 changes: 7 additions & 5 deletions builtin-blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "string-list.h"
#include "mailmap.h"
#include "parse-options.h"
#include "utf8.h"

static char blame_usage[] = "git blame [options] [rev-opts] [rev] [--] file";

Expand Down Expand Up @@ -1618,13 +1619,14 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
printf(" %*d", max_orig_digits,
ent->s_lno + 1 + cnt);

if (!(opt & OUTPUT_NO_AUTHOR))
printf(" (%-*.*s %10s",
longest_author, longest_author,
ci.author,
if (!(opt & OUTPUT_NO_AUTHOR)) {
int pad = longest_author - utf8_strwidth(ci.author);
printf(" (%s%*s %10s",
ci.author, pad, "",
format_time(ci.author_time,
ci.author_tz,
show_raw_time));
}
printf(" %*d) ",
max_digits, ent->lno + 1 + cnt);
}
Expand Down Expand Up @@ -1755,7 +1757,7 @@ static void find_alignment(struct scoreboard *sb, int *option)
if (!(suspect->commit->object.flags & METAINFO_SHOWN)) {
suspect->commit->object.flags |= METAINFO_SHOWN;
get_commit_info(suspect->commit, &ci, 1);
num = strlen(ci.author);
num = utf8_strwidth(ci.author);
if (longest_author < num)
longest_author = num;
}
Expand Down
19 changes: 19 additions & 0 deletions utf8.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,25 @@ int utf8_width(const char **start, size_t *remainder_p)
return git_wcwidth(ch);
}

/*
* Returns the total number of columns required by a null-terminated
* string, assuming that the string is utf8. Returns strlen() instead
* if the string does not look like a valid utf8 string.
*/
int utf8_strwidth(const char *string)
{
int width = 0;
const char *orig = string;

while (1) {
if (!string)
return strlen(orig);
if (!*string)
return width;
width += utf8_width(&string, NULL);
}
}

int is_utf8(const char *text)
{
while (*text) {
Expand Down
1 change: 1 addition & 0 deletions utf8.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ typedef unsigned int ucs_char_t; /* assuming 32bit int */

ucs_char_t pick_one_utf8_char(const char **start, size_t *remainder_p);
int utf8_width(const char **start, size_t *remainder_p);
int utf8_strwidth(const char *string);
int is_utf8(const char *text);
int is_encoding_utf8(const char *name);

Expand Down

0 comments on commit c26901a

Please sign in to comment.