Core/Utilities: Do not expose internal store structure in Tokens and rename it to Tokenizer

This commit is contained in:
Spp
2012-10-02 11:54:41 +02:00
parent d44ec4b7da
commit f8846cdeaf
21 changed files with 187 additions and 269 deletions

View File

@@ -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)
{
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;
}
}
result = ss.str();
}
int32 init = 0;
int32 end = arrayLen;
int8 op = 1;
if (reverse)
{
init = arrayLen - 1;
end = -1;
op = -1;
}
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]);