summaryrefslogtreecommitdiff
path: root/minion/src/util.hpp
blob: 2955cf116a807b564ebcd49d382707673210f6e6 (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
47
48
49
#pragma once

#include <stddef.h>
#include <stdlib.h>
#include <string.h>

namespace util
{

template <typename Type>
auto malloc(size_t size) noexcept -> Type *
{
	return static_cast<Type *>(::malloc(size));
}

/**
 * Returns whether or not a string ends with the content of another string.
 *
 * @param target The string to compare the end of.
 * @param target_end The end position of the target string.
 * @param other The string to compare with.
 */
auto str_ends_with(const char *target, size_t target_end, const char *other) noexcept
	-> bool;

/**
 * Extracts a portion of a string.
 *
 * @param str The target string.
 * @param end A pointer to a place inside the target string.
 * @param dest Output buffer.
 */
void substr(const char *str, const char *end, char *dest) noexcept;

/**
 * Compares two strings.
 *
 * Wrapper function for strcmp.
 *
 * @param str_one The first string.
 * @param str_two The second string.
 *
 * @returns Whether or not the two strings contain the same content.
 */
auto streq(const char *str_one, const char *str_two) noexcept -> bool;

void quit() noexcept;

} // namespace util