Codechange: move locale settings to std::string

pull/332/head
rubidium42 3 years ago committed by rubidium42
parent 16437b7c0d
commit 2022e34824

@ -221,9 +221,9 @@ struct LocaleSettings {
byte units_volume; ///< unit system for volume
byte units_force; ///< unit system for force
byte units_height; ///< unit system for height
char *digit_group_separator; ///< thousand separator for non-currencies
char *digit_group_separator_currency; ///< thousand separator for currencies
char *digit_decimal_separator; ///< decimal separator
std::string digit_group_separator; ///< thousand separator for non-currencies
std::string digit_group_separator_currency; ///< thousand separator for currencies
std::string digit_decimal_separator; ///< decimal separator
};
/** Settings related to news */

@ -343,8 +343,8 @@ static char *FormatNumber(char *buff, int64 number, const char *last, const char
uint64 tot = 0;
for (int i = 0; i < max_digits; i++) {
if (i == max_digits - fractional_digits) {
const char *decimal_separator = _settings_game.locale.digit_decimal_separator;
if (decimal_separator == nullptr) decimal_separator = _langpack.langpack->digit_decimal_separator;
const char *decimal_separator = _settings_game.locale.digit_decimal_separator.c_str();
if (StrEmpty(decimal_separator)) decimal_separator = _langpack.langpack->digit_decimal_separator;
buff += seprintf(buff, last, "%s", decimal_separator);
}
@ -368,8 +368,8 @@ static char *FormatNumber(char *buff, int64 number, const char *last, const char
static char *FormatCommaNumber(char *buff, int64 number, const char *last, int fractional_digits = 0)
{
const char *separator = _settings_game.locale.digit_group_separator;
if (separator == nullptr) separator = _langpack.langpack->digit_group_separator;
const char *separator = _settings_game.locale.digit_group_separator.c_str();
if (StrEmpty(separator)) separator = _langpack.langpack->digit_group_separator;
return FormatNumber(buff, number, last, separator, 1, fractional_digits);
}
@ -407,8 +407,8 @@ static char *FormatBytes(char *buff, int64 number, const char *last)
id++;
}
const char *decimal_separator = _settings_game.locale.digit_decimal_separator;
if (decimal_separator == nullptr) decimal_separator = _langpack.langpack->digit_decimal_separator;
const char *decimal_separator = _settings_game.locale.digit_decimal_separator.c_str();
if (StrEmpty(decimal_separator)) decimal_separator = _langpack.langpack->digit_decimal_separator;
if (number < 1024) {
id = 0;
@ -501,9 +501,9 @@ static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, Money n
}
}
const char *separator = _settings_game.locale.digit_group_separator_currency;
if (separator == nullptr && !StrEmpty(_currency->separator)) separator = _currency->separator;
if (separator == nullptr) separator = _langpack.langpack->digit_group_separator_currency;
const char *separator = _settings_game.locale.digit_group_separator_currency.c_str();
if (StrEmpty(separator)) separator = _currency->separator;
if (StrEmpty(separator)) separator = _langpack.langpack->digit_group_separator_currency;
buff = FormatNumber(buff, number, last, separator);
buff = strecpy(buff, multiplier, last);

@ -107,6 +107,9 @@ static size_t ConvertLandscape(const char *value);
#define SDT_STR(base, var, type, flags, guiflags, def, str, strhelp, strval, proc, from, to, cat, extra, startup)\
SDT_GENERAL(#var, SDT_STRING, SL_STR, type, flags, guiflags, base, var, sizeof(((base*)8)->var), def, 0, 0, 0, nullptr, str, strhelp, strval, proc, nullptr, from, to, cat, extra, startup)
#define SDT_SSTR(base, var, type, flags, guiflags, def, str, strhelp, strval, proc, from, to, cat, extra, startup)\
SDT_GENERAL(#var, SDT_STDSTRING, SL_STDSTR, type, flags, guiflags, base, var, sizeof(((base*)8)->var), def, 0, 0, 0, nullptr, str, strhelp, strval, proc, nullptr, from, to, cat, extra, startup)
#define SDT_OMANY(base, var, type, flags, guiflags, def, max, full, str, strhelp, strval, proc, from, to, load, cat, extra, startup)\
SDT_GENERAL(#var, SDT_ONEOFMANY, SL_VAR, type, flags, guiflags, base, var, 1, def, 0, max, 0, full, str, strhelp, strval, proc, load, from, to, cat, extra, startup)

@ -73,7 +73,7 @@ SDTC_SSTR = SDTC_SSTR( $var, $type, $flags, $guiflags, $def,
SDTC_VAR = SDTC_VAR( $var, $type, $flags, $guiflags, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
SDT_BOOL = SDT_BOOL($base, $var, $flags, $guiflags, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
SDT_OMANY = SDT_OMANY($base, $var, $type, $flags, $guiflags, $def, $max, $full, $str, $strhelp, $strval, $proc, $from, $to, $load, $cat, $extra, $startup),
SDT_STR = SDT_STR($base, $var, $type, $flags, $guiflags, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
SDT_SSTR = SDT_SSTR($base, $var, $type, $flags, $guiflags, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
SDT_VAR = SDT_VAR($base, $var, $type, $flags, $guiflags, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
SDT_NULL = SDT_NULL($length, $from, $to),
SDT_END = SDT_END()
@ -2640,7 +2640,7 @@ str = STR_CONFIG_SETTING_LOCALISATION_UNITS_HEIGHT
strhelp = STR_CONFIG_SETTING_LOCALISATION_UNITS_HEIGHT_HELPTEXT
strval = STR_CONFIG_SETTING_LOCALISATION_UNITS_HEIGHT_IMPERIAL
[SDT_STR]
[SDT_SSTR]
base = GameSettings
var = locale.digit_group_separator
type = SLE_STRQ
@ -2650,7 +2650,7 @@ def = nullptr
proc = RedrawScreen
cat = SC_BASIC
[SDT_STR]
[SDT_SSTR]
base = GameSettings
var = locale.digit_group_separator_currency
type = SLE_STRQ
@ -2660,7 +2660,7 @@ def = nullptr
proc = RedrawScreen
cat = SC_BASIC
[SDT_STR]
[SDT_SSTR]
base = GameSettings
var = locale.digit_decimal_separator
type = SLE_STRQ

Loading…
Cancel
Save