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
commit4a44fd852450d9e97032633524f92d1fad5f7187 (patch)
treee7e99b2532a0766190cba557131431b05ec4ceb2 /src/UniqueString.cxx
parentbdfbc5325157c037fdaa70d6c7fe757046f08906 (diff)
downloadscintilla-mirror-4a44fd852450d9e97032633524f92d1fad5f7187.tar.gz
Backport: Rename FontNames to UniqueStringSet and move into UniqueString.
It may be useful in more situations than just font names. Backport of changeset 7409:a70a4ee51448.
Diffstat (limited to 'src/UniqueString.cxx')
-rw-r--r--src/UniqueString.cxx27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/UniqueString.cxx b/src/UniqueString.cxx
index dcbdc441c..aadc2ae7e 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 <cstring>
+#include <vector>
#include <algorithm>
#include <memory>
@@ -25,4 +26,30 @@ 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;
+
+ for (const UniqueString &us : strings) {
+ if (text == us.get()) {
+ return us.get();
+ }
+ }
+
+ strings.push_back(UniqueStringCopy(text));
+ return strings.back().get();
+}
+
}