Re: [PATCH 2/4] Do attempt pretty print in ASCII-incompatible encodings
- From
Nguyen Thai Ngoc Duy <pclouds@gmail.com>
- Date
- Feb 21, 2012, 14:53 UTC
- Message-ID
- <CACsJy8C30mTFwduiSv_z458DgDBb0O=Jn19qMSwkAHuFadtBMg@mail.gmail.com>
- In-Reply-To
- <1329834292-2511-2-git-send-email-pclouds@gmail.com>
2012/2/21 Nguyễn Thái Ngọc Duy <pclouds@gmail.com>:
Show 19 quoted lines
> @@ -482,3 +482,18 @@ char *reencode_string(const char *in, const char *out_encoding, const char *in_e
> return out;
> }
> #endif
> +
> +int ascii_superset_encoding(const char *encoding)
> +{
> + const char *sample = " !\"#$%&'()*+,-./0123456789:;<=>?@"
> + "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`"
> + "abcdefghijklmnopqrstuvwxyz{|}~\n";
> + char *output;
> + int ret;
> + if (!encoding)
> + return 1;
> + output = reencode_string(sample, encoding, "US-ASCII");
> + ret = !output || !strcmp(sample, output);
> + free(output);
> + return ret;
> +}Side note about this function, which was written to ban all ascii-incompatible charsets from entering commit objects. The idea of mixing charsets in the same buffer without clear boundary does not sound healthy. Plus, ident.c will silently drop '\n', '<' and '>' in author/committer. If a hypothetical charset happens to place a letter in those, um.. code points?, the letter will be dropped. But meh..
-- Duy