git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Nguyen Thai Ngoc Duy <pclouds@gmail.com>
Date
Sep 6, 2012, 12:11 UTC
Message-ID
<CACsJy8A60Os1pupMQdi44vnmO+E_ZqtvTELCOR1GeHSPdZeo5g@mail.gmail.com>
In-Reply-To
<5047A602.1020802@web.de>
On Thu, Sep 6, 2012 at 2:20 AM, Torsten Bögershausen <tboegi@web.de> wrote:
Show 17 quoted lines
> 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?

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.

Show 23 quoted lines
> (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
Previous: Torsten BögershausenNext: Nguyen Thai Ngoc Duy
Message 11 of 14 in “fetch: align new ref summary printout in UTF-8 locales”
  1. fetch: align new ref summary printout in UTF-8 localesNguyễn Thái Ngọc Duy, Sep 3, 2012
  2. Junio C HamanoSep 3, 2012
  3. Johannes SixtSep 3, 2012
  4. Junio C HamanoSep 3, 2012
  5. Nguyen Thai Ngoc DuySep 4, 2012
  6. fetch: align new ref summary printout in UTF-8 localesNguyễn Thái Ngọc Duy, Sep 4, 2012
  7. Nguyen Thai Ngoc DuySep 12, 2012
  8. Junio C HamanoSep 12, 2012
  9. Torsten BögershausenSep 12, 2012
  10. Torsten BögershausenSep 5, 2012
  11. Nguyen Thai Ngoc DuySep 6, 2012
  12. Nguyen Thai Ngoc DuySep 6, 2012
  13. Torsten BögershausenSep 6, 2012
  14. Junio C HamanoSep 6, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.