aboutsummaryrefslogtreecommitdiff
path: root/frontend/strings.cpp
blob: bb4a419e3d58851146a2e4672213af25e18bdb8a (plain)
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
38
39
40
41
42
43
44
#include "strings.h"
#include "print.h"

using namespace std;

void print_string(const char * str) {
	lprtf("%s\n", wrap_string(str).c_str());
}

string wrap_string(const char * str) {
	string out;

	for (; *str != '\0'; str++) {
		if (str[0] == '\n') {
			if (str[1] == '\n') {
				out += "\n\n";
				str++;
			} else {
				out += " ";
			}
			continue;
		}

		out += *str;
	}

	return out;
}

vector<string> split_string(const string & src, const string & delim) {
	vector<string> out;
	size_t start = 0;
	size_t end = src.find(delim);

	while (end != string::npos) {
		out.push_back(src.substr(start, end - start));
		start = end + delim.length();
		end = src.find(delim, start);
	}
	out.push_back(src.substr(start));

	return out;
}