tboegi@xxxxxx:
+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/