summaryrefslogtreecommitdiff
path: root/backend/stringmanip.h
blob: c5a32dc1398f8c3b760c3c7f93cf3a3607891a36 (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
#pragma once
#include <string.h>

void copyUntilStr(char* destination, char* source, const char* cmpstr) {
    int index = 0;
    char* ptr = source;
    int cmpStrLen = strlen(cmpstr);
    while (strncmp(ptr, cmpstr, cmpStrLen) != 0) {
        destination[index++] = *ptr;
        ptr++;
    }

    destination[index] = '\0';
}

int endsWith(const char *str, const char *suffix) {
  size_t str_len = strlen(str);
  size_t suffix_len = strlen(suffix);

  return (str_len >= suffix_len) &&
         (!memcmp(str + str_len - suffix_len, suffix, suffix_len));
}

void getCurrentDateStr(char* text) {
    time_t now = time(NULL);
    sprintf(text, "%s GMT", ctime(&now));
}