Changeset - r5638:174d9d13ce21
[Not reviewed]
master
0 5 0
tron - 17 years ago 2007-01-13 15:00:16
tron@openttd.org
(svn r8097) Replace strlen() {==,!=,>} 0 by the more concise {,!}StrEmpty(). Additionally the test takes O(1) instead of O(n) now
5 files changed with 13 insertions and 9 deletions:
0 comments (0 inline, 0 general)
src/fontcache.cpp
Show inline comments
 
@@ -235,7 +235,7 @@ static void LoadFreeTypeFont(const char 
 
{
 
	FT_Error error;
 

	
 
	if (strlen(font_name) == 0) return;
 
	if (StrEmpty(font_name)) return;
 

	
 
	error = FT_New_Face(_library, font_name, 0, face);
 

	
 
@@ -278,7 +278,7 @@ static void LoadFreeTypeFont(const char 
 

	
 
void InitFreeType(void)
 
{
 
	if (strlen(_freetype.small_font) == 0 && strlen(_freetype.medium_font) == 0 && strlen(_freetype.large_font) == 0) {
 
	if (StrEmpty(_freetype.small_font) && StrEmpty(_freetype.medium_font) && StrEmpty(_freetype.large_font)) {
 
		DEBUG(freetype, 1, "No font faces specified, using sprite fonts instead");
 
		return;
 
	}
src/network/network_server.cpp
Show inline comments
 
@@ -1291,8 +1291,9 @@ void NetworkPopulateCompanyInfo(void)
 

	
 
		ci = DEREF_CLIENT_INFO(cs);
 
		if (ci != NULL && IsValidPlayer(ci->client_playas)) {
 
			if (strlen(_network_player_info[ci->client_playas].players) != 0)
 
			if (!StrEmpty(_network_player_info[ci->client_playas].players)) {
 
				ttd_strlcat(_network_player_info[ci->client_playas].players, ", ", lengthof(_network_player_info[0].players));
 
			}
 

	
 
			ttd_strlcat(_network_player_info[ci->client_playas].players, client_name, lengthof(_network_player_info[0].players));
 
		}
src/network/network_udp.cpp
Show inline comments
 
@@ -238,7 +238,7 @@ DEF_UDP_RECEIVE_COMMAND(Server, PACKET_U
 
		 * the current list and do not send the other data.
 
		 * The name could be an empty string, if so take the filename. */
 
		packet_len += sizeof(c.grfid) + sizeof(c.md5sum) +
 
				min(strlen((f->name != NULL && strlen(f->name) > 0) ? f->name : f->filename) + 1, (size_t)NETWORK_GRF_NAME_LENGTH);
 
				min(strlen((f->name != NULL && !StrEmpty(f->name)) ? f->name : f->filename) + 1, (size_t)NETWORK_GRF_NAME_LENGTH);
 
		if (packet_len > SEND_MTU - 4) { // 4 is 3 byte header + grf count in reply
 
			break;
 
		}
 
@@ -254,7 +254,7 @@ DEF_UDP_RECEIVE_COMMAND(Server, PACKET_U
 
		char name[NETWORK_GRF_NAME_LENGTH];
 

	
 
		/* The name could be an empty string, if so take the filename */
 
		ttd_strlcpy(name, (in_reply[i]->name != NULL && strlen(in_reply[i]->name) > 0) ?
 
		ttd_strlcpy(name, (in_reply[i]->name != NULL && !StrEmpty(in_reply[i]->name)) ?
 
				in_reply[i]->name : in_reply[i]->filename, sizeof(name));
 
	 	this->Send_GRFIdentifier(packet, in_reply[i]);
 
		NetworkSend_string(packet, name);
 
@@ -395,7 +395,7 @@ DEF_UDP_RECEIVE_COMMAND(Client, PACKET_U
 

	
 
		/* An empty name is not possible under normal circumstances
 
		 * and causes problems when showing the NewGRF list. */
 
		if (strlen(name) == 0) continue;
 
		if (StrEmpty(name)) continue;
 

	
 
		/* Finds the fake GRFConfig for the just read GRF ID and MD5sum tuple.
 
		 * If it exists and not resolved yet, then name of the fake GRF is
src/newgrf_gui.cpp
Show inline comments
 
@@ -75,7 +75,7 @@ static void ShowNewGRFInfo(const GRFConf
 
	if (HASBIT(c->flags, GCF_DISABLED))  y += DrawStringMultiLine(x, y, STR_NEWGRF_DISABLED, w);
 

	
 
	/* Draw GRF info if it exists */
 
	if (c->info != NULL && strlen(c->info) != 0) {
 
	if (c->info != NULL && !StrEmpty(c->info)) {
 
		SetDParamStr(0, c->info);
 
		y += DrawStringMultiLine(x, y, STR_02BD, w);
 
	} else {
 
@@ -116,7 +116,7 @@ static void NewGRFAddDlgWndProc(Window *
 
			for (c = _all_grfs; c != NULL; c = c->next) {
 
				if (n >= w->vscroll.pos && n < w->vscroll.pos + w->vscroll.cap) {
 
					bool h = c == WP(w, newgrf_add_d).sel;
 
					const char *text = (c->name != NULL && strlen(c->name) != 0) ? c->name : c->filename;
 
					const char *text = (c->name != NULL && !StrEmpty(c->name)) ? c->name : c->filename;
 

	
 
					/* Draw selection background */
 
					if (h) GfxFillRect(3, y, w->width - 15, y + 9, 156);
 
@@ -310,7 +310,7 @@ static void NewGRFWndProc(Window *w, Win
 
			y = w->widget[SNGRFS_FILE_LIST].top;
 
			for (c = *WP(w, newgrf_d).list, i = 0; c != NULL; c = c->next, i++) {
 
				if (i >= w->vscroll.pos && i < w->vscroll.pos + w->vscroll.cap) {
 
					const char *text = (c->name != NULL && strlen(c->name) != 0) ? c->name : c->filename;
 
					const char *text = (c->name != NULL && !StrEmpty(c->name)) ? c->name : c->filename;
 
					PalSpriteID pal;
 

	
 
					/* Pick a colour */
src/string.h
Show inline comments
 
@@ -47,6 +47,9 @@ typedef enum CharSetFilter {
 
void strtolower(char *str);
 

	
 

	
 
static inline bool StrEmpty(const char* s) { return s[0] == '\0'; }
 

	
 

	
 
/** Get the length of a string, within a limited buffer */
 
static inline int ttd_strnlen(const char *str, int maxlen)
 
{
0 comments (0 inline, 0 general)