git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
	"Ævar Arnfjörð" <avarab@gmail.com>,
	"SZEDER Gábor" <szeder.dev@gmail.com>,
	"Johannes Schindelin" <johannes.schindelin@gmx.de>
Subject: Re: [PATCH 02/11] Support GIT_TEST_GETTEXT_POISON=rot13
Date: Tue, 12 Jan 2021 11:37:37 -0800	[thread overview]
Message-ID: <xmqqmtxe3q0u.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <ab7832fc7ac783bc8f8c10014fc9747128fc37bc.1610441263.git.gitgitgadget@gmail.com> (Johannes Schindelin via GitGitGadget's message of "Tue, 12 Jan 2021 08:47:33 +0000")

"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
writes:

> +const char *gettext_maybe_rot13(const char *msgid)
> +{
> +...
> +	while (*msgid) {
> +		const char *p = strchrnul(msgid, '%'), *spec;
> +
> +		while (*p && p[1] == '%')
> +			p = strchrnul(p + 2, '%');

We are at '%', and while the next is '%' (i.e. a literal '%' is
asked), we skip these two bytes and then we go back to the
equivalent of the initialization of 'p'.  Effects?  We leave the
loop when we are at the end of the string, or at '%' that is not
followed by a '%'.

It would have been easier to understand what is going on in the loop
if there weren't duplicated strchrnul() call, perhaps

	const char *p = msgid;
	while (*(p = strchrnul(p, '%')) == '%' && p[1] == '%')
        	p += 2;

That reads "find '%' and if the next char is also '%', skip these
two and redo the loop", which would be equivalent.  And it would be
much easier to follow the logic.

> +		if (p != msgid) {

And if 'p' is different (actually we know p is the same as, or
always ahead of, msgid, so "if (msgid < p)" would be easier to
follow for readers) ...

> +			strbuf_addstr(buf, "<rot13>");
> +			while (p != msgid)

Ditto.

> +				strbuf_addch(buf, do_rot13(*(msgid++)));
> +			strbuf_addstr(buf, "</rot13>");

... we add a section of obfuscated output enclosed with an xml
looking marker.

> +		}
> +
> +		if (!*p)
> +			break;

And if we are at the end, we are done.

> +		spec = strpbrk(p + 1, "diouxXeEfFgGaAcsCSpnm%");
> +		if (!spec)
> +			BUG("Unrecognized format string: %s", p);

It is a bit surprising that things like "%.*d" and "%.7f" do not
appear in our translatable strings (or perhaps this is one of the
places why the series is marked RFH and is not complete?).

> +		strbuf_add(buf, p, spec + 1 - p);
> +		msgid = spec + 1;
> +	}
> +
> +	return buf->buf;
> +}

Anyway, thanks for a fun reading.


  reply	other threads:[~2021-01-12 19:40 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-12  8:47 [PATCH 00/11] [RFH] Introduce support for GETTEXT_POISON=rot13 Johannes Schindelin via GitGitGadget
2021-01-12  8:47 ` [PATCH 01/11] tests: remove unnecessary GIT_TEST_GETTEXT_POISON=false constructs Johannes Schindelin via GitGitGadget
2021-01-12  9:07   ` SZEDER Gábor
2021-01-12  8:47 ` [PATCH 02/11] Support GIT_TEST_GETTEXT_POISON=rot13 Johannes Schindelin via GitGitGadget
2021-01-12 19:37   ` Junio C Hamano [this message]
2021-01-12  8:47 ` [PATCH 03/11] parse-options: add forgotten translations Johannes Schindelin via GitGitGadget
2021-01-12  8:47 ` [PATCH 04/11] sha1dc: mark forgotten message for translation Johannes Schindelin via GitGitGadget
2021-01-12 11:37   ` Jeff King
2021-01-12 19:40     ` Junio C Hamano
2021-01-15 15:43     ` Johannes Schindelin
2021-01-15 16:29       ` Jeff King
2021-01-18 14:26         ` Johannes Schindelin
2021-01-18 21:06           ` Junio C Hamano
2021-01-19 15:52             ` Johannes Schindelin
2021-01-12  8:47 ` [PATCH 05/11] t0006: use `test_i18ncmp` only for C locales Johannes Schindelin via GitGitGadget
2021-01-12  8:47 ` [PATCH 06/11] t0041: stop using `test_i18ngrep` on untranslated output Johannes Schindelin via GitGitGadget
2021-01-12  8:47 ` [PATCH 07/11] t0027: mark a function as requiring the C locale Johannes Schindelin via GitGitGadget
2021-01-12  8:47 ` [PATCH 08/11] t6301: do not expect the output of `for-each-ref` to be translated Johannes Schindelin via GitGitGadget
2021-01-12  8:47 ` [PATCH 09/11] GETTEXT_POISON=rot13: do compare the output in `test_i18ncmp` Johannes Schindelin via GitGitGadget
2021-01-12 19:47   ` Junio C Hamano
2021-01-15 15:44     ` Johannes Schindelin
2021-01-15 19:58       ` Junio C Hamano
2021-01-18 14:36         ` Johannes Schindelin
2021-01-12  8:47 ` [PATCH 10/11] GETTEXT_POISON=rot13: perform actual checks in `test_i18ngrep` Johannes Schindelin via GitGitGadget
2021-01-12  8:47 ` [PATCH 11/11] test-tool i18n: do not complain about empty messages Johannes Schindelin via GitGitGadget
2021-01-12 11:34 ` [PATCH 00/11] [RFH] Introduce support for GETTEXT_POISON=rot13 Jeff King
2021-01-12 19:50   ` Junio C Hamano
2021-01-13  7:32     ` Jeff King
2021-01-16  6:38     ` Junio C Hamano
2021-01-12 13:32 ` Ævar Arnfjörð Bjarmason
2021-01-15 16:13   ` Johannes Schindelin

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=xmqqmtxe3q0u.fsf@gitster.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=johannes.schindelin@gmx.de \
    --cc=pclouds@gmail.com \
    --cc=szeder.dev@gmail.com \
    /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).