summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@yahooinc.com>2023-02-09 11:17:01 +0000
committerHåvard Pettersen <havardpe@yahooinc.com>2023-02-09 15:00:27 +0000
commit37391e9cb5b375a5a8c1c4acc21a10805cb2f5e0 (patch)
tree8892ac1ab31a310820c08a61e3a3513e64bfc6ba /vespalib
parent8be38796b3861b45c7bb7fc2aab3f0f8245a2e40 (diff)
trace global filter iterator tree
also simplify making and joining sub-traces
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/CMakeLists.txt1
-rw-r--r--vespalib/src/tests/util/static_string/CMakeLists.txt9
-rw-r--r--vespalib/src/tests/util/static_string/static_string_test.cpp34
-rw-r--r--vespalib/src/vespa/vespalib/util/static_string.h37
4 files changed, 81 insertions, 0 deletions
diff --git a/vespalib/CMakeLists.txt b/vespalib/CMakeLists.txt
index 76308260578..2720d8786cb 100644
--- a/vespalib/CMakeLists.txt
+++ b/vespalib/CMakeLists.txt
@@ -200,6 +200,7 @@ vespa_define_module(
src/tests/util/mmap_file_allocator_factory
src/tests/util/rcuvector
src/tests/util/size_literals
+ src/tests/util/static_string
src/tests/util/string_escape
src/tests/valgrind
src/tests/visit_ranges
diff --git a/vespalib/src/tests/util/static_string/CMakeLists.txt b/vespalib/src/tests/util/static_string/CMakeLists.txt
new file mode 100644
index 00000000000..14360470b6b
--- /dev/null
+++ b/vespalib/src/tests/util/static_string/CMakeLists.txt
@@ -0,0 +1,9 @@
+# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+vespa_add_executable(vespalib_static_string_test_app TEST
+ SOURCES
+ static_string_test.cpp
+ DEPENDS
+ vespalib
+ GTest::GTest
+)
+vespa_add_test(NAME vespalib_static_string_test_app COMMAND vespalib_static_string_test_app)
diff --git a/vespalib/src/tests/util/static_string/static_string_test.cpp b/vespalib/src/tests/util/static_string/static_string_test.cpp
new file mode 100644
index 00000000000..d91fb613f0a
--- /dev/null
+++ b/vespalib/src/tests/util/static_string/static_string_test.cpp
@@ -0,0 +1,34 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include <vespa/vespalib/util/static_string.h>
+#include <vespa/vespalib/gtest/gtest.h>
+
+using vespalib::StaticStringView;
+using namespace vespalib::literals;
+
+TEST(StaticStringViewTest, simple_usage) {
+ auto value = "foo bar"_ssv;
+ vespalib::string expect("foo bar");
+ std::string expect_std("foo bar");
+ static_assert(std::same_as<decltype(value),StaticStringView>);
+ auto a_ref = value.ref();
+ auto a_view = value.view();
+ static_assert(std::same_as<decltype(a_ref),vespalib::stringref>);
+ static_assert(std::same_as<decltype(a_view),std::string_view>);
+ vespalib::stringref ref = value;
+ std::string_view view = value;
+ EXPECT_EQ(a_ref, expect);
+ EXPECT_EQ(a_view, expect_std);
+ EXPECT_EQ(ref, expect);
+ EXPECT_EQ(view, expect_std);
+ EXPECT_EQ(value.ref(), expect);
+ EXPECT_EQ(value.view(), expect_std);
+}
+
+TEST(StaticStringViewTest, with_null_byte) {
+ auto value = "foo\0bar"_ssv;
+ std::string expect("foo\0bar", 7);
+ EXPECT_EQ(value.view(), expect);
+}
+
+GTEST_MAIN_RUN_ALL_TESTS()
diff --git a/vespalib/src/vespa/vespalib/util/static_string.h b/vespalib/src/vespa/vespalib/util/static_string.h
new file mode 100644
index 00000000000..570c49a127b
--- /dev/null
+++ b/vespalib/src/vespa/vespalib/util/static_string.h
@@ -0,0 +1,37 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+#include <string_view>
+#include <vespa/vespalib/stllike/string.h>
+
+namespace vespalib {
+
+class StaticStringView;
+namespace literals {
+constexpr StaticStringView operator "" _ssv(const char *literal, size_t size);
+} // literals
+
+/**
+ * Contains the view of a literal string
+ **/
+class StaticStringView {
+private:
+ std::string_view _view;
+ friend constexpr StaticStringView literals::operator "" _ssv(const char *, size_t);
+ constexpr StaticStringView(const char *literal, size_t size) noexcept
+ : _view(literal, size) {}
+public:
+ constexpr std::string_view view() const noexcept { return _view; }
+ constexpr operator std::string_view() const noexcept { return _view; }
+ vespalib::stringref ref() const noexcept { return {_view.data(), _view.size()}; }
+ operator vespalib::stringref() const noexcept { return ref(); }
+};
+
+namespace literals {
+constexpr StaticStringView operator "" _ssv(const char *literal, size_t size) {
+ return vespalib::StaticStringView(literal, size);
+}
+} // literals
+
+} // vespalib