summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-10-23 12:04:54 +0200
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2025-03-13 09:44:31 +0100
commit79e4325192f3260ed4ded264e43da8429650bf72 (patch)
treee64eaf10c378078fa97aecbeac3fa325df605ba2 /src
parentbde9d2d83dc703dd961861c3e6705bca28303cdb (diff)
downloadmana-79e4325192f3260ed4ded264e43da8429650bf72.tar.gz
mana-79e4325192f3260ed4ded264e43da8429650bf72.tar.bz2
mana-79e4325192f3260ed4ded264e43da8429650bf72.tar.xz
mana-79e4325192f3260ed4ded264e43da8429650bf72.zip
Removed needless case-insensitive string comparisons
These are not necessary since we can instead make sure the referenced values match case, like we do for everything else. This affects server types in the server list and colors referenced in theme files. The server version was also compared case-insensitively for some reason.
Diffstat (limited to 'src')
-rw-r--r--src/gui/serverdialog.cpp2
-rw-r--r--src/main.cpp1
-rw-r--r--src/net/manaserv/charhandler.cpp1
-rw-r--r--src/net/serverinfo.h8
-rw-r--r--src/resources/theme.cpp22
-rw-r--r--src/utils/stringutils.cpp23
-rw-r--r--src/utils/stringutils.h10
7 files changed, 13 insertions, 54 deletions
diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp
index 4c54f2ce..941bef82 100644
--- a/src/gui/serverdialog.cpp
+++ b/src/gui/serverdialog.cpp
@@ -455,7 +455,7 @@ void ServerDialog::loadServer(XML::Node serverNode)
std::string version = serverNode.getProperty("minimumVersion",
std::string());
- bool meetsMinimumVersion = compareStrI(version, PACKAGE_VERSION) <= 0;
+ bool meetsMinimumVersion = strcmp(version.c_str(), PACKAGE_VERSION) <= 0;
// For display in the list
if (meetsMinimumVersion)
diff --git a/src/main.cpp b/src/main.cpp
index 21e0264c..2eb970ba 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -25,6 +25,7 @@
#include "utils/filesystem.h"
#include "utils/gettext.h"
+#include "utils/stringutils.h"
#include "utils/xml.h"
#include <getopt.h>
diff --git a/src/net/manaserv/charhandler.cpp b/src/net/manaserv/charhandler.cpp
index 4d44aa93..8afbb90b 100644
--- a/src/net/manaserv/charhandler.cpp
+++ b/src/net/manaserv/charhandler.cpp
@@ -44,6 +44,7 @@
#include "utils/dtor.h"
#include "utils/gettext.h"
+#include "utils/stringutils.h"
extern Net::CharHandler *charHandler;
extern ManaServ::GameHandler *gameHandler;
diff --git a/src/net/serverinfo.h b/src/net/serverinfo.h
index d9520c1c..a9dc785c 100644
--- a/src/net/serverinfo.h
+++ b/src/net/serverinfo.h
@@ -21,8 +21,6 @@
#pragma once
-#include "utils/stringutils.h"
-
#include <cstdint>
#include <deque>
#include <string>
@@ -74,12 +72,12 @@ public:
static ServerType parseType(const std::string &type)
{
- if (compareStrI(type, "tmwathena") == 0)
+ if (type == "tmwathena")
return ServerType::TMWATHENA;
// Used for backward compatibility
- if (compareStrI(type, "eathena") == 0)
+ if (type == "eathena")
return ServerType::TMWATHENA;
- if (compareStrI(type, "manaserv") == 0)
+ if (type == "manaserv")
return ServerType::MANASERV;
return ServerType::UNKNOWN;
}
diff --git a/src/resources/theme.cpp b/src/resources/theme.cpp
index fe25a31b..b1b099ff 100644
--- a/src/resources/theme.cpp
+++ b/src/resources/theme.cpp
@@ -373,7 +373,7 @@ ResourceRef<Image> Theme::getImageFromTheme(const std::string &path)
static int readColorType(const std::string &type)
{
- static std::string colors[] = {
+ static const char *colors[] = {
"TEXT",
"SHADOW",
"OUTLINE",
@@ -419,12 +419,8 @@ static int readColorType(const std::string &type)
return -1;
for (int i = 0; i < Theme::THEME_COLORS_END; i++)
- {
- if (compareStrI(type, colors[i]) == 0)
- {
+ if (type == colors[i])
return i;
- }
- }
return -1;
}
@@ -463,7 +459,7 @@ static gcn::Color readColor(const std::string &description)
static Palette::GradientType readColorGradient(const std::string &grad)
{
- static std::string grads[] = {
+ static const char *grads[] = {
"STATIC",
"PULSE",
"SPECTRUM",
@@ -474,17 +470,15 @@ static Palette::GradientType readColorGradient(const std::string &grad)
return Palette::STATIC;
for (int i = 0; i < 4; i++)
- {
- if (compareStrI(grad, grads[i]))
- return (Palette::GradientType) i;
- }
+ if (grad == grads[i])
+ return static_cast<Palette::GradientType>(i);
return Palette::STATIC;
}
static int readProgressType(const std::string &type)
{
- static std::string colors[] = {
+ static const char *colors[] = {
"DEFAULT",
"HP",
"MP",
@@ -499,10 +493,8 @@ static int readProgressType(const std::string &type)
return -1;
for (int i = 0; i < Theme::THEME_PROG_END; i++)
- {
- if (compareStrI(type, colors[i]) == 0)
+ if (type == colors[i])
return i;
- }
return -1;
}
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp
index 0244dd8c..2354eb85 100644
--- a/src/utils/stringutils.cpp
+++ b/src/utils/stringutils.cpp
@@ -125,29 +125,6 @@ std::string removeColors(std::string msg)
return msg;
}
-int compareStrI(const std::string &a, const std::string &b)
-{
- std::string::const_iterator itA = a.begin();
- std::string::const_iterator endA = a.end();
- std::string::const_iterator itB = b.begin();
- std::string::const_iterator endB = b.end();
-
- for (; itA < endA && itB < endB; ++itA, ++itB)
- {
- int comp = tolower(*itA) - tolower(*itB);
- if (comp)
- return comp;
- }
-
- // Check string lengths
- if (itA == endA && itB == endB)
- return 0;
- else if (itA == endA)
- return -1;
- else
- return 1;
-}
-
bool isWordSeparator(char chr)
{
return (chr == ' ' || chr == ',' || chr == '.' || chr == '"');
diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h
index 349d2a66..01a04eeb 100644
--- a/src/utils/stringutils.h
+++ b/src/utils/stringutils.h
@@ -115,16 +115,6 @@ std::string &replaceCharacters(std::string &str,
std::string removeColors(std::string msg);
/**
- * Compares the two strings case-insensitively.
- *
- * @param a the first string in the comparison
- * @param b the second string in the comparison
- * @return 0 if the strings are equal, positive if the first is greater,
- * negative if the second is greater
- */
-int compareStrI(const std::string &a, const std::string &b);
-
-/**
* Returns whether a string starts with a given prefix.
*/
inline bool startsWith(const std::string &str, const char *prefix)