From f8846cdeaf1b0f104a986f227ed407359b46110f Mon Sep 17 00:00:00 2001 From: Spp Date: Tue, 2 Oct 2012 11:54:41 +0200 Subject: Core/Utilities: Do not expose internal store structure in Tokens and rename it to Tokenizer --- src/server/shared/Utilities/Util.cpp | 40 +++++++++++++++--------------------- 1 file changed, 16 insertions(+), 24 deletions(-) (limited to 'src/server/shared/Utilities/Util.cpp') 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>((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]); -- cgit v1.2.3