git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Eric Sunshine <sunshine@sunshineco.com>
To: Lars Schneider <lars.schneider@autodesk.com>
Cc: "Git List" <git@vger.kernel.org>,
	"Junio C Hamano" <gitster@pobox.com>,
	"Torsten Bögershausen" <tboegi@web.de>,
	"Johannes Sixt" <j6t@kdbg.org>, "Jeff King" <peff@peff.net>,
	"Ramsay Jones" <ramsay@ramsayjones.plus.com>,
	"Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
	"Lars Schneider" <larsxschneider@gmail.com>
Subject: Re: [PATCH v12 04/10] utf8: teach same_encoding() alternative UTF encoding names
Date: Thu, 15 Mar 2018 19:25:16 -0400	[thread overview]
Message-ID: <CAPig+cSvBi1pJYC-DND1_x9rHhmoAPs90B_3Fg53-X5FjtCQhA@mail.gmail.com> (raw)
In-Reply-To: <20180315225746.18119-5-lars.schneider@autodesk.com>

On Thu, Mar 15, 2018 at 6:57 PM,  <lars.schneider@autodesk.com> wrote:
> The function same_encoding() checked only for alternative UTF-8 encoding
> names. Teach it to check for all kinds of alternative UTF encoding
> names.
>
> Signed-off-by: Lars Schneider <larsxschneider@gmail.com>
> ---
> diff --git a/utf8.c b/utf8.c
> @@ -401,11 +401,27 @@ void strbuf_utf8_replace(struct strbuf *sb_src, int pos, int width,
> +static int same_utf_encoding(const char *src, const char *dst)
> +{
> +       if (istarts_with(src, "utf") && istarts_with(dst, "utf")) {
> +               /* src[3] or dst[3] might be '\0' */
> +               int i = (src[3] == '-' ? 4 : 3);
> +               int j = (dst[3] == '-' ? 4 : 3);
> +               return !strcasecmp(src+i, dst+j);
> +       }
> +       return 0;
> +}

Alternate implementation without magic numbers:

    if (iskip_prefix(src, "utf", &src) &&
        iskip_prefix(dst, "utf", &dst)) {
        if (*src == '-')
            src++;
        if (*dst == '-')
            dst++;
        return !strcasecmp(src, dst);
    }
    return 0;

... assuming you add an iskip_prefix() function (patterned after skip_prefix()).

>  int is_encoding_utf8(const char *name)
>  {
>         if (!name)
>                 return 1;
> -       if (!strcasecmp(name, "utf-8") || !strcasecmp(name, "utf8"))
> +       if (same_utf_encoding("utf-8", name))
>                 return 1;
>         return 0;
>  }
> @@ -414,6 +430,8 @@ int same_encoding(const char *src, const char *dst)
>  {
>         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);

?

  reply	other threads:[~2018-03-15 23:25 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-15 22:57 [PATCH v12 00/10] convert: add support for different encodings lars.schneider
2018-03-15 22:57 ` [PATCH v12 01/10] strbuf: remove unnecessary NUL assignment in xstrdup_tolower() lars.schneider
2018-03-15 22:57 ` [PATCH v12 02/10] strbuf: add xstrdup_toupper() lars.schneider
2018-03-15 22:57 ` [PATCH v12 03/10] strbuf: add a case insensitive starts_with() lars.schneider
2018-03-16 17:33   ` Morten Welinder
2018-03-16 17:39     ` Junio C Hamano
2018-03-15 22:57 ` [PATCH v12 04/10] utf8: teach same_encoding() alternative UTF encoding names lars.schneider
2018-03-15 23:25   ` Eric Sunshine [this message]
2018-03-15 23:35     ` Lars Schneider
2018-03-15 23:54       ` Eric Sunshine
2018-03-16 17:50         ` Junio C Hamano
2018-03-16 18:19           ` Eric Sunshine
2018-04-01 14:18             ` Lars Schneider
2018-03-15 22:57 ` [PATCH v12 05/10] utf8: add function to detect prohibited UTF-16/32 BOM lars.schneider
2018-03-15 22:57 ` [PATCH v12 06/10] utf8: add function to detect a missing " lars.schneider
2018-03-15 22:57 ` [PATCH v12 07/10] convert: add 'working-tree-encoding' attribute lars.schneider
2018-03-15 22:57 ` [PATCH v12 08/10] convert: check for detectable errors in UTF encodings lars.schneider
2018-03-15 22:57 ` [PATCH v12 09/10] convert: add tracing for 'working-tree-encoding' attribute lars.schneider
2018-03-15 22:57 ` [PATCH v12 10/10] convert: add round trip check based on 'core.checkRoundtripEncoding' lars.schneider
2018-03-29 18:37 ` [PATCH v12 00/10] convert: add support for different encodings Junio C Hamano
2018-04-02 18:31   ` Lars Schneider
2018-04-03  8:37     ` Lars Schneider

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAPig+cSvBi1pJYC-DND1_x9rHhmoAPs90B_3Fg53-X5FjtCQhA@mail.gmail.com \
    --to=sunshine@sunshineco.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j6t@kdbg.org \
    --cc=lars.schneider@autodesk.com \
    --cc=larsxschneider@gmail.com \
    --cc=pclouds@gmail.com \
    --cc=peff@peff.net \
    --cc=ramsay@ramsayjones.plus.com \
    --cc=tboegi@web.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).