summaryrefslogtreecommitdiff
path: root/src/util/string.cpp
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2013-09-17 02:57:10 -0400
committerkwolekr <kwolekr@minetest.net>2013-11-04 23:59:26 -0500
commite46c5277334e7435b74eedba7fdfe2c773f48d06 (patch)
tree9f5ebc7fc83d5436e1931f1118b76e021b2246d4 /src/util/string.cpp
parent1a96987d0fbbcf689825851ee282fe79e4658c02 (diff)
downloadminetest-e46c5277334e7435b74eedba7fdfe2c773f48d06.tar.gz
minetest-e46c5277334e7435b74eedba7fdfe2c773f48d06.tar.bz2
minetest-e46c5277334e7435b74eedba7fdfe2c773f48d06.zip
Accept hexadecimal and string values for seeds
Diffstat (limited to 'src/util/string.cpp')
-rw-r--r--src/util/string.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/util/string.cpp b/src/util/string.cpp
index 2c1dea497..a2312baf8 100644
--- a/src/util/string.cpp
+++ b/src/util/string.cpp
@@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "string.h"
#include "pointer.h"
+#include "numeric.h"
#include "../sha1.h"
#include "../base64.h"
@@ -136,3 +137,18 @@ char *mystrtok_r(char *s, const char *sep, char **lasts) {
*lasts = t;
return s;
}
+
+u64 read_seed(const char *str) {
+ char *endptr;
+ u64 num;
+
+ if (str[0] == '0' && str[1] == 'x')
+ num = strtoull(str, &endptr, 16);
+ else
+ num = strtoull(str, &endptr, 10);
+
+ if (*endptr)
+ num = murmur_hash_64_ua(str, (int)strlen(str), 0x1337);
+
+ return num;
+}