diff --git a/STYLE.md b/STYLE.md index b5767ae812949..c6e203f8f9fe8 100644 --- a/STYLE.md +++ b/STYLE.md @@ -67,6 +67,10 @@ annotations](https://github.com/abseil/abseil-cpp/blob/master/absl/base/thread_annotations.h), such as `GUARDED_BY`, should be used for shared state guarded by locks/mutexes. +* Functions intended to be local to a cc file should be declared in an anonymonus namespace, + rather than using the 'static' keyword. Note that the + [Google C++ style guide](https://google.github.io/styleguide/cppguide.html#Unnamed_Namespaces_and_Static_Variables) + allows either, but in Envoy we prefer annonymous namespaces. # Error handling diff --git a/source/common/stats/stats_impl.cc b/source/common/stats/stats_impl.cc index cb7055a5631c0..3b81301f120a0 100644 --- a/source/common/stats/stats_impl.cc +++ b/source/common/stats/stats_impl.cc @@ -28,6 +28,10 @@ size_t roundUpMultipleNaturalAlignment(size_t val) { return (val + multiple - 1) & ~(multiple - 1); } +bool regexStartsWithDot(absl::string_view regex) { + return absl::StartsWith(regex, "\\.") || absl::StartsWith(regex, "(?=\\.)"); +} + } // namespace size_t RawStatData::size() { @@ -75,7 +79,7 @@ std::string TagExtractorImpl::extractRegexPrefix(absl::string_view regex) { if (!absl::ascii_isalnum(regex[i]) && (regex[i] != '_')) { if (i > 1) { const bool last_char = i == regex.size() - 1; - if ((!last_char && (regex[i] == '\\') && (regex[i + 1] == '.')) || + if ((!last_char && regexStartsWithDot(regex.substr(i))) || (last_char && (regex[i] == '$'))) { prefix.append(regex.data() + 1, i - 1); } diff --git a/test/common/stats/stats_impl_test.cc b/test/common/stats/stats_impl_test.cc index 0f784dad7e161..0518fe31ae079 100644 --- a/test/common/stats/stats_impl_test.cc +++ b/test/common/stats/stats_impl_test.cc @@ -396,6 +396,7 @@ TEST(TagExtractorTest, ExtractRegexPrefix) { EXPECT_EQ("", extractRegexPrefix("^prefix(foo).")); EXPECT_EQ("prefix", extractRegexPrefix("^prefix\\.foo")); + EXPECT_EQ("prefix_optional", extractRegexPrefix("^prefix_optional(?=\\.)")); EXPECT_EQ("", extractRegexPrefix("^notACompleteToken")); // EXPECT_EQ("onlyToken", extractRegexPrefix("^onlyToken$")); // EXPECT_EQ("", extractRegexPrefix("(prefix)"));