forked from blechschmidt/massdns
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstring.h
43 lines (39 loc) · 854 Bytes
/
string.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
#ifndef INC_STRING
#define INC_STRING
#include <stdbool.h>
#include <strings.h>
void strtolower(char *str)
{
while (*str != '\0')
{
if (*str >= 'A' && *str <= 'Z')
{
*str = (char) (*str | (1 << 5));
}
str++;
}
}
void trim_end(char* str)
{
while (0 != *str)
{
if(*str == ' ' || *str == '\n' || *str == '\t' || *str == '\r')
{
*str = 0;
return;
}
str++;
}
}
bool endswith(char* haystack, char* needle, bool case_sensitive)
{
int (*cmp)(const char*, const char*) = strcmp;
if(!case_sensitive)
{
cmp = strcasecmp;
}
size_t haystack_len = strlen(haystack);
size_t needle_len = strlen(needle);
return needle_len <= haystack_len && cmp(haystack + haystack_len - needle_len, needle) == 0;
}
#endif