This repository was archived by the owner on Nov 9, 2017. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Original file line number Diff line number Diff line change 3
3
#include "cache.h"
4
4
#include "commit.h"
5
5
#include "color.h"
6
+ #include "utf8.h"
6
7
7
8
static int parse_options_usage (struct parse_opt_ctx_t * ctx ,
8
9
const char * const * usagestr ,
@@ -491,7 +492,7 @@ static int usage_argh(const struct option *opts, FILE *outfile)
491
492
s = literal ? "[%s]" : "[<%s>]" ;
492
493
else
493
494
s = literal ? " %s" : " <%s>" ;
494
- return fprintf (outfile , s , opts -> argh ? _ (opts -> argh ) : _ ("..." ));
495
+ return utf8_fprintf (outfile , s , opts -> argh ? _ (opts -> argh ) : _ ("..." ));
495
496
}
496
497
497
498
#define USAGE_OPTS_WIDTH 24
@@ -550,7 +551,7 @@ static int usage_with_options_internal(struct parse_opt_ctx_t *ctx,
550
551
if (opts -> long_name )
551
552
pos += fprintf (outfile , "--%s" , opts -> long_name );
552
553
if (opts -> type == OPTION_NUMBER )
553
- pos += fprintf (outfile , "-NUM" );
554
+ pos += utf8_fprintf (outfile , _ ( "-NUM" ) );
554
555
555
556
if ((opts -> flags & PARSE_OPT_LITERAL_ARGHELP ) ||
556
557
!(opts -> flags & PARSE_OPT_NOARG ))
Original file line number Diff line number Diff line change @@ -429,6 +429,27 @@ int same_encoding(const char *src, const char *dst)
429
429
return !strcasecmp (src , dst );
430
430
}
431
431
432
+ /*
433
+ * Wrapper for fprintf and returns the total number of columns required
434
+ * for the printed string, assuming that the string is utf8.
435
+ */
436
+ int utf8_fprintf (FILE * stream , const char * format , ...)
437
+ {
438
+ struct strbuf buf = STRBUF_INIT ;
439
+ va_list arg ;
440
+ int columns ;
441
+
442
+ va_start (arg , format );
443
+ strbuf_vaddf (& buf , format , arg );
444
+ va_end (arg );
445
+
446
+ columns = fputs (buf .buf , stream );
447
+ if (0 <= columns ) /* keep the error from the I/O */
448
+ columns = utf8_strwidth (buf .buf );
449
+ strbuf_release (& buf );
450
+ return columns ;
451
+ }
452
+
432
453
/*
433
454
* Given a buffer and its encoding, return it re-encoded
434
455
* with iconv. If the conversion fails, returns NULL.
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ int utf8_strwidth(const char *string);
8
8
int is_utf8 (const char * text );
9
9
int is_encoding_utf8 (const char * name );
10
10
int same_encoding (const char * , const char * );
11
+ int utf8_fprintf (FILE * , const char * , ...);
11
12
12
13
void strbuf_add_wrapped_text (struct strbuf * buf ,
13
14
const char * text , int indent , int indent2 , int width );
You can’t perform that action at this time.
0 commit comments