mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Helpers
- Implemented longestLine, which finds the longest line in a string.
This commit is contained in:
parent
6f17e80461
commit
56ccd16730
3 changed files with 38 additions and 5 deletions
27
src/text.cpp
27
src/text.cpp
|
@ -283,6 +283,33 @@ int longestWord (const std::string& input)
|
|||
return longest;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int longestLine (const std::string& input)
|
||||
{
|
||||
int longest = 0;
|
||||
int length = 0;
|
||||
std::string::size_type i = 0;
|
||||
int character;
|
||||
|
||||
while ((character = utf8_next_char (input, i)))
|
||||
{
|
||||
if (character == '\n')
|
||||
{
|
||||
if (length > longest)
|
||||
longest = length;
|
||||
|
||||
length = 0;
|
||||
}
|
||||
else
|
||||
++length;
|
||||
}
|
||||
|
||||
if (length > longest)
|
||||
longest = length;
|
||||
|
||||
return longest;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void extractLine (std::string& text, std::string& line, int length)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue