aboutsummaryrefslogtreecommitdiff
path: root/src/server/shared/Utilities/Util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/shared/Utilities/Util.cpp')
-rwxr-xr-xsrc/server/shared/Utilities/Util.cpp40
1 files changed, 16 insertions, 24 deletions
diff --git a/src/server/shared/Utilities/Util.cpp b/src/server/shared/Utilities/Util.cpp
index 89942b978df..e5f62bf9e6b 100755
--- a/src/server/shared/Utilities/Util.cpp
+++ b/src/server/shared/Utilities/Util.cpp
@@ -56,13 +56,13 @@ double rand_chance(void)
return sfmtRand->Random() * 100.0;
}
-Tokens::Tokens(const std::string &src, const char sep, uint32 vectorReserve)
+Tokenizer::Tokenizer(const std::string &src, const char sep, uint32 vectorReserve)
{
m_str = new char[src.length() + 1];
memcpy(m_str, src.c_str(), src.length() + 1);
if (vectorReserve)
- reserve(vectorReserve);
+ m_storage.reserve(vectorReserve);
char* posold = m_str;
char* posnew = m_str;
@@ -71,17 +71,17 @@ Tokens::Tokens(const std::string &src, const char sep, uint32 vectorReserve)
{
if (*posnew == sep)
{
- push_back(posold);
+ m_storage.push_back(posold);
posold = posnew + 1;
- *posnew = 0x00;
+ *posnew = '\0';
}
- else if (*posnew == 0x00)
+ else if (*posnew == '\0')
{
// Hack like, but the old code accepted these kind of broken strings,
// so changing it would break other things
if (posold != posnew)
- push_back(posold);
+ m_storage.push_back(posold);
break;
}
@@ -471,29 +471,21 @@ void vutf8printf(FILE* out, const char *str, va_list* ap)
#endif
}
-void hexEncodeByteArray(uint8* bytes, uint32 arrayLen, std::string& result)
+std::string ByteArrayToHexStr(uint8 const* bytes, uint32 arrayLen, bool reverse /* = false */)
{
- std::ostringstream ss;
- for (uint32 i=0; i<arrayLen; ++i)
+ int32 init = 0;
+ int32 end = arrayLen;
+ int8 op = 1;
+
+ if (reverse)
{
- for (uint8 j=0; j<2; ++j)
- {
- unsigned char nibble = 0x0F & (bytes[i]>>((1-j)*4));
- char encodedNibble;
- if (nibble < 0x0A)
- encodedNibble = '0'+nibble;
- else
- encodedNibble = 'A'+nibble-0x0A;
- ss << encodedNibble;
- }
+ init = arrayLen - 1;
+ end = -1;
+ op = -1;
}
- result = ss.str();
-}
-std::string ByteArrayToHexStr(uint8* bytes, uint32 length)
-{
std::ostringstream ss;
- for (uint32 i = 0; i < length; ++i)
+ for (int32 i = init; i != end; i += op)
{
char buffer[4];
sprintf(buffer, "%02X ", bytes[i]);