mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
util: Migrated strippedLength from text
This commit is contained in:
parent
0027c9face
commit
a0d88aaef8
5 changed files with 37 additions and 36 deletions
27
src/util.cpp
27
src/util.cpp
|
@ -328,3 +328,30 @@ bool nontrivial (const std::string& input)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Return the length, in characters, of the input, subtracting color control
|
||||
// codes.
|
||||
int strippedLength (const std::string& input)
|
||||
{
|
||||
int length = input.length ();
|
||||
bool inside = false;
|
||||
int count = 0;
|
||||
for (int i = 0; i < length; ++i)
|
||||
{
|
||||
if (inside)
|
||||
{
|
||||
if (input[i] == 'm')
|
||||
inside = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (input[i] == 033)
|
||||
inside = true;
|
||||
else
|
||||
++count;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue