Changed: Regex for Fx::uncolor() changed to string search and replace
This commit is contained in:
@@ -139,6 +139,25 @@ namespace Term {
|
||||
|
||||
//? --------------------------------------------------- FUNCTIONS -----------------------------------------------------
|
||||
|
||||
namespace Fx {
|
||||
string uncolor(const string& s) {
|
||||
string out = s;
|
||||
for (size_t offset = 0, start_pos = 0, end_pos = 0, next_pos = 0;;) {
|
||||
if ((start_pos = next_pos > 0 ? next_pos : out.find('\x1b', offset)) == string::npos)
|
||||
break;
|
||||
offset = start_pos;
|
||||
if ((end_pos = out.find('m', offset)) == string::npos)
|
||||
break;
|
||||
else if (next_pos = out.find('\x1b', offset + 1); end_pos - start_pos > next_pos - start_pos)
|
||||
continue;
|
||||
out.replace(start_pos, (end_pos - start_pos) + 1, "");
|
||||
next_pos = 0;
|
||||
}
|
||||
out.shrink_to_fit();
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
namespace Tools {
|
||||
|
||||
atomic<int> active_locks (0);
|
||||
|
||||
Reference in New Issue
Block a user