blob: c96698d091f1deb0108e3d496464bf7b666ae5a9 (
plain) (
blame)
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
|
#pragma once
#include <library/cpp/yson_pull/position_info.h>
#include <cstddef>
namespace NYsonPull {
namespace NDetail {
template <bool EnableLinePositionInfo>
class stream_counter;
template <>
class stream_counter<true> {
private:
size_t offset_ = 0;
size_t line_ = 1;
size_t column_ = 1;
public:
TPositionInfo info() const {
return {offset_, line_, column_};
}
void update(const ui8* begin, const ui8* end) {
offset_ += end - begin;
for (auto current = begin; current != end; ++current) {
++column_;
if (*current == '\n') { //TODO: memchr
++line_;
column_ = 1;
}
}
}
};
template <>
class stream_counter<false> {
private:
size_t offset_ = 0;
public:
TPositionInfo info() const {
return {offset_, {}, {}};
}
void update(const ui8* begin, const ui8* end) {
offset_ += end - begin;
}
};
}
}
|