|
|
@@ -3,6 +3,7 @@
|
|
|
* License: https://github.com/taylor001/crown/blob/master/LICENSE
|
|
|
*/
|
|
|
|
|
|
+#include "dynamic_string.h"
|
|
|
#include "error.h"
|
|
|
#include "murmur.h"
|
|
|
#include "string_id.h"
|
|
|
@@ -27,10 +28,11 @@ void StringId32::hash(const char* str, u32 len)
|
|
|
_id = murmur32(str, len, 0);
|
|
|
}
|
|
|
|
|
|
-const char* StringId32::to_string(char* buf)
|
|
|
+void StringId32::to_string(DynamicString& s)
|
|
|
{
|
|
|
- snprintf(buf, STRING_LENGTH, "%.8x", _id);
|
|
|
- return buf;
|
|
|
+ char buf[8+1];
|
|
|
+ snprintf(buf, sizeof(buf), "%.8x", _id);
|
|
|
+ s.set(buf, sizeof(buf)-1);
|
|
|
}
|
|
|
|
|
|
StringId64::StringId64(const char* str)
|
|
|
@@ -49,10 +51,11 @@ void StringId64::hash(const char* str, u32 len)
|
|
|
_id = murmur64(str, len, 0);
|
|
|
}
|
|
|
|
|
|
-const char* StringId64::to_string(char* buf)
|
|
|
+void StringId64::to_string(DynamicString& s)
|
|
|
{
|
|
|
- snprintf(buf, STRING_LENGTH, "%.16" PRIx64, _id);
|
|
|
- return buf;
|
|
|
+ char buf[16+1];
|
|
|
+ snprintf(buf, sizeof(buf), "%.16" PRIx64, _id);
|
|
|
+ s.set(buf, sizeof(buf)-1);
|
|
|
}
|
|
|
|
|
|
} // namespace crown
|