help.cpp 1.17 KB
Newer Older
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
45
46
47
48
49
50
51
52
53
54
55
#include <vector>
#include "libgweb/help.hpp"

namespace libgweb {
	int strlen(const char* instr) {
		int count = 0;
		while (instr[count] != '\0') {
			count++;
		}
		return count;
	}

	std::vector<char*> split(const char* instr, const char delim=' ') {
		char* strbuf;
		std::vector<char*> out;
		for (int i=0; i<strlen(instr); i++) {
			if (instr[i] == delim) {
				out.push_back(strbuf);
				strbuf = "";
			} else {
				strbuf += instr[i];
			}
		}
		return out;
	}

	//checks if str_a startswith str_b
	bool strstartswith(const char* str_a, const char* str_b) {
		if(libgweb::strlen(str_b) > libgweb::strlen(str_a)) {
			return false;
		} else {
			bool startswith = true;
			for(int i=0; i<libgweb::strlen(str_b); i++) {
				if(str_b[i] != str_a[i]) {
					startswith = false;
					break;
				}
			}

			return startswith;
		}
	}

	//returns a connected string of str_a and str_b
	char* strconnect(const char* str_a, const char* str_b) {
		char strbuf[sizeof(str_a) + sizeof(str_b)] = { ' ' };
		for(int i=0; i<libgweb::strlen(str_a); i++) {
			strbuf[i] = str_a[i];
		}
		for(int i=0; i<libgweb::strlen(str_b); i++) {
			strbuf[libgweb::strlen(str_a)+i] = str_b[i];
		}
		return strbuf;
	}
}