trantor
Non-blocking I/O cross-platform TCP network library, using C++14
Toggle main menu visibility
Loading...
Searching...
No Matches
Funcs.h
1
14
15
#pragma once
16
#include <algorithm>
17
#include <vector>
18
#include <cstdint>
19
namespace
trantor
20
{
21
inline
uint64_t hton64(uint64_t n)
22
{
23
static
const
int
one = 1;
24
static
const
char
sig = *(
char
*)&one;
25
if
(sig == 0)
26
return
n;
// for big endian machine just return the input
27
char
*ptr =
reinterpret_cast<
char
*
>
(&n);
28
std::reverse(ptr, ptr +
sizeof
(uint64_t));
29
return
n;
30
}
31
inline
uint64_t ntoh64(uint64_t n)
32
{
33
return
hton64(n);
34
}
35
inline
std::vector<std::string> splitString(
const
std::string &s,
36
const
std::string &delimiter,
37
bool
acceptEmptyString =
false
)
38
{
39
if
(delimiter.empty())
40
return
std::vector<std::string>{};
41
std::vector<std::string> v;
42
size_t
last = 0;
43
size_t
next = 0;
44
while
((next = s.find(delimiter, last)) != std::string::npos)
45
{
46
if
(next > last || acceptEmptyString)
47
v.push_back(s.substr(last, next - last));
48
last = next + delimiter.length();
49
}
50
if
(s.length() > last || acceptEmptyString)
51
v.push_back(s.substr(last));
52
return
v;
53
}
54
}
// namespace trantor
trantor
Definition
EventLoop.h:34
trantor
utils
Funcs.h
Generated by
1.17.0