2015-02-15 18:53:04 +03:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2005-2009 Anchorite (TeamX), <anchorite2001@yandex.ru>
|
2015-02-15 21:33:27 +03:00
|
|
|
* Copyright (c) 2014-2015 Nirran, phobos2077
|
|
|
|
|
* Copyright (c) 2015 alexeevdv <mail@alexeevdv.ru>
|
2015-02-15 18:53:04 +03:00
|
|
|
* Distributed under the GNU GPL v3. For full terms see the file license.txt
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// C++ standard includes
|
2015-02-16 00:30:55 +03:00
|
|
|
#include <stdio.h>
|
2015-02-15 18:53:04 +03:00
|
|
|
|
|
|
|
|
// int2ssl includes
|
2015-02-13 16:59:11 +03:00
|
|
|
#include "Utility.h"
|
|
|
|
|
|
2015-02-15 18:53:04 +03:00
|
|
|
// Third party includes
|
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;
|
|
|
|
|
}
|
2016-10-20 19:55:24 +07:00
|
|
|
|
|
|
|
|
std::string escape_str(std::string input)
|
|
|
|
|
{
|
|
|
|
|
std::string output;
|
|
|
|
|
output.reserve(input.length());
|
|
|
|
|
|
|
|
|
|
for (std::string::size_type i = 0; i < input.length(); ++i)
|
|
|
|
|
{
|
|
|
|
|
switch (input[i])
|
2018-05-22 20:49:45 +08:00
|
|
|
{
|
|
|
|
|
case '\n':
|
|
|
|
|
output += "\\n";
|
|
|
|
|
break;
|
2016-10-20 19:55:24 +07:00
|
|
|
|
2018-05-22 20:49:45 +08:00
|
|
|
case '\r':
|
|
|
|
|
output += "\\r";
|
|
|
|
|
break;
|
2016-10-20 19:55:24 +07:00
|
|
|
|
2018-05-22 20:49:45 +08:00
|
|
|
default:
|
|
|
|
|
output += input[i];
|
|
|
|
|
break;
|
2016-10-20 19:55:24 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return output;
|
|
|
|
|
}
|