X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=utf8.h;h=db73a2d8d374e7570471627693ecddc87d998f10;hb=7913f53b5628997165e075008d6142da1c04271a;hp=da19b431143ec125428c74fbaafac167548372c2;hpb=fc54c1af3ec09bab8b8ea09768c2da4069b7f53e;p=thirdparty%2Fgit.git diff --git a/utf8.h b/utf8.h index da19b43114..db73a2d8d3 100644 --- a/utf8.h +++ b/utf8.h @@ -75,4 +75,32 @@ typedef enum { void strbuf_utf8_align(struct strbuf *buf, align_type position, unsigned int width, const char *s); +/* + * If a data stream is declared as UTF-16BE or UTF-16LE, then a UTF-16 + * BOM must not be used [1]. The same applies for the UTF-32 equivalents. + * The function returns true if this rule is violated. + * + * [1] http://unicode.org/faq/utf_bom.html#bom10 + */ +int has_prohibited_utf_bom(const char *enc, const char *data, size_t len); + +/* + * If the endianness is not defined in the encoding name, then we + * require a BOM. The function returns true if a required BOM is missing. + * + * The Unicode standard instructs to assume big-endian if there in no + * BOM for UTF-16/32 [1][2]. However, the W3C/WHATWG encoding standard + * used in HTML5 recommends to assume little-endian to "deal with + * deployed content" [3]. + * + * Therefore, strictly requiring a BOM seems to be the safest option for + * content in Git. + * + * [1] http://unicode.org/faq/utf_bom.html#gen6 + * [2] http://www.unicode.org/versions/Unicode10.0.0/ch03.pdf + * Section 3.10, D98, page 132 + * [3] https://encoding.spec.whatwg.org/#utf-16le + */ +int is_missing_required_utf_bom(const char *enc, const char *data, size_t len); + #endif