git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Torsten Bögershausen" <tboegi@web.de>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Cc: git@vger.kernel.org, "Junio C Hamano" <gitster@pobox.com>,
	"torsten Bögershausen" <tboegi@web.de>
Subject: Re: [PATCH v2] fetch: align new ref summary printout in UTF-8 locales
Date: Wed, 05 Sep 2012 21:20:34 +0200	[thread overview]
Message-ID: <5047A602.1020802@web.de> (raw)
In-Reply-To: <504796A5.4070700@gmail.com>

On 09/05/2012 08:15 PM, Torsten Bögershausen wrote:
> On 04.09.12 12:39, Nguyễn Thái Ngọc Duy wrote:
>> +/* return the number of columns of string 's' in current locale */
>> +int gettext_width(const char *s)
>> +{
>> +	static int is_utf8 = -1;
>> +	if (is_utf8 == -1)
>> +		is_utf8 = !strcmp(charset, "UTF-8");
>> +
>> +	return is_utf8 ? utf8_strwidth(s) : strlen(s);
>
> Will that work for non-ASCII encodings?
> For ISO-8859-x we can say strlen() == strwidth(),
> but for other encodings using multibytes that doesn't work, does it?
(Sorry the message went out before completely written)
Something like that:

int gettext_width(const char *s) {
   static int is_utf8 = -1;

   if (is_utf8 == -1)
     is_utf8 = !strcmp(charset, "UTF-8");

   if (is_utf8)
     return utf8_strwidth(s);
   else  {
     char *s_utf = reencode_string(s, "UTF-8", charset);
     if (s_utf) {
       witdh = utf8_strwidth(s_utf);
       free(s_utf);
     } else
       width = strlen(s);

     return width;
}

  parent reply	other threads:[~2012-09-05 19:25 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-03 11:10 [PATCH] fetch: align new ref summary printout in UTF-8 locales Nguyễn Thái Ngọc Duy
2012-09-03 19:26 ` Junio C Hamano
2012-09-03 20:01   ` Johannes Sixt
2012-09-03 20:30     ` Junio C Hamano
2012-09-04  1:31   ` Nguyen Thai Ngoc Duy
2012-09-04 10:39 ` [PATCH v2] " Nguyễn Thái Ngọc Duy
     [not found]   ` <504796A5.4070700@gmail.com>
2012-09-05 19:20     ` Torsten Bögershausen [this message]
2012-09-06 12:11       ` Nguyen Thai Ngoc Duy
2012-09-06 15:36       ` Nguyen Thai Ngoc Duy
2012-09-06 16:21         ` Torsten Bögershausen
2012-09-06 18:08           ` Junio C Hamano
2012-09-12 14:02   ` Nguyen Thai Ngoc Duy
2012-09-12 18:02     ` Junio C Hamano
2012-09-12 20:12       ` Torsten Bögershausen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5047A602.1020802@web.de \
    --to=tboegi@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=pclouds@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).