From ebf77c636de88efc2257ddda9584a48fd36b1394 Mon Sep 17 00:00:00 2001 From: Kubo Kovac <733205+kuk0@users.noreply.github.com> Date: Thu, 24 Jun 2021 00:45:45 +0200 Subject: [PATCH] fix parsing headers 48105b07 see https://github.com/arq5x/bedtools2/commit/48105b07dc665d333a06677aed8340f82decacd7# that commit broke reading correct BED files --- src/utils/general/ParseTools.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/utils/general/ParseTools.cpp b/src/utils/general/ParseTools.cpp index 704585d3f..2a773a4eb 100644 --- a/src/utils/general/ParseTools.cpp +++ b/src/utils/general/ParseTools.cpp @@ -94,22 +94,21 @@ bool isHeaderLine(const string &line) { if (line[0] == '#') { return true; } - + + const char* full_text = NULL; + bool require_space = false; if(line.length() > 4) { uint32_t peek = *(uint32_t*)line.c_str() | 0x20202020u; - const char* full_text = NULL; - bool require_space = false; - bool require_digit = false; + switch(peek) { case 0x6f726863: full_text = "chrom"; require_space = true; - require_digit = false; break; case 0x20726863: - case 0x09726863: + case 0x29726863: full_text = "chr"; - require_space = require_digit = true; + require_space = true; break; case 0x776f7262: full_text = "browser"; @@ -130,8 +129,7 @@ bool isHeaderLine(const string &line) { if(c >= 'A' && c <= 'Z') c += 32; if(c != *full_text) return false; } - if(require_space && !isspace(*(ptr++))) return false; - if(require_digit && !isdigit(*(ptr++))) return false; + if(require_space && (!isspace(*(ptr++)) || isdigit(*ptr))) return false; return true; } }