6#include <portals/text.hpp>
7#include <portals/text_resource.hpp>
21template <
class T>
inline constexpr bool IS_LIVE_TEXT_SOURCE =
false;
58#if defined(_MSVC_STL_VERSION) && defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL != 0
71 return *
this =
static_cast<const TextValue &
>(other);
92 constexpr explicit TextValue(std::string_view bytes) : bytes_(bytes) {
100 [[nodiscard]]
constexpr std::string_view
resourceKey() const noexcept {
101 return resource_ ? std::string_view(bytes_) : std::string_view{};
106 return !resource_ && bytes_.empty();
122 return validate(bytes_, policy, limits);
138 template <
class Resolver>
139 requires std::invocable<Resolver, std::string_view> &&
140 std::same_as<std::invoke_result_t<Resolver, std::string_view>,
141 std::expected<std::string, TextResourceError>>
142 [[nodiscard]] std::expected<GraphemeText, TextValueError>
resolve(
WidthPolicy policy, Resolver &&resolver,
145 return validate(bytes_, policy, limits);
148 const auto resolved = resolveResource(std::forward<Resolver>(resolver));
154 return validate(*resolved, policy, limits);
158 friend class ManagedScene;
161 constexpr TextValue(std::string_view key,
bool resource) : bytes_(key), resource_(resource) {
164 static std::expected<GraphemeText, TextValueError> validate(std::string_view bytes, WidthPolicy policy,
172 return std::move(*resolved);
175 template <
class Resolver> std::expected<std::string, TextResourceError> resolveResource(Resolver &&resolver)
const {
177 return std::invoke(std::forward<Resolver>(resolver), std::string_view(bytes_));
178 }
catch (
const std::bad_alloc &) {
180 }
catch (
const std::length_error &) {
214template <
class... Args>
215 requires(
sizeof...(Args) > 0) && (!(detail::IS_LIVE_TEXT_SOURCE<std::remove_cvref_t<Args>> || ...))
216[[nodiscard]]
TextValue text(std::format_string<Args...> pattern, Args &&...args) {
217 return text(std::format(pattern, std::forward<Args>(args)...));
static std::expected< GraphemeText, TextError > from(std::string_view bytes, WidthPolicy policy={}, TextLimits limits={})
Validate, segment and measure a single logical UTF-8 buffer.
Owning literal bytes or a resource key, measured only at resolution.
Definition text_value.hpp:42
constexpr TextValue(const TextValue &other)=default
Copy expression bytes and kind into independent storage.
constexpr ~TextValue()=default
Release the independently owned expression bytes.
std::expected< GraphemeText, TextValueError > resolve(WidthPolicy policy, Resolver &&resolver, TextLimits limits={}) const
Resolve a key synchronously through the caller, or validate a literal directly.
Definition text_value.hpp:142
constexpr std::string_view resourceKey() const noexcept
Inspect the resource key without resolving or allocating.
Definition text_value.hpp:100
constexpr TextValue & operator=(const TextValue &other)=default
Replace expression bytes and kind with an owning copy.
constexpr TextValue & operator=(TextValue &&other)=default
Transfer expression storage using the standard library's default move assignment.
constexpr TextValue(TextValue &&other)=default
Transfer expression storage using the standard library's default move.
constexpr TextValue(std::string_view bytes)
Copy a literal buffer into independent expression storage.
Definition text_value.hpp:92
std::expected< GraphemeText, TextValueError > resolve(WidthPolicy policy, TextLimits limits={}) const
Resolve literal bytes without requiring a resource resolver.
Definition text_value.hpp:117
friend constexpr TextValue i18n(std::string_view key)
Copy a resource key for later resolution through an explicit caller.
Definition text_value.hpp:227
constexpr bool isEmptyLiteral() const noexcept
Definition text_value.hpp:105
Public Portals API.
Definition action.hpp:8
ui::ValueText text(std::format_string< const ui::detail::TextArgumentValue< Args > &... > pattern, Args &&...args)
Declare live formatted text over explicit scalar roots, fields or value properties.
Definition ui_value_text.hpp:567
@ RESOLVER_REQUIRED
Resource resolution was requested without a caller-owned resolver.
Definition text_resource.hpp:12
@ RESOLVER_FAILED
The resolver reported failure or threw a non-allocation exception.
Definition text_resource.hpp:14
std::variant< TextError, TextResourceError > TextValueError
Original text validation error or a distinct resource lookup error.
Definition text_value.hpp:26
Owning limits checked without silently truncating input or clusters.
Definition text.hpp:57
Owning deterministic width policy; no font or terminal matching promise.
Definition text.hpp:42