fix: fix issues
- restore some CKGlobals behavior because it will cause runtime exception. - move some classes from CmdHelper to UnvirtContext to make CmdHelper more common to use. - output warning string when fail to get utf8 or ordinary string.
This commit is contained in:
@ -522,6 +522,11 @@ if (!this->IsRootNode()) { \
|
||||
|
||||
#pragma region String Argument
|
||||
|
||||
StringArgument::StringArgument(const std::u8string_view& argname, Constraint_t constraint) :
|
||||
AbstractArgument(argname), m_Constraint(constraint) {}
|
||||
|
||||
StringArgument::~StringArgument() {}
|
||||
|
||||
bool StringArgument::BeginConsume(const std::u8string& cur_cmd, ArgumentsMap& am) {
|
||||
// check constraint
|
||||
if (m_Constraint.IsValid() && !m_Constraint.m_CheckFct(cur_cmd))
|
||||
@ -531,23 +536,6 @@ if (!this->IsRootNode()) { \
|
||||
return true;
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Encoding List Argument
|
||||
|
||||
bool EncodingListArgument::BeginConsume(const std::u8string& cur_cmd, ArgumentsMap& am) {
|
||||
// split given argument
|
||||
std::vector<std::u8string> encs = YYCC::StringHelper::Split(cur_cmd, u8",");
|
||||
// check each parts is a valid encoding name
|
||||
for (const auto& item : encs) {
|
||||
if (!LibCmo::EncodingHelper::IsValidEncodingName(item))
|
||||
return false;
|
||||
}
|
||||
// okey, add into map
|
||||
am.Add<ArgValue_t>(m_ArgumentName, encs);
|
||||
return true;
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
}
|
||||
|
@ -498,9 +498,8 @@ namespace Unvirt::CmdHelper {
|
||||
using ArgValue_t = AMItems::StringItem;
|
||||
using Constraint_t = YYCC::Constraints::Constraint<std::u8string>;
|
||||
public:
|
||||
StringArgument(const std::u8string_view& argname, Constraint_t constraint = Constraint_t {}) :
|
||||
AbstractArgument(argname), m_Constraint(constraint) {}
|
||||
virtual ~StringArgument() {}
|
||||
StringArgument(const std::u8string_view& argname, Constraint_t constraint = Constraint_t {});
|
||||
virtual ~StringArgument();
|
||||
YYCC_DEF_CLS_COPY_MOVE(StringArgument);
|
||||
|
||||
protected:
|
||||
@ -508,19 +507,6 @@ namespace Unvirt::CmdHelper {
|
||||
Constraint_t m_Constraint;
|
||||
};
|
||||
|
||||
class EncodingListArgument : public AbstractArgument {
|
||||
public:
|
||||
using ArgValue_t = AMItems::StringArrayItem;
|
||||
public:
|
||||
EncodingListArgument(const std::u8string_view& argname) :
|
||||
AbstractArgument(argname) {}
|
||||
virtual ~EncodingListArgument() {}
|
||||
YYCC_DEF_CLS_COPY_MOVE(EncodingListArgument);
|
||||
|
||||
protected:
|
||||
virtual bool BeginConsume(const std::u8string& cur_cmd, ArgumentsMap& am) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
class CommandParser {
|
||||
|
@ -204,7 +204,7 @@ namespace Unvirt::StructFormatter {
|
||||
for (LibCmo::CKDWORD i = 0; i < slot_count; ++i) {
|
||||
auto desc = bd.GetImageDesc(i);
|
||||
|
||||
Console::FormatLine(u8"#%" PRIuCKDWORD "\t%" PRIuCKDWORD "\t%" PRIuCKDWORD "\t0x%" PRIxCKDWORD " bytes\t",
|
||||
Console::FormatLine(u8"#%" PRIuCKDWORD "\t%" PRIuCKDWORD "\t%" PRIuCKDWORD "\t%s\t0x%" PRIxCKDWORD " bytes\t%s",
|
||||
i,
|
||||
desc->GetWidth(),
|
||||
desc->GetHeight(),
|
||||
|
@ -7,7 +7,31 @@
|
||||
|
||||
namespace Unvirt::Context {
|
||||
|
||||
#pragma region Constraint Help Function
|
||||
#pragma region Specialized for CmdHelper
|
||||
|
||||
class EncodingListArgument : public CmdHelper::Nodes::AbstractArgument {
|
||||
public:
|
||||
using ArgValue_t = CmdHelper::AMItems::StringArrayItem;
|
||||
public:
|
||||
EncodingListArgument(const std::u8string_view& argname) :
|
||||
AbstractArgument(argname) {}
|
||||
virtual ~EncodingListArgument() {}
|
||||
YYCC_DEF_CLS_COPY_MOVE(EncodingListArgument);
|
||||
|
||||
protected:
|
||||
virtual bool BeginConsume(const std::u8string& cur_cmd, CmdHelper::ArgumentsMap& am) override {
|
||||
// split given argument
|
||||
std::vector<std::u8string> encs = YYCC::StringHelper::Split(cur_cmd, u8",");
|
||||
// check each parts is a valid encoding name
|
||||
for (const auto& item : encs) {
|
||||
if (!LibCmo::EncodingHelper::IsValidEncodingName(item))
|
||||
return false;
|
||||
}
|
||||
// okey, add into map
|
||||
am.Add<ArgValue_t>(m_ArgumentName, encs);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
static YYCC::Constraints::Constraint<size_t> GetOneBasedIndexConstraint() {
|
||||
return YYCC::Constraints::Constraint<size_t> {
|
||||
@ -19,7 +43,6 @@ namespace Unvirt::Context {
|
||||
|
||||
#pragma endregion
|
||||
|
||||
|
||||
#pragma region UnvirtContext Misc
|
||||
|
||||
UnvirtContext::UnvirtContext() :
|
||||
@ -136,7 +159,7 @@ namespace Unvirt::Context {
|
||||
)
|
||||
)
|
||||
.Then<CmdHelper::Nodes::Literal>(CmdHelper::Nodes::Literal(u8"encoding")
|
||||
.Then<CmdHelper::Nodes::EncodingListArgument>(CmdHelper::Nodes::EncodingListArgument(u8"enc")
|
||||
.Then<EncodingListArgument>(EncodingListArgument(u8"enc")
|
||||
.Comment(u8"CKContext used encoding splitted by ','. Support mutiple encoding.")
|
||||
.Executes(
|
||||
std::bind(&UnvirtContext::ProcEncoding, this, std::placeholders::_1),
|
||||
@ -644,7 +667,7 @@ namespace Unvirt::Context {
|
||||
}
|
||||
|
||||
void UnvirtContext::ProcEncoding(const CmdHelper::ArgumentsMap& amap) {
|
||||
const auto& encodings = amap.Get<CmdHelper::Nodes::EncodingListArgument::ArgValue_t>(u8"enc").Get();
|
||||
const auto& encodings = amap.Get<EncodingListArgument::ArgValue_t>(u8"enc").Get();
|
||||
m_Ctx->SetEncoding(encodings);
|
||||
}
|
||||
|
||||
@ -706,12 +729,12 @@ namespace Unvirt::Context {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
PrintCommonError(u8"Test command only available in Debug mode.");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void Unvirt::Context::UnvirtContext::ProcHelp(const CmdHelper::ArgumentsMap&) {
|
||||
m_Help.Print();
|
||||
@ -723,4 +746,4 @@ namespace Unvirt::Context {
|
||||
|
||||
#pragma endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user