Changeset - r27202:5a7c474a171e
[Not reviewed]
master
0 10 0
Tyler Trahan - 19 months ago 2023-04-30 08:23:05
tyler@tylertrahan.com
Codechange: Pass more std::string to StringFilter::AddLine() (#10743)
10 files changed with 28 insertions and 24 deletions:
0 comments (0 inline, 0 general)
src/industry.h
Show inline comments
 
@@ -181,16 +181,16 @@ struct Industry : IndustryPool::PoolItem
 
	/** Resets industry counts. */
 
	static inline void ResetIndustryCounts()
 
	{
 
		memset(&counts, 0, sizeof(counts));
 
	}
 

	
 
	inline const char *GetCachedName() const
 
	inline const std::string &GetCachedName() const
 
	{
 
		if (this->cached_name.empty()) this->FillCachedName();
 
		return this->cached_name.c_str();
 
		return this->cached_name;
 
	}
 

	
 
private:
 
	void FillCachedName() const;
 

	
 
protected:
src/network/network_content_gui.cpp
Show inline comments
 
@@ -464,15 +464,15 @@ class NetworkContentListWindow : public 
 
	}
 

	
 
	/** Filter content by tags/name */
 
	static bool CDECL TagNameFilter(const ContentInfo * const *a, ContentListFilterData &filter)
 
	{
 
		filter.string_filter.ResetState();
 
		for (auto &tag : (*a)->tags) filter.string_filter.AddLine(tag.c_str());
 
		for (auto &tag : (*a)->tags) filter.string_filter.AddLine(tag);
 

	
 
		filter.string_filter.AddLine((*a)->name.c_str());
 
		filter.string_filter.AddLine((*a)->name);
 
		return filter.string_filter.GetState();
 
	}
 

	
 
	/** Filter content by type, but still show content selected for download. */
 
	static bool CDECL TypeOrSelectedFilter(const ContentInfo * const *a, ContentListFilterData &filter)
 
	{
src/network/network_gui.cpp
Show inline comments
 
@@ -376,13 +376,13 @@ protected:
 
	static bool CDECL NGameSearchFilter(NetworkGameList * const *item, StringFilter &sf)
 
	{
 
		assert(item != nullptr);
 
		assert((*item) != nullptr);
 

	
 
		sf.ResetState();
 
		sf.AddLine((*item)->info.server_name.c_str());
 
		sf.AddLine((*item)->info.server_name);
 
		return sf.GetState();
 
	}
 

	
 
	/**
 
	 * Draw a single server line.
 
	 * @param cur_item  the server to draw.
src/object_gui.cpp
Show inline comments
 
@@ -139,17 +139,15 @@ public:
 
	}
 

	
 
	/** Filter object classes by class name. */
 
	static bool CDECL TagNameFilter(ObjectClassID const *oc, StringFilter &filter)
 
	{
 
		ObjectClass *objclass = ObjectClass::Get(*oc);
 
		char buffer[DRAW_STRING_BUFFER];
 
		GetString(buffer, objclass->name, lastof(buffer));
 

	
 
		filter.ResetState();
 
		filter.AddLine(buffer);
 
		filter.AddLine(GetString(objclass->name));
 
		return filter.GetState();
 
	}
 

	
 
	/** Builds the filter list of available object classes. */
 
	void BuildObjectClassesAvailable()
 
	{
src/rail_gui.cpp
Show inline comments
 
@@ -1043,17 +1043,14 @@ public:
 
		return a < b;
 
	}
 

	
 
	/** Filter station classes by class name. */
 
	static bool CDECL TagNameFilter(StationClassID const * sc, StringFilter &filter)
 
	{
 
		char buffer[DRAW_STRING_BUFFER];
 
		GetString(buffer, StationClass::Get(*sc)->name, lastof(buffer));
 

	
 
		filter.ResetState();
 
		filter.AddLine(buffer);
 
		filter.AddLine(GetString(StationClass::Get(*sc)->name));
 
		return filter.GetState();
 
	}
 

	
 
	/** Builds the filter list of available station classes. */
 
	void BuildStationClassesAvailable()
 
	{
src/road_gui.cpp
Show inline comments
 
@@ -1246,17 +1246,14 @@ public:
 
		return a < b;
 
	}
 

	
 
	/** Filter classes by class name. */
 
	static bool CDECL TagNameFilter(RoadStopClassID const *sc, StringFilter &filter)
 
	{
 
		char buffer[DRAW_STRING_BUFFER];
 
		GetString(buffer, RoadStopClass::Get(*sc)->name, lastof(buffer));
 

	
 
		filter.ResetState();
 
		filter.AddLine(buffer);
 
		filter.AddLine(GetString(RoadStopClass::Get(*sc)->name));
 
		return filter.GetState();
 
	}
 

	
 
	inline bool ShowNewStops() const
 
	{
 
		return this->vscrollList != nullptr;
src/stringfilter.cpp
Show inline comments
 
@@ -122,12 +122,23 @@ void StringFilter::AddLine(const char *s
 
 *
 
 * You can call this multiple times for a single item, if the filter shall apply to multiple things.
 
 * Before processing the next item you have to call ResetState().
 
 *
 
 * @param str Another line from the item.
 
 */
 
void StringFilter::AddLine(const std::string &str)
 
{
 
	AddLine(str.c_str());
 
}
 

	
 
/**
 
 * Pass another text line from the current item to the filter.
 
 *
 
 * You can call this multiple times for a single item, if the filter shall apply to multiple things.
 
 * Before processing the next item you have to call ResetState().
 
 *
 
 * @param str Another line from the item.
 
 */
 
void StringFilter::AddLine(StringID str)
 
{
 
	char buffer[DRAW_STRING_BUFFER];
 
	GetString(buffer, str, lastof(buffer));
 
	AddLine(buffer);
 
	AddLine(GetString(str));
 
}
src/stringfilter_type.h
Show inline comments
 
@@ -57,12 +57,13 @@ public:
 
	 * @return true if no words were entered.
 
	 */
 
	bool IsEmpty() const { return this->word_index.size() == 0; }
 

	
 
	void ResetState();
 
	void AddLine(const char *str);
 
	void AddLine(const std::string &str);
 
	void AddLine(StringID str);
 

	
 
	/**
 
	 * Get the matching state of the current item.
 
	 * @return true if matched.
 
	 */
src/strings.cpp
Show inline comments
 
@@ -1455,13 +1455,13 @@ static char *FormatString(char *buff, co
 
				const Industry *i = Industry::GetIfValid(args->GetInt32(SCC_INDUSTRY_NAME));
 
				if (i == nullptr) break;
 

	
 
				static bool use_cache = true;
 
				if (use_cache) { // Use cached version if first call
 
					AutoRestoreBackup cache_backup(use_cache, false);
 
					buff = strecpy(buff, i->GetCachedName(), last);
 
					buff = strecpy(buff, i->GetCachedName().c_str(), last);
 
				} else 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(nullptr, 0, nullptr);
 
					buff = FormatString(buff, GetStringPtr(GetIndustrySpec(i->type)->name), &tmp_params, last, next_substr_case_index);
 
				} else {
 
@@ -1538,13 +1538,13 @@ static char *FormatString(char *buff, co
 
				const Town *t = Town::GetIfValid(args->GetInt32(SCC_TOWN_NAME));
 
				if (t == nullptr) break;
 

	
 
				static bool use_cache = true;
 
				if (use_cache) { // Use cached version if first call
 
					AutoRestoreBackup cache_backup(use_cache, false);
 
					buff = strecpy(buff, t->GetCachedName(), last);
 
					buff = strecpy(buff, t->GetCachedName().c_str(), last);
 
				} else if (!t->name.empty()) {
 
					int64 args_array[] = {(int64)(size_t)t->name.c_str()};
 
					StringParameters tmp_params(args_array);
 
					buff = GetStringWithArgs(buff, STR_JUST_RAW_STRING, &tmp_params, last);
 
				} else {
 
					buff = GetTownName(buff, t, last);
src/town.h
Show inline comments
 
@@ -122,17 +122,17 @@ struct Town : TownPool::PoolItem<&_town_
 
		/* 3 is added (the noise of the lowest airport), so the  user can at least build a small airfield. */
 
		return (this->cache.population / _settings_game.economy.town_noise_population[_settings_game.difficulty.town_council_tolerance]) + 3;
 
	}
 

	
 
	void UpdateVirtCoord();
 

	
 
	inline const char *GetCachedName() const
 
	inline const std::string &GetCachedName() const
 
	{
 
		if (!this->name.empty()) return this->name.c_str();
 
		if (!this->name.empty()) return this->name;
 
		if (this->cached_name.empty()) this->FillCachedName();
 
		return this->cached_name.c_str();
 
		return this->cached_name;
 
	}
 

	
 
	static inline Town *GetByTile(TileIndex tile)
 
	{
 
		return Town::Get(GetTownIndex(tile));
 
	}
0 comments (0 inline, 0 general)