aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2024-03-14 18:15:12 +0100
committerTor Egge <Tor.Egge@online.no>2024-03-14 18:15:12 +0100
commitc3026e157c35c8f488766bf43d8633f48cafd9fa (patch)
tree3082a66a57ad664e496e81bd0ac3340486fb421e /vespalib
parent1502728a967ab7b70c78f2ef54f5f14d16428697 (diff)
Move normalize_class_name to vespalib.
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/vespa/vespalib/util/CMakeLists.txt1
-rw-r--r--vespalib/src/vespa/vespalib/util/normalize_class_name.cpp31
-rw-r--r--vespalib/src/vespa/vespalib/util/normalize_class_name.h15
3 files changed, 47 insertions, 0 deletions
diff --git a/vespalib/src/vespa/vespalib/util/CMakeLists.txt b/vespalib/src/vespa/vespalib/util/CMakeLists.txt
index 518cbe337fa..79000a89f5f 100644
--- a/vespalib/src/vespa/vespalib/util/CMakeLists.txt
+++ b/vespalib/src/vespa/vespalib/util/CMakeLists.txt
@@ -57,6 +57,7 @@ vespa_add_library(vespalib_vespalib_util OBJECT
mmap_file_allocator.cpp
mmap_file_allocator_factory.cpp
monitored_refcount.cpp
+ normalize_class_name.cpp
nice.cpp
printable.cpp
priority_queue.cpp
diff --git a/vespalib/src/vespa/vespalib/util/normalize_class_name.cpp b/vespalib/src/vespa/vespalib/util/normalize_class_name.cpp
new file mode 100644
index 00000000000..f0ae498a1a9
--- /dev/null
+++ b/vespalib/src/vespa/vespalib/util/normalize_class_name.cpp
@@ -0,0 +1,31 @@
+// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include "normalize_class_name.h"
+
+namespace vespalib {
+
+namespace {
+
+void
+normalize_class_name_helper(vespalib::string& class_name, const vespalib::string& old, const vespalib::string& replacement)
+{
+ for (;;) {
+ auto pos = class_name.find(old);
+ if (pos == vespalib::string::npos) {
+ break;
+ }
+ class_name.replace(pos, old.size(), replacement);
+ }
+}
+
+}
+
+vespalib::string
+normalize_class_name(vespalib::string class_name)
+{
+ normalize_class_name_helper(class_name, "long long", "long");
+ normalize_class_name_helper(class_name, ">>", "> >");
+ return class_name;
+}
+
+}
diff --git a/vespalib/src/vespa/vespalib/util/normalize_class_name.h b/vespalib/src/vespa/vespalib/util/normalize_class_name.h
new file mode 100644
index 00000000000..597243bd091
--- /dev/null
+++ b/vespalib/src/vespa/vespalib/util/normalize_class_name.h
@@ -0,0 +1,15 @@
+// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+#include <vespa/vespalib/stllike/string.h>
+
+namespace vespalib {
+
+/*
+ * Normalize a demangled class name to compensate for different demangling
+ * with g++ / libstdc++ / binutils and clang++ / libc++ / llvm toolchains.
+ */
+vespalib::string normalize_class_name(vespalib::string class_name);
+
+}