Skip to content

Commit

Permalink
Reusing code of quoted instead of duplicating.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertoCasasOrtiz committed Feb 23, 2021
1 parent 1bbf958 commit 70014aa
Showing 1 changed file with 28 additions and 40 deletions.
68 changes: 28 additions & 40 deletions vcf.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,50 +426,38 @@ bcf_hrec_t *bcf_hdr_parse_line(const bcf_hdr_t *h, const char *line, int *len)
if (bcf_hrec_add_key(hrec, p, q-p-m) < 0) goto fail;
p = ++q;
while ( *q && *q==' ' ) { p++; q++; }
int quoted = *p=='"' ? 1 : 0;
int bracketed = *p=='[' ? 1 : 0;
if ( bracketed ) {
p++, q++;
while ( *q && *q != '\n' )
{
if ( bracketed ) { if ( *q==']' && !is_escaped(p,q) ) break; }
else
{
if ( *q=='<' ) nopen++;
if ( *q=='>' ) nopen--;
if ( !nopen ) break;
if ( *q==',' && nopen==1 ) break;
}
q++;
}
const char *r = q;
while ( r > p && r[-1] == ' ' ) r--;
if (bcf_hrec_set_val(hrec, hrec->nkeys-1, p, r-p, bracketed) < 0)
goto fail;
if ( bracketed && *q==']' ) q++;
if ( *q=='>' ) { nopen--; q++; }
} else

int quoted = 0;
char ending;
switch (*p) {
case '"':
quoted = 1;
ending = '"';
break;
case '[':
quoted = 1;
ending = ']';
break;
}
if ( quoted ) p++, q++;
while ( *q && *q != '\n' )
{
if ( quoted ) p++, q++;
while ( *q && *q != '\n' )
if ( quoted ) { if ( *q==ending && !is_escaped(p,q) ) break; }
else
{
if ( quoted ) { if ( *q=='"' && !is_escaped(p,q) ) break; }
else
{
if ( *q=='<' ) nopen++;
if ( *q=='>' ) nopen--;
if ( !nopen ) break;
if ( *q==',' && nopen==1 ) break;
}
q++;
if ( *q=='<' ) nopen++;
if ( *q=='>' ) nopen--;
if ( !nopen ) break;
if ( *q==',' && nopen==1 ) break;
}
const char *r = q;
while ( r > p && r[-1] == ' ' ) r--;
if (bcf_hrec_set_val(hrec, hrec->nkeys-1, p, r-p, quoted) < 0)
goto fail;
if ( quoted && *q=='"' ) q++;
if ( *q=='>' ) { nopen--; q++; }
q++;
}
const char *r = q;
while ( r > p && r[-1] == ' ' ) r--;
if (bcf_hrec_set_val(hrec, hrec->nkeys-1, p, r-p, quoted) < 0)
goto fail;
if ( quoted && *q==ending ) q++;
if ( *q=='>' ) { nopen--; q++; }
}

// Skip to end of line
Expand Down

0 comments on commit 70014aa

Please sign in to comment.