Scintilla 4.0.3
[TortoiseGit.git] / ext / scintilla / src / UniqueString.h
blobf047f94962916097c65e9d7de72dbdfc9298be2d
1 // Scintilla source code edit control
2 /** @file UniqueString.h
3 ** Define UniqueString, a unique_ptr based string type for storage in containers
4 ** and an allocator for UniqueString.
5 **/
6 // Copyright 2017 by Neil Hodgson <neilh@scintilla.org>
7 // The License.txt file describes the conditions under which this software may be distributed.
9 #ifndef UNIQUESTRING_H
10 #define UNIQUESTRING_H
12 namespace Scintilla {
14 using UniqueString = std::unique_ptr<const char[]>;
16 /// Equivalent to strdup but produces a std::unique_ptr<const char[]> allocation to go
17 /// into collections.
18 inline UniqueString UniqueStringCopy(const char *text) {
19 if (!text) {
20 return UniqueString();
22 const size_t len = strlen(text);
23 char *sNew = new char[len + 1];
24 std::copy(text, text + len + 1, sNew);
25 return UniqueString(sNew);
30 #endif