aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/UniqueString.cxx
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2019-04-08 08:34:52 +1000
committerNeil <nyamatongwe@gmail.com>2019-04-08 08:34:52 +1000
commit4333970abdd54863a591f95df3c3e7e968aa2519 (patch)
tree4ce4c0328efa72601422bb1674fcabd8942c1051 /src/UniqueString.cxx
parentd2bb3203067343b51bf3c543b331741f6fa4ad21 (diff)
downloadscintilla-mirror-4333970abdd54863a591f95df3c3e7e968aa2519.tar.gz
Rename FontNames to UniqueStringSet and move into UniqueString.
It may be useful in more situations than just font names.
Diffstat (limited to 'src/UniqueString.cxx')
-rw-r--r--src/UniqueString.cxx28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/UniqueString.cxx b/src/UniqueString.cxx
index 7e289a1a0..322599672 100644
--- a/src/UniqueString.cxx
+++ b/src/UniqueString.cxx
@@ -6,6 +6,7 @@
// The License.txt file describes the conditions under which this software may be distributed.
#include <string_view>
+#include <vector>
#include <algorithm>
#include <memory>
@@ -25,4 +26,31 @@ UniqueString UniqueStringCopy(const char *text) {
return UniqueString(upcNew.release());
}
+// A set of strings that always returns the same pointer for each string.
+
+UniqueStringSet::UniqueStringSet() noexcept = default;
+
+UniqueStringSet::~UniqueStringSet() {
+ strings.clear();
+}
+
+void UniqueStringSet::Clear() noexcept {
+ strings.clear();
+}
+
+const char *UniqueStringSet::Save(const char *text) {
+ if (!text)
+ return nullptr;
+
+ const std::string_view sv(text);
+ for (const UniqueString &us : strings) {
+ if (sv == us.get()) {
+ return us.get();
+ }
+ }
+
+ strings.push_back(UniqueStringCopy(text));
+ return strings.back().get();
+}
+
}