1
0
Fork 0

Codechange: use std::string_view for the string setting defaults

pull/14189/head
Rubidium 2025-05-01 17:47:47 +02:00 committed by rubidium42
parent 5c7b04a0c2
commit 5ca686261e
9 changed files with 42 additions and 42 deletions

View File

@ -592,7 +592,7 @@ void StringSettingDesc::MakeValueValid(std::string &str) const
* @param object The object the setting is to be saved in.
* @param str The string to save.
*/
void StringSettingDesc::Write(const void *object, const std::string &str) const
void StringSettingDesc::Write(const void *object, std::string_view str) const
{
reinterpret_cast<std::string *>(GetVariableAddress(object, this->save))->assign(str);
}
@ -665,7 +665,7 @@ void IntSettingDesc::ParseValue(const IniItem *item, void *object) const
void StringSettingDesc::ParseValue(const IniItem *item, void *object) const
{
std::string str = (item == nullptr) ? this->def : item->value.value_or("");
std::string str{(item == nullptr) ? this->def : item->value.value_or("")};
this->MakeValueValid(str);
this->Write(object, str);
}
@ -675,7 +675,7 @@ void ListSettingDesc::ParseValue(const IniItem *item, void *object) const
std::optional<std::string_view> str;
if (item != nullptr) {
str = item->value;
} else if (this->def != nullptr) {
} else if (!this->def.empty()) {
str = this->def;
}
void *ptr = GetVariableAddress(object, this->save);

View File

@ -323,12 +323,12 @@ struct StringSettingDesc : SettingDesc {
*/
typedef void PostChangeCallback(const std::string &value);
StringSettingDesc(const SaveLoad &save, SettingFlags flags, bool startup, const char *def,
StringSettingDesc(const SaveLoad &save, SettingFlags flags, bool startup, std::string_view def,
uint32_t max_length, PreChangeCheck pre_check, PostChangeCallback post_callback) :
SettingDesc(save, flags, startup), def(def == nullptr ? "" : def), max_length(max_length),
SettingDesc(save, flags, startup), def(def), max_length(max_length),
pre_check(pre_check), post_callback(post_callback) {}
std::string def; ///< Default value given when none is present
std::string_view def; ///< Default value given when none is present
uint32_t max_length; ///< Maximum length of the string, 0 means no maximum length
PreChangeCheck *pre_check; ///< Callback to check for the validity of the setting.
PostChangeCallback *post_callback; ///< Callback when the setting has been changed.
@ -345,15 +345,15 @@ struct StringSettingDesc : SettingDesc {
private:
void MakeValueValid(std::string &str) const;
void Write(const void *object, const std::string &str) const;
void Write(const void *object, std::string_view str) const;
};
/** List/array settings. */
struct ListSettingDesc : SettingDesc {
ListSettingDesc(const SaveLoad &save, SettingFlags flags, bool startup, const char *def) :
ListSettingDesc(const SaveLoad &save, SettingFlags flags, bool startup, std::string_view def) :
SettingDesc(save, flags, startup), def(def) {}
const char *def; ///< default value given when none is present
std::string_view def; ///< default value given when none is present
std::string FormatValue(const void *object) const override;
void ParseValue(const IniItem *item, void *object) const override;

View File

@ -61,7 +61,7 @@ max = CalendarTime::MAX_YEAR
[SDT_SSTR]
var = prefix
type = SLE_STRQ
def = nullptr
def = """"
[SDT_SSTR]
var = suffix

View File

@ -176,7 +176,7 @@ var = locale.digit_group_separator
type = SLE_STRQ
from = SLV_118
flags = SettingFlag::NoNetworkSync
def = nullptr
def = """"
post_cb = [](auto) { MarkWholeScreenDirty(); }
cat = SC_BASIC
@ -185,7 +185,7 @@ var = locale.digit_group_separator_currency
type = SLE_STRQ
from = SLV_118
flags = SettingFlag::NoNetworkSync
def = nullptr
def = """"
post_cb = [](auto) { MarkWholeScreenDirty(); }
cat = SC_BASIC
@ -194,6 +194,6 @@ var = locale.digit_decimal_separator
type = SLE_STRQ
from = SLV_126
flags = SettingFlag::NoNetworkSync
def = nullptr
def = """"
post_cb = [](auto) { MarkWholeScreenDirty(); }
cat = SC_BASIC

View File

@ -111,48 +111,48 @@ cat = SC_BASIC
name = ""soundsset""
type = SLE_STRQ
var = BaseSounds::ini_set
def = nullptr
def = """"
cat = SC_BASIC
[SDTG_SSTR]
name = ""musicset""
type = SLE_STRQ
var = BaseMusic::ini_set
def = nullptr
def = """"
cat = SC_BASIC
[SDTG_SSTR]
name = ""videodriver""
type = SLE_STRQ
var = _ini_videodriver
def = nullptr
def = """"
cat = SC_EXPERT
[SDTG_SSTR]
name = ""musicdriver""
type = SLE_STRQ
var = _ini_musicdriver
def = nullptr
def = """"
cat = SC_EXPERT
[SDTG_SSTR]
name = ""sounddriver""
type = SLE_STRQ
var = _ini_sounddriver
def = nullptr
def = """"
cat = SC_EXPERT
[SDTG_SSTR]
name = ""blitter""
type = SLE_STRQ
var = _ini_blitter
def = nullptr
def = """"
[SDTG_SSTR]
name = ""language""
type = SLE_STR
var = _config_language_file
def = nullptr
def = """"
cat = SC_BASIC
; workaround for implicit lengthof() in SDTG_LIST
@ -168,14 +168,14 @@ cat = SC_BASIC
name = ""screenshot_format""
type = SLE_STR
var = _screenshot_format_name
def = nullptr
def = """"
cat = SC_EXPERT
[SDTG_SSTR]
name = ""savegame_format""
type = SLE_STR
var = _savegame_format
def = nullptr
def = """"
cat = SC_EXPERT
[SDTG_BOOL]
@ -188,28 +188,28 @@ ifdef = HAS_TRUETYPE_FONT
name = ""small_font""
type = SLE_STR
var = _fcsettings.small.font
def = nullptr
def = """"
[SDTG_SSTR]
ifdef = HAS_TRUETYPE_FONT
name = ""medium_font""
type = SLE_STR
var = _fcsettings.medium.font
def = nullptr
def = """"
[SDTG_SSTR]
ifdef = HAS_TRUETYPE_FONT
name = ""large_font""
type = SLE_STR
var = _fcsettings.large.font
def = nullptr
def = """"
[SDTG_SSTR]
ifdef = HAS_TRUETYPE_FONT
name = ""mono_font""
type = SLE_STR
var = _fcsettings.mono.font
def = nullptr
def = """"
[SDTG_VAR]
ifdef = HAS_TRUETYPE_FONT
@ -308,14 +308,14 @@ cat = SC_BASIC
name = ""keyboard""
type = SLE_STR
var = _keyboard_opt[0]
def = nullptr
def = """"
cat = SC_EXPERT
[SDTG_SSTR]
name = ""keyboard_caps""
type = SLE_STR
var = _keyboard_opt[1]
def = nullptr
def = """"
cat = SC_EXPERT
[SDTG_VAR]

View File

@ -132,14 +132,14 @@ cat = SC_BASIC
var = music.custom_1
type = SLE_UINT8
flags = SettingFlag::NotInSave, SettingFlag::NoNetworkSync
def = nullptr
def = """"
cat = SC_BASIC
[SDTC_LIST]
var = music.custom_2
type = SLE_UINT8
flags = SettingFlag::NotInSave, SettingFlag::NoNetworkSync
def = nullptr
def = """"
cat = SC_BASIC
[SDTC_BOOL]

View File

@ -47,7 +47,7 @@ var = network.client_name
type = SLE_STR
length = NETWORK_CLIENT_NAME_LENGTH
flags = SettingFlag::NotInSave, SettingFlag::NoNetworkSync
def = nullptr
def = """"
pre_cb = NetworkValidateClientName
post_cb = NetworkUpdateClientName
cat = SC_BASIC
@ -57,7 +57,7 @@ var = network.server_name
type = SLE_STR
length = NETWORK_NAME_LENGTH
flags = SettingFlag::NotInSave, SettingFlag::NoNetworkSync, SettingFlag::NetworkOnly
def = nullptr
def = """"
pre_cb = NetworkValidateServerName
post_cb = [](auto) { UpdateClientConfigValues(); }
cat = SC_BASIC
@ -67,7 +67,7 @@ var = network.connect_to_ip
type = SLE_STR
length = 0
flags = SettingFlag::NotInSave, SettingFlag::NoNetworkSync
def = nullptr
def = """"
[SDTC_SSTR]
var = network.last_joined

View File

@ -39,7 +39,7 @@ var = network.server_password
type = SLE_STR
length = NETWORK_PASSWORD_LENGTH
flags = SettingFlag::NotInSave, SettingFlag::NoNetworkSync, SettingFlag::NetworkOnly
def = nullptr
def = """"
pre_cb = ReplaceAsteriskWithEmptyPassword
post_cb = [](auto) { NetworkServerUpdateGameInfo(); }
cat = SC_BASIC
@ -49,7 +49,7 @@ var = network.rcon_password
type = SLE_STR
length = NETWORK_PASSWORD_LENGTH
flags = SettingFlag::NotInSave, SettingFlag::NoNetworkSync, SettingFlag::NetworkOnly
def = nullptr
def = """"
pre_cb = ReplaceAsteriskWithEmptyPassword
cat = SC_BASIC
@ -58,7 +58,7 @@ var = network.admin_password
type = SLE_STR
length = NETWORK_PASSWORD_LENGTH
flags = SettingFlag::NotInSave, SettingFlag::NoNetworkSync, SettingFlag::NetworkOnly
def = nullptr
def = """"
cat = SC_BASIC
[SDTC_SSTR]
@ -66,7 +66,7 @@ var = network.client_secret_key
type = SLE_STR
length = NETWORK_SECRET_KEY_LENGTH
flags = SettingFlag::NotInSave, SettingFlag::NoNetworkSync
def = nullptr
def = """"
; Prevent the user from setting the secret key from the console using 'setting'
pre_cb = [](auto) { return false; }
@ -75,7 +75,7 @@ var = network.client_public_key
type = SLE_STR
length = NETWORK_SECRET_KEY_LENGTH
flags = SettingFlag::NotInSave, SettingFlag::NoNetworkSync
def = nullptr
def = """"
; Prevent the user from setting the public key from the console using 'setting'
pre_cb = [](auto) { return false; }
@ -84,11 +84,11 @@ var = network.server_invite_code
type = SLE_STR
length = NETWORK_INVITE_CODE_LENGTH
flags = SettingFlag::NotInSave, SettingFlag::NoNetworkSync, SettingFlag::NetworkOnly
def = nullptr
def = """"
[SDTC_SSTR]
var = network.server_invite_code_secret
type = SLE_STR
length = NETWORK_INVITE_CODE_SECRET_LENGTH
flags = SettingFlag::NotInSave, SettingFlag::NoNetworkSync, SettingFlag::NetworkOnly
def = nullptr
def = """"

View File

@ -75,7 +75,7 @@ type = SLE_FILE_I16 | SLE_VAR_U16
flags = SettingFlag::NotInConfig
var = _old_diff_custom
length = 17
def = nullptr
def = """"
to = SLV_4
[SDTG_LIST]
@ -86,7 +86,7 @@ type = SLE_UINT16
flags = SettingFlag::NotInConfig
var = _old_diff_custom
length = 18
def = nullptr
def = """"
full = nullptr
from = SLV_4