diff options
author | Subv <s.v.h21@hotmail.com> | 2012-10-04 19:39:09 -0500 |
---|---|---|
committer | Subv <s.v.h21@hotmail.com> | 2012-10-04 19:39:09 -0500 |
commit | f7d3600e7e7ffaba971b77e4371a705e55593cfd (patch) | |
tree | 2d4e898bb4e09ede5dba97918741597da6fd2d2e /src/server/shared/Utilities/Util.cpp | |
parent | d2437407f4f7ad1af3baeb351626b41bd700065c (diff) | |
parent | 74707a08d3d63dc66e7b6943431c91f50258b0f9 (diff) |
Merge branch 'master' of github.com:TrinityCore/TrinityCore into mmaps
Conflicts:
src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.cpp
Diffstat (limited to 'src/server/shared/Utilities/Util.cpp')
-rwxr-xr-x | src/server/shared/Utilities/Util.cpp | 44 |
1 files changed, 18 insertions, 26 deletions
diff --git a/src/server/shared/Utilities/Util.cpp b/src/server/shared/Utilities/Util.cpp index 89942b978df..9778e86d444 100755 --- a/src/server/shared/Utilities/Util.cpp +++ b/src/server/shared/Utilities/Util.cpp @@ -16,8 +16,8 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include <iostream> #include "Util.h" +#include "Common.h" #include "utf8.h" #include "SFMT.h" #include <ace/TSS_T.h> @@ -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,32 +471,24 @@ 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]); + sprintf(buffer, "%02X", bytes[i]); ss << buffer; } |