-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.cpp
40 lines (31 loc) · 850 Bytes
/
tools.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
#include "tools.h"
// find crlf in a c string
int find_crlf(const char *buf, int length) {
int offset = 0;
for (; offset < (length - 1); offset++)
if (buf[offset] == 0x0D && buf[offset + 1] == 0x0A)
return (offset + 2);
return 0;
}
std::string filter_nick(std::string host_mask) {
int pos;
if ((pos = host_mask.find('!')) > 0) {
return host_mask.substr(0, pos);
}
return "";
}
std::string filter_user(std::string host_mask) {
int pos1 = host_mask.find('!');
int pos2 = host_mask.find('@');
if (pos1 > 0 && pos2 > pos1) {
return host_mask.substr(pos1 + 1, pos2 - pos1 - 1);
}
return "";
}
std::string filter_host(std::string host_mask) {
int pos;
if ((pos = host_mask.find('@')) > 0) {
return host_mask.substr(pos + 1);
}
return "";
}