libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
LibXR::RuntimeStringView< Source, Args > Class Template Reference

运行期构造、长期保留的 NUL 结尾字符串视图。 More...

#include <libxr_string.hpp>

Public Member Functions

constexpr RuntimeStringView ()=default
 Constructs an empty valid view. / 构造一个空的有效视图。
 
 RuntimeStringView (const RuntimeStringView &)=delete
 
RuntimeStringViewoperator= (const RuntimeStringView &)=delete
 
 RuntimeStringView (RuntimeStringView &&other) noexcept
 Move-constructs by taking the retained storage handle. / 移动构造并接管保留存储句柄。
 
RuntimeStringViewoperator= (RuntimeStringView &&)=delete
 
 RuntimeStringView (std::string_view text)
 Copies text into retained storage. / 拷贝文本到保留存储。
 
template<size_t N>
requires (Source.Size() == 0 && sizeof...(Args) == 0)
 RuntimeStringView (char(&text)[N])
 Copies one bounded mutable char array as text. / 按文本语义拷贝一个有界可变字符数组。
 
template<size_t N>
requires (Source.Size() == 0 && sizeof...(Args) == 0)
 RuntimeStringView (const char(&text)[N])
 Copies one bounded const char array as text. / 按文本语义拷贝一个有界只读字符数组。
 
template<typename CharPtr >
requires (Source.Size() == 0 && sizeof...(Args) == 0 && (std::is_same_v<CharPtr, char*> || std::is_same_v<CharPtr, const char*>))
 RuntimeStringView (CharPtr text)
 Copies a NUL-terminated C-string pointer into retained storage. / 拷贝 NUL 结尾 C 字符串指针到保留存储。
 
 RuntimeStringView (std::nullptr_t text)
 Preserves the old bare-nullptr entry for runtime null checks. / 保留裸 nullptr 入口以维持运行期空指针检查语义。
 
template<typename First , typename Second , typename... Rest>
requires (Source.Size() == 0 && sizeof...(Args) == 0)
 RuntimeStringView (First &&first, Second &&second, Rest &&... rest)
 Concatenates text parts into retained storage. / 拼接多个文本片段到保留存储。
 
template<typename... CallArgs>
requires ((Source.Size() != 0 || sizeof...(Args) != 0) && Detail::RuntimeStringArgumentTypes<Args...>::template matches<CallArgs...>)
ErrorCode Reformat (CallArgs &&... args)
 使用绑定的 brace-style 格式重写当前内容。
 
template<typename... CallArgs>
requires ((Source.Size() != 0 || sizeof...(Args) != 0) && Detail::RuntimeStringArgumentTypes<Args...>::template matches<CallArgs...>)
ErrorCode Reprintf (CallArgs &&... args)
 使用绑定的 printf-style 格式重写当前内容。
 
constexpr std::string_view View () const
 Returns the current read-only view. / 返回当前只读视图。
 
const char * CStr () const
 Returns a NUL-terminated C string. / 返回 NUL 结尾 C 字符串。
 
constexpr size_t Size () const
 Returns the text size excluding the trailing NUL. / 返回不含结尾 NUL 的文本长度。
 
constexpr bool Empty () const
 Returns whether the current visible text is empty. / 返回当前可见文本是否为空。
 
constexpr ErrorCode Status () const
 Returns the latest operation status. / 返回最近一次操作状态。
 
constexpr operator std::string_view () const
 Converts to a read-only string view. / 转换为只读字符串视图。
 
 operator const char * () const
 Converts to a NUL-terminated C string. / 转换为 NUL 结尾 C 字符串。
 

Private Member Functions

ErrorCode SetFailure (ErrorCode status)
 记录最近一次失败,并在已有存储上保留一个有效的空 C 字符串。
 
ErrorCode EnsureCapacity (size_t payload_size)
 为首个非空结果分配保留存储,已有存储不会再次扩容。
 
ErrorCode AssignCopy (std::string_view text)
 构造期文本拷贝入口;空字符串保持零分配。
 
ErrorCode AssignCopy (const char *text)
 C 字符串入口负责空指针检查,再进入统一的文本拷贝路径。
 
template<typename... Parts>
ErrorCode AssignConcat (Parts &&... parts)
 拼接构造的两遍流程:先校验并统计所有片段,再一次性写入。
 
template<typename WriteFn >
ErrorCode AssignFormatted (size_t max_size, WriteFn &&write)
 格式化重写入口;首次调用按编译期上界分配,后续调用只覆盖已有存储。
 

Static Private Member Functions

static constexpr size_t BoundedTextLength (const char *text, size_t bound) noexcept
 在已知边界内查找文本长度;遇到首个 \0 截断,否则使用整个数组长度。
 
template<typename T >
static constexpr Detail::RuntimeStringTextPart NormalizeConcatPart (T &&text)
 把拼接构造支持的输入统一归一化为只读文本片段;普通拼接只接受文本类输入, 数值格式化必须显式走 Reformat()Reprintf()
 

Private Attributes

char * data_ = nullptr
 长期保留的 NUL 结尾存储;对象析构时不释放。 / Retained NUL-terminated storage; not released by the destructor.
 
size_t size_ = 0
 不含结尾 NUL 的当前可见文本长度。 / Current visible payload size excluding the trailing NUL.
 
size_t capacity_ = 0
 不含结尾 NUL 的已探测/分配容量。 / Probed/allocated payload capacity excluding the trailing NUL.
 
ErrorCode status_ = ErrorCode::OK
 最近一次构造或重写状态。 / Status of the latest construction or rewrite.
 

Detailed Description

template<Print::Text Source = "", typename... Args>
class LibXR::RuntimeStringView< Source, Args >

运行期构造、长期保留的 NUL 结尾字符串视图。

Runtime-built retained NUL-terminated string view.

文本构造用于模块名、topic 名、后缀拼接等只构造一次的名字。 格式化构造绑定字面量和参数类型,第一次 Reformat() / Reprintf() 前从编译后的格式元数据计算最大容量,之后只复用该容量。对象析构时 不释放已分配存储。

Text construction is for retained names such as module names and topic suffixes. Formatted instances bind the literal and argument types, compute maximum capacity from compiled format metadata before the first rewrite, then reuse that capacity. Allocated storage is intentionally not released by the object destructor.

Definition at line 254 of file libxr_string.hpp.

Constructor & Destructor Documentation

◆ RuntimeStringView() [1/7]

template<Print::Text Source = "", typename... Args>
LibXR::RuntimeStringView< Source, Args >::RuntimeStringView ( RuntimeStringView< Source, Args > && other)
inlinenoexcept

Move-constructs by taking the retained storage handle. / 移动构造并接管保留存储句柄。

Definition at line 273 of file libxr_string.hpp.

274 : data_(other.data_),
275 size_(other.size_),
276 capacity_(other.capacity_),
277 status_(other.status_)
278 {
279 other.data_ = nullptr;
280 other.size_ = 0;
281 other.capacity_ = 0;
282 other.status_ = ErrorCode::OK;
283 }
size_t capacity_
不含结尾 NUL 的已探测/分配容量。 / Probed/allocated payload capacity excluding the trailing NUL.
ErrorCode status_
最近一次构造或重写状态。 / Status of the latest construction or rewrite.
size_t size_
不含结尾 NUL 的当前可见文本长度。 / Current visible payload size excluding the trailing NUL.
char * data_
长期保留的 NUL 结尾存储;对象析构时不释放。 / Retained NUL-terminated storage; not released by the destructor.
@ OK
操作成功 | Operation successful

◆ RuntimeStringView() [2/7]

template<Print::Text Source = "", typename... Args>
LibXR::RuntimeStringView< Source, Args >::RuntimeStringView ( std::string_view text)
inlineexplicit

Copies text into retained storage. / 拷贝文本到保留存储。

Definition at line 288 of file libxr_string.hpp.

290 {
291 static_cast<void>(AssignCopy(text));
292 }
ErrorCode AssignCopy(std::string_view text)
构造期文本拷贝入口;空字符串保持零分配。

◆ RuntimeStringView() [3/7]

template<Print::Text Source = "", typename... Args>
template<size_t N>
requires (Source.Size() == 0 && sizeof...(Args) == 0)
LibXR::RuntimeStringView< Source, Args >::RuntimeStringView ( char(&) text[N])
inlineexplicit

Copies one bounded mutable char array as text. / 按文本语义拷贝一个有界可变字符数组。

Definition at line 296 of file libxr_string.hpp.

298 {
299 static_cast<void>(AssignCopy(std::string_view(text, BoundedTextLength(text, N))));
300 }
static constexpr size_t BoundedTextLength(const char *text, size_t bound) noexcept
在已知边界内查找文本长度;遇到首个 \0 截断,否则使用整个数组长度。

◆ RuntimeStringView() [4/7]

template<Print::Text Source = "", typename... Args>
template<size_t N>
requires (Source.Size() == 0 && sizeof...(Args) == 0)
LibXR::RuntimeStringView< Source, Args >::RuntimeStringView ( const char(&) text[N])
inlineexplicit

Copies one bounded const char array as text. / 按文本语义拷贝一个有界只读字符数组。

Definition at line 304 of file libxr_string.hpp.

306 {
307 static_cast<void>(AssignCopy(std::string_view(text, BoundedTextLength(text, N))));
308 }

◆ RuntimeStringView() [5/7]

template<Print::Text Source = "", typename... Args>
template<typename CharPtr >
requires (Source.Size() == 0 && sizeof...(Args) == 0 && (std::is_same_v<CharPtr, char*> || std::is_same_v<CharPtr, const char*>))
LibXR::RuntimeStringView< Source, Args >::RuntimeStringView ( CharPtr text)
inlineexplicit

Copies a NUL-terminated C-string pointer into retained storage. / 拷贝 NUL 结尾 C 字符串指针到保留存储。

Definition at line 314 of file libxr_string.hpp.

315 {
316 static_cast<void>(AssignCopy(text));
317 }

◆ RuntimeStringView() [6/7]

template<Print::Text Source = "", typename... Args>
LibXR::RuntimeStringView< Source, Args >::RuntimeStringView ( std::nullptr_t text)
inlineexplicit

Preserves the old bare-nullptr entry for runtime null checks. / 保留裸 nullptr 入口以维持运行期空指针检查语义。

Definition at line 320 of file libxr_string.hpp.

322 {
323 static_cast<void>(AssignCopy(static_cast<const char*>(text)));
324 }

◆ RuntimeStringView() [7/7]

template<Print::Text Source = "", typename... Args>
template<typename First , typename Second , typename... Rest>
requires (Source.Size() == 0 && sizeof...(Args) == 0)
LibXR::RuntimeStringView< Source, Args >::RuntimeStringView ( First && first,
Second && second,
Rest &&... rest )
inlineexplicit

Concatenates text parts into retained storage. / 拼接多个文本片段到保留存储。

Definition at line 328 of file libxr_string.hpp.

330 {
331 static_cast<void>(AssignConcat(std::forward<First>(first),
332 std::forward<Second>(second),
333 std::forward<Rest>(rest)...));
334 }
ErrorCode AssignConcat(Parts &&... parts)
拼接构造的两遍流程:先校验并统计所有片段,再一次性写入。

Member Function Documentation

◆ AssignConcat()

template<Print::Text Source = "", typename... Args>
template<typename... Parts>
ErrorCode LibXR::RuntimeStringView< Source, Args >::AssignConcat ( Parts &&... parts)
inlinenodiscardprivate

拼接构造的两遍流程:先校验并统计所有片段,再一次性写入。

Two-pass concatenation constructor: validate/count all parts before one retained write.

第一遍会传播空指针或非法片段错误,避免已经写了一半才发现参数不可用。 The first pass propagates null-pointer or invalid-part errors before any partial payload is written.

Definition at line 511 of file libxr_string.hpp.

512 {
513 size_t total_size = 0;
514 ErrorCode status = ErrorCode::OK;
515
516 auto count = [&](auto&& part)
517 {
518 if (status != ErrorCode::OK)
519 {
520 return;
521 }
522
523 Detail::RuntimeStringTextPart text =
524 NormalizeConcatPart(std::forward<decltype(part)>(part));
525 if (text.status != ErrorCode::OK)
526 {
527 status = text.status;
528 }
529 else if (std::numeric_limits<size_t>::max() - total_size < text.view.size())
530 {
532 }
533 else
534 {
535 total_size += text.view.size();
536 }
537 };
538 (count(std::forward<Parts>(parts)), ...);
539
540 if (status != ErrorCode::OK)
541 {
542 return SetFailure(status);
543 }
544 status = EnsureCapacity(total_size);
545 if (status != ErrorCode::OK)
546 {
547 return SetFailure(status);
548 }
549
550 size_t offset = 0;
551 auto copy = [&](auto&& part)
552 {
553 Detail::RuntimeStringTextPart text =
554 NormalizeConcatPart(std::forward<decltype(part)>(part));
555 if (!text.view.empty())
556 {
557 std::memcpy(data_ + offset, text.view.data(), text.view.size());
558 offset += text.view.size();
559 }
560 };
561 (copy(std::forward<Parts>(parts)), ...);
562
563 if (data_ != nullptr)
564 {
565 data_[total_size] = '\0';
566 }
567 size_ = total_size;
569 return status_;
570 }
ErrorCode SetFailure(ErrorCode status)
记录最近一次失败,并在已有存储上保留一个有效的空 C 字符串。
ErrorCode EnsureCapacity(size_t payload_size)
为首个非空结果分配保留存储,已有存储不会再次扩容。
static constexpr Detail::RuntimeStringTextPart NormalizeConcatPart(T &&text)
把拼接构造支持的输入统一归一化为只读文本片段;普通拼接只接受文本类输入, 数值格式化必须显式走 Reformat() 或 Reprintf()。
ErrorCode
定义错误码枚举
@ OUT_OF_RANGE
超出范围 | Out of range

◆ AssignCopy() [1/2]

template<Print::Text Source = "", typename... Args>
ErrorCode LibXR::RuntimeStringView< Source, Args >::AssignCopy ( const char * text)
inlinenodiscardprivate

C 字符串入口负责空指针检查,再进入统一的文本拷贝路径。

C-string entry checks null pointers before using the common text copy path.

Definition at line 495 of file libxr_string.hpp.

496 {
497 return text == nullptr ? SetFailure(ErrorCode::PTR_NULL)
498 : AssignCopy(std::string_view(text, std::strlen(text)));
499 }
constexpr operator std::string_view() const
Converts to a read-only string view. / 转换为只读字符串视图。
@ PTR_NULL
空指针 | Null pointer

◆ AssignCopy() [2/2]

template<Print::Text Source = "", typename... Args>
ErrorCode LibXR::RuntimeStringView< Source, Args >::AssignCopy ( std::string_view text)
inlinenodiscardprivate

构造期文本拷贝入口;空字符串保持零分配。

Construction-time text copy entry; empty text remains allocation-free.

Definition at line 470 of file libxr_string.hpp.

471 {
472 ErrorCode status = EnsureCapacity(text.size());
473 if (status != ErrorCode::OK)
474 {
475 return SetFailure(status);
476 }
477 if (!text.empty())
478 {
479 std::memcpy(data_, text.data(), text.size());
480 }
481 if (data_ != nullptr)
482 {
483 data_[text.size()] = '\0';
484 }
485 size_ = text.size();
487 return status_;
488 }

◆ AssignFormatted()

template<Print::Text Source = "", typename... Args>
template<typename WriteFn >
ErrorCode LibXR::RuntimeStringView< Source, Args >::AssignFormatted ( size_t max_size,
WriteFn && write )
inlinenodiscardprivate

格式化重写入口;首次调用按编译期上界分配,后续调用只覆盖已有存储。

Formatted rewrite entry; the first call allocates the compile-time upper bound, later calls only overwrite retained storage.

max_size 来自已编译格式元数据和字段类型上界;write 使用本次真实参数写入 buffer sink。 max_size comes from compiled format metadata and per-field type bounds; write uses the current call arguments with the buffer sink.

Definition at line 583 of file libxr_string.hpp.

584 {
585 if (data_ == nullptr)
586 {
587 ErrorCode status = EnsureCapacity(max_size);
588 if (status != ErrorCode::OK)
589 {
590 return SetFailure(status);
591 }
592 }
593
594 Detail::RuntimeStringBufferSink sink{.data = data_, .capacity = capacity_};
595 ErrorCode status = write(sink);
596 if (status != ErrorCode::OK)
597 {
598 return SetFailure(status);
599 }
600 if (data_ != nullptr)
601 {
602 data_[sink.size] = '\0';
603 }
604 size_ = sink.size;
606 return status_;
607 }

◆ BoundedTextLength()

template<Print::Text Source = "", typename... Args>
static constexpr size_t LibXR::RuntimeStringView< Source, Args >::BoundedTextLength ( const char * text,
size_t bound )
inlinestaticnodiscardconstexprprivatenoexcept

在已知边界内查找文本长度;遇到首个 \0 截断,否则使用整个数组长度。

Find text length within a known bound; stop at the first \0, otherwise use the whole array extent.

Definition at line 614 of file libxr_string.hpp.

616 {
617 size_t size = 0;
618 while (size < bound && text[size] != '\0')
619 {
620 ++size;
621 }
622 return size;
623 }

◆ CStr()

template<Print::Text Source = "", typename... Args>
const char * LibXR::RuntimeStringView< Source, Args >::CStr ( ) const
inlinenodiscard

Returns a NUL-terminated C string. / 返回 NUL 结尾 C 字符串。

Definition at line 391 of file libxr_string.hpp.

391{ return data_ == nullptr ? "" : data_; }

◆ Empty()

template<Print::Text Source = "", typename... Args>
bool LibXR::RuntimeStringView< Source, Args >::Empty ( ) const
inlinenodiscardconstexpr

Returns whether the current visible text is empty. / 返回当前可见文本是否为空。

Definition at line 395 of file libxr_string.hpp.

395{ return size_ == 0; }

◆ EnsureCapacity()

template<Print::Text Source = "", typename... Args>
ErrorCode LibXR::RuntimeStringView< Source, Args >::EnsureCapacity ( size_t payload_size)
inlinenodiscardprivate

为首个非空结果分配保留存储,已有存储不会再次扩容。

Allocate retained storage for the first non-empty result; existing storage is never grown.

RuntimeStringView 的容量策略是一次分配后复用。格式化路径会先从编译格式 元数据计算最大容量,因此已有存储不足表示设计边界被突破,不能在这里静默 new 第二块内存。 第一次保留分配若失败,开发期应直接暴露问题;发布构建仍保留 NO_MEM 回退状态。

RuntimeStringView reuses one allocation. The formatted path computes maximum capacity from compiled format metadata first, so an oversized later write is a boundary error rather than a reason to allocate again. If the first retained allocation fails, debug builds should surface it immediately; release builds still keep the NO_MEM fallback status.

Definition at line 437 of file libxr_string.hpp.

438 {
439 if (payload_size == std::numeric_limits<size_t>::max())
440 {
442 }
443 if (payload_size <= capacity_ && data_ != nullptr)
444 {
445 return ErrorCode::OK;
446 }
447 if (data_ != nullptr)
448 {
450 }
451 if (payload_size == 0)
452 {
453 return ErrorCode::OK;
454 }
455
456 data_ = new (std::nothrow) char[payload_size + 1U];
457 if (data_ == nullptr)
458 {
459 ASSERT(data_ != nullptr);
460 return ErrorCode::NO_MEM;
461 }
462 capacity_ = payload_size;
463 return ErrorCode::OK;
464 }
@ NO_MEM
内存不足 | Insufficient memory

◆ NormalizeConcatPart()

template<Print::Text Source = "", typename... Args>
template<typename T >
static constexpr Detail::RuntimeStringTextPart LibXR::RuntimeStringView< Source, Args >::NormalizeConcatPart ( T && text)
inlinestaticnodiscardconstexprprivate

把拼接构造支持的输入统一归一化为只读文本片段;普通拼接只接受文本类输入, 数值格式化必须显式走 Reformat()Reprintf()

Normalize one supported concatenation input into a read-only text part. Plain concatenation accepts text-like inputs only; numeric formatting must go through Reformat() or Reprintf().

Definition at line 633 of file libxr_string.hpp.

634 {
635 using Bare = std::remove_cvref_t<T>;
636 if constexpr (Detail::runtime_string_is_view_v<T>)
637 {
638 const auto& retained = text;
639 return retained.Status() == ErrorCode::OK
640 ? Detail::RuntimeStringTextPart{.view = retained.View()}
641 : Detail::RuntimeStringTextPart{.status = retained.Status()};
642 }
643 else if constexpr (std::is_array_v<Bare> &&
644 std::is_same_v<std::remove_cv_t<std::remove_extent_t<Bare>>, char>)
645 {
646 return {.view = std::string_view(text, BoundedTextLength(text, std::extent_v<Bare>))};
647 }
648 else if constexpr (std::is_same_v<Bare, std::string_view>)
649 {
650 return {.view = text};
651 }
652 else if constexpr (std::is_same_v<Bare, std::string>)
653 {
654 return {.view = std::string_view(text.data(), text.size())};
655 }
656 else if constexpr (std::is_same_v<Bare, std::nullptr_t>)
657 {
658 return {.status = ErrorCode::PTR_NULL};
659 }
660 else if constexpr (std::is_same_v<Bare, char*> || std::is_same_v<Bare, const char*>)
661 {
662 return text == nullptr
663 ? Detail::RuntimeStringTextPart{.status = ErrorCode::PTR_NULL}
664 : Detail::RuntimeStringTextPart{
665 .view = std::string_view(text, std::strlen(text))};
666 }
667 else
668 {
669 static_assert(Detail::runtime_string_always_false<T>,
670 "RuntimeStringView constructor only accepts text-like parts. "
671 "Use Reformat() or Reprintf() for numeric formatting.");
672 return {.status = ErrorCode::ARG_ERR};
673 }
674 }
@ ARG_ERR
参数错误 | Argument error

◆ operator const char *()

template<Print::Text Source = "", typename... Args>
LibXR::RuntimeStringView< Source, Args >::operator const char * ( ) const
inlinenodiscard

Converts to a NUL-terminated C string. / 转换为 NUL 结尾 C 字符串。

Definition at line 401 of file libxr_string.hpp.

401{ return CStr(); }
const char * CStr() const
Returns a NUL-terminated C string. / 返回 NUL 结尾 C 字符串。

◆ operator std::string_view()

template<Print::Text Source = "", typename... Args>
LibXR::RuntimeStringView< Source, Args >::operator std::string_view ( ) const
inlinenodiscardconstexpr

Converts to a read-only string view. / 转换为只读字符串视图。

Definition at line 399 of file libxr_string.hpp.

399{ return View(); }
constexpr std::string_view View() const
Returns the current read-only view. / 返回当前只读视图。

◆ Reformat()

template<Print::Text Source = "", typename... Args>
template<typename... CallArgs>
requires ((Source.Size() != 0 || sizeof...(Args) != 0) && Detail::RuntimeStringArgumentTypes<Args...>::template matches<CallArgs...>)
ErrorCode LibXR::RuntimeStringView< Source, Args >::Reformat ( CallArgs &&... args)
inlinenodiscard

使用绑定的 brace-style 格式重写当前内容。

Rewrite current content with the bound brace-style format.

Definition at line 341 of file libxr_string.hpp.

344 {
345 static_assert(LibXR::Format<Source>::template Matches<Args...>(),
346 "LibXR::RuntimeStringView format argument types do not match "
347 "the format");
348 using Built = typename LibXR::Format<Source>::template Compiled<Args...>;
349 static constexpr size_t max_size =
350 Detail::RuntimeStringMaxFormattedSize<Built>(Source.Size());
351 static_assert(max_size != Detail::runtime_string_unbounded_capacity,
352 "LibXR::RuntimeStringView cannot retain unbounded formatted "
353 "runtime strings");
354
355 return AssignFormatted(max_size, [&](auto& sink) {
356 return Print::FormatTo<Source>(sink, std::forward<CallArgs>(args)...);
357 });
358 }
ErrorCode AssignFormatted(size_t max_size, WriteFn &&write)
格式化重写入口;首次调用按编译期上界分配,后续调用只覆盖已有存储。

◆ Reprintf()

template<Print::Text Source = "", typename... Args>
template<typename... CallArgs>
requires ((Source.Size() != 0 || sizeof...(Args) != 0) && Detail::RuntimeStringArgumentTypes<Args...>::template matches<CallArgs...>)
ErrorCode LibXR::RuntimeStringView< Source, Args >::Reprintf ( CallArgs &&... args)
inlinenodiscard

使用绑定的 printf-style 格式重写当前内容。

Rewrite current content with the bound printf-style format.

Definition at line 365 of file libxr_string.hpp.

368 {
369 static_assert(Print::Printf::Matches<Source, Args...>(),
370 "LibXR::RuntimeStringView printf argument types do not match "
371 "the format");
372 using Built = Print::Printf::Compiled<Source>;
373 static constexpr size_t max_size =
374 Detail::RuntimeStringMaxFormattedSize<Built>(Source.Size());
375 static_assert(max_size != Detail::runtime_string_unbounded_capacity,
376 "LibXR::RuntimeStringView cannot retain unbounded formatted "
377 "runtime strings");
378
379 return AssignFormatted(max_size, [&](auto& sink) {
380 return Print::PrintfTo<Source>(sink, std::forward<CallArgs>(args)...);
381 });
382 }
static consteval bool Matches()
判断 Args... 是否与启用的转换项精确匹配 / Return whether Args... exactly match the enabled conversions
Definition printf.hpp:113

◆ SetFailure()

template<Print::Text Source = "", typename... Args>
ErrorCode LibXR::RuntimeStringView< Source, Args >::SetFailure ( ErrorCode status)
inlinenodiscardprivate

记录最近一次失败,并在已有存储上保留一个有效的空 C 字符串。

Record the latest failure and keep a valid empty C string when storage already exists.

Definition at line 409 of file libxr_string.hpp.

410 {
411 if (data_ != nullptr)
412 {
413 data_[0] = '\0';
414 }
415 size_ = 0;
416 status_ = status;
417 return status_;
418 }

◆ Size()

template<Print::Text Source = "", typename... Args>
size_t LibXR::RuntimeStringView< Source, Args >::Size ( ) const
inlinenodiscardconstexpr

Returns the text size excluding the trailing NUL. / 返回不含结尾 NUL 的文本长度。

Definition at line 393 of file libxr_string.hpp.

393{ return size_; }

◆ Status()

template<Print::Text Source = "", typename... Args>
ErrorCode LibXR::RuntimeStringView< Source, Args >::Status ( ) const
inlinenodiscardconstexpr

Returns the latest operation status. / 返回最近一次操作状态。

Definition at line 397 of file libxr_string.hpp.

397{ return status_; }

◆ View()

template<Print::Text Source = "", typename... Args>
std::string_view LibXR::RuntimeStringView< Source, Args >::View ( ) const
inlinenodiscardconstexpr

Returns the current read-only view. / 返回当前只读视图。

Definition at line 385 of file libxr_string.hpp.

386 {
387 return data_ == nullptr ? std::string_view{} : std::string_view(data_, size_);
388 }

Field Documentation

◆ capacity_

template<Print::Text Source = "", typename... Args>
size_t LibXR::RuntimeStringView< Source, Args >::capacity_ = 0
private

不含结尾 NUL 的已探测/分配容量。 / Probed/allocated payload capacity excluding the trailing NUL.

Definition at line 681 of file libxr_string.hpp.

◆ data_

template<Print::Text Source = "", typename... Args>
char* LibXR::RuntimeStringView< Source, Args >::data_ = nullptr
private

长期保留的 NUL 结尾存储;对象析构时不释放。 / Retained NUL-terminated storage; not released by the destructor.

Definition at line 677 of file libxr_string.hpp.

◆ size_

template<Print::Text Source = "", typename... Args>
size_t LibXR::RuntimeStringView< Source, Args >::size_ = 0
private

不含结尾 NUL 的当前可见文本长度。 / Current visible payload size excluding the trailing NUL.

Definition at line 679 of file libxr_string.hpp.

◆ status_

template<Print::Text Source = "", typename... Args>
ErrorCode LibXR::RuntimeStringView< Source, Args >::status_ = ErrorCode::OK
private

最近一次构造或重写状态。 / Status of the latest construction or rewrite.

Definition at line 683 of file libxr_string.hpp.


The documentation for this class was generated from the following file: