From 5c53afc4d4ce26277eed79b94448f6b43623f23d Mon Sep 17 00:00:00 2001 From: alistair Date: Sun, 4 Jul 2021 00:34:19 +1000 Subject: [PATCH] fix utf8 support --- colcat.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/colcat.c b/colcat.c index 08cbd56..1dec9d7 100644 --- a/colcat.c +++ b/colcat.c @@ -85,8 +85,11 @@ int display(FILE *file) { counter = num_colours; // so that print starts at reverse=true } bool in_escape = false; + bool in_utf8_mbchar = false; bool vert_reverse = false; while (c != EOF) { + + if (c == '\n') { if (frequency && end) { if (counter % (end) == 0) { @@ -101,6 +104,13 @@ int display(FILE *file) { } reverse = false; } + + if ((c & 0b11000000) == 0b10000000) { + in_utf8_mbchar = true; + } else { + in_utf8_mbchar = false; + } + if (c == '\033') { in_escape = true; } else if (end_hue_ansi_code(c) && in_escape) { @@ -111,7 +121,7 @@ int display(FILE *file) { continue; } - if (!in_escape) { + if (!in_escape && !in_utf8_mbchar) { print_next_colour(counter); }