blob: 07da0f1717cb4e5d15f5c1abdfac03079fb6df05 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
|