| 95 | } |
| 96 | |
| 97 | std::pair<const char *, std::unique_ptr<char[]>> |
| 98 | createNullTerminatedString(std::string_view View) noexcept { |
| 99 | const char *CStr = nullptr; |
| 100 | std::unique_ptr<char[]> Buffer; |
| 101 | if (!View.empty()) { |
| 102 | if (const auto Pos = View.find_first_of('\0'); |
| 103 | Pos != std::string_view::npos) { |
| 104 | CStr = View.data(); |
| 105 | } else { |
| 106 | Buffer = std::make_unique<char[]>(View.size() + 1); |
| 107 | std::copy(View.begin(), View.end(), Buffer.get()); |
| 108 | CStr = Buffer.get(); |
| 109 | } |
| 110 | } |
| 111 | return {CStr, std::move(Buffer)}; |
| 112 | } |
| 113 | |
| 114 | } // namespace |
| 115 | |