Skip to content

Commit

Permalink
Factor out common code.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwsw committed Oct 20, 2017
1 parent a4cf344 commit 3af9450
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
9 changes: 1 addition & 8 deletions charset.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,14 +571,7 @@ utf_bin_count(data, len)
{
if (is_utf8_well_formed(data, edata-data))
{
LWCHAR c = step_char(&data, +1, edata);
if (ctldisp == OPT_ONPLUS && IS_CSI_START(c))
{
do {
c = step_char(&data, +1, edata);
} while (data < edata && is_ansi_middle(c));
}
if (binary_char(c))
if (bin_char_in_string(&data, edata))
bin_count++;
} else /* invalid UTF-8 */
{
Expand Down
28 changes: 21 additions & 7 deletions filename.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,13 +477,7 @@ bin_file(f)
pend = &data[n];
for (p = data; p < pend; )
{
LWCHAR c = step_char(&p, +1, pend);
if (ctldisp == OPT_ONPLUS && IS_CSI_START(c))
{
do {
c = step_char(&p, +1, pend);
} while (p < pend && is_ansi_middle(c));
} else if (binary_char(c))
if (bin_char_in_string(&p, pend))
bin_count++;
}
}
Expand All @@ -494,6 +488,26 @@ bin_file(f)
return (bin_count > 5);
}

/*
* Determine if the next char in a string is binary.
*/
public int
bin_char_in_string(pp, limit)
char **pp;
constant char *limit;
{
LWCHAR c = step_char(pp, +1, limit);
if (ctldisp == OPT_ONPLUS && IS_CSI_START(c))
{
/* Skip the CSI sequence. */
do {
c = step_char(pp, +1, limit);
} while (*pp < limit && is_ansi_middle(c));
} else if (binary_char(c))
return (1);
return (0);
}

/*
* Try to determine the size of a file by seeking to the end.
*/
Expand Down

0 comments on commit 3af9450

Please sign in to comment.