-
Notifications
You must be signed in to change notification settings - Fork 4
/
boilerplate.h
43 lines (33 loc) · 866 Bytes
/
boilerplate.h
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
#pragma once
#include <stdbool.h>
#include <string.h>
#define array_size(x) (sizeof(x)/sizeof(x[0]))
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define NEW(type, count) (type*)malloc(sizeof(type)*(count))
#define DELETE(ptr) free(ptr)
inline bool strEqual(char const* a, char const* b) {
return strcmp(a,b)==0;
}
inline bool charEqualIgnoreCaseAssumeAscii(char a, char b) {
char const aa = a & 0xdf;
char const bb = b & 0xdf;
return (a==b) || ((aa == bb) && (aa >= 'A') && (aa <= 'Z'));
}
inline bool strEqualIgnoreCaseAssumeAscii(char const* a, char const* b) {
while (*a && *b) {
if (!charEqualIgnoreCaseAssumeAscii(*a, *b)) {
return false;
}
++a;
++b;
}
return *a == *b;
}
inline int alignToMultiple(int a, int divisor)
{
if (divisor <= 1)
return a;
if ((a % divisor) == 0)
return a;
return a + divisor - (a % divisor);
}