Re: [PATCH/RFC 1/1] Auto diff of UTF-16 files in UTF-8
- From
Peter Krefting <peter@softwolves.pp.se>
- Date
- Feb 26, 2018, 18:43 UTC
- Message-ID
- <alpine.DEB.2.00.1802261939390.15209@ds9.cixit.se>
- In-Reply-To
- <20180226172706.7822-1-tboegi@web.de>
tboegi@web.de:
Show 10 quoted lines
> +static inline int buffer_has_utf16_bom(const void *buf, size_t len) {
> + const unsigned char *text = (unsigned char *)buf;
> + if (!text || len < 2)
> + return 0;
> + if (text[0] == 0xff && text[1] == 0xfe)
> + return 1;
> + if (text[0] == 0xfe && text[1] == 0xff)
> + return 1;
> + return 0;
> +}This would also match a UTF-32LE BOM, not that I think anyone would actually use that for text files, but it might be worth adding a test for that, just in case?
if (text[0] == 0xff && text[1] == 0xfe)
return len < 4 || (text[2] != 0 && text[3] != 0);-- \\// Peter - http://www.softwolves.pp.se/