summaryrefslogtreecommitdiff
path: root/Runtime/Utilities/Hash128.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Runtime/Utilities/Hash128.cpp')
-rw-r--r--Runtime/Utilities/Hash128.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/Runtime/Utilities/Hash128.cpp b/Runtime/Utilities/Hash128.cpp
new file mode 100644
index 0000000..8e8cb68
--- /dev/null
+++ b/Runtime/Utilities/Hash128.cpp
@@ -0,0 +1,33 @@
+#include "UnityPrefix.h"
+#include "Hash128.h"
+
+std::string Hash128ToString(const Hash128& digest)
+{
+ std::string name;
+ name.resize (32);
+ for(int i=0; i < 16; i++)
+ sprintf(&name[i*2],"%02hhx",digest.hashData.bytes[i]);
+ return name;
+}
+
+static inline int HexToNumber(char c)
+{
+ if( c >= '0' && c <= '9')
+ return c-'0';
+ if( c >= 'a' && c <= 'f')
+ return c-'a'+10;
+ if( c >= 'A' && c <= 'F')
+ return c-'A'+10;
+ return 0;
+}
+
+
+Hash128 StringToHash128(const std::string& name)
+{
+ Hash128 digest;
+ int end = name.size() > 32 ? 16 : name.size()/2;
+ for( int i = 0; i < end; ++i ) {
+ digest.hashData.bytes[i] = HexToNumber(name[i*2]) * 16 + HexToNumber(name[i*2+1]);
+ }
+ return digest;
+} \ No newline at end of file