diff --git a/charset.c b/charset.c index 9e6fec78..bb58d8df 100644 --- a/charset.c +++ b/charset.c @@ -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 */ { diff --git a/filename.c b/filename.c index cbc7e0ee..c519c591 100644 --- a/filename.c +++ b/filename.c @@ -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++; } } @@ -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. */