-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathskip.hh
42 lines (36 loc) · 1022 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
39
40
41
42
// Copyright (c) 2022 Mikael Simonsson <https://mikaelsimonsson.com>.
// SPDX-License-Identifier: BSL-1.0
// # Skip valid bytes in front of range
#pragma once
#include "snn-core/ascii/skip.hh"
#include "snn-core/chr/common.hh"
#include "snn-core/range/contiguous.hh"
#include "snn-core/utf8/core.hh"
namespace snn::utf8
{
// ## Functions
// ### skip
template <character Char>
[[nodiscard]] constexpr snn::range::contiguous<Char*> skip(
snn::range::contiguous<Char*> rng) noexcept
{
while (rng)
{
const char c = rng.front(promise::not_empty);
if (chr::is_ascii(c))
{
rng = ascii::skip(rng);
}
else
{
const auto rng_before = rng;
const auto p = rng.pop_front_codepoint();
if (p.value == utf8::invalid)
{
return rng_before;
}
}
}
return rng;
}
}