Files
int2ssl/Utility.cpp
T

48 lines
1.3 KiB
C++
Raw Normal View History

2015-02-13 16:59:11 +03:00
#include "stdafx.h"
#include "Utility.h"
2015-02-15 18:20:01 +03:00
uint32_t ReadMSBWord(CArchive& ar, uint16_t& wValue)
2015-02-13 16:59:11 +03:00
{
2015-02-13 22:31:52 +03:00
char* pBuffer = reinterpret_cast<char*>(&wValue);
2015-02-14 13:39:47 +03:00
return (ar.Read(pBuffer + 1, 1) + ar.Read(pBuffer, 1));
2015-02-13 16:59:11 +03:00
}
2015-02-15 18:20:01 +03:00
uint32_t ReadMSBULong(CArchive& ar, uint32_t& ulValue)
2015-02-13 16:59:11 +03:00
{
2015-02-13 22:31:52 +03:00
char* pBuffer = reinterpret_cast<char*>(&ulValue);
2015-02-14 13:39:47 +03:00
return (ar.Read(pBuffer + 3, 1) + ar.Read(pBuffer + 2, 1) +
ar.Read(pBuffer + 1, 1) + ar.Read(pBuffer, 1));
2015-02-13 16:59:11 +03:00
}
2015-02-15 16:16:45 +03:00
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;
}