summaryrefslogtreecommitdiff
path: root/minion/src/util.cpp
blob: 15cf8408310aec959230115c092b3036ad0a5c53 (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
45
46
#include "util.hpp"

namespace util
{

auto str_ends_with(const char *str, const char *other_str) noexcept -> bool
{
	if (str == nullptr || other_str == nullptr)
	{
		return false;
	}

	auto str_length = strlen(str);
	auto other_str_length = strlen(other_str);

	if (other_str_length > str_length)
	{
		return false;
	}

	return strncmp(str + str_length - other_str_length, other_str, other_str_length) == 0;
}

void substr(const char *str, const char *end, char *dest) noexcept
{
	auto *dest_head = dest;

	for (const char *char_ptr = str; char_ptr != end; ++char_ptr)
	{
		*dest_head = *char_ptr;
		dest_head++;
	}
}

auto streq(const char *str_one, const char *str_two) noexcept -> bool
{
	return strcmp(str_one, str_two) == 0;
}

void quit() noexcept
{
	while (true)
		;
}

} // namespace util