Module: check_mk
Branch: master
Commit: 8f4bef8c21c530f9c6a2895512f0d124b279d9b8
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8f4bef8c21c530…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Mon Nov 20 10:03:47 2017 +0100
Nuked plain C versions of lstrip/rstrip.
Change-Id: I31035bbeb6394a395fa384806e924d6eb654dcfb
---
livestatus/src/Query.cc | 25 ++++++++-----------------
livestatus/src/strutil.cc | 31 +++++++++----------------------
livestatus/src/strutil.h | 2 --
3 files changed, 17 insertions(+), 41 deletions(-)
diff --git a/livestatus/src/Query.cc b/livestatus/src/Query.cc
index 459fa19..4171ee9 100644
--- a/livestatus/src/Query.cc
+++ b/livestatus/src/Query.cc
@@ -323,13 +323,9 @@ void Query::parseStatsLine(char *line) {
auto column = _table->column(column_name);
std::unique_ptr<Filter> filter;
if (operation == StatsOperation::count) {
- RelationalOperator relOp =
- relationalOperatorForName(nextStringArgument(&line));
- char *value = lstrip(line);
- if (value == nullptr) {
- throw std::runtime_error("missing value after operator");
- }
- filter = column->createFilter(relOp, value);
+ auto relOp = relationalOperatorForName(nextStringArgument(&line));
+ auto operand = mk::lstrip(line);
+ filter = column->createFilter(relOp, operand);
} else {
// create an "accept all" filter, just in case we fall back to
counting
filter = std::make_unique<AndingFilter>(
@@ -346,14 +342,9 @@ void Query::parseStatsLine(char *line) {
void Query::parseFilterLine(char *line, FilterStack &filters) {
auto column = _table->column(nextStringArgument(&line));
- RelationalOperator relOp =
- relationalOperatorForName(nextStringArgument(&line));
- char *value = lstrip(line);
- if (value == nullptr) {
- throw std::runtime_error("missing value after operator");
- }
-
- auto sub_filter = column->createFilter(relOp, value);
+ auto relOp = relationalOperatorForName(nextStringArgument(&line));
+ auto operand = mk::lstrip(line);
+ auto sub_filter = column->createFilter(relOp, operand);
filters.push_back(std::move(sub_filter));
_all_columns.insert(column);
}
@@ -490,10 +481,10 @@ void Query::parseWaitTriggerLine(char *line) {
}
void Query::parseWaitObjectLine(char *line) {
- char *objectspec = lstrip(line);
+ auto objectspec = mk::lstrip(line);
_wait_object = _table->findObject(objectspec);
if (_wait_object.isNull()) {
- throw std::runtime_error("object '" + std::string(objectspec) +
+ throw std::runtime_error("object '" + objectspec +
"' not found or not supported by this
table");
}
}
diff --git a/livestatus/src/strutil.cc b/livestatus/src/strutil.cc
index 779be3a..3659479 100644
--- a/livestatus/src/strutil.cc
+++ b/livestatus/src/strutil.cc
@@ -24,30 +24,17 @@
#include "strutil.h"
#include <cctype>
-#include <cstring>
-char *rstrip(char *c) {
- char *w = c + strlen(c) - 1;
- while (w >= c && (isspace(*w) != 0)) {
- *w-- = '\0';
- }
- return c;
-}
-
-char *lstrip(char *c) {
- while (isspace(*c) != 0) {
- c++;
- }
- return c;
-}
-
-/* *c points to a string containing white space separated columns. This method
- returns a pointer to the zero-terminated next field. That might be identical
- with *c itself. The pointer c is then moved to the possible beginning of the
- next field. */
+// *c points to a string containing white space separated columns. This method
+// returns a pointer to the zero-terminated next field. That might be identical
+// with *c itself. The pointer c is then moved to the possible beginning of the
+// next field.
char *next_field(char **c) {
- /* *c points to first character of field */
- char *begin = lstrip(*c); // skip leading spaces
+ // skip leading spaces
+ char *begin = *c;
+ while (isspace(*begin) != 0) {
+ begin++;
+ }
if (*begin == 0) {
*c = begin;
return nullptr; // found end of string -> no more field
diff --git a/livestatus/src/strutil.h b/livestatus/src/strutil.h
index 4e47ca6..4802315 100644
--- a/livestatus/src/strutil.h
+++ b/livestatus/src/strutil.h
@@ -27,8 +27,6 @@
#include "config.h" // IWYU pragma: keep
-char *rstrip(char *);
-char *lstrip(char *);
char *next_token(char **c, char delim);
const char *safe_next_token(char **c, char delim);
char *next_field(char **c);