aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/util.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-11-16 16:26:29 +0100
committerEelco Dolstra <edolstra@gmail.com>2020-11-16 16:41:53 +0100
commitef84c780bb901011e090b9f12d293d136193a428 (patch)
tree2ba8ce71f17094c35e03dda80b6868bab1c622f7 /src/libutil/util.cc
parent0d6419ad87f5a569da182de1be54bce735245512 (diff)
filterANSIEscapes(): Handle UTF-8 characters
Diffstat (limited to 'src/libutil/util.cc')
-rw-r--r--src/libutil/util.cc23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 53342b5cb..01ab9111f 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -1409,7 +1409,28 @@ std::string filterANSIEscapes(const std::string & s, bool filterAll, unsigned in
i++;
else {
- t += *i++; w++;
+ w++;
+ // Copy one UTF-8 character.
+ if ((*i & 0xe0) == 0xc0) {
+ t += *i++;
+ if (i != s.end() && ((*i & 0xc0) == 0x80)) t += *i++;
+ } else if ((*i & 0xf0) == 0xe0) {
+ t += *i++;
+ if (i != s.end() && ((*i & 0xc0) == 0x80)) {
+ t += *i++;
+ if (i != s.end() && ((*i & 0xc0) == 0x80)) t += *i++;
+ }
+ } else if ((*i & 0xf8) == 0xf0) {
+ t += *i++;
+ if (i != s.end() && ((*i & 0xc0) == 0x80)) {
+ t += *i++;
+ if (i != s.end() && ((*i & 0xc0) == 0x80)) {
+ t += *i++;
+ if (i != s.end() && ((*i & 0xc0) == 0x80)) t += *i++;
+ }
+ }
+ } else
+ t += *i++;
}
}