open62541pp 0.19.0
C++ wrapper of open62541
Loading...
Searching...
No Matches
string_utils.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <string_view>
4
5#include "open62541pp/detail/open62541/common.h" // UA_String
6
7namespace opcua::detail {
8
9/// Convert std::string_view to UA_String (no copy)
10UA_String toNativeString(std::string_view src) noexcept;
11
12/// Allocate UA_String from std::string_view
13[[nodiscard]] UA_String allocNativeString(std::string_view src);
14
15/// Allocate const char* from std::string_view
16[[nodiscard]] char* allocCString(std::string_view src);
17
18void clear(const char* str) noexcept;
19
20/// Convert UA_String to std::string_view
21/// Can be marked noexcept: https://stackoverflow.com/a/62061549/9967707
22inline std::string_view toStringView(const UA_String& src) noexcept {
23 if (src.data == nullptr || src.length == 0U) {
24 return {};
25 }
26 return {(const char*)src.data, src.length}; // NOLINT
27}
28
29} // namespace opcua::detail