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:
2024-08-27 11:25:53 +08:00
parent 3735a202f3
commit 65861143bf
14 changed files with 91 additions and 70 deletions

View File

@ -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
}