Files
int2ssl/Utility.cpp
T
2015-02-15 18:53:04 +03:00

61 lines
1.6 KiB
C++

/**
*
* Copyright (c) 2005-2009 Anchorite (TeamX), <anchorite2001@yandex.ru>
* Copyright (c) 20014-2015 Nirran, phobos2077
* Copyright (c) 20015 alexeevdv <mail@alexeevdv.ru>
* Distributed under the GNU GPL v3. For full terms see the file license.txt
*
*/
// C++ standard includes
// int2ssl includes
#include "stdafx.h"
#include "Utility.h"
// Third party includes
uint32_t ReadMSBWord(CArchive& ar, uint16_t& wValue)
{
char* pBuffer = reinterpret_cast<char*>(&wValue);
return (ar.Read(pBuffer + 1, 1) + ar.Read(pBuffer, 1));
}
uint32_t ReadMSBULong(CArchive& ar, uint32_t& ulValue)
{
char* pBuffer = reinterpret_cast<char*>(&ulValue);
return (ar.Read(pBuffer + 3, 1) + ar.Read(pBuffer + 2, 1) +
ar.Read(pBuffer + 1, 1) + ar.Read(pBuffer, 1));
}
std::string format(std::string format, ...)
{
char buffer[1024]; // big enough for any string that will be formated
int size;
va_list args;
va_start( args, format );
size = vsprintf(buffer, format.c_str(), args);
return std::string(buffer, size);
}
std::string format(std::string format, std::string value)
{
char buffer[1024]; // big enough for any string that will be formated
int size;
size = sprintf(buffer, format.c_str(), value.c_str());
return std::string(buffer, size);
}
std::string replace(std::string subject, std::string search, std::string replacement)
{
size_t pos = 0;
while((pos = subject.find(search, pos)) != std::string::npos)
{
subject.replace(pos, search.length(), replacement);
pos += replacement.length();
}
return subject;
}