-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathskip.hh
38 lines (32 loc) · 987 Bytes
/
skip.hh
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
// Copyright (c) 2022 Mikael Simonsson <https://mikaelsimonsson.com>.
// SPDX-License-Identifier: BSL-1.0
// # Skip characters in front of range
#pragma once
#include "snn-core/array_view.hh"
#include "snn-core/chr/common.hh"
#include "snn-core/range/contiguous.hh"
namespace snn::ascii
{
// ## Functions
// ### skip
template <character Char>
[[nodiscard]] constexpr range::contiguous<Char*> skip(range::contiguous<Char*> rng) noexcept
{
static_assert(sizeof(u64) == 8);
while (rng.size() >= sizeof(u64))
{
const array_view<const char, sizeof(u64)> v{rng.begin(), promise::has_capacity};
const auto i = v.load<u64>();
if ((i & 0x8080808080808080u) == 0) // 0x80 == 0b1000'0000
{
rng.pop_front_n(sizeof(u64));
}
else
{
break;
}
}
rng.pop_front_while(chr::is_ascii);
return rng;
}
}