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

Re: [PATCH v12 04/10] utf8: teach same_encoding() alternative UTF encoding names

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Mar 15, 2018, 23:54 UTC
Message-ID
<CAPig+cQpDKHwzjCHpka+v1uGaJNfJGSmXpAVwPWVXSf5F1pR-g@mail.gmail.com>
In-Reply-To
<328BE614-1927-450A-85D1-7391D0BB5C47@gmail.com>

On Thu, Mar 15, 2018 at 7:35 PM, Lars Schneider <larsxschneider@gmail.com> wrote:

Show 22 quoted lines
>> On 16 Mar 2018, at 00:25, Eric Sunshine <sunshine@sunshineco.com> wrote:
>>>        if (is_encoding_utf8(src) && is_encoding_utf8(dst))
>>>                return 1;
>>> +       if (same_utf_encoding(src, dst))
>>> +               return 1;
>>>        return !strcasecmp(src, dst);
>>> }
>>
>> This seems odd. I would have expected the newly-added generalized
>> conditional to replace the original UTF-8-specific conditional, not
>> supplement it. That is, shouldn't the entire function body be:
>>
>>    if (same_utf_encoding(src, dst))
>>        return 1;
>>    return !strcasecmp(src, dst);
>
> No, because is_encoding_utf8() returns "true" (=1) if the encoding
> is NULL. That is not the case for UTF-16 et al. The caller of
> same_encoding() might expect that behavior.
> I could have moved the "UTF-8" == NULL assumption into
> same_utf_encoding() but that did not feel right.
> Does this make sense?
Not particularly.

Looking at 677cfed56a (commit-tree: cope with different ways "utf-8" can be spelled., 2006-12-30), which introduced is_encoding_utf8() along with its builtin NULL-check, I can see why that function wants to treat NULL the same as UTF-8.

However, I'm having a tough time imagining cases in which callers would want same_encoding() to return true if both arguments are NULL, but outright crash if only one is NULL (which is the behavior even before this patch). In other words, same_encoding() takes advantage of is_encoding_utf8() for its convenience, not for its NULL-handling. Given that view, the two explicit is_encoding_utf8() calls in same_encoding() seem redundant once the same_utf_encoding() call is added.

Previous: Lars SchneiderNext: Junio C Hamano
Message 10 of 22 in “convert: add support for different encodings”
  1. 00/10 convert: add support for different encodingslars.schneider@autodesk.com, Mar 15, 2018
  2. 01/10 strbuf: remove unnecessary NUL assignment in xstrdup_tolower()lars.schneider@autodesk.com, Mar 15, 2018
  3. 02/10 strbuf: add xstrdup_toupper()lars.schneider@autodesk.com, Mar 15, 2018
  4. 03/10 strbuf: add a case insensitive starts_with()lars.schneider@autodesk.com, Mar 15, 2018
  5. Morten WelinderMar 16, 2018
  6. Junio C HamanoMar 16, 2018
  7. 04/10 utf8: teach same_encoding() alternative UTF encoding nameslars.schneider@autodesk.com, Mar 15, 2018
  8. Eric SunshineMar 15, 2018
  9. Lars SchneiderMar 15, 2018
  10. Eric SunshineMar 15, 2018
  11. Junio C HamanoMar 16, 2018
  12. Eric SunshineMar 16, 2018
  13. Lars SchneiderApr 1, 2018
  14. 05/10 utf8: add function to detect prohibited UTF-16/32 BOMlars.schneider@autodesk.com, Mar 15, 2018
  15. 06/10 utf8: add function to detect a missing UTF-16/32 BOMlars.schneider@autodesk.com, Mar 15, 2018
  16. 07/10 convert: add 'working-tree-encoding' attributelars.schneider@autodesk.com, Mar 15, 2018
  17. 08/10 convert: check for detectable errors in UTF encodingslars.schneider@autodesk.com, Mar 15, 2018
  18. 10/10 convert: add round trip check based on 'core.checkRoundtripEncoding'lars.schneider@autodesk.com, Mar 15, 2018
  19. 09/10 convert: add tracing for 'working-tree-encoding' attributelars.schneider@autodesk.com, Mar 15, 2018
  20. Junio C HamanoMar 29, 2018
  21. Lars SchneiderApr 2, 2018
  22. Lars SchneiderApr 3, 2018

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.