From 14e3038571ce741b50bc8254567dbaf26b30700b Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 11 Dec 2016 17:34:50 -0500 Subject: [PATCH] util: Migrated nontrivial from text --- src/Hooks.cpp | 2 +- src/text.cpp | 12 ------------ src/text.h | 1 - src/util.cpp | 12 ++++++++++++ src/util.h | 1 + test/text.t.cpp | 13 +------------ test/util.t.cpp | 13 ++++++++++++- 7 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/Hooks.cpp b/src/Hooks.cpp index 109aa0490..f779b6b59 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -44,7 +44,7 @@ #include #include #include -#include +#include #include extern Context context; diff --git a/src/text.cpp b/src/text.cpp index c1a4ffb0f..3b64eea1c 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -52,18 +52,6 @@ const char* optionalBlankLine () 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 // codes. diff --git a/src/text.h b/src/text.h index 3154a9ff6..683cd825d 100644 --- a/src/text.h +++ b/src/text.h @@ -34,7 +34,6 @@ // text.cpp, Non-UTF-8 aware. const char* optionalBlankLine (); -bool nontrivial (const std::string&); int strippedLength (const std::string&); #endif diff --git a/src/util.cpp b/src/util.cpp index b718b07f6..ee6703cb7 100644 --- a/src/util.cpp +++ b/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; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/util.h b/src/util.h index 766e8ce73..bce568846 100644 --- a/src/util.h +++ b/src/util.h @@ -62,6 +62,7 @@ const std::vector extractParents ( std::string osName (); const std::string obfuscateText (const std::string&); +bool nontrivial (const std::string&); #endif //////////////////////////////////////////////////////////////////////////////// diff --git a/test/text.t.cpp b/test/text.t.cpp index 651a04e78..dd4d980ec 100644 --- a/test/text.t.cpp +++ b/test/text.t.cpp @@ -37,18 +37,7 @@ Context context; //////////////////////////////////////////////////////////////////////////////// int main (int, char**) { - UnitTest t (14); - - // 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"); + UnitTest t (5); // int strippedLength (const std::string&); t.is (strippedLength (std::string ("")), 0, "strippedLength -> 0"); diff --git a/test/util.t.cpp b/test/util.t.cpp index fb199dea9..03050d360 100644 --- a/test/util.t.cpp +++ b/test/util.t.cpp @@ -36,7 +36,7 @@ Context context; //////////////////////////////////////////////////////////////////////////////// int main (int, char**) { - UnitTest t (22); + UnitTest t (19); // Ensure environment has no influence. 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.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; }