From 68ae3c4fd9db8baef4fea99d91766af5bc210506 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Thu, 5 Feb 2015 02:46:00 +0100 Subject: Added hasNonWhitepaceChar function --- src/core/common/Utils.cpp | 11 ++++++++++- src/core/common/Utils.hpp | 8 ++++++++ src/core/parser/ParserStack.cpp | 7 ++----- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/core/common/Utils.cpp b/src/core/common/Utils.cpp index f59061a..e5e2d39 100644 --- a/src/core/common/Utils.cpp +++ b/src/core/common/Utils.cpp @@ -46,6 +46,16 @@ bool Utils::isIdentifier(const std::string &name) return true; } +bool Utils::hasNonWhitepaceChar(const std::string &s) +{ + for (char c : s) { + if (!isWhitespace(c)) { + return true; + } + } + return false; +} + std::vector Utils::split(const std::string &s, char delim) { std::vector res; @@ -84,6 +94,5 @@ std::string Utils::extractFileExtension(const std::string &filename) } return std::string{}; } - } diff --git a/src/core/common/Utils.hpp b/src/core/common/Utils.hpp index a88c716..fa3788a 100644 --- a/src/core/common/Utils.hpp +++ b/src/core/common/Utils.hpp @@ -70,6 +70,14 @@ public: return (c == ' ') || (c == '\t') || (c == '\n') || (c == '\r'); } + /** + * Returns true if the given string has a non-whitespace character. + * + * @param s is the string that should be checked. + * @return true if the string contains a non-whitespace character. + */ + static bool hasNonWhitepaceChar(const std::string &s); + /** * Returns true if the given character is a whitespace character. */ diff --git a/src/core/parser/ParserStack.cpp b/src/core/parser/ParserStack.cpp index cc875cb..50a97c9 100644 --- a/src/core/parser/ParserStack.cpp +++ b/src/core/parser/ParserStack.cpp @@ -51,11 +51,8 @@ public: void Handler::data(const std::string &data, int field) { - for (auto &c : data) { - if (!Utils::isWhitespace(c)) { - logger().error("Expected command but found character data."); - return; - } + if (Utils::hasNonWhitepaceChar(data)) { + logger().error("Expected command but found character data."); } } -- cgit v1.2.3