-
Notifications
You must be signed in to change notification settings - Fork 46
/
bark-util.h
30 lines (23 loc) · 704 Bytes
/
bark-util.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
#pragma once
#include <fstream>
#define BARK_ASSERT(x) \
do { \
if (!(x)) { \
fprintf(stderr, "BARK_ASSERT: %s:%d: %s\n", __FILE__, __LINE__, #x); \
abort(); \
} \
} while (0)
static const size_t MB = 4*1024*1024;
template<typename T>
static void read_safe(std::ifstream& fin, T& dest) {
fin.read((char*)& dest, sizeof(T));
}
template<typename T>
static void write_safe(std::ofstream& fout, T& dest) {
fout.write((char*)& dest, sizeof(T));
}
static size_t utf8_len(char src) {
const size_t lookup[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 3, 4};
uint8_t highbits = static_cast<uint8_t>(src) >> 4;
return lookup[highbits];
}