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 ** Define UniqueStringSet which holds a set of strings, used to avoid holding many copies
8 // Copyright 2017 by Neil Hodgson <neilh@scintilla.org>
9 // The License.txt file describes the conditions under which this software may be distributed.
11 #ifndef UNIQUESTRING_H
12 #define UNIQUESTRING_H
14 namespace Scintilla::Internal
{
16 constexpr bool IsNullOrEmpty(const char *text
) noexcept
{
17 return text
== nullptr || *text
== '\0';
20 using UniqueString
= std::unique_ptr
<const char[]>;
22 /// Equivalent to strdup but produces a std::unique_ptr<const char[]> allocation to go
24 UniqueString
UniqueStringCopy(const char *text
);
26 // A set of strings that always returns the same pointer for each string.
28 class UniqueStringSet
{
30 std::vector
<UniqueString
> strings
;
33 void Clear() noexcept
;
34 const char *Save(const char *text
);