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)
{
#define MYMIN(a,b) ((a)<(b)?(a):(b))
#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
*/
return s;
}
-//
+// Creates a string encoded in JSON format (almost equivalent to a C string literal)
+std::string serializeJsonString(const std::string &plain);
-inline u32 time_to_daynight_ratio(u32 time_of_day)
-{
- const s32 daylength = 16;
- const s32 nightlength = 6;
- const s32 daytimelength = 8;
- s32 d = daylength;
- s32 t = (((time_of_day)%24000)/(24000/d));
- if(t < nightlength/2 || t >= d - nightlength/2)
- //return 300;
- return 350;
- else if(t >= d/2 - daytimelength/2 && t < d/2 + daytimelength/2)
- return 1000;
- else
- return 750;
-}
+// Reads a string encoded in JSON format
+std::string deSerializeJsonString(std::istream &is);
+
+//
// Random helper. Usually d=BS
inline core::aabbox3d<f32> getNodeBox(v3s16 p, float d)
float m_accumulator;
};
+/*
+ Splits a list into "pages". For example, the list [1,2,3,4,5] split
+ into two pages would be [1,2,3],[4,5]. This function computes the
+ minimum and maximum indices of a single page.
+
+ length: Length of the list that should be split
+ page: Page number, 1 <= page <= pagecount
+ pagecount: The number of pages, >= 1
+ minindex: Receives the minimum index (inclusive).
+ maxindex: Receives the maximum index (exclusive).
+
+ Ensures 0 <= minindex <= maxindex <= length.
+*/
+inline void paging(u32 length, u32 page, u32 pagecount, u32 &minindex, u32 &maxindex)
+{
+ if(length < 1 || pagecount < 1 || page < 1 || page > pagecount)
+ {
+ // Special cases or invalid parameters
+ minindex = maxindex = 0;
+ }
+ else if(pagecount <= length)
+ {
+ // Less pages than entries in the list:
+ // Each page contains at least one entry
+ minindex = (length * (page-1) + (pagecount-1)) / pagecount;
+ maxindex = (length * page + (pagecount-1)) / pagecount;
+ }
+ else
+ {
+ // More pages than entries in the list:
+ // Make sure the empty pages are at the end
+ if(page < length)
+ {
+ minindex = page-1;
+ maxindex = page;
+ }
+ else
+ {
+ minindex = 0;
+ maxindex = 0;
+ }
+ }
+}
+
std::string translatePassword(std::string playername, std::wstring password);
enum PointedThingType