mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-18 01:42:38 +01:00
Codechange: replace C-style strings with std::string_view related to strings functions
This commit is contained in:
@@ -457,10 +457,10 @@ std::string GetStringWithArgs(StringID string, std::span<StringParameter> args)
|
||||
return result;
|
||||
}
|
||||
|
||||
static const char *GetDecimalSeparator()
|
||||
static std::string_view GetDecimalSeparator()
|
||||
{
|
||||
const char *decimal_separator = _settings_game.locale.digit_decimal_separator.c_str();
|
||||
if (StrEmpty(decimal_separator)) decimal_separator = _langpack.langpack->digit_decimal_separator;
|
||||
std::string_view decimal_separator = _settings_game.locale.digit_decimal_separator;
|
||||
if (decimal_separator.empty()) decimal_separator = _langpack.langpack->digit_decimal_separator;
|
||||
return decimal_separator;
|
||||
}
|
||||
|
||||
@@ -470,7 +470,7 @@ static const char *GetDecimalSeparator()
|
||||
* @param number the number to write down
|
||||
* @param separator the thousands-separator to use
|
||||
*/
|
||||
static void FormatNumber(StringBuilder &builder, int64_t number, const char *separator)
|
||||
static void FormatNumber(StringBuilder &builder, int64_t number, std::string_view separator)
|
||||
{
|
||||
static const int max_digits = 20;
|
||||
uint64_t divisor = 10000000000000000000ULL;
|
||||
@@ -500,8 +500,8 @@ static void FormatNumber(StringBuilder &builder, int64_t number, const char *sep
|
||||
|
||||
static void FormatCommaNumber(StringBuilder &builder, int64_t number)
|
||||
{
|
||||
const char *separator = _settings_game.locale.digit_group_separator.c_str();
|
||||
if (StrEmpty(separator)) separator = _langpack.langpack->digit_group_separator;
|
||||
std::string_view separator = _settings_game.locale.digit_group_separator;
|
||||
if (separator.empty()) separator = _langpack.langpack->digit_group_separator;
|
||||
FormatNumber(builder, number, separator);
|
||||
}
|
||||
|
||||
@@ -529,8 +529,8 @@ static void FormatBytes(StringBuilder &builder, int64_t number)
|
||||
{
|
||||
assert(number >= 0);
|
||||
|
||||
/* 1 2^10 2^20 2^30 2^40 2^50 2^60 */
|
||||
const char * const iec_prefixes[] = {"", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei"};
|
||||
/* 1 2^10 2^20 2^30 2^40 2^50 2^60 */
|
||||
const std::string_view iec_prefixes[] = {"", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei"};
|
||||
uint id = 1;
|
||||
while (number >= 1024 * 1024) {
|
||||
number /= 1024;
|
||||
@@ -620,9 +620,9 @@ static void FormatGenericCurrency(StringBuilder &builder, const CurrencySpec *sp
|
||||
}
|
||||
}
|
||||
|
||||
const char *separator = _settings_game.locale.digit_group_separator_currency.c_str();
|
||||
if (StrEmpty(separator)) separator = GetCurrency().separator.c_str();
|
||||
if (StrEmpty(separator)) separator = _langpack.langpack->digit_group_separator_currency;
|
||||
std::string_view separator = _settings_game.locale.digit_group_separator_currency;
|
||||
if (separator.empty()) separator = GetCurrency().separator;
|
||||
if (separator.empty()) separator = _langpack.langpack->digit_group_separator_currency;
|
||||
FormatNumber(builder, number, separator);
|
||||
if (number_str != STR_NULL) {
|
||||
FormatString(builder, GetStringPtr(number_str), {});
|
||||
@@ -1808,7 +1808,7 @@ static void StationGetSpecialString(StringBuilder &builder, StationFacilities x)
|
||||
if (x.Test(StationFacility::Airport)) builder.PutUtf8(SCC_PLANE);
|
||||
}
|
||||
|
||||
static const char * const _silly_company_names[] = {
|
||||
static const std::string_view _silly_company_names[] = {
|
||||
"Bloggs Brothers",
|
||||
"Tiny Transport Ltd.",
|
||||
"Express Travel",
|
||||
@@ -1824,7 +1824,7 @@ static const char * const _silly_company_names[] = {
|
||||
"Getout & Pushit Ltd."
|
||||
};
|
||||
|
||||
static const char * const _surname_list[] = {
|
||||
static const std::string_view _surname_list[] = {
|
||||
"Adams",
|
||||
"Allan",
|
||||
"Baker",
|
||||
@@ -1856,7 +1856,7 @@ static const char * const _surname_list[] = {
|
||||
"Watkins"
|
||||
};
|
||||
|
||||
static const char * const _silly_surname_list[] = {
|
||||
static const std::string_view _silly_surname_list[] = {
|
||||
"Grumpy",
|
||||
"Dozy",
|
||||
"Speedy",
|
||||
@@ -1876,7 +1876,7 @@ static const char _initial_name_letters[] = {
|
||||
'K', 'L', 'M', 'N', 'P', 'R', 'S', 'T', 'W',
|
||||
};
|
||||
|
||||
static std::span<const char * const> GetSurnameOptions()
|
||||
static std::span<const std::string_view> GetSurnameOptions()
|
||||
{
|
||||
if (_settings_game.game_creation.landscape == LandscapeType::Toyland) return _silly_surname_list;
|
||||
return _surname_list;
|
||||
@@ -1887,7 +1887,7 @@ static std::span<const char * const> GetSurnameOptions()
|
||||
* @param seed The seed the surname was generated from.
|
||||
* @return The surname.
|
||||
*/
|
||||
static const char *GetSurname(uint32_t seed)
|
||||
static std::string_view GetSurname(uint32_t seed)
|
||||
{
|
||||
auto surname_options = GetSurnameOptions();
|
||||
return surname_options[surname_options.size() * GB(seed, 16, 8) >> 8];
|
||||
@@ -2037,7 +2037,7 @@ bool ReadLanguagePack(const LanguageMetadata *lang)
|
||||
#endif
|
||||
|
||||
#ifdef WITH_COCOA
|
||||
extern void MacOSSetCurrentLocaleName(const char *iso_code);
|
||||
extern void MacOSSetCurrentLocaleName(std::string_view iso_code);
|
||||
MacOSSetCurrentLocaleName(_current_language->isocode);
|
||||
#endif
|
||||
|
||||
@@ -2220,7 +2220,7 @@ void InitializeLanguagePacks()
|
||||
* Get the ISO language code of the currently loaded language.
|
||||
* @return the ISO code.
|
||||
*/
|
||||
const char *GetCurrentLanguageIsoCode()
|
||||
std::string_view GetCurrentLanguageIsoCode()
|
||||
{
|
||||
return _langpack.langpack->isocode;
|
||||
}
|
||||
@@ -2297,7 +2297,7 @@ class LanguagePackGlyphSearcher : public MissingGlyphSearcher {
|
||||
return false;
|
||||
}
|
||||
|
||||
void SetFontNames([[maybe_unused]] FontCacheSettings *settings, [[maybe_unused]] const char *font_name, [[maybe_unused]] const void *os_data) override
|
||||
void SetFontNames([[maybe_unused]] FontCacheSettings *settings, [[maybe_unused]] std::string_view font_name, [[maybe_unused]] const void *os_data) override
|
||||
{
|
||||
#if defined(WITH_FREETYPE) || defined(_WIN32) || defined(WITH_COCOA)
|
||||
settings->small.font = font_name;
|
||||
|
||||
Reference in New Issue
Block a user