Files
ruby/prism/stringy.hpp
T
Kevin Newton 957a081892 [ruby/prism] Ship an official C++ interface
The C++ interface is intentionally minimal: it provides only a
couple of niceties in order to largely stay out of the way. It is
mostly used to provide:

* RAII for opaque resources
* Safe up and down casting for nodes
* string_view for various resources
* Iteration over resource lists

Note that if consumers want to use it, they must be on C++17 at
minimum.

https://github.com/ruby/prism/commit/57b8dbe0e9
2026-10-20 22:15:29 +00:00

32 lines
645 B
C++

/**
* @file stringy.hpp
*
* Access to the contents of strings from C++.
*/
#ifndef PRISM_STRINGY_HPP
#define PRISM_STRINGY_HPP
#include "prism/compiler/cplusplus.hpp"
#include "prism/compiler/lifetimebound.hpp"
#include "prism/stringy.h"
#include <string_view>
namespace prism {
/**
* The bytes of the given string.
*
* @param string The string to view.
* @return A view of the bytes of the string.
*/
[[nodiscard]] inline std::string_view
view(const pm_string_t &string PRISM_LIFETIMEBOUND) noexcept {
return std::string_view(reinterpret_cast<const char *>(pm_string_source(&string)), pm_string_length(&string));
}
}
#endif