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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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;
}

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]