mirror of
https://github.com/aristocratos/btop.git
synced 2024-09-21 02:41:31 +02:00
Fixed: Fx::uncolor() optimization
This commit is contained in:
parent
897769a90d
commit
08f3957817
@ -144,15 +144,17 @@ namespace Fx {
|
|||||||
string uncolor(const string& s) {
|
string uncolor(const string& s) {
|
||||||
string out = s;
|
string out = s;
|
||||||
for (size_t offset = 0, start_pos = 0, end_pos = 0;;) {
|
for (size_t offset = 0, start_pos = 0, end_pos = 0;;) {
|
||||||
start_pos = out.find('\x1b', offset);
|
start_pos = (offset == 0) ? out.find('\x1b') : offset;
|
||||||
if (start_pos == string::npos)
|
if (start_pos == string::npos)
|
||||||
break;
|
break;
|
||||||
offset = start_pos + 1;
|
offset = start_pos + 1;
|
||||||
end_pos = out.find('m', offset);
|
end_pos = out.find('m', offset);
|
||||||
if (end_pos == string::npos)
|
if (end_pos == string::npos)
|
||||||
break;
|
break;
|
||||||
else if (auto next_pos = out.find('\x1b', offset); not isdigit(out[end_pos - 1]) or end_pos > next_pos)
|
else if (auto next_pos = out.find('\x1b', offset); not isdigit(out[end_pos - 1]) or end_pos > next_pos) {
|
||||||
continue;
|
offset = next_pos;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
out.erase(start_pos, (end_pos - start_pos)+1);
|
out.erase(start_pos, (end_pos - start_pos)+1);
|
||||||
offset = 0;
|
offset = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user