Re: [PATCH v2] fetch: align new ref summary printout in UTF-8 locales

4 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH v2] fetch: align new ref summary printout in UTF-8 locales

From: Torsten Bögershausen <hidden>
Date: 2016-06-15 22:54:38

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:
quoted
+/* 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;
}

Re: [PATCH v2] fetch: align new ref summary printout in UTF-8 locales

From: Nguyen Thai Ngoc Duy <hidden>
Date: 2016-06-15 22:54:38

On Thu, Sep 6, 2012 at 2:20 AM, Torsten Bögershausen [off-list ref] wrote:
On 09/05/2012 08:15 PM, Torsten Bögershausen wrote:
quoted
On 04.09.12 12:39, Nguyễn Thái Ngọc Duy wrote:
quoted
+/* 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?
No it does not. I think I mentioned that in the first version that I
was only interested in utf-8. Others can extend the function for their
favourite encodings.
(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;
}
Yes, something like that, assuming that column information is intact
after the conversion. Maybe you can make that a new function, int
strwidth(const char *str, const char *charset), and make
gettext_strwidth() a thin wrapper:

int gettext_strwidth(const char *s)
{
   return strwidth(s, charset);
}
-- 
Duy

Re: [PATCH v2] fetch: align new ref summary printout in UTF-8 locales

From: Nguyen Thai Ngoc Duy <hidden>
Date: 2016-06-15 22:54:38

On Thu, Sep 6, 2012 at 2:20 AM, Torsten Bögershausen [off-list ref] wrote:
quoted
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?
BTW if you are interested in supporting non-utf8 output, you may want
to look at 1452bd6 (branch -v: align even when branch names are in
UTF-8 - 2012-08-26), which assumes branches are in utf-8. So you have
to convert them to output charset before printing.
-- 
Duy

Re: [PATCH v2] fetch: align new ref summary printout in UTF-8 locales

From: Torsten Bögershausen <hidden>
Date: 2016-06-15 22:54:38

Am 06.09.2012 um 17:36 schrieb Nguyen Thai Ngoc Duy:
On Thu, Sep 6, 2012 at 2:20 AM, Torsten Bögershausen [off-list ref] wrote:
quoted
quoted
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?
BTW if you are interested in supporting non-utf8 output, you may want
to look at 1452bd6 (branch -v: align even when branch names are in
UTF-8 - 2012-08-26), which assumes branches are in utf-8. So you have
to convert them to output charset before printing.
-- 
Duy
Thanks,
I try to re-phrase my question:

Do installations still exist which use e.g. BIG5 or any other
multi byte encoding which is not UTF-8?

Do we want to support other encodings than ASCII or UTF-8?
(Because then the screen width needs to be calculate different, I think)

/Torsten
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help