This repository was archived by the owner on Feb 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtokenizer_stream.hpp
More file actions
68 lines (56 loc) · 1.96 KB
/
Copy pathtokenizer_stream.hpp
File metadata and controls
68 lines (56 loc) · 1.96 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#pragma once
/**
* Copyright (C) 2020 Tristan. All Rights Reserved.
* This file is licensed under the BSD 2-Clause license.
* See the COPYING file for licensing information.
*/
#include <iosfwd>
#include "data/text/unicode.hpp"
#include "data/text/ustring.hpp"
namespace CSS {
class TokenizerStream {
public:
explicit
TokenizerStream(const Unicode::UString *string) noexcept;
// Returns how many code points there are left to be read.
// Assures that you can call Next this many times succesfully, or Peek
// with offset of `CodePointsLeft() - 1`.
[[nodiscard]] inline std::size_t
CodePointsLeft() const noexcept {
return string->length() - position;
}
// Consumes the character if possible.
// If destination is nullptr, it won't fail.
//
// Returns true if not at the end, otherwise false.
// If false is returned, destination and position are untouched.
[[nodiscard]] bool
Next(Unicode::CodePoint *destination) noexcept;
// Get a character without consuming it.
// If destination is nullptr, it won't fail.
//
// Returns true if not at the end, otherwise false.
// If false is returned, destination is untouched.
[[nodiscard]] bool
Peek(Unicode::CodePoint *destination, std::size_t offset = 0) const noexcept;
// Reconsume the previous code point. The next time Next/Peek is called,
// the previous code point will be returned (if the stream isn't at the
// end).
void
Reconsume() noexcept;
// Uses this string instead of the one passed by the constructor.
// Will set position to 0, of course.
void
SetString(const Unicode::UString *string) noexcept;
// Discards/skips the current character if possible.
// Effectively the same as: `Next(nullptr)`.
//
// Returns true if not at the end, otherwise false.
// If false is returned, destination and position are untouched.
/* discardable */ bool
Skip() noexcept;
private:
const Unicode::UString *string;
std::size_t position{ 0 };
};
} // namespace CSS