-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathutilities.cpp
37 lines (34 loc) · 945 Bytes
/
utilities.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* Implementation of \ref utility functions
*/
#include "utilities.h"
using namespace std;
using namespace llvm;
/**
* Replace newline characters in a string
* @param str string to be modified
* @return modified string in which new line characters are removed
*/
string replace_newline(string str) {
size_t index = 0;
string search = "\\n";
while (true) {
/* Locate the substring to replace. */
index = str.find(search, index);
if (index == std::string::npos) break;
/* Make the replacement. */
str.erase(index, search.length());
str.insert(index, "\n");
/* Advance index forward so the next iteration doesn't pick it up as well. */
index += 1;
}
return str;
}
/**
* Report error to the stderr
* @param error_str name of the error to be reported
*/
llvm::Value *reportError(string error_str) {
cerr << error_str << endl;
return nullptr;
}