summarylogtreecommitdiffstats
path: root/Txt.cpp
blob: 50d953d19abeba4e21317d2beedf5cf8ef97a4c1 (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
#include "./Txt.h"

int Txt::contains(std::string s, char c)
{
	for(int i = 0; i < s.size(); i++)
	{
		if(s[i] == c) return i;
	}

	return -1;
}

std::string Txt::substring(std::string s, int start, int end)
{
	std::string r = std::string();
	for(int c = start; c <= end; c++)
	{
		r += s[c];
	}
	return r;
}

std::string Txt::trimEnd(std::string s)
{
	std::string r = s;
	while(r.back() == ' ' || r.back() == '\t' || r.back() == '\n')
		r.pop_back();

	return r;
}

std::string Txt::trimFront(std::string s)
{
	std::string r = s;
	while(r[0] == ' ' || r[0] == '\t' || r[0] == '\n')
		r.erase(r.begin());

	return r;
}