-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcommon.cpp
73 lines (60 loc) · 1.56 KB
/
common.cpp
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "common.h"
bool string_same_ignore_case(const char * one, const char * other) {
#ifdef WIN32
if(0 == _stricmp(one, other))
#else
if(0 == strcasecmp(one, other))
#endif
{
return true;
}
return false;
}
bool string_same_with_size(const char * one, const char * other, size_t length) {
if(0 == strncmp(one, other, length))
{
return true;
}
return false;
}
bool string_same_ignore_case_with_size(const char * one, const char * other, size_t length) {
#ifdef WIN32
if(0 == _strnicmp(one, other, length))
#else
if(0 == strncasecmp(one, other, length))
#endif
{
return true;
}
return false;
}
#ifdef _WIN32
#include <Ws2tcpip.h>
#include <mswsock.h>
#include <string.h> // _stricmp
double now() {
SYSTEMTIME system_time;
FILETIME file_time;
GetSystemTime(&system_time);
SystemTimeToFileTime(&system_time, &file_time);
ULARGE_INTEGER convert;
convert.LowPart = file_time.dwLowDateTime;
convert.HighPart = file_time.dwHighDateTime;
return (convert.QuadPart / 10000) / 1000.0;
}
#else // _WIN32
#include <sys/time.h>
#include <sys/stat.h>
#include <strings.h> // strcasecmp
double now() {
struct timeval time_destination;
gettimeofday(&time_destination, NULL);
return ((double) time_destination.tv_sec) + (time_destination.tv_usec / 1000000.0);
}
#endif // _WIN32
bool string_endswith(std::string & txt, std::string ending) {
if(txt.length() >= ending.length()) {
return (0 == txt.compare(txt.length() - ending.length(), ending.length(), ending));
}
return false;
}