fix: fix ConfigManager::StringSetting issues
- use yycc_u8string_view in default value and Set function instead of const yycc_char8_t* - fix value check error in Set function.
This commit is contained in:
parent
4f1e2447d0
commit
d27a66e770
|
@ -137,21 +137,17 @@ namespace YYCC::ConfigManager {
|
||||||
|
|
||||||
class StringSetting : public AbstractSetting {
|
class StringSetting : public AbstractSetting {
|
||||||
public:
|
public:
|
||||||
StringSetting(const yycc_char8_t* name, const yycc_char8_t* default_value, Constraint<yycc_u8string> constraint = Constraint<yycc_u8string> {}) :
|
StringSetting(const yycc_char8_t* name, const yycc_u8string_view& default_value, Constraint<yycc_u8string_view> constraint = Constraint<yycc_u8string_view> {}) :
|
||||||
AbstractSetting(name), m_Data(), m_DefaultData(), m_Constraint(constraint) {
|
AbstractSetting(name), m_Data(), m_DefaultData(), m_Constraint(constraint) {
|
||||||
if (default_value != nullptr) {
|
m_Data = default_value;
|
||||||
m_Data = default_value;
|
m_DefaultData = default_value;
|
||||||
m_DefaultData = default_value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
virtual ~StringSetting() {}
|
virtual ~StringSetting() {}
|
||||||
|
|
||||||
const yycc_u8string& Get() const { return m_Data; }
|
const yycc_u8string& Get() const { return m_Data; }
|
||||||
bool Set(const yycc_char8_t* new_data) {
|
bool Set(const yycc_u8string_view& new_data) {
|
||||||
// check data validation
|
// check data validation
|
||||||
if (new_data == nullptr)
|
if (m_Constraint.IsValid() && !m_Constraint.m_CheckFct(new_data))
|
||||||
return false;
|
|
||||||
if (m_Constraint.IsValid() && !m_Constraint.m_CheckFct(m_Data))
|
|
||||||
return false;
|
return false;
|
||||||
// assign data
|
// assign data
|
||||||
m_Data = new_data;
|
m_Data = new_data;
|
||||||
|
@ -194,7 +190,7 @@ namespace YYCC::ConfigManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
yycc_u8string m_Data, m_DefaultData;
|
yycc_u8string m_Data, m_DefaultData;
|
||||||
Constraint<yycc_u8string> m_Constraint;
|
Constraint<yycc_u8string_view> m_Constraint;
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
Loading…
Reference in New Issue
Block a user