mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
util: Migrated nontrivial from text
This commit is contained in:
parent
9ae171f57c
commit
14e3038571
7 changed files with 27 additions and 27 deletions
|
@ -44,7 +44,7 @@
|
||||||
#include <Timer.h>
|
#include <Timer.h>
|
||||||
#include <format.h>
|
#include <format.h>
|
||||||
#include <shared.h>
|
#include <shared.h>
|
||||||
#include <text.h>
|
#include <util.h>
|
||||||
#include <i18n.h>
|
#include <i18n.h>
|
||||||
|
|
||||||
extern Context context;
|
extern Context context;
|
||||||
|
|
12
src/text.cpp
12
src/text.cpp
|
@ -52,18 +52,6 @@ const char* optionalBlankLine ()
|
||||||
return context.verbose ("blank") ? newline : noline;
|
return context.verbose ("blank") ? newline : noline;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
bool nontrivial (const std::string& input)
|
|
||||||
{
|
|
||||||
std::string::size_type i = 0;
|
|
||||||
int character;
|
|
||||||
while ((character = utf8_next_char (input, i)))
|
|
||||||
if (! Lexer::isWhitespace (character))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Return the length, in characters, of the input, subtracting color control
|
// Return the length, in characters, of the input, subtracting color control
|
||||||
// codes.
|
// codes.
|
||||||
|
|
|
@ -34,7 +34,6 @@
|
||||||
|
|
||||||
// text.cpp, Non-UTF-8 aware.
|
// text.cpp, Non-UTF-8 aware.
|
||||||
const char* optionalBlankLine ();
|
const char* optionalBlankLine ();
|
||||||
bool nontrivial (const std::string&);
|
|
||||||
int strippedLength (const std::string&);
|
int strippedLength (const std::string&);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
12
src/util.cpp
12
src/util.cpp
|
@ -316,3 +316,15 @@ const std::string obfuscateText (const std::string& input)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
bool nontrivial (const std::string& input)
|
||||||
|
{
|
||||||
|
std::string::size_type i = 0;
|
||||||
|
int character;
|
||||||
|
while ((character = utf8_next_char (input, i)))
|
||||||
|
if (! Lexer::isWhitespace (character))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -62,6 +62,7 @@ const std::vector <std::string> extractParents (
|
||||||
|
|
||||||
std::string osName ();
|
std::string osName ();
|
||||||
const std::string obfuscateText (const std::string&);
|
const std::string obfuscateText (const std::string&);
|
||||||
|
bool nontrivial (const std::string&);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -37,18 +37,7 @@ Context context;
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
int main (int, char**)
|
int main (int, char**)
|
||||||
{
|
{
|
||||||
UnitTest t (14);
|
UnitTest t (5);
|
||||||
|
|
||||||
// bool nontrivial (const std::string&);
|
|
||||||
t.notok (nontrivial (""), "nontrivial '' -> false");
|
|
||||||
t.notok (nontrivial (" "), "nontrivial ' ' -> false");
|
|
||||||
t.notok (nontrivial ("\t\t"), "nontrivial '\\t\\t' -> false");
|
|
||||||
t.notok (nontrivial (" \t \t"), "nontrivial ' \\t \\t' -> false");
|
|
||||||
t.ok (nontrivial ("a"), "nontrivial 'a' -> true");
|
|
||||||
t.ok (nontrivial (" a"), "nontrivial ' a' -> true");
|
|
||||||
t.ok (nontrivial ("a "), "nontrivial 'a ' -> true");
|
|
||||||
t.ok (nontrivial (" \t\ta"), "nontrivial ' \\t\\ta' -> true");
|
|
||||||
t.ok (nontrivial ("a\t\t "), "nontrivial 'a\\t\\t ' -> true");
|
|
||||||
|
|
||||||
// int strippedLength (const std::string&);
|
// int strippedLength (const std::string&);
|
||||||
t.is (strippedLength (std::string ("")), 0, "strippedLength -> 0");
|
t.is (strippedLength (std::string ("")), 0, "strippedLength -> 0");
|
||||||
|
|
|
@ -36,7 +36,7 @@ Context context;
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
int main (int, char**)
|
int main (int, char**)
|
||||||
{
|
{
|
||||||
UnitTest t (22);
|
UnitTest t (19);
|
||||||
|
|
||||||
// Ensure environment has no influence.
|
// Ensure environment has no influence.
|
||||||
unsetenv ("TASKDATA");
|
unsetenv ("TASKDATA");
|
||||||
|
@ -75,6 +75,17 @@ int main (int, char**)
|
||||||
t.is (indentProject ("one.two"), " two", "indentProject 'one.two' -> ' two'");
|
t.is (indentProject ("one.two"), " two", "indentProject 'one.two' -> ' two'");
|
||||||
t.is (indentProject ("one.two.three"), " three", "indentProject 'one.two.three' -> ' three'");
|
t.is (indentProject ("one.two.three"), " three", "indentProject 'one.two.three' -> ' three'");
|
||||||
|
|
||||||
|
// bool nontrivial (const std::string&);
|
||||||
|
t.notok (nontrivial (""), "nontrivial '' -> false");
|
||||||
|
t.notok (nontrivial (" "), "nontrivial ' ' -> false");
|
||||||
|
t.notok (nontrivial ("\t\t"), "nontrivial '\\t\\t' -> false");
|
||||||
|
t.notok (nontrivial (" \t \t"), "nontrivial ' \\t \\t' -> false");
|
||||||
|
t.ok (nontrivial ("a"), "nontrivial 'a' -> true");
|
||||||
|
t.ok (nontrivial (" a"), "nontrivial ' a' -> true");
|
||||||
|
t.ok (nontrivial ("a "), "nontrivial 'a ' -> true");
|
||||||
|
t.ok (nontrivial (" \t\ta"), "nontrivial ' \\t\\ta' -> true");
|
||||||
|
t.ok (nontrivial ("a\t\t "), "nontrivial 'a\\t\\t ' -> true");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue