From dde843e7378f65004415bd108038659de9ce2abd Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 16 Apr 2015 10:45:29 -0700 Subject: utf8-bom: introduce skip_utf8_bom() helper With the recent change to ignore the UTF8 BOM at the beginning of .gitignore files, we now have two codepaths that do such a skipping (the other one is for reading the configuration files). Introduce utf8_bom[] constant string and skip_utf8_bom() helper and teach .gitignore code how to use it. Signed-off-by: Junio C Hamano --- utf8.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'utf8.c') diff --git a/utf8.c b/utf8.c index 520fbb4994..28e6d76a42 100644 --- a/utf8.c +++ b/utf8.c @@ -633,3 +633,14 @@ int is_hfs_dotgit(const char *path) return 1; } + +const char utf8_bom[] = "\357\273\277"; + +int skip_utf8_bom(char **text, size_t len) +{ + if (len < strlen(utf8_bom) || + memcmp(*text, utf8_bom, strlen(utf8_bom))) + return 0; + *text += strlen(utf8_bom); + return 1; +} -- cgit v1.2.1