From 15740faf9fe9fe4be08965098bbf2947e096aeeb Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 14 Aug 2019 22:50:43 +0800 Subject: +Unity Runtime code --- Runtime/Utilities/Hash128.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Runtime/Utilities/Hash128.cpp (limited to 'Runtime/Utilities/Hash128.cpp') 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 -- cgit v1.1-26-g67d0