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
Lars Schneider <larsxschneider@gmail.com>
Date
Apr 1, 2018, 14:18 UTC
Message-ID
<3CF5EC69-3DBD-4BC6-8D89-F6437A4686A0@gmail.com>
In-Reply-To
<CAPig+cS2xRPP9P7GZMgkKzE899AQiMkkpNsGeB-MwmAymAzCiQ@mail.gmail.com>
Show 35 quoted lines
> On 16 Mar 2018, at 19:19, Eric Sunshine <sunshine@sunshineco.com> wrote:
> 
> On Fri, Mar 16, 2018 at 1:50 PM, Junio C Hamano <gitster@pobox.com> wrote:
>> Eric Sunshine <sunshine@sunshineco.com> writes:
>>> 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.
>> 
>> So... does that mean we'd want something like this, or do you have
>> something else in mind?
>> 
>>        int same_encoding(const char *src, const char *dst)
>>        {
>>                static const char utf8[] = "UTF-8";
>> 
>>                if (!src)
>>                        src = utf8;
>>                if (!dst)
>>                        dst = utf8;
>>                if (same_utf_encoding(src, dst))
>>                        return 1;
>>                return !strcasecmp(src, dst);
>>        }
> 
> I am not proposing anything like that for this patch or patch series.
> I'm merely asking why, after this patch, same_encoding() still
> contains the (in my mind) now-unneeded conditional:
> 
>    if (is_encoding_utf8(src) && is_encoding_utf8(dst))
>        return 1;

My main motivation was to keep the existing behavior "as-is" to avoid any regressions.

However, I agree with your critic of the inconsistencies. 

Therefore, I will use Junio's suggestion above as it makes the intented behaivior clear.

Thanks, Lars

Previous: Eric SunshineNext: lars.schneider@autodesk.com
Message 13 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.