OpenPine C++ API
C++ wrapper for the OpenPine Pine Script VM
Loading...
Searching...
No Matches
string_ref.hpp
Go to the documentation of this file.
1#pragma once
2
7
8#if (defined(_MSVC_LANG) ? _MSVC_LANG : __cplusplus) < 201703L
9#error \
10 "OpenPine C++ wrapper headers require C++17 (std::optional, std::string_view)."
11#endif
12
13#include <optional>
14#include <string_view>
15
16#include "ffi.hpp"
17
18namespace openpine {
19
20namespace detail {
21
24inline std::string_view refToView(const ffi::PineStringRef& ref) {
25 if (!ref.data) return std::string_view{};
26 return std::string_view(reinterpret_cast<const char*>(ref.data), ref.len);
27}
28
30inline std::optional<std::string_view> optRefToView(
31 bool has_field, const ffi::PineStringRef& ref) {
32 return has_field ? std::optional<std::string_view>(refToView(ref))
33 : std::nullopt;
34}
35
36} // namespace detail
37} // namespace openpine
std::optional< std::string_view > optRefToView(bool has_field, const ffi::PineStringRef &ref)
Returns optional string_view when has_field is true, otherwise std::nullopt.
std::string_view refToView(const ffi::PineStringRef &ref)