| 118 | } |
| 119 | |
| 120 | std::pair<const char *, std::unique_ptr<char[]>> |
| 121 | createNullTerminatedString(std::string_view View) noexcept { |
| 122 | const char *CStr = nullptr; |
| 123 | std::unique_ptr<char[]> Buffer; |
| 124 | if (!View.empty()) { |
| 125 | if (const auto Pos = View.find_first_of('\0'); |
| 126 | Pos != std::string_view::npos) { |
| 127 | CStr = View.data(); |
| 128 | } else { |
| 129 | Buffer = std::make_unique<char[]>(View.size() + 1); |
| 130 | std::copy(View.begin(), View.end(), Buffer.get()); |
| 131 | CStr = Buffer.get(); |
| 132 | } |
| 133 | } |
| 134 | return {CStr, std::move(Buffer)}; |
| 135 | } |
| 136 | |
| 137 | } // namespace |
| 138 | |