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)
|
||||
{
|
||||
|
|
|
@ -39,6 +39,7 @@ std::string trimRight (const std::string& in, const std::string& t = " ");
|
|||
std::string trim (const std::string& in, const std::string& t = " ");
|
||||
std::string unquoteText (const std::string&);
|
||||
int longestWord (const std::string&);
|
||||
int longestLine (const std::string&);
|
||||
void extractLine (std::string&, std::string&, int);
|
||||
void splitq (std::vector<std::string>&, const std::string&, const char);
|
||||
void split (std::vector<std::string>&, const std::string&, const char);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue