aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/UniqueString.h
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2017-05-21 23:08:04 +1000
committerNeil <nyamatongwe@gmail.com>2017-05-21 23:08:04 +1000
commit3debda34b8aa21a770142a055b8fa7e4a8a7355f (patch)
tree64079ad63efbe256cac9639d58a38c9d6fd41e5b /src/UniqueString.h
parent8ef4f3d54de1328a1d9753f4317a5d7692a72ae8 (diff)
downloadscintilla-mirror-3debda34b8aa21a770142a055b8fa7e4a8a7355f.tar.gz
Make SparseVector work with move-only types.
Define UniqueString as a move-only string and use in a SparseVector for ContractionState. Remove SparseVector method specializations that are no longer needed.
Diffstat (limited to 'src/UniqueString.h')
-rw-r--r--src/UniqueString.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/UniqueString.h b/src/UniqueString.h
new file mode 100644
index 000000000..07da0f171
--- /dev/null
+++ b/src/UniqueString.h
@@ -0,0 +1,34 @@
+// Scintilla source code edit control
+/** @file UniqueString.h
+ ** Define UniqueString, a unique_ptr based string type for storage in containers
+ ** and an allocator for UniqueString.
+ **/
+// Copyright 2017 by Neil Hodgson <neilh@scintilla.org>
+// The License.txt file describes the conditions under which this software may be distributed.
+
+#ifndef UNIQUESTRING_H
+#define UNIQUESTRING_H
+
+#ifdef SCI_NAMESPACE
+namespace Scintilla {
+#endif
+
+using UniqueString = std::unique_ptr<const char[]>;
+
+/// Equivalent to strdup but produces a std::unique_ptr<const char[]> allocation to go
+/// into collections.
+inline UniqueString UniqueStringCopy(const char *text) {
+ if (!text) {
+ return UniqueString();
+ }
+ const size_t len = strlen(text);
+ char *sNew = new char[len + 1];
+ std::copy(text, text + len + 1, sNew);
+ return UniqueString(sNew);
+}
+
+#ifdef SCI_NAMESPACE
+}
+#endif
+
+#endif