Thread (25 messages) 25 messages, 7 authors, 2018-02-27

Re: [PATCH/RFC 1/1] Auto diff of UTF-16 files in UTF-8

From: Peter Krefting <hidden>
Date: 2018-02-26 18:51:24

tboegi@web.de:
+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/
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help