mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-29 07:57:20 +02:00
Enhancement - strippedLength
- Added a text method that calculates a string length but does not include color control codes.
This commit is contained in:
parent
ce99cbf2d4
commit
844c980bce
3 changed files with 37 additions and 1 deletions
27
src/text.cpp
27
src/text.cpp
|
@ -568,3 +568,30 @@ std::string::size_type find (
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// 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