From b797dfefb2b599b0085fa8e03180b9d6648e0acd Mon Sep 17 00:00:00 2001 From: Neil Date: Fri, 5 Apr 2019 19:39:23 +1100 Subject: Move UniqueStringCopy into its own source file UniqueString.cxx to hide the implementation. --- src/UniqueString.cxx | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/UniqueString.cxx (limited to 'src/UniqueString.cxx') diff --git a/src/UniqueString.cxx b/src/UniqueString.cxx new file mode 100644 index 000000000..7e289a1a0 --- /dev/null +++ b/src/UniqueString.cxx @@ -0,0 +1,28 @@ +// Scintilla source code edit control +/** @file UniqueString.cxx + ** Define an allocator for UniqueString. + **/ +// Copyright 2017 by Neil Hodgson +// The License.txt file describes the conditions under which this software may be distributed. + +#include +#include +#include + +#include "UniqueString.h" + +namespace Scintilla { + +/// Equivalent to strdup but produces a std::unique_ptr allocation to go +/// into collections. +UniqueString UniqueStringCopy(const char *text) { + if (!text) { + return UniqueString(); + } + const std::string_view sv(text); + std::unique_ptr upcNew = std::make_unique(sv.length() + 1); + sv.copy(upcNew.get(), sv.length()); + return UniqueString(upcNew.release()); +} + +} -- cgit v1.2.3