summaryrefslogtreecommitdiff
path: root/src/strings.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/strings.cpp')
-rw-r--r--src/strings.cpp134
1 files changed, 67 insertions, 67 deletions
diff --git a/src/strings.cpp b/src/strings.cpp
index be45a098b..ed8d439b4 100644
--- a/src/strings.cpp
+++ b/src/strings.cpp
@@ -45,12 +45,12 @@
char _config_language_file[MAX_PATH]; ///< The file (name) stored in the configuration.
LanguageList _languages; ///< The actual list of language meta data.
-const LanguageMetadata *_current_language = NULL; ///< The currently loaded language.
+const LanguageMetadata *_current_language = nullptr; ///< The currently loaded language.
TextDirection _current_text_dir; ///< Text direction of the currently selected language.
#ifdef WITH_ICU_I18N
-icu::Collator *_current_collator = NULL; ///< Collator for the language currently in use.
+icu::Collator *_current_collator = nullptr; ///< Collator for the language currently in use.
#endif /* WITH_ICU_I18N */
static uint64 _global_string_params_data[20]; ///< Global array of string parameters. To access, use #SetDParam.
@@ -60,7 +60,7 @@ StringParameters _global_string_params(_global_string_params_data, 20, _global_s
/** Reset the type array. */
void StringParameters::ClearTypeInformation()
{
- assert(this->type != NULL);
+ assert(this->type != nullptr);
MemSetT(this->type, 0, this->num_param);
}
@@ -75,7 +75,7 @@ int64 StringParameters::GetInt64(WChar type)
DEBUG(misc, 0, "Trying to read invalid string parameter");
return 0;
}
- if (this->type != NULL) {
+ if (this->type != nullptr) {
if (this->type[this->offset] != 0 && this->type[this->offset] != type) {
DEBUG(misc, 0, "Trying to read string parameter with wrong type");
return 0;
@@ -172,7 +172,7 @@ void CopyOutDParam(uint64 *dst, const char **strings, StringID string, int num)
strings[i] = stredup((const char *)(size_t)_global_string_params.GetParam(i));
dst[i] = (size_t)strings[i];
} else {
- strings[i] = NULL;
+ strings[i] = nullptr;
}
}
}
@@ -320,7 +320,7 @@ static char *FormatNumber(char *buff, int64 number, const char *last, const char
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 == NULL) decimal_separator = _langpack->digit_decimal_separator;
+ if (decimal_separator == nullptr) decimal_separator = _langpack->digit_decimal_separator;
buff += seprintf(buff, last, "%s", decimal_separator);
}
@@ -345,7 +345,7 @@ 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 == NULL) separator = _langpack->digit_group_separator;
+ if (separator == nullptr) separator = _langpack->digit_group_separator;
return FormatNumber(buff, number, last, separator, 1, fractional_digits);
}
@@ -384,7 +384,7 @@ static char *FormatBytes(char *buff, int64 number, const char *last)
}
const char *decimal_separator = _settings_game.locale.digit_decimal_separator;
- if (decimal_separator == NULL) decimal_separator = _langpack->digit_decimal_separator;
+ if (decimal_separator == nullptr) decimal_separator = _langpack->digit_decimal_separator;
if (number < 1024) {
id = 0;
@@ -478,8 +478,8 @@ static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, Money n
}
const char *separator = _settings_game.locale.digit_group_separator_currency;
- if (separator == NULL && !StrEmpty(_currency->separator)) separator = _currency->separator;
- if (separator == NULL) separator = _langpack->digit_group_separator_currency;
+ if (separator == nullptr && !StrEmpty(_currency->separator)) separator = _currency->separator;
+ if (separator == nullptr) separator = _langpack->digit_group_separator_currency;
buff = FormatNumber(buff, number, last, separator);
buff = strecpy(buff, multiplier, last);
@@ -937,7 +937,7 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
char buf[256];
bool old_sgd = _scan_for_gender_data;
_scan_for_gender_data = true;
- StringParameters tmp_params(args->GetPointerToOffset(offset), args->num_param - offset, NULL);
+ StringParameters tmp_params(args->GetPointerToOffset(offset), args->num_param - offset, nullptr);
p = FormatString(buf, input, &tmp_params, lastof(buf));
_scan_for_gender_data = old_sgd;
*p = '\0';
@@ -1016,8 +1016,8 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
if (game_script && GetStringTab(str) != TEXT_TAB_GAMESCRIPT_START) break;
/* WARNING. It's prohibited for the included string to consume any arguments.
* For included strings that consume argument, you should use STRING1, STRING2 etc.
- * To debug stuff you can set argv to NULL and it will tell you */
- StringParameters tmp_params(args->GetDataPointer(), args->GetDataLeft(), NULL);
+ * To debug stuff you can set argv to nullptr and it will tell you */
+ StringParameters tmp_params(args->GetDataPointer(), args->GetDataLeft(), nullptr);
buff = GetStringWithArgs(buff, str, &tmp_params, last, next_substr_case_index, game_script);
next_substr_case_index = 0;
break;
@@ -1270,9 +1270,9 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
case SCC_COMPANY_NAME: { // {COMPANY}
const Company *c = Company::GetIfValid(args->GetInt32());
- if (c == NULL) break;
+ if (c == nullptr) break;
- if (c->name != NULL) {
+ if (c->name != nullptr) {
int64 args_array[] = {(int64)(size_t)c->name};
StringParameters tmp_params(args_array);
buff = GetStringWithArgs(buff, STR_JUST_RAW_STRING, &tmp_params, last);
@@ -1307,7 +1307,7 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
}
const Depot *d = Depot::Get(args->GetInt32());
- if (d->name != NULL) {
+ if (d->name != nullptr) {
int64 args_array[] = {(int64)(size_t)d->name};
StringParameters tmp_params(args_array);
buff = GetStringWithArgs(buff, STR_JUST_RAW_STRING, &tmp_params, last);
@@ -1321,14 +1321,14 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
case SCC_ENGINE_NAME: { // {ENGINE}
const Engine *e = Engine::GetIfValid(args->GetInt32(SCC_ENGINE_NAME));
- if (e == NULL) break;
+ if (e == nullptr) break;
- if (e->name != NULL && e->IsEnabled()) {
+ if (e->name != nullptr && e->IsEnabled()) {
int64 args_array[] = {(int64)(size_t)e->name};
StringParameters tmp_params(args_array);
buff = GetStringWithArgs(buff, STR_JUST_RAW_STRING, &tmp_params, last);
} else {
- StringParameters tmp_params(NULL, 0, NULL);
+ StringParameters tmp_params(nullptr, 0, nullptr);
buff = GetStringWithArgs(buff, e->info.string_id, &tmp_params, last);
}
break;
@@ -1336,9 +1336,9 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
case SCC_GROUP_NAME: { // {GROUP}
const Group *g = Group::GetIfValid(args->GetInt32());
- if (g == NULL) break;
+ if (g == nullptr) break;
- if (g->name != NULL) {
+ if (g->name != nullptr) {
int64 args_array[] = {(int64)(size_t)g->name};
StringParameters tmp_params(args_array);
buff = GetStringWithArgs(buff, STR_JUST_RAW_STRING, &tmp_params, last);
@@ -1353,12 +1353,12 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
case SCC_INDUSTRY_NAME: { // {INDUSTRY}
const Industry *i = Industry::GetIfValid(args->GetInt32(SCC_INDUSTRY_NAME));
- if (i == NULL) break;
+ if (i == nullptr) break;
if (_scan_for_gender_data) {
/* Gender is defined by the industry type.
* STR_FORMAT_INDUSTRY_NAME may have the town first, so it would result in the gender of the town name */
- StringParameters tmp_params(NULL, 0, NULL);
+ StringParameters tmp_params(nullptr, 0, nullptr);
buff = FormatString(buff, GetStringPtr(GetIndustrySpec(i->type)->name), &tmp_params, last, next_substr_case_index);
} else {
/* First print the town name and the industry type name. */
@@ -1373,9 +1373,9 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
case SCC_PRESIDENT_NAME: { // {PRESIDENT_NAME}
const Company *c = Company::GetIfValid(args->GetInt32(SCC_PRESIDENT_NAME));
- if (c == NULL) break;
+ if (c == nullptr) break;
- if (c->president_name != NULL) {
+ if (c->president_name != nullptr) {
int64 args_array[] = {(int64)(size_t)c->president_name};
StringParameters tmp_params(args_array);
buff = GetStringWithArgs(buff, STR_JUST_RAW_STRING, &tmp_params, last);
@@ -1391,16 +1391,16 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
StationID sid = args->GetInt32(SCC_STATION_NAME);
const Station *st = Station::GetIfValid(sid);
- if (st == NULL) {
+ if (st == nullptr) {
/* The station doesn't exist anymore. The only place where we might
* be "drawing" an invalid station is in the case of cargo that is
* in transit. */
- StringParameters tmp_params(NULL, 0, NULL);
+ StringParameters tmp_params(nullptr, 0, nullptr);
buff = GetStringWithArgs(buff, STR_UNKNOWN_STATION, &tmp_params, last);
break;
}
- if (st->name != NULL) {
+ if (st->name != nullptr) {
int64 args_array[] = {(int64)(size_t)st->name};
StringParameters tmp_params(args_array);
buff = GetStringWithArgs(buff, STR_JUST_RAW_STRING, &tmp_params, last);
@@ -1428,9 +1428,9 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
case SCC_TOWN_NAME: { // {TOWN}
const Town *t = Town::GetIfValid(args->GetInt32(SCC_TOWN_NAME));
- if (t == NULL) break;
+ if (t == nullptr) break;
- if (t->name != NULL) {
+ if (t->name != nullptr) {
int64 args_array[] = {(int64)(size_t)t->name};
StringParameters tmp_params(args_array);
buff = GetStringWithArgs(buff, STR_JUST_RAW_STRING, &tmp_params, last);
@@ -1442,9 +1442,9 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
case SCC_WAYPOINT_NAME: { // {WAYPOINT}
Waypoint *wp = Waypoint::GetIfValid(args->GetInt32(SCC_WAYPOINT_NAME));
- if (wp == NULL) break;
+ if (wp == nullptr) break;
- if (wp->name != NULL) {
+ if (wp->name != nullptr) {
int64 args_array[] = {(int64)(size_t)wp->name};
StringParameters tmp_params(args_array);
buff = GetStringWithArgs(buff, STR_JUST_RAW_STRING, &tmp_params, last);
@@ -1460,9 +1460,9 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
case SCC_VEHICLE_NAME: { // {VEHICLE}
const Vehicle *v = Vehicle::GetIfValid(args->GetInt32(SCC_VEHICLE_NAME));
- if (v == NULL) break;
+ if (v == nullptr) break;
- if (v->name != NULL) {
+ if (v->name != nullptr) {
int64 args_array[] = {(int64)(size_t)v->name};
StringParameters tmp_params(args_array);
buff = GetStringWithArgs(buff, STR_JUST_RAW_STRING, &tmp_params, last);
@@ -1486,14 +1486,14 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
case SCC_SIGN_NAME: { // {SIGN}
const Sign *si = Sign::GetIfValid(args->GetInt32());
- if (si == NULL) break;
+ if (si == nullptr) break;
- if (si->name != NULL) {
+ if (si->name != nullptr) {
int64 args_array[] = {(int64)(size_t)si->name};
StringParameters tmp_params(args_array);
buff = GetStringWithArgs(buff, STR_JUST_RAW_STRING, &tmp_params, last);
} else {
- StringParameters tmp_params(NULL, 0, NULL);
+ StringParameters tmp_params(nullptr, 0, nullptr);
buff = GetStringWithArgs(buff, STR_DEFAULT_SIGN_NAME, &tmp_params, last);
}
break;
@@ -1717,7 +1717,7 @@ bool ReadLanguagePack(const LanguageMetadata *lang)
/* Current language pack */
size_t len;
LanguagePack *lang_pack = (LanguagePack *)ReadFileToMem(lang->file, &len, 1U << 20);
- if (lang_pack == NULL) return false;
+ if (lang_pack == nullptr) return false;
/* End of read data (+ terminating zero added in ReadFileToMem()) */
const char *end = (char *)lang_pack + len + 1;
@@ -1797,20 +1797,20 @@ bool ReadLanguagePack(const LanguageMetadata *lang)
#ifdef WITH_ICU_I18N
/* Delete previous collator. */
- if (_current_collator != NULL) {
+ if (_current_collator != nullptr) {
delete _current_collator;
- _current_collator = NULL;
+ _current_collator = nullptr;
}
/* Create a collator instance for our current locale. */
UErrorCode status = U_ZERO_ERROR;
_current_collator = icu::Collator::createInstance(icu::Locale(_current_language->isocode), status);
/* Sort number substrings by their numerical value. */
- if (_current_collator != NULL) _current_collator->setAttribute(UCOL_NUMERIC_COLLATION, UCOL_ON, status);
+ if (_current_collator != nullptr) _current_collator->setAttribute(UCOL_NUMERIC_COLLATION, UCOL_ON, status);
/* Avoid using the collator if it is not correctly set. */
if (U_FAILURE(status)) {
delete _current_collator;
- _current_collator = NULL;
+ _current_collator = nullptr;
}
#endif /* WITH_ICU_I18N */
@@ -1840,22 +1840,22 @@ bool ReadLanguagePack(const LanguageMetadata *lang)
* First check some default values, after this one we passed ourselves
* and if none exist return the value for $LANG
* @param param environment variable to check conditionally if default ones are not
- * set. Pass NULL if you don't want additional checks.
- * @return return string containing current charset, or NULL if not-determinable
+ * set. Pass nullptr if you don't want additional checks.
+ * @return return string containing current charset, or nullptr if not-determinable
*/
const char *GetCurrentLocale(const char *param)
{
const char *env;
env = getenv("LANGUAGE");
- if (env != NULL) return env;
+ if (env != nullptr) return env;
env = getenv("LC_ALL");
- if (env != NULL) return env;
+ if (env != nullptr) return env;
- if (param != NULL) {
+ if (param != nullptr) {
env = getenv(param);
- if (env != NULL) return env;
+ if (env != nullptr) return env;
}
return getenv("LANG");
@@ -1877,7 +1877,7 @@ int CDECL StringIDSorter(const StringID *a, const StringID *b)
/**
* Get the language with the given NewGRF language ID.
* @param newgrflangid NewGRF languages ID to check.
- * @return The language's metadata, or NULL if it is not known.
+ * @return The language's metadata, or nullptr if it is not known.
*/
const LanguageMetadata *GetLanguage(byte newgrflangid)
{
@@ -1885,7 +1885,7 @@ const LanguageMetadata *GetLanguage(byte newgrflangid)
if (newgrflangid == lang.newgrflangid) return &lang;
}
- return NULL;
+ return nullptr;
}
/**
@@ -1897,7 +1897,7 @@ const LanguageMetadata *GetLanguage(byte newgrflangid)
static bool GetLanguageFileHeader(const char *file, LanguagePackHeader *hdr)
{
FILE *f = fopen(file, "rb");
- if (f == NULL) return false;
+ if (f == nullptr) return false;
size_t read = fread(hdr, sizeof(*hdr), 1, f);
fclose(f);
@@ -1919,14 +1919,14 @@ static bool GetLanguageFileHeader(const char *file, LanguagePackHeader *hdr)
static void GetLanguageList(const char *path)
{
DIR *dir = ttd_opendir(path);
- if (dir != NULL) {
+ if (dir != nullptr) {
struct dirent *dirent;
- while ((dirent = readdir(dir)) != NULL) {
+ while ((dirent = readdir(dir)) != nullptr) {
const char *d_name = FS2OTTD(dirent->d_name);
const char *extension = strrchr(d_name, '.');
/* Not a language file */
- if (extension == NULL || strcmp(extension, ".lng") != 0) continue;
+ if (extension == nullptr || strcmp(extension, ".lng") != 0) continue;
LanguageMetadata lmd;
seprintf(lmd.file, lastof(lmd.file), "%s%s", path, d_name);
@@ -1934,7 +1934,7 @@ static void GetLanguageList(const char *path)
/* Check whether the file is of the correct version */
if (!GetLanguageFileHeader(lmd.file, &lmd)) {
DEBUG(misc, 3, "%s is not a valid language file", lmd.file);
- } else if (GetLanguage(lmd.newgrflangid) != NULL) {
+ } else if (GetLanguage(lmd.newgrflangid) != nullptr) {
DEBUG(misc, 3, "%s's language ID is already known", lmd.file);
} else {
_languages.push_back(lmd);
@@ -1961,10 +1961,10 @@ void InitializeLanguagePacks()
/* Acquire the locale of the current system */
const char *lang = GetCurrentLocale("LC_MESSAGES");
- if (lang == NULL) lang = "en_GB";
+ if (lang == nullptr) lang = "en_GB";
- const LanguageMetadata *chosen_language = NULL; ///< Matching the language in the configuration file or the current locale
- const LanguageMetadata *language_fallback = NULL; ///< Using pt_PT for pt_BR locale when pt_BR is not available
+ const LanguageMetadata *chosen_language = nullptr; ///< Matching the language in the configuration file or the current locale
+ const LanguageMetadata *language_fallback = nullptr; ///< Using pt_PT for pt_BR locale when pt_BR is not available
const LanguageMetadata *en_GB_fallback = _languages.data(); ///< Fallback when no locale-matching language has been found
/* Find a proper language. */
@@ -1985,8 +1985,8 @@ void InitializeLanguagePacks()
/* We haven't found the language in the config nor the one in the locale.
* Now we set it to one of the fallback languages */
- if (chosen_language == NULL) {
- chosen_language = (language_fallback != NULL) ? language_fallback : en_GB_fallback;
+ if (chosen_language == nullptr) {
+ chosen_language = (language_fallback != nullptr) ? language_fallback : en_GB_fallback;
}
if (!ReadLanguagePack(chosen_language)) usererror("Can't read language pack '%s'", chosen_language->file);
@@ -2005,7 +2005,7 @@ const char *GetCurrentLanguageIsoCode()
* Check whether there are glyphs missing in the current language.
* @param[out] str Pointer to an address for storing the text pointer.
* @return If glyphs are missing, return \c true, else return \c false.
- * @post If \c true is returned and str is not NULL, *str points to a string that is found to contain at least one missing glyph.
+ * @post If \c true is returned and str is not nullptr, *str points to a string that is found to contain at least one missing glyph.
*/
bool MissingGlyphSearcher::FindMissingGlyphs(const char **str)
{
@@ -2017,9 +2017,9 @@ bool MissingGlyphSearcher::FindMissingGlyphs(const char **str)
}
this->Reset();
- for (const char *text = this->NextString(); text != NULL; text = this->NextString()) {
+ for (const char *text = this->NextString(); text != nullptr; text = this->NextString()) {
FontSize size = this->DefaultSize();
- if (str != NULL) *str = text;
+ if (str != nullptr) *str = text;
for (WChar c = Utf8Consume(&text); c != '\0'; c = Utf8Consume(&text)) {
if (c >= SCC_FIRST_FONT && c <= SCC_LAST_FONT) {
size = (FontSize)(c - SCC_FIRST_FONT);
@@ -2050,7 +2050,7 @@ class LanguagePackGlyphSearcher : public MissingGlyphSearcher {
const char *NextString() override
{
- if (this->i >= TEXT_TAB_END) return NULL;
+ if (this->i >= TEXT_TAB_END) return nullptr;
const char *ret = _langpack_offs[_langtab_start[this->i] + this->j];
@@ -2089,13 +2089,13 @@ class LanguagePackGlyphSearcher : public MissingGlyphSearcher {
* been added.
* @param base_font Whether to look at the base font as well.
* @param searcher The methods to use to search for strings to check.
- * If NULL the loaded language pack searcher is used.
+ * If nullptr the loaded language pack searcher is used.
*/
void CheckForMissingGlyphs(bool base_font, MissingGlyphSearcher *searcher)
{
static LanguagePackGlyphSearcher pack_searcher;
- if (searcher == NULL) searcher = &pack_searcher;
- bool bad_font = !base_font || searcher->FindMissingGlyphs(NULL);
+ if (searcher == nullptr) searcher = &pack_searcher;
+ bool bad_font = !base_font || searcher->FindMissingGlyphs(nullptr);
#ifdef WITH_FREETYPE
if (bad_font) {
/* We found an unprintable character... lets try whether we can find