diff options
author | Henry Wilson <m3henry@googlemail.com> | 2019-04-10 22:07:06 +0100 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2019-04-10 23:22:20 +0200 |
commit | 7c8e7c6b6e16d4a26259a676db32d8776b99817e (patch) | |
tree | 99f134b7e66367cf11e10bc5061896eab4a3264f /src/newgrf_text.cpp | |
parent | 3b4f224c0bc50e7248050d4bcbb6d83fd510c1cc (diff) | |
download | openttd-7c8e7c6b6e16d4a26259a676db32d8776b99817e.tar.xz |
Codechange: Use null pointer literal instead of the NULL macro
Diffstat (limited to 'src/newgrf_text.cpp')
-rw-r--r-- | src/newgrf_text.cpp | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/src/newgrf_text.cpp b/src/newgrf_text.cpp index e1f73a5c3..4cba3c368 100644 --- a/src/newgrf_text.cpp +++ b/src/newgrf_text.cpp @@ -115,7 +115,7 @@ private: * @param text_ The text to store in this GRFText. * @param len_ The length of the text to store. */ - GRFText(byte langid_, const char *text_, size_t len_) : next(NULL), len(len_), langid(langid_) + GRFText(byte langid_, const char *text_, size_t len_) : next(nullptr), len(len_), langid(langid_) { /* We need to use memcpy instead of strcpy due to * the possibility of "choice lists" and therefore @@ -232,7 +232,7 @@ struct UnmappedChoiceList : ZeroedMemoryAllocator { } char *d = old_d; - if (lm == NULL) { + if (lm == nullptr) { /* In case there is no mapping, just ignore everything but the default. * A probable cause for this happening is when the language file has * been removed by the user and as such no mapping could be made. */ @@ -342,7 +342,7 @@ char *TranslateTTDPatchCodes(uint32 grfid, uint8 language_id, bool allow_newline size_t len = Utf8Decode(&c, str); /* Helper variable for a possible (string) mapping. */ - UnmappedChoiceList *mapping = NULL; + UnmappedChoiceList *mapping = nullptr; if (c == NFO_UTF8_IDENTIFIER) { unicode = true; @@ -461,7 +461,7 @@ char *TranslateTTDPatchCodes(uint32 grfid, uint8 language_id, bool allow_newline if (str[0] == '\0') goto string_end; const LanguageMap *lm = LanguageMap::GetLanguageMap(grfid, language_id); int index = *str++; - int mapped = lm != NULL ? lm->GetMapping(index, code == 0x0E) : -1; + int mapped = lm != nullptr ? lm->GetMapping(index, code == 0x0E) : -1; if (mapped >= 0) { d += Utf8Encode(d, code == 0x0E ? SCC_GENDER_INDEX : SCC_SET_CASE); d += Utf8Encode(d, code == 0x0E ? mapped : mapped + 1); @@ -472,7 +472,7 @@ char *TranslateTTDPatchCodes(uint32 grfid, uint8 language_id, bool allow_newline case 0x10: case 0x11: if (str[0] == '\0') goto string_end; - if (mapping == NULL) { + if (mapping == nullptr) { if (code == 0x10) str++; // Skip the index grfmsg(1, "choice list %s marker found when not expected", code == 0x10 ? "next" : "default"); break; @@ -490,7 +490,7 @@ char *TranslateTTDPatchCodes(uint32 grfid, uint8 language_id, bool allow_newline break; case 0x12: - if (mapping == NULL) { + if (mapping == nullptr) { grfmsg(1, "choice list end marker found when not expected"); } else { /* Terminate the previous string. */ @@ -499,7 +499,7 @@ char *TranslateTTDPatchCodes(uint32 grfid, uint8 language_id, bool allow_newline /* Now we can start flushing everything and clean everything up. */ d = mapping->Flush(LanguageMap::GetLanguageMap(grfid, language_id)); delete mapping; - mapping = NULL; + mapping = nullptr; } break; @@ -507,7 +507,7 @@ char *TranslateTTDPatchCodes(uint32 grfid, uint8 language_id, bool allow_newline case 0x14: case 0x15: if (str[0] == '\0') goto string_end; - if (mapping != NULL) { + if (mapping != nullptr) { grfmsg(1, "choice lists can't be stacked, it's going to get messy now..."); if (code != 0x14) str++; } else { @@ -559,13 +559,13 @@ char *TranslateTTDPatchCodes(uint32 grfid, uint8 language_id, bool allow_newline } string_end: - if (mapping != NULL) { + if (mapping != nullptr) { grfmsg(1, "choice list was incomplete, the whole list is ignored"); delete mapping; } *d = '\0'; - if (olen != NULL) *olen = d - tmp + 1; + if (olen != nullptr) *olen = d - tmp + 1; tmp = ReallocT(tmp, d - tmp + 1); return tmp; } @@ -580,7 +580,7 @@ void AddGRFTextToList(GRFText **list, GRFText *text_to_add) GRFText **ptext, *text; /* Loop through all languages and see if we can replace a string */ - for (ptext = list; (text = *ptext) != NULL; ptext = &text->next) { + for (ptext = list; (text = *ptext) != nullptr; ptext = &text->next) { if (text->langid == text_to_add->langid) { text_to_add->next = text->next; *ptext = text_to_add; @@ -630,9 +630,9 @@ void AddGRFTextToList(struct GRFText **list, const char *text_to_add) */ GRFText *DuplicateGRFText(GRFText *orig) { - GRFText *newtext = NULL; + GRFText *newtext = nullptr; GRFText **ptext = &newtext; - for (; orig != NULL; orig = orig->next) { + for (; orig != nullptr; orig = orig->next) { *ptext = GRFText::Copy(orig); ptext = &(*ptext)->next; } @@ -684,7 +684,7 @@ StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool ne /* If we didn't find our stringid and grfid in the list, allocate a new id */ if (id == _num_grf_texts) _num_grf_texts++; - if (_grf_text[id].textholder == NULL) { + if (_grf_text[id].textholder == nullptr) { _grf_text[id].grfid = grfid; _grf_text[id].stringid = stringid; _grf_text[id].def_string = def_string; @@ -715,20 +715,20 @@ StringID GetGRFStringID(uint32 grfid, StringID stringid) * Get a C-string from a GRFText-list. If there is a translation for the * current language it is returned, otherwise the default translation * is returned. If there is neither a default nor a translation for the - * current language NULL is returned. + * current language nullptr is returned. * @param text The GRFText to get the string from. */ const char *GetGRFStringFromGRFText(const GRFText *text) { - const char *default_text = NULL; + const char *default_text = nullptr; /* Search the list of lang-strings of this stringid for current lang */ - for (; text != NULL; text = text->next) { + for (; text != nullptr; text = text->next) { if (text->langid == _currentLangID) return text->text; /* If the current string is English or American, set it as the * fallback language if the specific language isn't available. */ - if (text->langid == GRFLX_UNSPECIFIED || (default_text == NULL && (text->langid == GRFLX_ENGLISH || text->langid == GRFLX_AMERICAN))) { + if (text->langid == GRFLX_UNSPECIFIED || (default_text == nullptr && (text->langid == GRFLX_ENGLISH || text->langid == GRFLX_AMERICAN))) { default_text = text->text; } } @@ -744,7 +744,7 @@ const char *GetGRFStringPtr(uint16 stringid) assert(_grf_text[stringid].grfid != 0); const char *str = GetGRFStringFromGRFText(_grf_text[stringid].textholder); - if (str != NULL) return str; + if (str != nullptr) return str; /* Use the default string ID if the fallback string isn't available */ return GetStringPtr(_grf_text[stringid].def_string); @@ -783,7 +783,7 @@ bool CheckGrfLangID(byte lang_id, byte grf_version) */ void CleanUpGRFText(GRFText *grftext) { - while (grftext != NULL) { + while (grftext != nullptr) { GRFText *grftext2 = grftext->next; delete grftext; grftext = grftext2; @@ -802,7 +802,7 @@ void CleanUpStrings() CleanUpGRFText(_grf_text[id].textholder); _grf_text[id].grfid = 0; _grf_text[id].stringid = 0; - _grf_text[id].textholder = NULL; + _grf_text[id].textholder = nullptr; } _num_grf_texts = 0; @@ -814,7 +814,7 @@ struct TextRefStack { const GRFFile *grffile; bool used; - TextRefStack() : position(0), grffile(NULL), used(false) {} + TextRefStack() : position(0), grffile(nullptr), used(false) {} TextRefStack(const TextRefStack &stack) : position(stack.position), @@ -872,7 +872,7 @@ struct TextRefStack { void ResetStack(const GRFFile *grffile) { - assert(grffile != NULL); + assert(grffile != nullptr); this->position = 0; this->grffile = grffile; this->used = true; @@ -928,7 +928,7 @@ void RestoreTextRefStackBackup(struct TextRefStack *backup) * * @param grffile the NewGRF providing the stack data * @param numEntries number of entries to copy from the registers - * @param values values to copy onto the stack; if NULL the temporary NewGRF registers will be used instead + * @param values values to copy onto the stack; if nullptr the temporary NewGRF registers will be used instead */ void StartTextRefStackUsage(const GRFFile *grffile, byte numEntries, const uint32 *values) { @@ -938,7 +938,7 @@ void StartTextRefStackUsage(const GRFFile *grffile, byte numEntries, const uint3 byte *p = _newgrf_textrefstack.stack; for (uint i = 0; i < numEntries; i++) { - uint32 value = values != NULL ? values[i] : _temp_store.GetValue(0x100 + i); + uint32 value = values != nullptr ? values[i] : _temp_store.GetValue(0x100 + i); for (uint j = 0; j < 32; j += 8) { *p = GB(value, j, 8); p++; |