summaryrefslogtreecommitdiff
path: root/src/utility.h
diff options
context:
space:
mode:
authorKahrl <kahrl@gmx.net>2011-12-03 09:01:14 +0100
committerPerttu Ahola <celeron55@gmail.com>2012-03-10 20:11:10 +0200
commit967f25461bbde28dbc0247fa1c491e9d9938a5b2 (patch)
treed1e26464862551db3f1d12627cdbe9e31fe211a9 /src/utility.h
parent00536518142a586f3fc51a07f76e12085e3cbd30 (diff)
downloadminetest-967f25461bbde28dbc0247fa1c491e9d9938a5b2.tar.gz
minetest-967f25461bbde28dbc0247fa1c491e9d9938a5b2.tar.bz2
minetest-967f25461bbde28dbc0247fa1c491e9d9938a5b2.zip
Chat console, including a number of rebases and modifications.
Defaults modified from original: alpha=200, key=F10
Diffstat (limited to 'src/utility.h')
-rw-r--r--src/utility.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/utility.h b/src/utility.h
index f4c7c3017..aa64c28bb 100644
--- a/src/utility.h
+++ b/src/utility.h
@@ -694,6 +694,46 @@ private:
u32 *m_result;
};
+// Tests if two strings are equal, optionally case insensitive
+inline bool str_equal(const std::wstring& s1, const std::wstring& s2,
+ bool case_insensitive = false)
+{
+ if(case_insensitive)
+ {
+ if(s1.size() != s2.size())
+ return false;
+ for(size_t i = 0; i < s1.size(); ++i)
+ if(tolower(s1[i]) != tolower(s2[i]))
+ return false;
+ return true;
+ }
+ else
+ {
+ return s1 == s2;
+ }
+}
+
+// Tests if the second string is a prefix of the first, optionally case insensitive
+inline bool str_starts_with(const std::wstring& str, const std::wstring& prefix,
+ bool case_insensitive = false)
+{
+ if(str.size() < prefix.size())
+ return false;
+ if(case_insensitive)
+ {
+ for(size_t i = 0; i < prefix.size(); ++i)
+ if(tolower(str[i]) != tolower(prefix[i]))
+ return false;
+ }
+ else
+ {
+ for(size_t i = 0; i < prefix.size(); ++i)
+ if(str[i] != prefix[i])
+ return false;
+ }
+ return true;
+}
+
// Calculates the borders of a "d-radius" cube
inline void getFacePositions(core::list<v3s16> &list, u16 d)
{
@@ -1566,6 +1606,15 @@ inline std::string wrap_rows(const std::string &from, u32 rowlen)
#define MYMAX(a,b) ((a)>(b)?(a):(b))
/*
+ Returns nearest 32-bit integer for given floating point number.
+ <cmath> and <math.h> in VC++ don't provide round().
+*/
+inline s32 myround(f32 f)
+{
+ return floor(f + 0.5);
+}
+
+/*
Returns integer position of node in given floating point position
*/
inline v3s16 floatToInt(v3f p, f32 d)