diff options
author | Tor Egge <Tor.Egge@broadpark.no> | 2019-10-06 02:24:04 +0200 |
---|---|---|
committer | Tor Egge <Tor.Egge@broadpark.no> | 2019-10-07 10:56:03 +0200 |
commit | bfe2f51a1442d3722aab09f273d6746e0b1c5e96 (patch) | |
tree | e2436c3d61c77e555ee88e1633969402555d937d | |
parent | 81e811c1952f77aa5da5b66c6848b224f61aa0a0 (diff) |
Use std::regex in metrics module.
-rw-r--r-- | metrics/src/vespa/metrics/metric.cpp | 7 | ||||
-rw-r--r-- | metrics/src/vespa/metrics/metric.h | 3 | ||||
-rw-r--r-- | metrics/src/vespa/metrics/textwriter.cpp | 11 | ||||
-rw-r--r-- | metrics/src/vespa/metrics/textwriter.h | 5 |
4 files changed, 15 insertions, 11 deletions
diff --git a/metrics/src/vespa/metrics/metric.cpp b/metrics/src/vespa/metrics/metric.cpp index 20083300271..a7a212d759c 100644 --- a/metrics/src/vespa/metrics/metric.cpp +++ b/metrics/src/vespa/metrics/metric.cpp @@ -13,6 +13,7 @@ #include <cassert> #include <algorithm> #include <ostream> +#include <regex> namespace metrics { @@ -39,10 +40,9 @@ MetricVisitor::visitMetric(const Metric&, bool) namespace { std::string namePattern = "[a-zA-Z][_a-zA-Z0-9]*"; + std::regex name_pattern_regex(namePattern); } -vespalib::Regexp Metric::_namePattern(namePattern); - Tag::Tag(vespalib::stringref k) : _key(NameRepo::tagKeyId(k)), _value(TagValueId::empty_handle) @@ -143,7 +143,8 @@ Metric::verifyConstructionParameters() throw vespalib::IllegalArgumentException( "Metric cannot have empty name", VESPA_STRLOC); } - if (!_namePattern.match(getName())) { + const auto &name = getName(); + if (!std::regex_search(name.c_str(), name.c_str() + name.size(), name_pattern_regex)) { throw vespalib::IllegalArgumentException( "Illegal metric name '" + getName() + "'. Names must match pattern " + namePattern, VESPA_STRLOC); diff --git a/metrics/src/vespa/metrics/metric.h b/metrics/src/vespa/metrics/metric.h index 85832ba08d1..845f40a335b 100644 --- a/metrics/src/vespa/metrics/metric.h +++ b/metrics/src/vespa/metrics/metric.h @@ -3,7 +3,6 @@ #include <vespa/vespalib/util/printable.h> #include <vespa/vespalib/stllike/string.h> -#include <vespa/vespalib/util/regexp.h> #include "name_repo.h" namespace metrics { @@ -110,8 +109,6 @@ public: using SP = std::shared_ptr<Metric>; using Tags = std::vector<Tag>; - static vespalib::Regexp _namePattern; - Metric(const String& name, Tags dimensions, const String& description, diff --git a/metrics/src/vespa/metrics/textwriter.cpp b/metrics/src/vespa/metrics/textwriter.cpp index 9ce1005821f..4edfb93b452 100644 --- a/metrics/src/vespa/metrics/textwriter.cpp +++ b/metrics/src/vespa/metrics/textwriter.cpp @@ -11,8 +11,13 @@ namespace metrics { TextWriter::TextWriter(std::ostream& out, uint32_t period, const std::string& regex, bool verbose) - : _period(period), _out(out), _regex(regex), _verbose(verbose) -{ } + : _period(period), _out(out), _regex(), _verbose(verbose) +{ + try { + _regex = std::regex(regex); + } catch (std::regex_error &) { + } +} TextWriter::~TextWriter() { } @@ -50,7 +55,7 @@ TextWriter::writeCommon(const Metric& metric) } std::string mypath(path.str()); path << metric.getMangledName(); - if (_regex.match(path.str())) { + if (_regex && std::regex_search(path.str(), *_regex)) { if (metric.used() || _verbose) { _out << "\n" << mypath; return true; diff --git a/metrics/src/vespa/metrics/textwriter.h b/metrics/src/vespa/metrics/textwriter.h index c4267f07197..b1f09d1f0ed 100644 --- a/metrics/src/vespa/metrics/textwriter.h +++ b/metrics/src/vespa/metrics/textwriter.h @@ -3,7 +3,8 @@ #pragma once #include "metric.h" -#include <vespa/vespalib/util/regexp.h> +#include <regex> +#include <optional> namespace metrics { @@ -11,7 +12,7 @@ class TextWriter : public MetricVisitor { uint32_t _period; std::ostream& _out; std::vector<std::string> _path; - vespalib::Regexp _regex; + std::optional<std::regex> _regex; bool _verbose; public: |