2013-06-04 19:50:16 -04:00
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
|
|
std::string intToString(int theInt) {
|
|
|
|
|
std::stringstream converter;
|
|
|
|
|
converter << theInt;
|
|
|
|
|
return converter.str();
|
2013-06-23 05:54:58 -04:00
|
|
|
}
|
2013-08-11 00:37:12 -04:00
|
|
|
|
2013-08-11 01:15:26 -04:00
|
|
|
std::string replaceExEscape(std::string first, std::string search, std::string replace) {
|
2013-08-11 00:37:12 -04:00
|
|
|
size_t pos = 0;
|
2013-12-22 01:34:59 -06:00
|
|
|
while (pos <= first.size()-search.size()) {
|
2013-08-11 00:37:12 -04:00
|
|
|
pos = first.find(search, pos);
|
|
|
|
|
if (pos == std::string::npos)
|
|
|
|
|
break;
|
|
|
|
|
//std::cout << "Position is " << pos << " size of first is " << first.size() << " size of replace is " << replace.size() << std::endl;
|
2013-08-11 01:15:26 -04:00
|
|
|
//If excaped, don't worry about it.
|
|
|
|
|
if (pos > 0) {
|
|
|
|
|
int numBackslashes = 0;
|
|
|
|
|
int countBack = 1;
|
|
|
|
|
while (pos-countBack >= 0 && first[pos-countBack] == '\\') {
|
|
|
|
|
numBackslashes++;
|
|
|
|
|
countBack++;
|
|
|
|
|
}
|
|
|
|
|
if (numBackslashes % 2 == 1) {
|
|
|
|
|
pos++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-08-11 00:37:12 -04:00
|
|
|
first = first.replace(pos, search.size(), replace);
|
2013-08-11 01:15:26 -04:00
|
|
|
pos += replace.size();
|
2013-08-11 00:37:12 -04:00
|
|
|
}
|
|
|
|
|
return first;
|
|
|
|
|
}
|
2013-12-19 10:39:36 -06:00
|
|
|
|
|
|
|
|
//String slicing is crazy useful. substr isn't bad, but slicing with negative indicies is wonderful
|
|
|
|
|
std::string strSlice(std::string str, int begin, int end) {
|
|
|
|
|
if (begin < 0)
|
|
|
|
|
begin += str.length()+1;
|
|
|
|
|
if (end < 0)
|
|
|
|
|
end += str.length()+1;
|
|
|
|
|
return str.substr(begin, end-begin);
|
|
|
|
|
}
|
2014-01-07 21:31:56 -05:00
|
|
|
|
|
|
|
|
int findPerenEnd(std::string str, int i) {
|
|
|
|
|
int numHangingOpen = 0;
|
|
|
|
|
for (; i< str.length(); i++) {
|
|
|
|
|
if (str[i] == '(')
|
|
|
|
|
numHangingOpen++;
|
|
|
|
|
else if (str[i] == ')')
|
|
|
|
|
numHangingOpen--;
|
|
|
|
|
if (numHangingOpen == 0)
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|