Blang/src/src/Utils.cpp

39 lines
692 B
C++

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <fstream>
#include <unistd.h>
#include <cstdlib>
#include <regex>
using namespace std;
string intToString(int i) {
string str;
char x;
int n=0;
while((x = (i >> (8*n)) & 0xff) != 0){
n++;
str.insert(0,1,x);
}
return str;
}
string replaceAll(std::string str, const std::string& from, const std::string& to) {
if(from.empty())
return str;
size_t start_pos = 0;
while((start_pos = str.find(from, start_pos)) != std::string::npos) {
str.replace(start_pos, from.length(), to);
start_pos += to.length();
}
return str;
}