diff --git a/hts.c b/hts.c index 5ceb44173..cb911c002 100644 --- a/hts.c +++ b/hts.c @@ -1869,6 +1869,12 @@ long long hts_parse_decimal(const char *str, char **strend, int flags) } const char *hts_parse_reg(const char *s, int *beg, int *end) +{ + return hts_parse_region(s, NULL, beg, end, HTS_PARSE_THOUSANDS_SEP); +} + +const char * +hts_parse_region(const char *s, char **strend, int *beg, int *end, int flags) { char *hyphen; const char *colon = strrchr(s, ':'); @@ -1877,11 +1883,12 @@ const char *hts_parse_reg(const char *s, int *beg, int *end) return s + strlen(s); } - *beg = hts_parse_decimal(colon+1, &hyphen, HTS_PARSE_THOUSANDS_SEP) - 1; + *beg = hts_parse_decimal(colon+1, &hyphen, flags) - 1; if (*beg < 0) *beg = 0; + // FIXME \0 vs. return NULL if (*hyphen == '\0') *end = INT_MAX; - else if (*hyphen == '-') *end = hts_parse_decimal(hyphen+1, NULL, HTS_PARSE_THOUSANDS_SEP); + else if (*hyphen == '-') *end = hts_parse_decimal(hyphen+1, strend, flags); else return NULL; if (*beg >= *end) return NULL; diff --git a/htslib/hts.h b/htslib/hts.h index 6962013d7..964cd1259 100644 --- a/htslib/hts.h +++ b/htslib/hts.h @@ -494,14 +494,23 @@ hts_idx_t *hts_idx_load2(const char *fn, const char *fnidx); */ long long hts_parse_decimal(const char *str, char **strend, int flags); +/// Equivalent to hts_parse_region(str, NULL, beg, end, HTS_PARSE_THOUSANDS_SEP) +const char *hts_parse_reg(const char *str, int *beg, int *end); + /// Parse a "CHR:START-END"-style region string -/** @param str String to be parsed - @param beg Set on return to the 0-based start of the region - @param end Set on return to the 1-based end of the region - @return Pointer to the colon or '\0' after the reference sequence name, - or NULL if @a str could not be parsed. +/** @param str String to be parsed + @param strend If non-NULL, set on return to point to the first character + in @a str after those forming the parsed region + @param beg Set on return to the 0-based start of the region + @param end Set on return to the 1-based end of the region + @param flags Or'ed-together combination of HTS_PARSE_* flags + @return Pointer to the colon or terminating character after the reference + sequence name, or NULL if @a str could not be parsed. + + When @a strend is NULL, a warning will be printed (if hts_verbose is 2 + or more) if there are any trailing characters after the region string. */ -const char *hts_parse_reg(const char *str, int *beg, int *end); +const char *hts_parse_region(const char *str, char **strend, int *beg, int *end, int flags); hts_itr_t *hts_itr_query(const hts_idx_t *idx, int tid, int beg, int end, hts_readrec_func *readrec); void hts_itr_destroy(hts_itr_t *iter);