1
0

feat: finish clap manual table filler

- finish clap manual table fill functions.
- fix iterator object for the requirements of std::ranges::end().
This commit is contained in:
2025-10-02 16:57:15 +08:00
parent 446f880df4
commit d69563b5df
3 changed files with 52 additions and 19 deletions

View File

@ -55,13 +55,44 @@ namespace yycc::carton::clap::manual {
for (const auto &reg_opt : options.all_options()) { for (const auto &reg_opt : options.all_options()) {
const auto &opt = reg_opt.get_option(); const auto &opt = reg_opt.get_option();
//for (const auto [index, item] : std::views::enumerate(header)) { auto desc_by_line = OP::lazy_split(opt.get_description(), u8"\n");
// for (const auto [index, item] : std::views::enumerate(desc_by_line)) {
//} if (index == 0) {
auto full_name = TERMCOLOR::colored(opt.to_showcase_name(),
TERMCOLOR::Color::LightYellow,
TERMCOLOR::Color::Default,
TERMCOLOR::Attribute::Default);
auto value_hint = TERMCOLOR::colored(opt.to_showcase_value(),
TERMCOLOR::Color::LightGreen,
TERMCOLOR::Color::Default,
TERMCOLOR::Attribute::Default);
this->opt_printer.add_row({full_name, value_hint, item});
} else {
this->opt_printer.add_row({u8"", u8"", item});
}
}
} }
} }
void Manual::fill_var_table() {} void Manual::fill_var_table() {
const auto &variables = app.get_variables();
for (const auto &reg_var : variables.all_variables()) {
const auto &var = reg_var.get_variable();
auto desc_by_line = OP::lazy_split(var.get_description(), u8"\n");
for (const auto [index, item] : std::views::enumerate(desc_by_line)) {
if (index == 0) {
auto name = TERMCOLOR::colored(var.get_name(),
TERMCOLOR::Color::LightYellow,
TERMCOLOR::Color::Default,
TERMCOLOR::Attribute::Default);
this->var_printer.add_row({name, item});
} else {
this->var_printer.add_row({u8"", item});
}
}
}
}
void Manual::print_version(std::ostream &dst) const { void Manual::print_version(std::ostream &dst) const {
const auto &summary = this->app.get_summary(); const auto &summary = this->app.get_summary();

View File

@ -181,12 +181,12 @@ namespace yycc::string::op {
std::u8string_view next_str; std::u8string_view next_str;
public: public:
CodePointIterator() : CodePointIterator(std::u8string_view()) {}
CodePointIterator(const std::u8string_view& strl) : current_str(), next_str(strl) { ++(*this); } CodePointIterator(const std::u8string_view& strl) : current_str(), next_str(strl) { ++(*this); }
YYCC_DEFAULT_COPY_MOVE(CodePointIterator)
reference operator*() const { return this->current_str; } reference operator*() const { return this->current_str; }
pointer operator->() const { return &this->current_str; } pointer operator->() const { return &this->current_str; }
CodePointIterator& operator++() { CodePointIterator& operator++() {
// move next string to current string and analyse it // move next string to current string and analyse it
current_str = next_str; current_str = next_str;
@ -214,17 +214,14 @@ namespace yycc::string::op {
// return self // return self
return *this; return *this;
} }
CodePointIterator operator++(int) { CodePointIterator operator++(int) {
CodePointIterator temp = *this; CodePointIterator temp = *this;
++(*this); ++(*this);
return temp; return temp;
} }
bool operator==(const CodePointIterator& other) const { bool operator==(const CodePointIterator& other) const {
return this->current_str == other.current_str && this->next_str == other.next_str; return this->current_str == other.current_str && this->next_str == other.next_str;
} }
bool operator!=(const CodePointIterator& other) const { return !(*this == other); } bool operator!=(const CodePointIterator& other) const { return !(*this == other); }
private: private:
@ -263,9 +260,9 @@ namespace yycc::string::op {
public: public:
explicit CodePoint(std::u8string_view u8str) : u8str(u8str) {} explicit CodePoint(std::u8string_view u8str) : u8str(u8str) {}
YYCC_DEFAULT_COPY_MOVE(CodePoint)
CodePointIterator begin() const { return CodePointIterator(u8str); } CodePointIterator begin() const { return CodePointIterator(u8str); }
CodePointIterator end() const { CodePointIterator end() const {
// Pass empty string view indicate end. // Pass empty string view indicate end.
return CodePointIterator(std::u8string_view()); return CodePointIterator(std::u8string_view());
@ -295,7 +292,7 @@ namespace yycc::string::op {
// Do not accept root element always (no empty string). // Do not accept root element always (no empty string).
root->is_end = false; root->is_end = false;
} }
/** /**
* @brief Insert new words in trie tree. * @brief Insert new words in trie tree.
* @details * @details
@ -352,18 +349,18 @@ namespace yycc::string::op {
// YYC MARK: // YYC MARK:
// There is a fatal bug for Trie Tree, but it doesn't matter with our usage scenario. // There is a fatal bug for Trie Tree, but it doesn't matter with our usage scenario.
// //
// Assume there is two string "ab" and "abcd". If user give "abc", // Assume there is two string "ab" and "abcd". If user give "abc",
// we should match it with "ab" prefix, but this function will return there is no match. // we should match it with "ab" prefix, but this function will return there is no match.
// However, this is impossible for UTF8 sequence. // However, this is impossible for UTF8 sequence.
// There is no possibility that two UTF8 sequence, indicating two different Unicode code point respectively, // There is no possibility that two UTF8 sequence, indicating two different Unicode code point respectively,
// has the same prefix and different length. Because their first byte must be different, // has the same prefix and different length. Because their first byte must be different,
// the first byte indicate the length of sequence. // the first byte indicate the length of sequence.
// //
// This result also can be proven for suffix, // This result also can be proven for suffix,
// because first byte must not be equal to any other continuation bytes. // because first byte must not be equal to any other continuation bytes.
// It is impossible that they have same "ab". // It is impossible that they have same "ab".
// //
// So it is safe for our usage scenario although this bug is presented. // So it is safe for our usage scenario although this bug is presented.
// check whether current is valid end. // check whether current is valid end.
@ -471,10 +468,8 @@ namespace yycc::string::op {
return internal_trim<false, true>(strl, words); return internal_trim<false, true>(strl, words);
} }
#pragma endregion #pragma endregion
#pragma region Split #pragma region Split
// Reference: // Reference:
@ -482,6 +477,8 @@ namespace yycc::string::op {
#pragma region Lazy Split Iterator #pragma region Lazy Split Iterator
LazySplitIterator::LazySplitIterator() : LazySplitIterator(std::nullopt, std::u8string_view()) {}
LazySplitIterator::LazySplitIterator(std::optional<std::u8string_view> strl, const std::u8string_view& delimiter) : LazySplitIterator::LazySplitIterator(std::optional<std::u8string_view> strl, const std::u8string_view& delimiter) :
m_current_str(std::nullopt), m_next_str(strl), m_delimiter(delimiter) { m_current_str(std::nullopt), m_next_str(strl), m_delimiter(delimiter) {
// We can archive result by assign string into next string, // We can archive result by assign string into next string,
@ -542,8 +539,8 @@ namespace yycc::string::op {
} }
bool LazySplitIterator::operator==(const LazySplitIterator& other) const { bool LazySplitIterator::operator==(const LazySplitIterator& other) const {
return (this->m_current_str == other.m_current_str) && (this->m_next_str == other.m_next_str) // YYC MARK: do not compare the delimiter
&& (this->m_delimiter == other.m_delimiter); return (this->m_current_str == other.m_current_str) && (this->m_next_str == other.m_next_str);
} }
bool LazySplitIterator::operator!=(const LazySplitIterator& other) const { bool LazySplitIterator::operator!=(const LazySplitIterator& other) const {

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include "../macro/printf_checker.hpp" #include "../macro/printf_checker.hpp"
#include "../macro/class_copy_move.hpp"
#include <string> #include <string>
#include <string_view> #include <string_view>
#include <cstdarg> #include <cstdarg>
@ -243,7 +244,9 @@ namespace yycc::string::op {
std::u8string_view m_delimiter; ///< Delimiter std::u8string_view m_delimiter; ///< Delimiter
public: public:
LazySplitIterator();
LazySplitIterator(std::optional<std::u8string_view> strl, const std::u8string_view& delimiter); LazySplitIterator(std::optional<std::u8string_view> strl, const std::u8string_view& delimiter);
YYCC_DEFAULT_COPY_MOVE(LazySplitIterator)
reference operator*() const; reference operator*() const;
pointer operator->() const; pointer operator->() const;
@ -263,6 +266,8 @@ namespace yycc::string::op {
public: public:
LazySplit(const std::u8string_view& strl, const std::u8string_view& delimiter); LazySplit(const std::u8string_view& strl, const std::u8string_view& delimiter);
YYCC_DEFAULT_COPY_MOVE(LazySplit)
LazySplitIterator begin() const; LazySplitIterator begin() const;
LazySplitIterator end() const; LazySplitIterator end() const;
}; };