diff options
author | Russell Belfer <rb@github.com> | 2012-11-28 21:58:48 +0400 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2012-11-28 21:58:48 +0400 |
commit | 7bf87ab6987cf6b9e166e23d2d9dbdcd2511fb32 (patch) | |
tree | dcc8a92ce69b2a0d9d8cca98d67f0cc71177ce40 /src/config_file.c | |
parent | 693021262ba0eeac2923bbce1b2262717019c807 (diff) |
Consolidate text buffer functions
There are many scattered functions that look into the contents of
buffers to do various text manipulations (such as escaping or
unescaping data, calculating text stats, guessing if content is
binary, etc). This groups all those functions together into a
new file and converts the code to use that.
This has two enhancements to existing functionality. The old
text stats function is significantly rewritten and the BOM
detection code was extended (although largely we can't deal with
anything other than a UTF8 BOM).
Diffstat (limited to 'src/config_file.c')
-rw-r--r-- | src/config_file.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/config_file.c b/src/config_file.c index 7cc812aa4..354a91986 100644 --- a/src/config_file.c +++ b/src/config_file.c @@ -10,6 +10,7 @@ #include "fileops.h" #include "filebuf.h" #include "buffer.h" +#include "buf_text.h" #include "git2/config.h" #include "git2/types.h" #include "strmap.h" @@ -854,17 +855,14 @@ fail_parse: static int skip_bom(diskfile_backend *cfg) { - static const char utf8_bom[] = { '\xef', '\xbb', '\xbf' }; + git_bom_t bom; + int bom_offset = git_buf_text_detect_bom(&bom, + &cfg->reader.buffer, cfg->reader.read_ptr - cfg->reader.buffer.ptr); - if (cfg->reader.buffer.size < sizeof(utf8_bom)) - return 0; - - if (memcmp(cfg->reader.read_ptr, utf8_bom, sizeof(utf8_bom)) == 0) - cfg->reader.read_ptr += sizeof(utf8_bom); + if (bom == GIT_BOM_UTF8) + cfg->reader.read_ptr += bom_offset; - /* TODO: the reference implementation does pretty stupid - stuff with the BoM - */ + /* TODO: reference implementation is pretty stupid with BoM */ return 0; } |