summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-09-04 19:11:53 +0300
committerAndrei Karas <akaras@inbox.ru>2012-09-04 19:11:53 +0300
commit3a407bb6b73a186eafd99bcec570f88097c4b2e1 (patch)
treeea57a752c348ba0a883294855ad3c62c16e9749d /src/utils
parent872fc368f7b253f26714fc47323064f270b62b40 (diff)
downloadmv-3a407bb6b73a186eafd99bcec570f88097c4b2e1.tar.gz
mv-3a407bb6b73a186eafd99bcec570f88097c4b2e1.tar.bz2
mv-3a407bb6b73a186eafd99bcec570f88097c4b2e1.tar.xz
mv-3a407bb6b73a186eafd99bcec570f88097c4b2e1.zip
Add const to more classes.
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/base64.cpp12
-rw-r--r--src/utils/checkutils.cpp6
-rw-r--r--src/utils/checkutils.h6
-rw-r--r--src/utils/langs.cpp6
-rw-r--r--src/utils/mathutils.h10
-rw-r--r--src/utils/mkdir.cpp4
-rw-r--r--src/utils/mkdir.h2
-rw-r--r--src/utils/mutex.h2
-rw-r--r--src/utils/paths.cpp2
-rw-r--r--src/utils/physfsrwops.cpp17
-rw-r--r--src/utils/process.cpp2
-rw-r--r--src/utils/stringutils.cpp46
-rw-r--r--src/utils/stringutils.h26
-rw-r--r--src/utils/translation/podict.cpp2
-rw-r--r--src/utils/translation/podict.h2
-rw-r--r--src/utils/translation/poparser.cpp11
-rw-r--r--src/utils/translation/poparser.h10
-rw-r--r--src/utils/translation/translationmanager.cpp8
-rw-r--r--src/utils/translation/translationmanager.h6
-rw-r--r--src/utils/xml.cpp36
-rw-r--r--src/utils/xml.h23
21 files changed, 127 insertions, 112 deletions
diff --git a/src/utils/base64.cpp b/src/utils/base64.cpp
index 094cd6227..52c6821fd 100644
--- a/src/utils/base64.cpp
+++ b/src/utils/base64.cpp
@@ -44,12 +44,12 @@ static char base64_table[] =
};
static char base64_pad = '=';
-unsigned char *php3_base64_encode(const unsigned char *string,
- int length, int *ret_length)
+unsigned char *php3_base64_encode(const unsigned char *const string,
+ int length, int *const ret_length)
{
const unsigned char *current = string;
int i = 0;
- unsigned char *result = static_cast<unsigned char *>(calloc(
+ unsigned char *const result = static_cast<unsigned char *>(calloc(
((length + 3 - length % 3) * 4 / 3 + 1) * sizeof(char), 1));
while (length > 2)
@@ -92,12 +92,12 @@ unsigned char *php3_base64_encode(const unsigned char *string,
}
/* as above, but backwards. :) */
-unsigned char *php3_base64_decode(const unsigned char *string,
- int length, int *ret_length)
+unsigned char *php3_base64_decode(const unsigned char *const string,
+ const int length, int *const ret_length)
{
const unsigned char *current = string;
int ch, i = 0, j = 0, k;
- char *chp;
+ const char *chp;
unsigned char *result = static_cast<unsigned char *>(
calloc(length + 1, 1));
diff --git a/src/utils/checkutils.cpp b/src/utils/checkutils.cpp
index abbc6138a..c943d8f36 100644
--- a/src/utils/checkutils.cpp
+++ b/src/utils/checkutils.cpp
@@ -26,14 +26,16 @@
#include "debug.h"
-bool reportFalseReal(bool val, const char* file, unsigned line)
+bool reportFalseReal(const bool val, const char *const file,
+ const unsigned line)
{
if (!val)
logger->log("Debug: false value at %s:%u", file, line);
return val;
}
-bool reportTrueReal(bool val, const char* file, unsigned line)
+bool reportTrueReal(const bool val, const char *const file,
+ const unsigned line)
{
if (val)
logger->log("Debug: true value at %s:%u", file, line);
diff --git a/src/utils/checkutils.h b/src/utils/checkutils.h
index 6791ff7e0..de5dd8fe2 100644
--- a/src/utils/checkutils.h
+++ b/src/utils/checkutils.h
@@ -23,8 +23,10 @@
#include <string>
-bool reportFalseReal(bool val, const char* file, unsigned line);
+bool reportFalseReal(const bool val, const char *const file,
+ const unsigned line);
-bool reportTrueReal(bool val, const char* file, unsigned line);
+bool reportTrueReal(const bool val, const char *const file,
+ const unsigned line);
#endif // UTILS_CHECKUTILS_H
diff --git a/src/utils/langs.cpp b/src/utils/langs.cpp
index 90a83d6c4..bc2837a27 100644
--- a/src/utils/langs.cpp
+++ b/src/utils/langs.cpp
@@ -37,7 +37,7 @@ LangVect getLang()
std::string lang = config.getValue("lang", "").c_str();
if (lang.empty())
{
- char *lng = getenv("LANG");
+ const char *const lng = getenv("LANG");
if (!lng)
return langs;
lang = lng;
@@ -58,7 +58,7 @@ std::string getLangSimple()
std::string lang = config.getValue("lang", "").c_str();
if (lang.empty())
{
- char *lng = getenv("LANG");
+ const char *const lng = getenv("LANG");
if (!lng)
return "";
return lng;
@@ -71,7 +71,7 @@ std::string getLangShort()
std::string lang = config.getValue("lang", "").c_str();
if (lang.empty())
{
- char *lng = getenv("LANG");
+ const char *const lng = getenv("LANG");
if (!lng)
return "";
lang = lng;
diff --git a/src/utils/mathutils.h b/src/utils/mathutils.h
index 6d5a8339d..7e43a3574 100644
--- a/src/utils/mathutils.h
+++ b/src/utils/mathutils.h
@@ -27,7 +27,7 @@
#include <stdint.h>
#include <cstring>
-static uint16_t crc_table[256] =
+static const uint16_t crc_table[256] =
{
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
@@ -90,7 +90,7 @@ inline uint16_t getCrc16(const std::string &str)
inline float fastInvSqrt(float x)
{
union { int i; float x; } tmp;
- float xhalf = 0.5f * x;
+ const float xhalf = 0.5f * x;
tmp.x = x;
tmp.i = 0x5f375a86 - (tmp.i >> 1);
x = tmp.x;
@@ -98,12 +98,12 @@ inline float fastInvSqrt(float x)
return x;
}
-inline float fastSqrt(float x)
+inline float fastSqrt(const float x)
{
return 1.0f / fastInvSqrt(x);
}
-inline float weightedAverage(float n1, float n2, float w)
+inline float weightedAverage(const float n1, const float n2, const float w)
{
if (w < 0.0f)
return n1;
@@ -114,7 +114,7 @@ inline float weightedAverage(float n1, float n2, float w)
return w * n2 + (1.0f - w) * n1;
}
-inline int roundDouble(double v)
+inline int roundDouble(const double v)
{
return (v > 0.0) ? (v + 0.5) : (v - 0.5);
}
diff --git a/src/utils/mkdir.cpp b/src/utils/mkdir.cpp
index 05e7d4bd3..e07b3979f 100644
--- a/src/utils/mkdir.cpp
+++ b/src/utils/mkdir.cpp
@@ -40,7 +40,7 @@
#include "debug.h"
#if defined WIN32
-int mkdir_r(const char *pathname)
+int mkdir_r(const char *const pathname)
{
char tmp[PATH_MAX];
char tmp2[PATH_MAX];
@@ -111,7 +111,7 @@ int mkdir_r(const char *pathname)
}
#else
/// Create a directory, making leading components first if necessary
-int mkdir_r(const char *pathname)
+int mkdir_r(const char *const pathname)
{
size_t len = static_cast<int>(strlen(pathname));
char *tmp = new char[len + 2];
diff --git a/src/utils/mkdir.h b/src/utils/mkdir.h
index 8c5ab4ca2..f72548c92 100644
--- a/src/utils/mkdir.h
+++ b/src/utils/mkdir.h
@@ -22,6 +22,6 @@
#ifndef M_MKDIR_H
#define M_MKDIR_H
-int mkdir_r(const char *pathname);
+int mkdir_r(const char *const pathname);
#endif
diff --git a/src/utils/mutex.h b/src/utils/mutex.h
index 61129b4a9..fe560e354 100644
--- a/src/utils/mutex.h
+++ b/src/utils/mutex.h
@@ -84,7 +84,7 @@ inline void Mutex::unlock()
}
-inline MutexLocker::MutexLocker(Mutex *mutex):
+inline MutexLocker::MutexLocker(Mutex *const mutex) :
mMutex(mutex)
{
mMutex->lock();
diff --git a/src/utils/paths.cpp b/src/utils/paths.cpp
index 081b642c0..05a00c1ea 100644
--- a/src/utils/paths.cpp
+++ b/src/utils/paths.cpp
@@ -118,7 +118,7 @@ std::string getSelfName()
std::string getSelfName()
{
char buf[257];
- ssize_t sz = readlink("/proc/self/exe", buf, 256);
+ const ssize_t sz = readlink("/proc/self/exe", buf, 256);
if (sz > 0 && sz < 256)
{
buf[sz] = 0;
diff --git a/src/utils/physfsrwops.cpp b/src/utils/physfsrwops.cpp
index 1afedf2a3..95ba7db82 100644
--- a/src/utils/physfsrwops.cpp
+++ b/src/utils/physfsrwops.cpp
@@ -32,7 +32,8 @@
static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence)
{
- PHYSFS_file *handle = static_cast<PHYSFS_file *>(rw->hidden.unknown.data1);
+ PHYSFS_file *const handle = static_cast<PHYSFS_file *const>(
+ rw->hidden.unknown.data1);
int pos = 0;
if (whence == SEEK_SET)
@@ -41,7 +42,7 @@ static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence)
} /* if */
else if (whence == SEEK_CUR)
{
- PHYSFS_sint64 current = PHYSFS_tell(handle);
+ const PHYSFS_sint64 current = PHYSFS_tell(handle);
if (current == -1)
{
SDL_SetError("Can't find position in file: %s",
@@ -63,7 +64,7 @@ static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence)
} /* else if */
else if (whence == SEEK_END)
{
- PHYSFS_sint64 len = PHYSFS_fileLength(handle);
+ const PHYSFS_sint64 len = PHYSFS_fileLength(handle);
if (len == -1)
{
SDL_SetError("Can't find end of file: %s", PHYSFS_getLastError());
@@ -102,8 +103,9 @@ static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence)
static int physfsrwops_read(SDL_RWops *rw, void *ptr, int size, int maxnum)
{
- PHYSFS_file *handle = static_cast<PHYSFS_file*>(rw->hidden.unknown.data1);
- PHYSFS_sint64 rc = PHYSFS_read(handle, ptr, size, maxnum);
+ PHYSFS_file *const handle = static_cast<PHYSFS_file *const>(
+ rw->hidden.unknown.data1);
+ const PHYSFS_sint64 rc = PHYSFS_read(handle, ptr, size, maxnum);
if (rc != maxnum)
{
if (!PHYSFS_eof(handle)) /* not EOF? Must be an error. */
@@ -115,8 +117,9 @@ static int physfsrwops_read(SDL_RWops *rw, void *ptr, int size, int maxnum)
static int physfsrwops_write(SDL_RWops *rw, const void *ptr, int size, int num)
{
- PHYSFS_file *handle = static_cast<PHYSFS_file*>(rw->hidden.unknown.data1);
- PHYSFS_sint64 rc = PHYSFS_write(handle, ptr, size, num);
+ PHYSFS_file *const handle = static_cast<PHYSFS_file *const>(
+ rw->hidden.unknown.data1);
+ const PHYSFS_sint64 rc = PHYSFS_write(handle, ptr, size, num);
if (rc != num)
SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
diff --git a/src/utils/process.cpp b/src/utils/process.cpp
index 36e53c305..a5629fbc9 100644
--- a/src/utils/process.cpp
+++ b/src/utils/process.cpp
@@ -176,7 +176,7 @@ int execFileWait(std::string pathName, std::string name,
}
// monitoring process
- pid_t exited_pid = wait(&status);
+ const pid_t exited_pid = wait(&status);
int ret = -1;
if (exited_pid == pid)
{
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp
index a4eafda26..2daad464b 100644
--- a/src/utils/stringutils.cpp
+++ b/src/utils/stringutils.cpp
@@ -73,7 +73,7 @@ unsigned int atox(const std::string &str)
return value;
}
-const char *ipToString(int address)
+const char *ipToString(const int address)
{
static char asciiIP[18];
@@ -86,7 +86,7 @@ const char *ipToString(int address)
return asciiIP;
}
-std::string strprintf(char const *format, ...)
+std::string strprintf(char const *const format, ...)
{
char buf[257];
va_list(args);
@@ -139,13 +139,13 @@ std::string removeColors(std::string 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();
+ const std::string::const_iterator endA = a.end();
std::string::const_iterator itB = b.begin();
- std::string::const_iterator endB = b.end();
+ const std::string::const_iterator endB = b.end();
for (; itA < endA, itB < endB; ++itA, ++itB)
{
- int comp = tolower(*itA) - tolower(*itB);
+ const int comp = tolower(*itA) - tolower(*itB);
if (comp)
return comp;
}
@@ -160,7 +160,7 @@ int compareStrI(const std::string &a, const std::string &b)
}
-bool isWordSeparator(char chr)
+bool isWordSeparator(const char chr)
{
return (chr == ' ' || chr == ',' || chr == '.' || chr == '"');
}
@@ -168,7 +168,7 @@ bool isWordSeparator(char chr)
const std::string findSameSubstring(const std::string &str1,
const std::string &str2)
{
- int minLength = str1.length() > str2.length()
+ const int minLength = str1.length() > str2.length()
? static_cast<int>(str2.length()) : static_cast<int>(str1.length());
for (int f = 0; f < minLength; f ++)
{
@@ -222,7 +222,7 @@ size_t findI(std::string text, StringVect &list)
int base = 94;
int start = 33;
-const std::string encodeStr(unsigned int value, unsigned int size)
+const std::string encodeStr(unsigned int value, const unsigned int size)
{
std::string buf;
@@ -269,7 +269,7 @@ std::string extractNameFromSprite(std::string str)
if (pos2 == std::string::npos)
pos2 = static_cast<size_t>(-1);
- int size = static_cast<int>(pos1) - static_cast<int>(pos2) - 1;
+ const int size = static_cast<int>(pos1) - static_cast<int>(pos2) - 1;
if (size > 0)
str = str.substr(pos2 + 1, size);
}
@@ -292,7 +292,7 @@ std::string removeSpriteIndex(std::string str)
if (pos2 == std::string::npos)
pos2 = static_cast<size_t>(-1);
- int size = static_cast<int>(pos1) - static_cast<int>(pos2) - 1;
+ const int size = static_cast<int>(pos1) - static_cast<int>(pos2) - 1;
if (size > 0)
str = str.substr(pos2 + 1, size);
}
@@ -301,16 +301,16 @@ std::string removeSpriteIndex(std::string str)
const char* getSafeUtf8String(std::string text)
{
- int size = static_cast<int>(text.size()) + UTF8_MAX_SIZE;
- char* buf = new char[size];
+ const int size = static_cast<int>(text.size()) + UTF8_MAX_SIZE;
+ char *const buf = new char[size];
memcpy(buf, text.c_str(), text.size());
memset(buf + text.size(), 0, UTF8_MAX_SIZE);
return buf;
}
-void getSafeUtf8String(std::string text, char *buf)
+void getSafeUtf8String(std::string text, char *const buf)
{
- int size = static_cast<int>(text.size()) + UTF8_MAX_SIZE;
+ const int size = static_cast<int>(text.size()) + UTF8_MAX_SIZE;
if (size > 65500)
text = text.substr(0, 65500);
memcpy(buf, text.c_str(), text.size());
@@ -412,7 +412,7 @@ std::string normalize(const std::string &name)
return toLower(trim(normalized));
}
-std::set<int> splitToIntSet(const std::string &text, char separator)
+std::set<int> splitToIntSet(const std::string &text, const char separator)
{
std::set<int> tokens;
std::stringstream ss(text);
@@ -423,7 +423,7 @@ std::set<int> splitToIntSet(const std::string &text, char separator)
return tokens;
}
-std::list<int> splitToIntList(const std::string &text, char separator)
+std::list<int> splitToIntList(const std::string &text, const char separator)
{
std::list<int> tokens;
std::stringstream ss(text);
@@ -436,7 +436,7 @@ std::list<int> splitToIntList(const std::string &text, char separator)
std::list<std::string> splitToStringList(const std::string &text,
- char separator)
+ const char separator)
{
std::list<std::string> tokens;
std::stringstream ss(text);
@@ -448,7 +448,7 @@ std::list<std::string> splitToStringList(const std::string &text,
}
void splitToStringVector(StringVect &tokens, const std::string &text,
- char separator)
+ const char separator)
{
std::stringstream ss(text);
std::string item;
@@ -461,7 +461,7 @@ void splitToStringVector(StringVect &tokens, const std::string &text,
}
void splitToStringSet(std::set<std::string> &tokens, const std::string &text,
- char separator)
+ const char separator)
{
std::stringstream ss(text);
std::string item;
@@ -540,7 +540,7 @@ std::string stringToHexPath(const std::string &str)
return hex;
}
-void deleteCharLeft(std::string &str, unsigned *pos)
+void deleteCharLeft(std::string &str, unsigned *const pos)
{
if (!pos)
return;
@@ -548,14 +548,14 @@ void deleteCharLeft(std::string &str, unsigned *pos)
while (*pos > 0)
{
(*pos)--;
- int v = str[*pos];
+ const int v = str[*pos];
str.erase(*pos, 1);
if ((v & 192) != 128)
break;
}
}
-bool findLast(std::string &str1, std::string str2)
+bool findLast(const std::string &str1, const std::string &str2)
{
const size_t s1 = str1.size();
const size_t s2 = str2.size();
@@ -567,7 +567,7 @@ bool findLast(std::string &str1, std::string str2)
return false;
}
-bool findFirst(std::string &str1, std::string str2)
+bool findFirst(const std::string &str1, const std::string &str2)
{
const size_t s1 = str1.size();
const size_t s2 = str2.size();
diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h
index 2ac31dd2b..1fb3d9d23 100644
--- a/src/utils/stringutils.h
+++ b/src/utils/stringutils.h
@@ -86,12 +86,12 @@ template<typename T> std::string toString(const T &arg)
* @param address the address to convert to a string
* @return the string representation of the address
*/
-const char *ipToString(int address);
+const char *ipToString(const int address);
/**
* A safe version of sprintf that returns a std::string of the result.
*/
-std::string strprintf(char const *, ...)
+std::string strprintf(char const *const format, ...)
#ifdef __GNUC__
/* This attribute is nice: it even works through gettext invokation. For
example, gcc will complain that strprintf(_("%s"), 42) is ill-formed. */
@@ -134,13 +134,13 @@ int compareStrI(const std::string &a, const std::string &b);
/**
* Tells wether the character is a word separator.
*/
-bool isWordSeparator(char chr);
+bool isWordSeparator(const char chr);
size_t findI(std::string str, std::string subStr);
size_t findI(std::string text, StringVect &list);
-const std::string encodeStr(unsigned int value, unsigned int size = 0);
+const std::string encodeStr(unsigned int value, const unsigned int size = 0);
unsigned int decodeStr(const std::string &str);
@@ -150,7 +150,7 @@ std::string removeSpriteIndex(std::string str);
const char* getSafeUtf8String(std::string text);
-void getSafeUtf8String(std::string text, char *buf);
+void getSafeUtf8String(std::string text, char *const buf);
std::string getFileName(std::string path);
@@ -174,18 +174,18 @@ void replaceSpecialChars(std::string &text);
*/
std::string normalize(const std::string &name);
-std::set<int> splitToIntSet(const std::string &text, char separator);
+std::set<int> splitToIntSet(const std::string &text, const char separator);
-std::list<int> splitToIntList(const std::string &text, char separator);
+std::list<int> splitToIntList(const std::string &text, const char separator);
std::list<std::string> splitToStringList(const std::string &text,
- char separator);
+ const char separator);
void splitToStringVector(StringVect &tokens,
- const std::string &text, char separator);
+ const std::string &text, const char separator);
void splitToStringSet(std::set<std::string> &tokens,
- const std::string &text, char separator);
+ const std::string &text, const char separator);
std::string combineDye(std::string file, std::string dye);
@@ -197,11 +197,11 @@ std::list<std::string> unpackList(const std::string &str);
std::string stringToHexPath(const std::string &str);
-void deleteCharLeft(std::string &str, unsigned *pos);
+void deleteCharLeft(std::string &str, unsigned *const pos);
-bool findLast(std::string &str1, std::string str2);
+bool findLast(const std::string &str1, const std::string &str2);
-bool findFirst(std::string &str1, std::string str2);
+bool findFirst(const std::string &str1, const std::string &str2);
bool findCutLast(std::string &str1, std::string str2);
diff --git a/src/utils/translation/podict.cpp b/src/utils/translation/podict.cpp
index 5b1e2a2f2..ebd0682ed 100644
--- a/src/utils/translation/podict.cpp
+++ b/src/utils/translation/podict.cpp
@@ -47,7 +47,7 @@ const std::string PoDict::getStr(const std::string &str)
return mPoLines[str];
}
-const char *PoDict::getChar(const char *str)
+const char *PoDict::getChar(const char *const str)
{
if (mPoLines.find(str) == mPoLines.end())
return str;
diff --git a/src/utils/translation/podict.h b/src/utils/translation/podict.h
index 4c41aadcc..86a09b0d9 100644
--- a/src/utils/translation/podict.h
+++ b/src/utils/translation/podict.h
@@ -35,7 +35,7 @@ class PoDict
const std::string getStr(const std::string &str);
- const char *getChar(const char *str);
+ const char *getChar(const char *const str);
protected:
friend class PoParser;
diff --git a/src/utils/translation/poparser.cpp b/src/utils/translation/poparser.cpp
index b2278c741..57d9b1604 100644
--- a/src/utils/translation/poparser.cpp
+++ b/src/utils/translation/poparser.cpp
@@ -40,7 +40,7 @@ PoParser::PoParser() :
void PoParser::openFile(std::string name)
{
- ResourceManager *resman = ResourceManager::getInstance();
+ const ResourceManager *const resman = ResourceManager::getInstance();
int size;
char *buf = static_cast<char*>(resman->loadFile(getFileName(name), size));
@@ -48,7 +48,8 @@ void PoParser::openFile(std::string name)
free(buf);
}
-PoDict *PoParser::load(std::string lang, std::string fileName, PoDict *dict)
+PoDict *PoParser::load(const std::string &lang, const std::string &fileName,
+ PoDict *const dict)
{
logger->log("loading lang: %s, file: %s", lang.c_str(), fileName.c_str());
@@ -214,7 +215,7 @@ PoDict *PoParser::getEmptyDict()
bool PoParser::checkLang(std::string lang) const
{
// check is po file exists
- ResourceManager *resman = ResourceManager::getInstance();
+ ResourceManager *const resman = ResourceManager::getInstance();
return resman->exists(getFileName(lang));
}
@@ -225,12 +226,12 @@ std::string PoParser::getFileName(std::string lang) const
return strprintf("translations/%s.po", lang.c_str());
}
-PoDict *PoParser::getDict()
+PoDict *PoParser::getDict() const
{
return new PoDict(mLang);
}
-void PoParser::convertStr(std::string &str)
+void PoParser::convertStr(std::string &str) const
{
if (str.empty())
return;
diff --git a/src/utils/translation/poparser.h b/src/utils/translation/poparser.h
index 35a9cd772..254c44a34 100644
--- a/src/utils/translation/poparser.h
+++ b/src/utils/translation/poparser.h
@@ -33,9 +33,9 @@ class PoParser
public:
PoParser();
- PoDict *load(std::string lang,
- std::string fileName = "",
- PoDict *dict = nullptr);
+ PoDict *load(const std::string &lang,
+ const std::string &fileName = "",
+ PoDict *const dict = nullptr);
bool checkLang(std::string lang) const;
@@ -57,9 +57,9 @@ class PoParser
std::string getFileName(std::string lang) const;
- PoDict *getDict();
+ PoDict *getDict() const;
- void convertStr(std::string &str);
+ void convertStr(std::string &str) const;
// current lang
std::string mLang;
diff --git a/src/utils/translation/translationmanager.cpp b/src/utils/translation/translationmanager.cpp
index 4c811ab60..110353baf 100644
--- a/src/utils/translation/translationmanager.cpp
+++ b/src/utils/translation/translationmanager.cpp
@@ -57,8 +57,8 @@ void TranslationManager::close()
}
PoDict *TranslationManager::loadLang(LangVect lang,
- std::string subName,
- PoDict *dict)
+ const std::string &subName,
+ PoDict *const dict)
{
std::string name = "";
PoParser parser;
@@ -84,14 +84,14 @@ PoDict *TranslationManager::loadLang(LangVect lang,
}
bool TranslationManager::translateFile(const std::string &fileName,
- PoDict *dict,
+ PoDict *const dict,
StringVect &lines)
{
if (!dict || fileName.empty())
return false;
int contentsLength;
- ResourceManager *resman = ResourceManager::getInstance();
+ const ResourceManager *const resman = ResourceManager::getInstance();
char *fileContents = static_cast<char*>(
resman->loadFile(fileName, contentsLength));
diff --git a/src/utils/translation/translationmanager.h b/src/utils/translation/translationmanager.h
index debb555ea..25f88a4c1 100644
--- a/src/utils/translation/translationmanager.h
+++ b/src/utils/translation/translationmanager.h
@@ -31,8 +31,8 @@ class TranslationManager
{
public:
static PoDict *loadLang(StringVect lang,
- std::string subName,
- PoDict *dict = nullptr);
+ const std::string &subName,
+ PoDict *const dict = nullptr);
static void init();
@@ -41,7 +41,7 @@ class TranslationManager
static void loadCurrentLang();
static bool translateFile(const std::string &fileName,
- PoDict *dict,
+ PoDict *const dict,
StringVect &lines);
};
diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp
index 0da516cbf..4d434f46a 100644
--- a/src/utils/xml.cpp
+++ b/src/utils/xml.cpp
@@ -41,14 +41,15 @@ static void xmlNullLogger(void *ctx A_UNUSED, const char *msg A_UNUSED, ...)
namespace XML
{
- Document::Document(const std::string &filename, bool useResman):
+ Document::Document(const std::string &filename, const bool useResman) :
mDoc(nullptr)
{
int size;
char *data = nullptr;
if (useResman)
{
- ResourceManager *resman = ResourceManager::getInstance();
+ const ResourceManager *const resman
+ = ResourceManager::getInstance();
data = static_cast<char*>(resman->loadFile(
filename.c_str(), size));
}
@@ -89,7 +90,7 @@ namespace XML
}
}
- Document::Document(const char *data, int size)
+ Document::Document(const char *const data, const int size)
{
if (data)
mDoc = xmlParseMemory(data, size);
@@ -108,11 +109,11 @@ namespace XML
return mDoc ? xmlDocGetRootElement(mDoc) : nullptr;
}
- int getProperty(XmlNodePtr node, const char* name, int def)
+ int getProperty(const XmlNodePtr node, const char *const name, int def)
{
int &ret = def;
- xmlChar *prop = xmlGetProp(node, BAD_CAST name);
+ xmlChar *const prop = xmlGetProp(node, BAD_CAST name);
if (prop)
{
ret = atoi(reinterpret_cast<char*>(prop));
@@ -122,12 +123,12 @@ namespace XML
return ret;
}
- int getIntProperty(XmlNodePtr node, const char* name, int def,
- int min, int max)
+ int getIntProperty(const XmlNodePtr node, const char *const name, int def,
+ const int min, const int max)
{
int &ret = def;
- xmlChar *prop = xmlGetProp(node, BAD_CAST name);
+ xmlChar *const prop = xmlGetProp(node, BAD_CAST name);
if (prop)
{
ret = atoi(reinterpret_cast<char*>(prop));
@@ -140,11 +141,12 @@ namespace XML
return ret;
}
- double getFloatProperty(XmlNodePtr node, const char* name, double def)
+ double getFloatProperty(const XmlNodePtr node, const char *const name,
+ double def)
{
double &ret = def;
- xmlChar *prop = xmlGetProp(node, BAD_CAST name);
+ xmlChar *const prop = xmlGetProp(node, BAD_CAST name);
if (prop)
{
ret = atof(reinterpret_cast<char*>(prop));
@@ -154,10 +156,10 @@ namespace XML
return ret;
}
- std::string getProperty(XmlNodePtr node, const char *name,
+ std::string getProperty(const XmlNodePtr node, const char *const name,
const std::string &def)
{
- xmlChar *prop = xmlGetProp(node, BAD_CAST name);
+ xmlChar *const prop = xmlGetProp(node, BAD_CAST name);
if (prop)
{
std::string val = reinterpret_cast<char*>(prop);
@@ -168,7 +170,7 @@ namespace XML
return def;
}
- std::string langProperty(XmlNodePtr node, const char *name,
+ std::string langProperty(const XmlNodePtr node, const char *const name,
const std::string &def)
{
std::string str = getProperty(node, name, def);
@@ -178,9 +180,10 @@ namespace XML
return translator->getStr(str);
}
- bool getBoolProperty(XmlNodePtr node, const char* name, bool def)
+ bool getBoolProperty(const XmlNodePtr node, const char *const name,
+ const bool def)
{
- xmlChar *prop = xmlGetProp(node, BAD_CAST name);
+ const xmlChar *const prop = xmlGetProp(node, BAD_CAST name);
if (xmlStrEqual(prop, BAD_CAST "true" ))
return true;
@@ -189,7 +192,8 @@ namespace XML
return def;
}
- XmlNodePtr findFirstChildByName(XmlNodePtr parent, const char *name)
+ XmlNodePtr findFirstChildByName(const XmlNodePtr parent,
+ const char *const name)
{
for_each_xml_child_node(child, parent)
{
diff --git a/src/utils/xml.h b/src/utils/xml.h
index c5f217c78..cef1ebae2 100644
--- a/src/utils/xml.h
+++ b/src/utils/xml.h
@@ -50,7 +50,7 @@ namespace XML
* Constructor that attempts to load the given file through the
* resource manager. Logs errors.
*/
- Document(const std::string &filename, bool useResman = true);
+ Document(const std::string &filename, const bool useResman = true);
/**
* Constructor that attempts to load an XML document from memory.
@@ -59,7 +59,7 @@ namespace XML
* @param data the string to parse as XML
* @param size the length of the string in bytes
*/
- Document(const char *data, int size);
+ Document(const char *const data, const int size);
/**
* Destructor. Frees the loaded XML file.
@@ -79,40 +79,43 @@ namespace XML
/**
* Gets an floating point property from an XmlNodePtr.
*/
- double getFloatProperty(XmlNodePtr node, const char *name, double def);
+ double getFloatProperty(const XmlNodePtr node, const char *const name,
+ double def);
/**
* Gets an integer property from an XmlNodePtr.
*/
- int getProperty(XmlNodePtr node, const char *name, int def);
+ int getProperty(const XmlNodePtr node, const char *const name, int def);
/**
* Gets an integer property from an XmlNodePtr.
*/
- int getIntProperty(XmlNodePtr node, const char* name, int def,
- int min, int max);
+ int getIntProperty(const XmlNodePtr node, const char *const name, int def,
+ const int min, const int max);
/**
* Gets a string property from an XmlNodePtr.
*/
- std::string getProperty(XmlNodePtr node, const char *name,
+ std::string getProperty(const XmlNodePtr node, const char *const name,
const std::string &def);
/**
* Gets a translated string property from an XmlNodePtr.
*/
- std::string langProperty(XmlNodePtr node, const char *name,
+ std::string langProperty(const XmlNodePtr node, const char *const name,
const std::string &def);
/**
* Gets a boolean property from an XmlNodePtr.
*/
- bool getBoolProperty(XmlNodePtr node, const char *name, bool def);
+ bool getBoolProperty(const XmlNodePtr node, const char *const name,
+ const bool def);
/**
* Finds the first child node with the given name
*/
- XmlNodePtr findFirstChildByName(XmlNodePtr parent, const char *name);
+ XmlNodePtr findFirstChildByName(const XmlNodePtr parent,
+ const char *const name);
void initXML();