mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-28 22:47:20 +02:00
Enhancement
- Implemented leftJustify, rightJustify for composing justified strings.
This commit is contained in:
parent
9b85cb47ce
commit
d0a91acf28
3 changed files with 26 additions and 1 deletions
13
src/text.cpp
13
src/text.cpp
|
@ -655,6 +655,7 @@ int characters (const std::string& str)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Truncates a long line, and include a two-character ellipsis.
|
||||
std::string cutOff (const std::string& str, std::string::size_type len)
|
||||
{
|
||||
if (str.length () > len)
|
||||
|
@ -715,3 +716,15 @@ std::string format (double value, int width, int precision)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::string leftJustify (const std::string& input, const int width)
|
||||
{
|
||||
return input + std::string (width - input.length (), ' ');
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::string rightJustify (const std::string& input, const int width)
|
||||
{
|
||||
return std::string (width - input.length (), ' ') + input;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue