2012-05-29 07:19:50 +02:00
|
|
|
#include "string.hh"
|
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
|
|
|
String int_to_str(int value)
|
|
|
|
{
|
|
|
|
const bool negative = value < 0;
|
|
|
|
if (negative)
|
|
|
|
value = -value;
|
|
|
|
|
|
|
|
char buffer[16];
|
|
|
|
size_t pos = sizeof(buffer);
|
|
|
|
buffer[--pos] = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
buffer[--pos] = '0' + (value % 10);
|
|
|
|
value /= 10;
|
|
|
|
}
|
|
|
|
while (value);
|
|
|
|
|
|
|
|
if (negative)
|
|
|
|
buffer[--pos] = '-';
|
|
|
|
|
|
|
|
return String(buffer + pos);
|
|
|
|
}
|
|
|
|
|
2012-06-27 14:26:29 +02:00
|
|
|
int str_to_int(const String& str)
|
|
|
|
{
|
|
|
|
return atoi(str.c_str());
|
|
|
|
}
|
|
|
|
|
2012-10-01 20:20:08 +02:00
|
|
|
std::vector<String> split(const String& str, char separator)
|
2012-05-29 07:19:50 +02:00
|
|
|
{
|
|
|
|
auto begin = str.begin();
|
|
|
|
auto end = str.begin();
|
|
|
|
|
|
|
|
std::vector<String> res;
|
|
|
|
while (end != str.end())
|
|
|
|
{
|
|
|
|
while (end != str.end() and *end != separator)
|
|
|
|
++end;
|
|
|
|
res.push_back(String(begin, end));
|
|
|
|
if (end == str.end())
|
|
|
|
break;
|
|
|
|
begin = ++end;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2012-08-29 21:50:48 +02:00
|
|
|
String String::replace(const String& expression,
|
|
|
|
const String& replacement) const
|
|
|
|
{
|
2013-03-29 14:21:55 +01:00
|
|
|
boost::regex re(expression);
|
|
|
|
return String(boost::regex_replace(*this, re, replacement));
|
2012-08-29 21:50:48 +02:00
|
|
|
}
|
|
|
|
|
2012-05-29 07:19:50 +02:00
|
|
|
}
|