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.
8 
9 #ifndef UNIQUESTRING_H
10 #define UNIQUESTRING_H
11 
12 namespace Scintilla {
13 
14 using UniqueString = std::unique_ptr<const char[]>;
15 
16 /// Equivalent to strdup but produces a std::unique_ptr<const char[]> allocation to go
17 /// into collections.
UniqueStringCopy(const char * text)18 inline UniqueString UniqueStringCopy(const char *text) {
19 	if (!text) {
20 		return UniqueString();
21 	}
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);
26 }
27 
28 }
29 
30 #endif
31